Skip to content

Commit

Permalink
SctackBoundsTest.cpp: fix compilation error on Windows
Browse files Browse the repository at this point in the history
Summary:
MSVC doesn't support __builtin_frame_address(), which breaks
compilation. Technically, we don't have support for stack-checking on
Windows at all, but at least we should be able to compile this test and
it should just start working automatically when we do add support.

Differential Revision: D65375190
  • Loading branch information
Tzvetan Mikov authored and facebook-github-bot committed Nov 2, 2024
1 parent c98b00e commit c2374b8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions unittests/Support/StackBoundsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,25 @@ bool isStackOverflowingSlowPath() {
auto [highPtr, size] = oscompat::thread_stack_bounds(nativeStackGap);
nativeStackHigh = (const char *)highPtr;
nativeStackSize = size;
#ifdef __GNUC__
void *sp = __builtin_frame_address(0);
#else
volatile char *var = 0;
void *sp = (void *)&var;
#endif
return (uintptr_t)nativeStackHigh - (uintptr_t)sp > nativeStackSize;
}

/// \return true if the native stack is overflowing the bounds of the
/// current thread. Updates the stack bounds if the thread which Runtime
/// is executing on changes.
inline bool isOverflowing() {
#ifdef __GNUC__
void *sp = __builtin_frame_address(0);
#else
volatile char *var = 0;
void *sp = (void *)&var;
#endif
// Check for overflow by subtracting the sp from the high pointer.
// If the sp is outside the valid stack range, the difference will
// be greater than the known stack size.
Expand Down Expand Up @@ -118,6 +128,8 @@ TEST(StackBoundsTest, unboundRecursion_thread) {
}

#if !defined(_WINDOWS) && !defined(__EMSCRIPTEN__)
// Windows/EMSCRIPTEN don't support pthreads well.

void runInThreadWith64KGuard(void *(threadFunc)(void *)) {
pthread_t thread;
pthread_attr_t attr;
Expand Down

0 comments on commit c2374b8

Please sign in to comment.