Skip to content

Commit 0fb7f4e

Browse files
authored
1 parent 291eb9c commit 0fb7f4e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cutils.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ extern "C" {
6262
# define __maybe_unused
6363
# define __attribute__(x)
6464
# define __attribute(x)
65-
# include <intrin.h>
66-
static void *__builtin_frame_address(unsigned int level) {
67-
return (void *)((char*)_AddressOfReturnAddress() - sizeof(int *) - level * sizeof(int *));
68-
}
6965
#else
7066
# define likely(x) __builtin_expect(!!(x), 1)
7167
# define unlikely(x) __builtin_expect(!!(x), 0)

quickjs.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#if !defined(_MSC_VER)
3434
#include <sys/time.h>
3535
#if defined(_WIN32)
36+
#include <intrin.h>
3637
#include <timezoneapi.h>
3738
#endif
3839
#endif
@@ -1774,10 +1775,23 @@ static int init_class_range(JSRuntime *rt, JSClassShortDef const *tab,
17741775
return 0;
17751776
}
17761777

1777-
/* Note: OS and CPU dependent */
1778+
/* Uses code from LLVM project. */
17781779
static inline uintptr_t js_get_stack_pointer(void)
17791780
{
1781+
#if defined(__clang__) || defined(__GNUC__)
17801782
return (uintptr_t)__builtin_frame_address(0);
1783+
#elif defined(_MSC_VER)
1784+
return (uintptr_t)_AddressOfReturnAddress();
1785+
#else
1786+
char CharOnStack = 0;
1787+
// The volatile store here is intended to escape the local variable, to
1788+
// prevent the compiler from optimizing CharOnStack into anything other
1789+
// than a char on the stack.
1790+
//
1791+
// Tested on: MSVC 2015 - 2019, GCC 4.9 - 9, Clang 3.2 - 9, ICC 13 - 19.
1792+
char *volatile Ptr = &CharOnStack;
1793+
return (uintptr_t) Ptr;
1794+
#endif
17811795
}
17821796

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

0 commit comments

Comments
 (0)