1 /* $NetBSD: t_ptrace_wait.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */
4 * Copyright (c) 2016 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: t_ptrace_wait.c,v 1.2 2017/01/13 21:30:41 christos Exp $");
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/ptrace.h>
35 #include <sys/resource.h>
37 #include <sys/sysctl.h>
39 #include <machine/reg.h>
54 #include "../../t_ptrace_wait.h"
57 #if defined(HAVE_GPREGS)
59 ATF_TC_HEAD(regs1, tc)
61 atf_tc_set_md_var(tc, "descr",
62 "Call PT_GETREGS and iterate over General Purpose registers");
65 ATF_TC_BODY(regs1, tc)
67 const int exitval = 5;
68 const int sigval = SIGSTOP;
70 #if defined(TWAIT_HAVE_STATUS)
75 printf("Before forking process PID=%d\n", getpid());
76 ATF_REQUIRE((child = fork()) != -1);
78 printf("Before calling PT_TRACE_ME from child %d\n", getpid());
79 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
81 printf("Before raising %s from child\n", strsignal(sigval));
82 FORKEE_ASSERT(raise(sigval) == 0);
84 printf("Before exiting of the child process\n");
87 printf("Parent process PID=%d, child's PID=%d\n", getpid(), child);
89 printf("Before calling %s() for the child\n", TWAIT_FNAME);
90 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
92 validate_status_stopped(status, sigval);
94 printf("Call GETREGS for the child process\n");
95 ATF_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
97 printf("EAX=%#" PRIxREGISTER "\n", r.r_eax);
98 printf("EBX=%#" PRIxREGISTER "\n", r.r_ebx);
99 printf("ECX=%#" PRIxREGISTER "\n", r.r_ecx);
100 printf("EDX=%#" PRIxREGISTER "\n", r.r_edx);
102 printf("ESP=%#" PRIxREGISTER "\n", r.r_esp);
103 printf("EBP=%#" PRIxREGISTER "\n", r.r_ebp);
105 printf("ESI=%#" PRIxREGISTER "\n", r.r_esi);
106 printf("EDI=%#" PRIxREGISTER "\n", r.r_edi);
108 printf("EIP=%#" PRIxREGISTER "\n", r.r_eip);
110 printf("EFLAGS=%#" PRIxREGISTER "\n", r.r_eflags);
112 printf("CS=%#" PRIxREGISTER "\n", r.r_cs);
113 printf("SS=%#" PRIxREGISTER "\n", r.r_ss);
114 printf("DS=%#" PRIxREGISTER "\n", r.r_ds);
115 printf("ES=%#" PRIxREGISTER "\n", r.r_es);
116 printf("FS=%#" PRIxREGISTER "\n", r.r_fs);
117 printf("GS=%#" PRIxREGISTER "\n", r.r_gs);
119 printf("Before resuming the child process where it left off and "
120 "without signal to be sent\n");
121 ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
123 printf("Before calling %s() for the child\n", TWAIT_FNAME);
124 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
126 validate_status_exited(status, exitval);
128 printf("Before calling %s() for the child\n", TWAIT_FNAME);
129 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
135 setvbuf(stdout, NULL, _IONBF, 0);
136 setvbuf(stderr, NULL, _IONBF, 0);
138 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1);
140 return atf_no_error();