mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Make js_get_stack_pointer more portable (#793)
By using code from LLVM.
3f79057338/clang/lib/Basic/Stack.cpp (L23-L38)
This commit is contained in:
parent
291eb9c5db
commit
0fb7f4e208
2 changed files with 15 additions and 5 deletions
4
cutils.h
4
cutils.h
|
@ -62,10 +62,6 @@ extern "C" {
|
||||||
# define __maybe_unused
|
# define __maybe_unused
|
||||||
# define __attribute__(x)
|
# define __attribute__(x)
|
||||||
# define __attribute(x)
|
# define __attribute(x)
|
||||||
# include <intrin.h>
|
|
||||||
static void *__builtin_frame_address(unsigned int level) {
|
|
||||||
return (void *)((char*)_AddressOfReturnAddress() - sizeof(int *) - level * sizeof(int *));
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
# define likely(x) __builtin_expect(!!(x), 1)
|
# define likely(x) __builtin_expect(!!(x), 1)
|
||||||
# define unlikely(x) __builtin_expect(!!(x), 0)
|
# define unlikely(x) __builtin_expect(!!(x), 0)
|
||||||
|
|
16
quickjs.c
16
quickjs.c
|
@ -33,6 +33,7 @@
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
#include <intrin.h>
|
||||||
#include <timezoneapi.h>
|
#include <timezoneapi.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -1774,10 +1775,23 @@ static int init_class_range(JSRuntime *rt, JSClassShortDef const *tab,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note: OS and CPU dependent */
|
/* Uses code from LLVM project. */
|
||||||
static inline uintptr_t js_get_stack_pointer(void)
|
static inline uintptr_t js_get_stack_pointer(void)
|
||||||
{
|
{
|
||||||
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
return (uintptr_t)__builtin_frame_address(0);
|
return (uintptr_t)__builtin_frame_address(0);
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
return (uintptr_t)_AddressOfReturnAddress();
|
||||||
|
#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)
|
static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)
|
||||||
|
|
Loading…
Reference in a new issue