Repository navigation
pass a fault outside Scheme code to the previously installed handler - #1076
Merged
Merged
Conversation
When Chez Scheme is embedded in a process that handles SIGSEGV/SIGBUS itself (.NET and Java runtimes turn a null dereference into an exception that way), Sscheme_init replaces the host's handler: a fault in host code then reaches handle_signal, which aborts with "nonrecoverable invalid memory reference" although no Scheme code was involved. Keep the handlers that init_signal_handlers replaces for SIGSEGV, SIGBUS, SIGFPE and SIGILL, and pass such a signal to the saved handler when the thread has no context or its context is deactivated. Sscheme_deinit puts the saved handlers back, so a fault after it reaches the host, and a later Sscheme_init saves them afresh. Without a saved handler, or in Scheme code, nothing changes.
This was referenced Oct 8, 2026
Contributor
|
I will look at this more, but I think it's probably a good idea. |
burinc
pushed a commit
to burinc/jolt
that referenced
this pull request
Oct 9, 2026
Sscheme_init takes SIGSEGV/SIGBUS/SIGFPE/SIGILL for the whole process, so a host that handles those itself (.NET, the JVM) aborted with "invalid memory reference" on a null dereference in its own code once a jolt library was loaded. The library stub now saves the host's handlers before init, puts a handler in front of Chez's that sends a fault to the host's when the thread has no Chez context or is the released init thread, and gives the signals back at shutdown. A fault in jolt code on other threads is still a jolt exception. This stands in for cisco/ChezScheme#1076, which checks the context's active flag directly; jolt can't see that flag, so a fault in jolt code while the released init thread is inside an export goes to the host. The signals driver now also checks a fault in Scheme code and a host fault on a worker thread that called an export, and the smoke step fails instead of reporting. Fixes jolt-lang#1277
mflatt
approved these changes
Oct 9, 2026
Contributor
|
Should |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When Chez Scheme is embedded in a process that already handles SIGSEGV or
SIGBUS,
Sscheme_initreplaces that handler. .NET and Java runtimes workthis way: they turn a null dereference in their own code into an exception
from a signal handler. Once Chez Scheme is initialized, a fault like that on
one of the host's threads reaches
handle_signal, which finds no threadcontext and aborts with "nonrecoverable invalid memory reference", even
though no Scheme code was running.
This keeps the handlers that
init_signal_handlersreplaces for SIGSEGV,SIGBUS, SIGFPE and SIGILL. When one of those signals arrives on a thread
that has no context, or whose context is deactivated (in a
__collect_safecall or after
Sdeactivate_thread), it goes to the saved handler instead. Ifthere was no saved handler (
SIG_DFLorSIG_IGN), or the fault happenswhile the thread is running Scheme code, behavior is unchanged.
Sscheme_deinitputs the saved handlers back, since the signals belong tothe host again once Chez Scheme is gone, and a later
Sscheme_initsavesthem afresh.
I tested it with a small C program that installs a SIGSEGV/SIGBUS handler,
then calls
Sscheme_init, and dereferences NULL in a few situations(macOS arm64, tarm64osx):
Sdeactivate_threadSscheme_deinit,Sscheme_init, then fault on a new pthreadSscheme_deinit, then fault on the main thread(foreign-ref 'int 0 0)in Scheme codemake test-onepasses. I can add the C program to the PR if that's useful,though I didn't see an existing place in
matsfor tests that need to ownmain.Some things this doesn't do:
sa_maskand flags suchas
SA_ONSTACKandSA_RESETHANDaren't applied. In particular, a stackoverflow in host code still can't be handled, since Chez Scheme's handler
isn't installed with
SA_ONSTACK.fault inside that C code now goes to the host's handler too, if the host
has one.
non-threaded build.