t_ptrace_amd64_wait.h revision 1.2 1 1.2 christos /* $NetBSD: t_ptrace_amd64_wait.h,v 1.2 2017/12/14 22:06:54 christos Exp $ */
2 1.1 kamil
3 1.1 kamil /*-
4 1.1 kamil * Copyright (c) 2016 The NetBSD Foundation, Inc.
5 1.1 kamil * All rights reserved.
6 1.1 kamil *
7 1.1 kamil * Redistribution and use in source and binary forms, with or without
8 1.1 kamil * modification, are permitted provided that the following conditions
9 1.1 kamil * are met:
10 1.1 kamil * 1. Redistributions of source code must retain the above copyright
11 1.1 kamil * notice, this list of conditions and the following disclaimer.
12 1.1 kamil * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 kamil * notice, this list of conditions and the following disclaimer in the
14 1.1 kamil * documentation and/or other materials provided with the distribution.
15 1.1 kamil *
16 1.1 kamil * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 kamil * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 kamil * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 kamil * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 kamil * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 kamil * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 kamil * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 kamil * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 kamil * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 kamil * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 kamil * POSSIBILITY OF SUCH DAMAGE.
27 1.1 kamil */
28 1.1 kamil
29 1.1 kamil #if defined(__x86_64__)
30 1.1 kamil ATF_TC(x86_64_regs1);
31 1.1 kamil ATF_TC_HEAD(x86_64_regs1, tc)
32 1.1 kamil {
33 1.1 kamil atf_tc_set_md_var(tc, "descr",
34 1.1 kamil "Call PT_GETREGS and iterate over General Purpose registers");
35 1.1 kamil }
36 1.1 kamil
37 1.1 kamil ATF_TC_BODY(x86_64_regs1, tc)
38 1.1 kamil {
39 1.1 kamil const int exitval = 5;
40 1.1 kamil const int sigval = SIGSTOP;
41 1.1 kamil pid_t child, wpid;
42 1.1 kamil #if defined(TWAIT_HAVE_STATUS)
43 1.1 kamil int status;
44 1.1 kamil #endif
45 1.1 kamil struct reg r;
46 1.1 kamil
47 1.2 christos DPRINTF("Before forking process PID=%d\n", getpid());
48 1.2 christos SYSCALL_REQUIRE((child = fork()) != -1);
49 1.1 kamil if (child == 0) {
50 1.2 christos DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
51 1.1 kamil FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
52 1.1 kamil
53 1.2 christos DPRINTF("Before raising %s from child\n", strsignal(sigval));
54 1.1 kamil FORKEE_ASSERT(raise(sigval) == 0);
55 1.1 kamil
56 1.2 christos DPRINTF("Before exiting of the child process\n");
57 1.1 kamil _exit(exitval);
58 1.1 kamil }
59 1.2 christos DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
60 1.1 kamil
61 1.2 christos DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
62 1.1 kamil TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
63 1.1 kamil
64 1.1 kamil validate_status_stopped(status, sigval);
65 1.1 kamil
66 1.2 christos DPRINTF("Call GETREGS for the child process\n");
67 1.2 christos SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
68 1.1 kamil
69 1.2 christos DPRINTF("RAX=%#" PRIxREGISTER "\n", r.regs[_REG_RAX]);
70 1.2 christos DPRINTF("RBX=%#" PRIxREGISTER "\n", r.regs[_REG_RBX]);
71 1.2 christos DPRINTF("RCX=%#" PRIxREGISTER "\n", r.regs[_REG_RCX]);
72 1.2 christos DPRINTF("RDX=%#" PRIxREGISTER "\n", r.regs[_REG_RDX]);
73 1.2 christos
74 1.2 christos DPRINTF("RDI=%#" PRIxREGISTER "\n", r.regs[_REG_RDI]);
75 1.2 christos DPRINTF("RSI=%#" PRIxREGISTER "\n", r.regs[_REG_RSI]);
76 1.2 christos
77 1.2 christos DPRINTF("GS=%#" PRIxREGISTER "\n", r.regs[_REG_GS]);
78 1.2 christos DPRINTF("FS=%#" PRIxREGISTER "\n", r.regs[_REG_FS]);
79 1.2 christos DPRINTF("ES=%#" PRIxREGISTER "\n", r.regs[_REG_ES]);
80 1.2 christos DPRINTF("DS=%#" PRIxREGISTER "\n", r.regs[_REG_DS]);
81 1.2 christos DPRINTF("CS=%#" PRIxREGISTER "\n", r.regs[_REG_CS]);
82 1.2 christos DPRINTF("SS=%#" PRIxREGISTER "\n", r.regs[_REG_SS]);
83 1.2 christos
84 1.2 christos DPRINTF("RSP=%#" PRIxREGISTER "\n", r.regs[_REG_RSP]);
85 1.2 christos DPRINTF("RIP=%#" PRIxREGISTER "\n", r.regs[_REG_RIP]);
86 1.2 christos
87 1.2 christos DPRINTF("RFLAGS=%#" PRIxREGISTER "\n", r.regs[_REG_RFLAGS]);
88 1.2 christos
89 1.2 christos DPRINTF("R8=%#" PRIxREGISTER "\n", r.regs[_REG_R8]);
90 1.2 christos DPRINTF("R9=%#" PRIxREGISTER "\n", r.regs[_REG_R9]);
91 1.2 christos DPRINTF("R10=%#" PRIxREGISTER "\n", r.regs[_REG_R10]);
92 1.2 christos DPRINTF("R11=%#" PRIxREGISTER "\n", r.regs[_REG_R11]);
93 1.2 christos DPRINTF("R12=%#" PRIxREGISTER "\n", r.regs[_REG_R12]);
94 1.2 christos DPRINTF("R13=%#" PRIxREGISTER "\n", r.regs[_REG_R13]);
95 1.2 christos DPRINTF("R14=%#" PRIxREGISTER "\n", r.regs[_REG_R14]);
96 1.2 christos DPRINTF("R15=%#" PRIxREGISTER "\n", r.regs[_REG_R15]);
97 1.1 kamil
98 1.2 christos DPRINTF("Before resuming the child process where it left off and "
99 1.1 kamil "without signal to be sent\n");
100 1.2 christos SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
101 1.1 kamil
102 1.2 christos DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
103 1.1 kamil TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
104 1.1 kamil
105 1.1 kamil validate_status_exited(status, exitval);
106 1.1 kamil
107 1.2 christos DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
108 1.1 kamil TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
109 1.1 kamil }
110 1.1 kamil #define ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64() \
111 1.1 kamil ATF_TP_ADD_TC_HAVE_GPREGS(tp, x86_64_regs1);
112 1.1 kamil #else
113 1.1 kamil #define ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64()
114 1.1 kamil #endif
115