Browse Source

Also need fatal handler on the heap

Bradley Ouellette 4 years ago
parent
commit
f4c3ca9507
1 changed files with 11 additions and 1 deletions
  1. 11 1
      oboo-clock-cards/src/oboo-runtime/runtime.c

+ 11 - 1
oboo-clock-cards/src/oboo-runtime/runtime.c

@@ -31,6 +31,16 @@ struct callbacks {
 struct callbacksq q;
 TAILQ_HEAD(callbacksq, callbacks);
 
+static void duktape_fatal_handler(void *udata, const char *msg) {
+  (void) udata;  /* ignored in this case, silence warning */
+    /* Note that 'msg' may be NULL. */
+  fprintf(stderr, "*** FATAL ERROR: %s\n", msg ? msg : "no message");
+  fprintf(stderr, "Causing intentional segfault...\n");
+  fflush(stderr);
+  *((volatile unsigned int *) 0) = (unsigned int) 0xdeadbeefUL;
+  abort();
+}
+
 void initRuntime() {
   int status = 0;
   time_t t;
@@ -39,7 +49,7 @@ void initRuntime() {
   srand((unsigned) time(&t));
 
   /* Init Duktape */
-  ctx = duk_create_heap_default();
+  ctx = duk_create_heap(NULL, NULL, NULL, NULL, duktape_fatal_handler);
 
   /* Init Module Loader */
   // TODO: implement module search function