Skip to content
Snippets Groups Projects
Commit 57cd96ef authored by rswindell's avatar rswindell
Browse files

Added -S option to set thread stack size limit (using newish

JS_SetThreadStackLimit API function), default is 32K bytes. This should
keep jsexec from crashing due to the ircd recursion bug. It'll log a JS
exception/error and exit (or loop) instead. Use "-S0" to set an unlimited
thread stack size.
parent 377818a5
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#define DEFAULT_LOG_MASK 0xff /* Display all LOG levels */ #define DEFAULT_LOG_MASK 0xff /* Display all LOG levels */
#define DEFAULT_ERR_LOG_LVL LOG_WARNING #define DEFAULT_ERR_LOG_LVL LOG_WARNING
#define DEFAULT_STACK_LIMIT (32*1024)
JSRuntime* js_runtime; JSRuntime* js_runtime;
JSContext* js_cx; JSContext* js_cx;
...@@ -55,6 +56,7 @@ js_branch_t branch; ...@@ -55,6 +56,7 @@ js_branch_t branch;
scfg_t scfg; scfg_t scfg;
ulong js_max_bytes=JAVASCRIPT_MAX_BYTES; ulong js_max_bytes=JAVASCRIPT_MAX_BYTES;
ulong js_cx_stack=JAVASCRIPT_CONTEXT_STACK; ulong js_cx_stack=JAVASCRIPT_CONTEXT_STACK;
ulong stack_limit=DEFAULT_STACK_LIMIT;
FILE* confp; FILE* confp;
FILE* errfp; FILE* errfp;
FILE* nulfp; FILE* nulfp;
...@@ -94,6 +96,7 @@ void usage(FILE* fp) ...@@ -94,6 +96,7 @@ void usage(FILE* fp)
#endif #endif
"\t-m<bytes> set maximum heap size (default=%u bytes)\n" "\t-m<bytes> set maximum heap size (default=%u bytes)\n"
"\t-s<bytes> set context stack size (default=%u bytes)\n" "\t-s<bytes> set context stack size (default=%u bytes)\n"
"\t-S<bytes> set thread stack size limit (default=%u, 0=unlimited)\n"
"\t-b<limit> set branch limit (default=%u, 0=unlimited)\n" "\t-b<limit> set branch limit (default=%u, 0=unlimited)\n"
"\t-y<interval> set yield interval (default=%u, 0=never)\n" "\t-y<interval> set yield interval (default=%u, 0=never)\n"
"\t-g<interval> set garbage collection interval (default=%u, 0=never)\n" "\t-g<interval> set garbage collection interval (default=%u, 0=never)\n"
...@@ -112,6 +115,7 @@ void usage(FILE* fp) ...@@ -112,6 +115,7 @@ void usage(FILE* fp)
"\t-! wait for keypress (pause) on error\n" "\t-! wait for keypress (pause) on error\n"
,JAVASCRIPT_MAX_BYTES ,JAVASCRIPT_MAX_BYTES
,JAVASCRIPT_CONTEXT_STACK ,JAVASCRIPT_CONTEXT_STACK
,DEFAULT_STACK_LIMIT
,JAVASCRIPT_BRANCH_LIMIT ,JAVASCRIPT_BRANCH_LIMIT
,JAVASCRIPT_YIELD_INTERVAL ,JAVASCRIPT_YIELD_INTERVAL
,JAVASCRIPT_GC_INTERVAL ,JAVASCRIPT_GC_INTERVAL
...@@ -585,6 +589,7 @@ static const char* js_ext(const char* fname) ...@@ -585,6 +589,7 @@ static const char* js_ext(const char* fname)
long js_exec(const char *fname, char** args) long js_exec(const char *fname, char** args)
{ {
ulong stack_frame;
int argc=0; int argc=0;
uint line_no; uint line_no;
char path[MAX_PATH+1]; char path[MAX_PATH+1];
...@@ -622,6 +627,14 @@ long js_exec(const char *fname, char** args) ...@@ -622,6 +627,14 @@ long js_exec(const char *fname, char** args)
} }
JS_ClearPendingException(js_cx); JS_ClearPendingException(js_cx);
if(stack_limit) {
#if JS_STACK_GROWTH_DIRECTION > 0
stack_frame=((ulong)&stack_frame)+stack_limit;
#else
stack_frame=((ulong)&stack_frame)-stack_limit;
#endif
JS_SetThreadStackLimit(js_cx, stack_frame);
}
argv=JS_NewArrayObject(js_cx, 0, NULL); argv=JS_NewArrayObject(js_cx, 0, NULL);
JS_DefineProperty(js_cx, js_glob, "argv", OBJECT_TO_JSVAL(argv) JS_DefineProperty(js_cx, js_glob, "argv", OBJECT_TO_JSVAL(argv)
...@@ -790,6 +803,10 @@ int main(int argc, char **argv, char** environ) ...@@ -790,6 +803,10 @@ int main(int argc, char **argv, char** environ)
if(*p==0) p=argv[++argn]; if(*p==0) p=argv[++argn];
js_cx_stack=strtoul(p,NULL,0); js_cx_stack=strtoul(p,NULL,0);
break; break;
case 'S':
if(*p==0) p=argv[++argn];
stack_limit=strtoul(p,NULL,0);
break;
case 'b': case 'b':
if(*p==0) p=argv[++argn]; if(*p==0) p=argv[++argn];
branch.limit=strtoul(p,NULL,0); branch.limit=strtoul(p,NULL,0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment