Skip to content

Commit be2db73

Browse files
committedDec 17, 2024
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 be2db73

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1843,9 +1843,10 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
18431843
rt->js_class_id_alloc = JS_CLASS_INIT_COUNT;
18441844

18451845
rt->stack_size = JS_DEFAULT_STACK_SIZE;
1846-
#ifdef __ASAN__
1847-
rt->stack_size *= 2; // stack frames are bigger under AddressSanitizer
1846+
#ifdef __wasi__
1847+
rt->stack_size = 0;
18481848
#endif
1849+
18491850
JS_UpdateStackTop(rt);
18501851

18511852
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)