Skip to content
New issue

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

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

Already on GitHub? # to your account

Make js_get_stack_pointer more portable #793

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion quickjs.c
Original file line number Diff line number Diff line change
@@ -1774,10 +1774,25 @@ static int init_class_range(JSRuntime *rt, JSClassShortDef const *tab,
return 0;
}

/* Note: OS and CPU dependent */
/* Uses code from LLVM project. */
static inline uintptr_t js_get_stack_pointer(void)
{
#ifdef _MSC_VER
return (uintptr_t)_AddressOfReturnAddress();
#elif defined(__has_builtin) && __has_builtin(__builtin_frame_address)
return (uintptr_t)__builtin_frame_address(0);
#elif defined(__GNUC__)
return (uintptr_t)__builtin_frame_address(0);
#else
char CharOnStack = 0;
// The volatile store here is intended to escape the local variable, to
// prevent the compiler from optimizing CharOnStack into anything other
// than a char on the stack.
//
// Tested on: MSVC 2015 - 2019, GCC 4.9 - 9, Clang 3.2 - 9, ICC 13 - 19.
char *volatile Ptr = &CharOnStack;
return (uintptr_t) Ptr;
#endif
}

static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)