Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/kern/ptrace_test.c
Show All 26 Lines | |||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/cpuset.h> | #include <sys/cpuset.h> | ||||
#include <sys/event.h> | #include <sys/event.h> | ||||
#include <sys/file.h> | #include <sys/file.h> | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <sys/procctl.h> | #include <sys/procctl.h> | ||||
#include <sys/procdesc.h> | |||||
#include <sys/ptrace.h> | #include <sys/ptrace.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/runq.h> | #include <sys/runq.h> | ||||
#include <sys/syscall.h> | #include <sys/syscall.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/user.h> | #include <sys/user.h> | ||||
#include <sys/wait.h> | #include <sys/wait.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
▲ Show 20 Lines • Show All 3,856 Lines • ▼ Show 20 Lines | ATF_TC_BODY(ptrace__PT_LWPINFO_stale_siginfo, tc) | ||||
ATF_REQUIRE(WIFEXITED(status)); | ATF_REQUIRE(WIFEXITED(status)); | ||||
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); | ||||
} | } | ||||
/* | |||||
* Verify that when the process is traced that it isn't reparent | |||||
* to the init process when we close all process descriptors. | |||||
*/ | |||||
ATF_TC(ptrace__proc_reparent); | |||||
ATF_TC_HEAD(ptrace__proc_reparent, tc) | |||||
{ | |||||
atf_tc_set_md_var(tc, "timeout", "2"); | |||||
} | |||||
ATF_TC_BODY(ptrace__proc_reparent, tc) | |||||
{ | |||||
pid_t traced, debuger, wpid; | |||||
int pd, status; | |||||
traced = pdfork(&pd, 0); | |||||
ATF_REQUIRE(traced >= 0); | |||||
if (traced == 0) { | |||||
raise(SIGSTOP); | |||||
exit(0); | |||||
} | |||||
ATF_REQUIRE(pd >= 0); | |||||
debuger = fork(); | |||||
ATF_REQUIRE(debuger >= 0); | |||||
if (debuger == 0) { | |||||
/* The traced process is reparented to debuger. */ | |||||
ATF_REQUIRE(ptrace(PT_ATTACH, traced, 0, 0) == 0); | |||||
wpid = waitpid(traced, &status, 0); | |||||
ATF_REQUIRE(wpid == traced); | |||||
ATF_REQUIRE(WIFSTOPPED(status)); | |||||
ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP); | |||||
ATF_REQUIRE(close(pd) == 0); | |||||
ATF_REQUIRE(ptrace(PT_DETACH, traced, (caddr_t)1, 0) == 0); | |||||
/* We closed pd so we should not have any child. */ | |||||
wpid = wait(&status); | |||||
ATF_REQUIRE(wpid == -1); | |||||
ATF_REQUIRE(errno == ECHILD); | |||||
exit(0); | |||||
} | |||||
ATF_REQUIRE(close(pd) == 0); | |||||
wpid = waitpid(debuger, &status, 0); | |||||
ATF_REQUIRE(wpid == debuger); | |||||
ATF_REQUIRE(WEXITSTATUS(status) == 0); | |||||
/* Check if we still have any child. */ | |||||
wpid = wait(&status); | |||||
ATF_REQUIRE(wpid == -1); | |||||
ATF_REQUIRE(errno == ECHILD); | |||||
} | |||||
ATF_TP_ADD_TCS(tp) | ATF_TP_ADD_TCS(tp) | ||||
{ | { | ||||
ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_trace_me); | ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_trace_me); | ||||
ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_attach); | ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_attach); | ||||
ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_child_debugger); | ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_child_debugger); | ||||
ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_unrelated_debugger); | ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_unrelated_debugger); | ||||
ATF_TP_ADD_TC(tp, ptrace__parent_exits_before_child); | ATF_TP_ADD_TC(tp, ptrace__parent_exits_before_child); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
#ifdef HAVE_BREAKPOINT | #ifdef HAVE_BREAKPOINT | ||||
ATF_TP_ADD_TC(tp, ptrace__breakpoint_siginfo); | ATF_TP_ADD_TC(tp, ptrace__breakpoint_siginfo); | ||||
#endif | #endif | ||||
ATF_TP_ADD_TC(tp, ptrace__step_siginfo); | ATF_TP_ADD_TC(tp, ptrace__step_siginfo); | ||||
#if defined(HAVE_BREAKPOINT) && defined(SKIP_BREAK) | #if defined(HAVE_BREAKPOINT) && defined(SKIP_BREAK) | ||||
ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_different_thread); | ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_different_thread); | ||||
#endif | #endif | ||||
ATF_TP_ADD_TC(tp, ptrace__PT_LWPINFO_stale_siginfo); | ATF_TP_ADD_TC(tp, ptrace__PT_LWPINFO_stale_siginfo); | ||||
ATF_TP_ADD_TC(tp, ptrace__proc_reparent); | |||||
return (atf_no_error()); | return (atf_no_error()); | ||||
} | } |