casaroli commented on code in PR #3859:
URL: https://github.com/apache/nuttx-apps/pull/3859#discussion_r4469888951


##########
interpreters/duktape/duk_cmdline.patch:
##########
@@ -2,17 +2,55 @@ diff --color -ur duktape/examples/cmdline/duk_cmdline.c 
duktape-2.5.0-modifed/ex
 --- duktape/examples/cmdline/duk_cmdline.c     2019-11-25 06:04:27.000000000 
+0800
 +++ duktape-2.5.0-modifed/examples/cmdline/duk_cmdline.c       2020-08-07 
23:20:27.320000000 +0800
 @@ -103,7 +103,7 @@
+ 
  #define  MEM_LIMIT_NORMAL   (128*1024*1024)   /* 128 MB */
  #define  MEM_LIMIT_HIGH     (2047*1024*1024)  /* ~2 GB */
 -#define  LINEBUF_SIZE       65536
 +#define  LINEBUF_SIZE       256
  
  static int main_argc = 0;
  static char **main_argv = NULL;
-
-@@ -810,10 +810,12 @@
+@@ -167,14 +167,28 @@ static void set_resource_limits(rlim_t m
+ #endif  /* DUK_CMDLINE_RLIMIT */
+ 
+ #if defined(DUK_CMDLINE_SIGNAL)
++#include <signal.h>
++
++static volatile sig_atomic_t g_interrupted = 0;
++
++duk_bool_t duk_cmdline_timeout_check(void *udata) {
++      (void) udata;
++      return g_interrupted;

Review Comment:
   `set_sigint_handler()` runs before `create_duktape_heap()`. A Ctrl+C in that 
time sets `g_interrupted`, and the first bytecode of the unprotected 
`duk_eval_string()` in `create_duktape_heap()` throws: `*** FATAL ERROR: 
uncaught: 'execution timeout'`, then `cmdline_fatal_handler()` writes to 
address 0 and the board panics. On qemu-armv8a:nsh (TCG) with Ctrl+C 1 to 12 ms 
after the command, 39 of 42 runs panic; without this PR, 2 to 3 of 42.
   
   Fix: return `g_heap_ready && g_interrupted` in 
`duk_cmdline_timeout_check()`, and set `g_heap_ready = 1` in `main()` after 
`create_duktape_heap()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to