tools/testing/selftests/x86/sysret_rip.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/x86/sysret_rip.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/x86/sysret_rip.c- Extension
.c- Size
- 3920 bytes
- Lines
- 158
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
stdlib.hunistd.hstdio.hstring.hinttypes.hsys/signal.hsys/ucontext.hsys/syscall.herr.hstddef.hstdbool.hsetjmp.hsys/user.hsys/mman.hassert.hhelpers.h
Detected Declarations
function sigsegv_for_sigreturn_testfunction sigusr1function test_sigreturn_tofunction sigsegv_for_fallthroughfunction test_syscall_fallthrough_tofunction main
Annotated Snippet
if (ip <= (1UL << 47) - PAGE_SIZE) {
err(1, "mremap to %p", new_address);
} else {
printf("[OK]\tmremap to %p failed\n", new_address);
return;
}
}
if (ret != new_address)
errx(1, "mremap malfunctioned: asked for %p but got %p\n",
new_address, ret);
current_test_page_addr = new_address;
rip = ip;
if (sigsetjmp(jmpbuf, 1) == 0) {
asm volatile ("call *%[syscall_insn]" :: "a" (SYS_getpid),
[syscall_insn] "rm" (ip - 2));
errx(1, "[FAIL]\tSyscall trampoline returned");
}
printf("[OK]\tWe survived\n");
}
int main(void)
{
/*
* When the kernel returns from a slow-path syscall, it will
* detect whether SYSRET is appropriate. If it incorrectly
* thinks that SYSRET is appropriate when RIP is noncanonical,
* it'll crash on Intel CPUs.
*/
sethandler(SIGUSR1, sigusr1, 0);
for (int i = 47; i < 64; i++)
test_sigreturn_to(1UL<<i);
clearhandler(SIGUSR1);
sethandler(SIGSEGV, sigsegv_for_fallthrough, 0);
/* One extra test to check that we didn't screw up the mremap logic. */
test_syscall_fallthrough_to((1UL << 47) - 2*PAGE_SIZE);
/* These are the interesting cases. */
for (int i = 47; i < 64; i++) {
test_syscall_fallthrough_to((1UL<<i) - PAGE_SIZE);
test_syscall_fallthrough_to(1UL<<i);
}
return 0;
}
Annotation
- Immediate include surface: `stdlib.h`, `unistd.h`, `stdio.h`, `string.h`, `inttypes.h`, `sys/signal.h`, `sys/ucontext.h`, `sys/syscall.h`.
- Detected declarations: `function sigsegv_for_sigreturn_test`, `function sigusr1`, `function test_sigreturn_to`, `function sigsegv_for_fallthrough`, `function test_syscall_fallthrough_to`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.