Skip to content

Add trampoline preamble with red zone reservation and R11 restart address#812

Open
wdcui wants to merge 10 commits intomainfrom
wdcui/pr1-trampoline-format
Open

Add trampoline preamble with red zone reservation and R11 restart address#812
wdcui wants to merge 10 commits intomainfrom
wdcui/pr1-trampoline-format

Conversation

@wdcui
Copy link
Copy Markdown
Member

@wdcui wdcui commented Apr 25, 2026

This PR adds the red zone reservation and saves the syscall address for restart in the syscall rewriter and the userland platforms. It also adds an empty trampoline to ELF files that don't have syscalls so the runtime knows it's already patched.

…ress

The syscall rewriter now emits a 12-byte preamble before each trampoline
stub: LEA RSP,[RSP-0x80] to reserve the SysV 128-byte red zone, and
LEA R11,[RIP+disp32] to load the call-site restart address into R11 for
future SA_RESTART support.

Platform callbacks are renamed to syscall_callback_redzone to reflect
the new calling convention. The callback recovers the architectural RSP
with LEA R11,[RSP+128] and saves the restart address to TLS
(saved_restart_addr) before clobbering R11.

The rewriter also emits a size=0 header sentinel for binaries with no
syscall instructions, allowing the loader to distinguish 'checked, no
syscalls' from 'never processed.' The is_already_hooked check treats
size=0 as already-hooked. The rtld_audit library is updated to handle
both the new calling convention (red zone + R11) and size=0 binaries
(via mincore probe before reading trampoline memory).
@wdcui wdcui force-pushed the wdcui/pr1-trampoline-format branch from 75ea7ec to 0bcb6ff Compare April 25, 2026 04:06
@wdcui wdcui marked this pull request as ready for review April 25, 2026 18:50
wdcui added 7 commits April 25, 2026 11:53
The pre-built binary had old-format trampolines that jumped to
syscall_callback_redzone without reserving the red zone, causing
an access violation (0xc0000005) on Windows.
…ore probe)

The rtld_audit library uses a real syscall instruction in raw_syscall3()
for the mincore probe before syscall_entry is known. Rewriting it would
hook that instruction and jump to address 0. Rebuild from source (which
already has the new do_syscall preamble) and copy without rewriting.
parse_object is only called for the main binary and interpreter, which
always have syscall instructions and mapped trampolines. The mincore
probe for the size=0 sentinel case is unnecessary. Removing the raw
syscall instruction also means the rewriter can safely process
rtld_audit.so (it finds no syscall instructions to hook).
parse_object can be called on binaries without mapped trampolines
(e.g. vdso, non-PIE main). The mincore probe safely detects this
case. The raw syscall instruction is needed because syscall_entry
may not be initialized yet at probe time.
The raw syscall instruction breaks on Windows. This will be fully
resolved when runtime patching (PR4) lands and removes rtld_audit.
@wdcui wdcui force-pushed the wdcui/pr1-trampoline-format branch from a897889 to fd4fcb7 Compare April 25, 2026 21:31
@github-actions
Copy link
Copy Markdown

🤖 SemverChecks 🤖 No breaking API changes detected

Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered.

@wdcui
Copy link
Copy Markdown
Member Author

wdcui commented Apr 25, 2026

This PR is ready for review. Ignore the rtld changes since it will be removed after PR #810 is merged.

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