Skip to content

Commit

Permalink
Outline StackOverflowGuard::isStackOverflowingSlowPath
Browse files Browse the repository at this point in the history
Summary: The slowpath should be defined out of line.

Reviewed By: avp

Differential Revision: D66546965

fbshipit-source-id: 218d907cd8259bbdf4772ff2f000ea87afb6d5e7
  • Loading branch information
fbmal7 authored and facebook-github-bot committed Dec 2, 2024
1 parent b275bde commit 68529da
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
15 changes: 4 additions & 11 deletions include/hermes/Support/StackOverflowGuard.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#ifndef HERMES_SUPPORT_STACKOVERFLOWGUARD_H
#define HERMES_SUPPORT_STACKOVERFLOWGUARD_H

#include <cstddef>
#include "hermes/Support/OSCompat.h"
#include "llvh/Support/Compiler.h"
#include "llvh/Support/raw_ostream.h"

#include <cstddef>
#include <cstdint>

namespace hermes {

Expand Down Expand Up @@ -91,14 +91,7 @@ class StackOverflowGuard {
/// Sets \c stackLow_ \c stackHigh_.
/// \return true if the native stack is overflowing the bounds of the
/// current thread.
bool isStackOverflowingSlowPath() {
auto [highPtr, size] = oscompat::thread_stack_bounds(nativeStackGap);
nativeStackHigh = (const char *)highPtr;
nativeStackSize = size;
return LLVM_UNLIKELY(
(uintptr_t)nativeStackHigh - (uintptr_t)__builtin_frame_address(0) >
nativeStackSize);
}
bool isStackOverflowingSlowPath();
};

#else
Expand Down
1 change: 1 addition & 0 deletions lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_hermes_library(hermesSupport
SemaphorePosix.cpp
SerialExecutor.cpp
StackExecutor.cpp
StackOverflowGuard.cpp
SHA1.cpp
SNPrintfBuf.cpp
SourceErrorManager.cpp
Expand Down
26 changes: 26 additions & 0 deletions lib/Support/StackOverflowGuard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "hermes/Support/StackOverflowGuard.h"
#include "hermes/Support/OSCompat.h"

namespace hermes {

#ifdef HERMES_CHECK_NATIVE_STACK

bool StackOverflowGuard::isStackOverflowingSlowPath() {
auto [highPtr, size] = oscompat::thread_stack_bounds(nativeStackGap);
nativeStackHigh = (const char *)highPtr;
nativeStackSize = size;
return LLVM_UNLIKELY(
(uintptr_t)nativeStackHigh - (uintptr_t)__builtin_frame_address(0) >
nativeStackSize);
}

#endif

} // namespace hermes

0 comments on commit 68529da

Please sign in to comment.