tools/testing/selftests/x86/ptrace_syscall.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/x86/ptrace_syscall.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/x86/ptrace_syscall.c- Extension
.c- Size
- 11967 bytes
- Lines
- 411
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/ptrace.hsys/types.hsys/wait.hsys/syscall.hsys/user.hunistd.herrno.hstddef.hstdio.herr.hstring.hasm/ptrace-abi.hsys/auxv.hhelpers.h
Detected Declarations
struct syscall_args32function do_full_int80function AT_SYSINFOfunction wait_trapfunction setsigignfunction empty_handlerfunction test_ptrace_syscall_restartfunction test_restart_under_ptracefunction main
Annotated Snippet
struct syscall_args32 {
uint32_t nr, arg0, arg1, arg2, arg3, arg4, arg5;
};
#ifdef __i386__
extern void sys32_helper(struct syscall_args32 *, void *);
extern void int80_and_ret(void);
#endif
/*
* Helper to invoke int80 with controlled regs and capture the final regs.
*/
static void do_full_int80(struct syscall_args32 *args)
{
#ifdef __x86_64__
register unsigned long bp asm("bp") = args->arg5;
asm volatile ("int $0x80"
: "+a" (args->nr),
"+b" (args->arg0), "+c" (args->arg1), "+d" (args->arg2),
"+S" (args->arg3), "+D" (args->arg4), "+r" (bp)
: : "r8", "r9", "r10", "r11");
args->arg5 = bp;
#else
sys32_helper(args, int80_and_ret);
#endif
}
#ifdef __i386__
static void (*vsyscall32)(void);
/*
* Nasty helper to invoke AT_SYSINFO (i.e. __kernel_vsyscall) with
* controlled regs and capture the final regs. This is so nasty that it
* crashes my copy of gdb :)
*/
static void do_full_vsyscall32(struct syscall_args32 *args)
{
sys32_helper(args, vsyscall32);
}
#endif
static siginfo_t wait_trap(pid_t chld)
{
siginfo_t si;
if (waitid(P_PID, chld, &si, WEXITED|WSTOPPED) != 0)
err(1, "waitid");
if (si.si_pid != chld)
errx(1, "got unexpected pid in event\n");
if (si.si_code != CLD_TRAPPED)
errx(1, "got unexpected event type %d\n", si.si_code);
return si;
}
static void setsigign(int sig, int flags)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = (void *)SIG_IGN;
sa.sa_flags = flags;
sigemptyset(&sa.sa_mask);
if (sigaction(sig, &sa, 0))
err(1, "sigaction");
}
#ifdef __x86_64__
# define REG_BP REG_RBP
#else
# define REG_BP REG_EBP
#endif
static void empty_handler(int sig, siginfo_t *si, void *ctx_void)
{
}
static void test_sys32_regs(void (*do_syscall)(struct syscall_args32 *))
{
struct syscall_args32 args = {
.nr = 224, /* gettid */
.arg0 = 10, .arg1 = 11, .arg2 = 12,
.arg3 = 13, .arg4 = 14, .arg5 = 15,
};
do_syscall(&args);
if (args.nr != getpid() ||
args.arg0 != 10 || args.arg1 != 11 || args.arg2 != 12 ||
args.arg3 != 13 || args.arg4 != 14 || args.arg5 != 15) {
printf("[FAIL]\tgetpid() failed to preserve regs\n");
nerrs++;
} else {
Annotation
- Immediate include surface: `sys/ptrace.h`, `sys/types.h`, `sys/wait.h`, `sys/syscall.h`, `sys/user.h`, `unistd.h`, `errno.h`, `stddef.h`.
- Detected declarations: `struct syscall_args32`, `function do_full_int80`, `function AT_SYSINFO`, `function wait_trap`, `function setsigign`, `function empty_handler`, `function test_ptrace_syscall_restart`, `function test_restart_under_ptrace`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: core 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.