Changeset View
Changeset View
Standalone View
Standalone View
head/tests/sys/kern/ptrace_test.c
Show First 20 Lines • Show All 3,899 Lines • ▼ Show 20 Lines | ATF_TC_BODY(ptrace__PT_LWPINFO_stale_siginfo, tc) | ||||
ATF_REQUIRE(WEXITSTATUS(status) == 1); | ATF_REQUIRE(WEXITSTATUS(status) == 1); | ||||
wpid = wait(&status); | wpid = wait(&status); | ||||
ATF_REQUIRE(wpid == -1); | ATF_REQUIRE(wpid == -1); | ||||
ATF_REQUIRE(errno == ECHILD); | ATF_REQUIRE(errno == ECHILD); | ||||
} | } | ||||
/* | /* | ||||
* A simple test of PT_GET_SC_ARGS. | * A simple test of PT_GET_SC_ARGS and PT_GET_SC_RET. | ||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(ptrace__syscall_args); | ATF_TC_WITHOUT_HEAD(ptrace__syscall_args); | ||||
ATF_TC_BODY(ptrace__syscall_args, tc) | ATF_TC_BODY(ptrace__syscall_args, tc) | ||||
{ | { | ||||
struct ptrace_lwpinfo pl; | struct ptrace_lwpinfo pl; | ||||
struct ptrace_sc_ret psr; | |||||
pid_t fpid, wpid; | pid_t fpid, wpid; | ||||
register_t args[2]; | register_t args[2]; | ||||
int events, status; | int events, status; | ||||
ATF_REQUIRE((fpid = fork()) != -1); | ATF_REQUIRE((fpid = fork()) != -1); | ||||
if (fpid == 0) { | if (fpid == 0) { | ||||
trace_me(); | trace_me(); | ||||
kill(getpid(), 0); | kill(getpid(), 0); | ||||
close(3); | |||||
exit(1); | exit(1); | ||||
} | } | ||||
/* The first wait() should report the stop from SIGSTOP. */ | /* The first wait() should report the stop from SIGSTOP. */ | ||||
wpid = waitpid(fpid, &status, 0); | wpid = waitpid(fpid, &status, 0); | ||||
ATF_REQUIRE(wpid == fpid); | ATF_REQUIRE(wpid == fpid); | ||||
ATF_REQUIRE(WIFSTOPPED(status)); | ATF_REQUIRE(WIFSTOPPED(status)); | ||||
ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP); | ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP); | ||||
/* | /* | ||||
* Continue the process ignoring the signal, but enabling | * Continue the process ignoring the signal, but enabling | ||||
* syscall entry traps. | * syscall traps. | ||||
*/ | */ | ||||
ATF_REQUIRE(ptrace(PT_TO_SCE, fpid, (caddr_t)1, 0) == 0); | ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0); | ||||
/* | /* | ||||
* The next stop should be the syscall entry from getpid(). | * The next stop should be the syscall entry from getpid(). | ||||
*/ | */ | ||||
wpid = waitpid(fpid, &status, 0); | wpid = waitpid(fpid, &status, 0); | ||||
ATF_REQUIRE(wpid == fpid); | ATF_REQUIRE(wpid == fpid); | ||||
ATF_REQUIRE(WIFSTOPPED(status)); | ATF_REQUIRE(WIFSTOPPED(status)); | ||||
ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP); | ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP); | ||||
ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1); | ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1); | ||||
ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE); | ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE); | ||||
ATF_REQUIRE(pl.pl_syscall_code == SYS_getpid); | ATF_REQUIRE(pl.pl_syscall_code == SYS_getpid); | ||||
ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0); | ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0); | ||||
/* | /* | ||||
* The next stop should be the syscall exit from getpid(). | |||||
*/ | |||||
wpid = waitpid(fpid, &status, 0); | |||||
ATF_REQUIRE(wpid == fpid); | |||||
ATF_REQUIRE(WIFSTOPPED(status)); | |||||
ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP); | |||||
ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1); | |||||
ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX); | |||||
ATF_REQUIRE(pl.pl_syscall_code == SYS_getpid); | |||||
ATF_REQUIRE(ptrace(PT_GET_SC_RET, wpid, (caddr_t)&psr, | |||||
sizeof(psr)) != -1); | |||||
ATF_REQUIRE(psr.sr_error == 0); | |||||
ATF_REQUIRE(psr.sr_retval[0] == wpid); | |||||
ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0); | |||||
/* | |||||
* The next stop should be the syscall entry from kill(). | * The next stop should be the syscall entry from kill(). | ||||
*/ | */ | ||||
wpid = waitpid(fpid, &status, 0); | wpid = waitpid(fpid, &status, 0); | ||||
ATF_REQUIRE(wpid == fpid); | ATF_REQUIRE(wpid == fpid); | ||||
ATF_REQUIRE(WIFSTOPPED(status)); | ATF_REQUIRE(WIFSTOPPED(status)); | ||||
ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP); | ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP); | ||||
ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1); | ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1); | ||||
ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE); | ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE); | ||||
ATF_REQUIRE(pl.pl_syscall_code == SYS_kill); | ATF_REQUIRE(pl.pl_syscall_code == SYS_kill); | ||||
ATF_REQUIRE(pl.pl_syscall_narg == 2); | ATF_REQUIRE(pl.pl_syscall_narg == 2); | ||||
ATF_REQUIRE(ptrace(PT_GET_SC_ARGS, wpid, (caddr_t)args, | ATF_REQUIRE(ptrace(PT_GET_SC_ARGS, wpid, (caddr_t)args, | ||||
sizeof(args)) != -1); | sizeof(args)) != -1); | ||||
ATF_REQUIRE(args[0] == wpid); | ATF_REQUIRE(args[0] == wpid); | ||||
ATF_REQUIRE(args[1] == 0); | ATF_REQUIRE(args[1] == 0); | ||||
ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0); | |||||
/* | |||||
* The next stop should be the syscall exit from kill(). | |||||
*/ | |||||
wpid = waitpid(fpid, &status, 0); | |||||
ATF_REQUIRE(wpid == fpid); | |||||
ATF_REQUIRE(WIFSTOPPED(status)); | |||||
ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP); | |||||
ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1); | |||||
ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX); | |||||
ATF_REQUIRE(pl.pl_syscall_code == SYS_kill); | |||||
ATF_REQUIRE(ptrace(PT_GET_SC_RET, wpid, (caddr_t)&psr, | |||||
sizeof(psr)) != -1); | |||||
ATF_REQUIRE(psr.sr_error == 0); | |||||
ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0); | |||||
/* | |||||
* The next stop should be the syscall entry from close(). | |||||
*/ | |||||
wpid = waitpid(fpid, &status, 0); | |||||
ATF_REQUIRE(wpid == fpid); | |||||
ATF_REQUIRE(WIFSTOPPED(status)); | |||||
ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP); | |||||
ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1); | |||||
ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE); | |||||
ATF_REQUIRE(pl.pl_syscall_code == SYS_close); | |||||
ATF_REQUIRE(pl.pl_syscall_narg == 1); | |||||
ATF_REQUIRE(ptrace(PT_GET_SC_ARGS, wpid, (caddr_t)args, | |||||
sizeof(args)) != -1); | |||||
ATF_REQUIRE(args[0] == 3); | |||||
ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0); | |||||
/* | |||||
* The next stop should be the syscall exit from close(). | |||||
*/ | |||||
wpid = waitpid(fpid, &status, 0); | |||||
ATF_REQUIRE(wpid == fpid); | |||||
ATF_REQUIRE(WIFSTOPPED(status)); | |||||
ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP); | |||||
ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1); | |||||
ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCX); | |||||
ATF_REQUIRE(pl.pl_syscall_code == SYS_close); | |||||
ATF_REQUIRE(ptrace(PT_GET_SC_RET, wpid, (caddr_t)&psr, | |||||
sizeof(psr)) != -1); | |||||
ATF_REQUIRE(psr.sr_error == EBADF); | |||||
/* Disable syscall tracing and continue the child to let it exit. */ | /* Disable syscall tracing and continue the child to let it exit. */ | ||||
ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events, | ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events, | ||||
sizeof(events)) == 0); | sizeof(events)) == 0); | ||||
events &= ~PTRACE_SYSCALL; | events &= ~PTRACE_SYSCALL; | ||||
ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events, | ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events, | ||||
sizeof(events)) == 0); | sizeof(events)) == 0); | ||||
ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0); | ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0); | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |