Skip to content

Commit beb1b15

Browse files
committed
Use 1 MB as the default stack size
In addition: - Move the WASI override to quickjs.c - Allow it to be user defined Ref: #749 (comment)
1 parent 374915a commit beb1b15

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

quickjs-libc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3636,7 +3636,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValue new_target,
36363636
/* no join at the end */
36373637
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
36383638
// musl libc gives threads 80 kb stacks, much smaller than
3639-
// JS_DEFAULT_STACK_SIZE (256 kb)
3639+
// JS_DEFAULT_STACK_SIZE (1 MB)
36403640
pthread_attr_setstacksize(&attr, 2 << 20); // 2 MB, glibc default
36413641
ret = pthread_create(&tid, &attr, worker_func, args);
36423642
pthread_attr_destroy(&attr);

quickjs.c

+4
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,10 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
18461846
#ifdef __ASAN__
18471847
rt->stack_size *= 2; // stack frames are bigger under AddressSanitizer
18481848
#endif
1849+
#ifdef __wasi__
1850+
rt->stack_size = 0;
1851+
#endif
1852+
18491853
JS_UpdateStackTop(rt);
18501854

18511855
rt->current_exception = JS_UNINITIALIZED;

quickjs.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,8 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
280280
#define JS_PROP_DEFINE_PROPERTY (1 << 18) /* internal use */
281281
#define JS_PROP_REFLECT_DEFINE_PROPERTY (1 << 19) /* internal use */
282282

283-
#if defined(__wasi__)
284-
#define JS_DEFAULT_STACK_SIZE 0
285-
#else
286-
#define JS_DEFAULT_STACK_SIZE (256 * 1024)
283+
#ifndef JS_DEFAULT_STACK_SIZE
284+
#define JS_DEFAULT_STACK_SIZE (1024 * 1024)
287285
#endif
288286

289287
/* JS_Eval() flags */

run-test262.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static JSValue js_evalScript_262(JSContext *ctx, JSValue this_val,
515515
static void start_thread(js_thread_t *thrd, void *(*start)(void *), void *arg)
516516
{
517517
// musl libc gives threads 80 kb stacks, much smaller than
518-
// JS_DEFAULT_STACK_SIZE (256 kb)
518+
// JS_DEFAULT_STACK_SIZE (1 MB)
519519
static const unsigned stacksize = 2 << 20; // 2 MB, glibc default
520520
#ifdef _WIN32
521521
HANDLE h, cp;

0 commit comments

Comments
 (0)