t_ptrace_i386_wait.h revision 1.3
1/* $NetBSD: t_ptrace_i386_wait.h,v 1.3 2019/02/10 02:13:45 kamil Exp $ */ 2 3/*- 4 * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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. 15 * 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. 27 */ 28 29#if defined(__i386__) 30ATF_TC(i386_regs1); 31ATF_TC_HEAD(i386_regs1, tc) 32{ 33 atf_tc_set_md_var(tc, "descr", 34 "Call PT_GETREGS and iterate over General Purpose registers"); 35} 36 37ATF_TC_BODY(i386_regs1, tc) 38{ 39 const int exitval = 5; 40 const int sigval = SIGSTOP; 41 pid_t child, wpid; 42#if defined(TWAIT_HAVE_STATUS) 43 int status; 44#endif 45 struct reg r; 46 47 DPRINTF("Before forking process PID=%d\n", getpid()); 48 SYSCALL_REQUIRE((child = fork()) != -1); 49 if (child == 0) { 50 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 51 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 52 53 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 54 FORKEE_ASSERT(raise(sigval) == 0); 55 56 DPRINTF("Before exiting of the child process\n"); 57 _exit(exitval); 58 } 59 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 60 61 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 62 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 63 64 validate_status_stopped(status, sigval); 65 66 DPRINTF("Call GETREGS for the child process\n"); 67 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 68 69 DPRINTF("EAX=%#" PRIxREGISTER "\n", r.r_eax); 70 DPRINTF("EBX=%#" PRIxREGISTER "\n", r.r_ebx); 71 DPRINTF("ECX=%#" PRIxREGISTER "\n", r.r_ecx); 72 DPRINTF("EDX=%#" PRIxREGISTER "\n", r.r_edx); 73 74 DPRINTF("ESP=%#" PRIxREGISTER "\n", r.r_esp); 75 DPRINTF("EBP=%#" PRIxREGISTER "\n", r.r_ebp); 76 77 DPRINTF("ESI=%#" PRIxREGISTER "\n", r.r_esi); 78 DPRINTF("EDI=%#" PRIxREGISTER "\n", r.r_edi); 79 80 DPRINTF("EIP=%#" PRIxREGISTER "\n", r.r_eip); 81 82 DPRINTF("EFLAGS=%#" PRIxREGISTER "\n", r.r_eflags); 83 84 DPRINTF("CS=%#" PRIxREGISTER "\n", r.r_cs); 85 DPRINTF("SS=%#" PRIxREGISTER "\n", r.r_ss); 86 DPRINTF("DS=%#" PRIxREGISTER "\n", r.r_ds); 87 DPRINTF("ES=%#" PRIxREGISTER "\n", r.r_es); 88 DPRINTF("FS=%#" PRIxREGISTER "\n", r.r_fs); 89 DPRINTF("GS=%#" PRIxREGISTER "\n", r.r_gs); 90 91 DPRINTF("Before resuming the child process where it left off and " 92 "without signal to be sent\n"); 93 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 94 95 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 96 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 97 98 validate_status_exited(status, exitval); 99 100 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 101 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 102} 103#define ATF_TP_ADD_TCS_PTRACE_WAIT_I386() \ 104 ATF_TP_ADD_TC_HAVE_GPREGS(tp, i386_regs1); 105#else 106#define ATF_TP_ADD_TCS_PTRACE_WAIT_I386() 107#endif 108