Skip to content

Commit a5b9e54

Browse files
authored
Re-enable stack depth checks under ASan (bellard#161)
The default 256 kb stack is too small to run some of the test262 tests when ASAN is enabled. Double it to 512 kb and ensure threads created by quickjs have big enough stacks.
1 parent 0745c3a commit a5b9e54

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

quickjs-libc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,6 +3409,9 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValueConst new_target,
34093409
pthread_attr_init(&attr);
34103410
/* no join at the end */
34113411
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
3412+
// musl libc gives threads 80 kb stacks, much smaller than
3413+
// JS_DEFAULT_STACK_SIZE (256 kb)
3414+
pthread_attr_setstacksize(&attr, 2 << 20); // 2 MB, glibc default
34123415
ret = pthread_create(&tid, &attr, worker_func, args);
34133416
pthread_attr_destroy(&attr);
34143417
if (ret != 0) {

quickjs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#define CONFIG_PRINTF_RNDN
6868
#endif
6969

70-
#if !defined(EMSCRIPTEN) && !defined(__ASAN__)
70+
#if !defined(EMSCRIPTEN)
7171
/* enable stack limitation */
7272
#define CONFIG_STACK_CHECK
7373
#endif
@@ -1635,6 +1635,9 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
16351635
rt->js_class_id_alloc = JS_CLASS_INIT_COUNT;
16361636

16371637
rt->stack_size = JS_DEFAULT_STACK_SIZE;
1638+
#ifdef __ASAN__
1639+
rt->stack_size *= 2; // stack frames are bigger under AddressSanitizer
1640+
#endif
16381641
JS_UpdateStackTop(rt);
16391642

16401643
rt->current_exception = JS_NULL;

run-test262.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ static JSValue js_agent_start(JSContext *ctx, JSValue this_val,
531531
{
532532
const char *script;
533533
Test262Agent *agent;
534+
pthread_attr_t attr;
534535

535536
if (JS_GetContextOpaque(ctx) != NULL)
536537
return JS_ThrowTypeError(ctx, "cannot be called inside an agent");
@@ -545,7 +546,12 @@ static JSValue js_agent_start(JSContext *ctx, JSValue this_val,
545546
agent->script = strdup(script);
546547
JS_FreeCString(ctx, script);
547548
list_add_tail(&agent->link, &agent_list);
548-
pthread_create(&agent->tid, NULL, agent_start, agent);
549+
pthread_attr_init(&attr);
550+
// musl libc gives threads 80 kb stacks, much smaller than
551+
// JS_DEFAULT_STACK_SIZE (256 kb)
552+
pthread_attr_setstacksize(&attr, 2 << 20); // 2 MB, glibc default
553+
pthread_create(&agent->tid, &attr, agent_start, agent);
554+
pthread_attr_destroy(&attr);
549555
return JS_UNDEFINED;
550556
}
551557

0 commit comments

Comments
 (0)