Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify disabling stack checks on WASI and ASAN #637

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,17 @@ static int init_class_range(JSRuntime *rt, JSClassShortDef const *tab,
return 0;
}

#if defined(__wasi__) || defined(__ASAN__)
static inline uintptr_t js_get_stack_pointer(void)
{
return 0;
}

static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
{
return FALSE;
}
#else
/* Note: OS and CPU dependent */
static inline uintptr_t js_get_stack_pointer(void)
{
Expand All @@ -1750,6 +1761,7 @@ static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
sp = js_get_stack_pointer() - alloca_size;
return unlikely(sp < rt->stack_limit);
}
#endif

JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
{
Expand Down Expand Up @@ -1807,9 +1819,6 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
rt->js_class_id_alloc = JS_CLASS_INIT_COUNT;

rt->stack_size = JS_DEFAULT_STACK_SIZE;
#ifdef __ASAN__
rt->stack_size *= 2; // stack frames are bigger under AddressSanitizer
#endif
JS_UpdateStackTop(rt);

rt->current_exception = JS_UNINITIALIZED;
Expand Down Expand Up @@ -2478,15 +2487,11 @@ JSRuntime *JS_GetRuntime(JSContext *ctx)

static void update_stack_limit(JSRuntime *rt)
{
#if defined(__wasi__) || (defined(__ASAN__) && !defined(NDEBUG))
rt->stack_limit = 0; /* no limit */
#else
if (rt->stack_size == 0) {
rt->stack_limit = 0; /* no limit */
} else {
rt->stack_limit = rt->stack_top - rt->stack_size;
}
#endif
}

void JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size)
Expand Down
Loading