Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13
Use sigsetjmp/siglongjmp instead of setjmp/longjmp#686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
6c453ea7b547793c643bf36151d7b91473875d514dd2773a4adad10327a559cb4a0284File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -58,12 +58,12 @@ class ProfiledThread : public ThreadLocalData { | ||
| static void freeValue(void* value); | ||
| static ThreadLocal<ProfiledThread*, nullptr, freeValue> _current_thread; | ||
| // longjmp buffer. Used by hotspot only at this moment. | ||
| // siglongjmp buffer. Used by hotspot only at this moment. | ||
| // Published in walkVM() and consumed in checkFault() from an asynchronous | ||
| // SEGV-handler context on the same thread; atomic makes the publish/observe | ||
| // ordering explicit instead of relying on plain load/store, matching how | ||
| // _crash_depth is hardened below. | ||
| std::atomic<jmp_buf*> _jmp_buf; | ||
| std::atomic<sigjmp_buf*> _jmp_buf; | ||
| u64 _pc; | ||
| u64 _sp; | ||
| @@ -238,11 +238,11 @@ class ProfiledThread : public ThreadLocalData { | ||
| return __atomic_load_n(&_crash_depth, __ATOMIC_RELAXED) > CRASH_HANDLER_NESTING_LIMIT; | ||
| } | ||
| inline void setJmpCtx(jmp_buf* buf) { | ||
| _jmp_buf = buf; | ||
| inline void setJmpCtx(sigjmp_buf* buf) { | ||
| _jmp_buf = buf; | ||
| } | ||
Copilot marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| inline jmp_buf* getJmpCtx() const { | ||
| inline sigjmp_buf* getJmpCtx() const { | ||
zhengyu123 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return _jmp_buf; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -51,7 +51,7 @@ TEST(FaultInjectionTest, DisabledValueMacrosAreIdentity) { | ||
| #else // __FAULT_INJECTION__ enabled (built under -PenableFaultInjection) | ||
| // Chain: safefetch recovery first, then walkVM setjmp/longjmp recovery, then | ||
| // Chain: safefetch recovery first, then walkVM sigsetjmp/siglongjmp recovery, then | ||
| // the crash handler as a last resort so a genuine bug still produces a report. | ||
| static void (*orig_segvHandler)(int, siginfo_t*, void*); | ||
| static void (*orig_busHandler)(int, siginfo_t*, void*); | ||
| @@ -60,7 +60,7 @@ static void fi_signal_wrapper(int signo, siginfo_t* siginfo, void* context) { | ||
| if (SafeAccess::handle_safefetch(signo, context)) { | ||
| return; // safefetch load recovered; PC already rewritten to _cont. | ||
| } | ||
| HotspotSupport::checkFault(ProfiledThread::current()); // longjmp if protected | ||
| HotspotSupport::checkFault(ProfiledThread::current()); // siglongjmp if protected | ||
| // Not protected and not a safefetch fault — real crash. | ||
| if (signo == SIGBUS && orig_busHandler != nullptr) { | ||
| orig_busHandler(signo, siginfo, context); | ||
| @@ -144,8 +144,8 @@ TEST_F(FaultInjectionTest, SafeAccessRecoversFromInjectedFault) { | ||
| } | ||
| // (c2) walkVM path: a raw dereference of an injected poison pointer must be | ||
| // caught by the setjmp/longjmp crash protection, returning control to setjmp. | ||
| TEST_F(FaultInjectionTest, WalkVmSetjmpRecoversFromInjectedFault) { | ||
| // caught by the sigsetjmp/siglongjmp crash protection, returning control to sigsetjmp. | ||
| TEST_F(FaultInjectionTest, WalkVmSigsetjmpRecoversFromInjectedFault) { | ||
| ProfiledThread* t = ProfiledThread::current(); | ||
| ASSERT_NE(t, nullptr); | ||
| @@ -155,9 +155,9 @@ TEST_F(FaultInjectionTest, WalkVmSetjmpRecoversFromInjectedFault) { | ||
| volatile size_t reads = 0; | ||
| volatile size_t faults = 0; | ||
| jmp_buf ctx; | ||
| if (setjmp(ctx) != 0) { | ||
| recovered = true; // returned here via checkFault -> longjmp | ||
| sigjmp_buf ctx; | ||
| if (sigsetjmp(ctx, 1) != 0) { | ||
| recovered = true; // returned here via checkFault -> siglongjmp | ||
zhengyu123 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| faults++; | ||
| } | ||
| t->setJmpCtx(&ctx); | ||
| @@ -174,8 +174,8 @@ TEST_F(FaultInjectionTest, WalkVmSetjmpRecoversFromInjectedFault) { | ||
| // We should have observed a recovered fault, or the loop completed cleanly. The | ||
| // essential assertion is that the process did not die and, when a fault was | ||
| // injected, setjmp regained control. | ||
| EXPECT_GT(faults, 0u) << "expected at least one injected fault to longjmp-recover"; | ||
| // injected, sigsetjmp regained control. | ||
| EXPECT_GT(faults, 0u) << "expected at least one injected fault to siglongjmp-recover"; | ||
| EXPECT_TRUE(recovered); | ||
| SUCCEED(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.