Home | History | Annotate | Line # | Download | only in sys
t_ptrace_amd64_wait.h revision 1.5
      1  1.5     kamil /*	$NetBSD: t_ptrace_amd64_wait.h,v 1.5 2018/05/26 20:27:48 kamil 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.3     kamil 
     31  1.3     kamil /// ----------------------------------------------------------------------------
     32  1.3     kamil 
     33  1.1     kamil ATF_TC(x86_64_regs1);
     34  1.1     kamil ATF_TC_HEAD(x86_64_regs1, tc)
     35  1.1     kamil {
     36  1.1     kamil 	atf_tc_set_md_var(tc, "descr",
     37  1.1     kamil 	    "Call PT_GETREGS and iterate over General Purpose registers");
     38  1.1     kamil }
     39  1.1     kamil 
     40  1.1     kamil ATF_TC_BODY(x86_64_regs1, tc)
     41  1.1     kamil {
     42  1.1     kamil 	const int exitval = 5;
     43  1.1     kamil 	const int sigval = SIGSTOP;
     44  1.1     kamil 	pid_t child, wpid;
     45  1.1     kamil #if defined(TWAIT_HAVE_STATUS)
     46  1.1     kamil 	int status;
     47  1.1     kamil #endif
     48  1.1     kamil 	struct reg r;
     49  1.1     kamil 
     50  1.2  christos 	DPRINTF("Before forking process PID=%d\n", getpid());
     51  1.2  christos 	SYSCALL_REQUIRE((child = fork()) != -1);
     52  1.1     kamil 	if (child == 0) {
     53  1.2  christos 		DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
     54  1.1     kamil 		FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
     55  1.1     kamil 
     56  1.2  christos 		DPRINTF("Before raising %s from child\n", strsignal(sigval));
     57  1.1     kamil 		FORKEE_ASSERT(raise(sigval) == 0);
     58  1.1     kamil 
     59  1.2  christos 		DPRINTF("Before exiting of the child process\n");
     60  1.1     kamil 		_exit(exitval);
     61  1.1     kamil 	}
     62  1.2  christos 	DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
     63  1.1     kamil 
     64  1.2  christos 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
     65  1.1     kamil 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
     66  1.1     kamil 
     67  1.1     kamil 	validate_status_stopped(status, sigval);
     68  1.1     kamil 
     69  1.2  christos 	DPRINTF("Call GETREGS for the child process\n");
     70  1.2  christos 	SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
     71  1.1     kamil 
     72  1.2  christos 	DPRINTF("RAX=%#" PRIxREGISTER "\n", r.regs[_REG_RAX]);
     73  1.2  christos 	DPRINTF("RBX=%#" PRIxREGISTER "\n", r.regs[_REG_RBX]);
     74  1.2  christos 	DPRINTF("RCX=%#" PRIxREGISTER "\n", r.regs[_REG_RCX]);
     75  1.2  christos 	DPRINTF("RDX=%#" PRIxREGISTER "\n", r.regs[_REG_RDX]);
     76  1.2  christos 
     77  1.2  christos 	DPRINTF("RDI=%#" PRIxREGISTER "\n", r.regs[_REG_RDI]);
     78  1.2  christos 	DPRINTF("RSI=%#" PRIxREGISTER "\n", r.regs[_REG_RSI]);
     79  1.2  christos 
     80  1.2  christos 	DPRINTF("GS=%#" PRIxREGISTER "\n", r.regs[_REG_GS]);
     81  1.2  christos 	DPRINTF("FS=%#" PRIxREGISTER "\n", r.regs[_REG_FS]);
     82  1.2  christos 	DPRINTF("ES=%#" PRIxREGISTER "\n", r.regs[_REG_ES]);
     83  1.2  christos 	DPRINTF("DS=%#" PRIxREGISTER "\n", r.regs[_REG_DS]);
     84  1.2  christos 	DPRINTF("CS=%#" PRIxREGISTER "\n", r.regs[_REG_CS]);
     85  1.2  christos 	DPRINTF("SS=%#" PRIxREGISTER "\n", r.regs[_REG_SS]);
     86  1.2  christos 
     87  1.2  christos 	DPRINTF("RSP=%#" PRIxREGISTER "\n", r.regs[_REG_RSP]);
     88  1.2  christos 	DPRINTF("RIP=%#" PRIxREGISTER "\n", r.regs[_REG_RIP]);
     89  1.2  christos 
     90  1.2  christos 	DPRINTF("RFLAGS=%#" PRIxREGISTER "\n", r.regs[_REG_RFLAGS]);
     91  1.2  christos 
     92  1.2  christos 	DPRINTF("R8=%#" PRIxREGISTER "\n", r.regs[_REG_R8]);
     93  1.2  christos 	DPRINTF("R9=%#" PRIxREGISTER "\n", r.regs[_REG_R9]);
     94  1.2  christos 	DPRINTF("R10=%#" PRIxREGISTER "\n", r.regs[_REG_R10]);
     95  1.2  christos 	DPRINTF("R11=%#" PRIxREGISTER "\n", r.regs[_REG_R11]);
     96  1.2  christos 	DPRINTF("R12=%#" PRIxREGISTER "\n", r.regs[_REG_R12]);
     97  1.2  christos 	DPRINTF("R13=%#" PRIxREGISTER "\n", r.regs[_REG_R13]);
     98  1.2  christos 	DPRINTF("R14=%#" PRIxREGISTER "\n", r.regs[_REG_R14]);
     99  1.2  christos 	DPRINTF("R15=%#" PRIxREGISTER "\n", r.regs[_REG_R15]);
    100  1.1     kamil 
    101  1.2  christos 	DPRINTF("Before resuming the child process where it left off and "
    102  1.1     kamil 	    "without signal to be sent\n");
    103  1.2  christos 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
    104  1.1     kamil 
    105  1.2  christos 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    106  1.1     kamil 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
    107  1.1     kamil 
    108  1.1     kamil 	validate_status_exited(status, exitval);
    109  1.1     kamil 
    110  1.2  christos 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    111  1.1     kamil 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
    112  1.1     kamil }
    113  1.3     kamil 
    114  1.3     kamil /// ----------------------------------------------------------------------------
    115  1.3     kamil 
    116  1.3     kamil 
    117  1.1     kamil #define ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64() \
    118  1.5     kamil 	ATF_TP_ADD_TC_HAVE_GPREGS(tp, x86_64_regs1);
    119  1.1     kamil #else
    120  1.1     kamil #define ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64()
    121  1.1     kamil #endif
    122