tools/testing/selftests/powerpc/ptrace/ptrace-syscall.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/ptrace/ptrace-syscall.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/ptrace/ptrace-syscall.c- Extension
.c- Size
- 6239 bytes
- Lines
- 229
- 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.hsys/auxv.hutils.h
Detected Declarations
function wait_trapfunction test_ptrace_syscall_restartfunction sys_gettidfunction ptrace_syscallfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* A ptrace test for testing PTRACE_SYSEMU, PTRACE_SETREGS and
* PTRACE_GETREG. This test basically create a child process that executes
* syscalls and the parent process check if it is being traced appropriated.
*
* This test is heavily based on tools/testing/selftests/x86/ptrace_syscall.c
* test, and it was adapted to run on Powerpc by
* Breno Leitao <leitao@debian.org>
*/
#define _GNU_SOURCE
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/syscall.h>
#include <sys/user.h>
#include <unistd.h>
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <err.h>
#include <string.h>
#include <sys/auxv.h>
#include "utils.h"
/* Bitness-agnostic defines for user_regs_struct fields. */
#define user_syscall_nr gpr[0]
#define user_arg0 gpr[3]
#define user_arg1 gpr[4]
#define user_arg2 gpr[5]
#define user_arg3 gpr[6]
#define user_arg4 gpr[7]
#define user_arg5 gpr[8]
#define user_ip nip
#define PTRACE_SYSEMU 0x1d
static int nerrs;
static void 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);
}
static void test_ptrace_syscall_restart(void)
{
int status;
struct pt_regs regs;
pid_t chld;
printf("[RUN]\tptrace-induced syscall restart\n");
chld = fork();
if (chld < 0)
err(1, "fork");
/*
* Child process is running 4 syscalls after ptrace.
*
* 1) getpid()
* 2) gettid()
* 3) tgkill() -> Send SIGSTOP
* 4) gettid() -> Where the tests will happen essentially
*/
if (chld == 0) {
if (ptrace(PTRACE_TRACEME, 0, 0, 0) != 0)
err(1, "PTRACE_TRACEME");
pid_t pid = getpid(), tid = syscall(SYS_gettid);
printf("\tChild will make one syscall\n");
syscall(SYS_tgkill, pid, tid, SIGSTOP);
syscall(SYS_gettid, 10, 11, 12, 13, 14, 15);
_exit(0);
}
/* Parent process below */
/* Wait for SIGSTOP sent by tgkill above. */
if (waitpid(chld, &status, 0) != chld || !WIFSTOPPED(status))
err(1, "waitpid");
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: `function wait_trap`, `function test_ptrace_syscall_restart`, `function sys_gettid`, `function ptrace_syscall`, `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.