Skip to content

Feature/custom handler#29

Merged
maximmenshikov merged 6 commits into
masterfrom
feature/custom_handler
Jun 10, 2026
Merged

Feature/custom handler#29
maximmenshikov merged 6 commits into
masterfrom
feature/custom_handler

Conversation

@maximmenshikov

Copy link
Copy Markdown
Collaborator

No description provided.

…r zkVM

Wrap exit/_Exit/abort so musl's exit_group (syscall 94) is replaced by pal's
real ZisK exit ecall (a7=93), which ZisK recognizes as program end. Also no-op
RhpReversePInvoke/RhpReversePInvokeReturn, whose GC-safe-point parking deadlocks
when a managed exception handler is entered from __wrap_RhpThrowEx in the
single-threaded zkVM.

Signed-off-by: Maxim Menshikov <maksim.menshikov@nethermind.io>
musl's exit()/_Exit()/abort() issue exit_group (94), which ZisK does not
recognise as program end, leaving emulation "not completed". Wrap these
terminators via --wrap to emit the real ZisK exit ecall (a7 == 93, CAUSE_EXIT)
so the emulator sees the `end` flag and stops cleanly.

Signed-off-by: Maxim Menshikov <maksim.menshikov@nethermind.io>
Add --wrap linker flags for exit, _Exit, and abort so these libc calls can be
redirected to the ZisK exit ecall.

Signed-off-by: Maxim Menshikov <maksim.menshikov@nethermind.io>
No-op RhpReversePInvoke and RhpReversePInvokeReturn: in the zkVM the thread is
already cooperative when a managed exception handler runs, so the real
AttachOrTrapThread2 transition spins on a GC rendezvous that never comes.
RhpThrowEx now forwards the managed exception object to a weakly-linked
ZkvmThrow handler that programs may export via [UnmanagedCallersOnly]; absent
that symbol it falls back to exit(1), so existing binaries are unchanged.
FailFast keeps the plain fail-fast path since it carries a message, not an
exception object.

Signed-off-by: Maxim Menshikov <maksim.menshikov@nethermind.io>
Add --wrap flags for RhpReversePInvoke and RhpReversePInvokeReturn so the zkVM
linker can intercept these reverse P/Invoke transitions alongside the existing
forward P/Invoke wrappers.

Signed-off-by: Maxim Menshikov <maksim.menshikov@nethermind.io>
Add a sample showing how to take over the zkVM fail-fast on a managed throw with
a C# handler. The wrapped RhpThrowEx forwards the exception object to a weak
ZkvmThrow symbol, which a program exports via UnmanagedCallersOnly to receive
the live Exception, print it via sys_write, and exit through the native Zisk
exit ecall. The README documents the throw routing and the two zkVM-specific
rules: print with sys_write rather than Console, and terminate with native
exit() rather than Environment.Exit to avoid recursing through the handler.

Signed-off-by: Maxim Menshikov <maksim.menshikov@nethermind.io>
@maximmenshikov maximmenshikov merged commit b295881 into master Jun 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant