Home | History | Annotate | Line # | Download | only in sys
      1  1.10    mgorny /*	$NetBSD: t_ptrace_i386_wait.h,v 1.10 2020/01/08 17:23:15 mgorny Exp $	*/
      2   1.1     kamil 
      3   1.1     kamil /*-
      4   1.3     kamil  * Copyright (c) 2016, 2017, 2018, 2019 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(__i386__)
     30   1.1     kamil ATF_TC(i386_regs1);
     31   1.1     kamil ATF_TC_HEAD(i386_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(i386_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("EAX=%#" PRIxREGISTER "\n", r.r_eax);
     70   1.2  christos 	DPRINTF("EBX=%#" PRIxREGISTER "\n", r.r_ebx);
     71   1.2  christos 	DPRINTF("ECX=%#" PRIxREGISTER "\n", r.r_ecx);
     72   1.2  christos 	DPRINTF("EDX=%#" PRIxREGISTER "\n", r.r_edx);
     73   1.1     kamil 
     74   1.2  christos 	DPRINTF("ESP=%#" PRIxREGISTER "\n", r.r_esp);
     75   1.2  christos 	DPRINTF("EBP=%#" PRIxREGISTER "\n", r.r_ebp);
     76   1.1     kamil 
     77   1.2  christos 	DPRINTF("ESI=%#" PRIxREGISTER "\n", r.r_esi);
     78   1.2  christos 	DPRINTF("EDI=%#" PRIxREGISTER "\n", r.r_edi);
     79   1.1     kamil 
     80   1.2  christos 	DPRINTF("EIP=%#" PRIxREGISTER "\n", r.r_eip);
     81   1.1     kamil 
     82   1.2  christos 	DPRINTF("EFLAGS=%#" PRIxREGISTER "\n", r.r_eflags);
     83   1.1     kamil 
     84   1.2  christos 	DPRINTF("CS=%#" PRIxREGISTER "\n", r.r_cs);
     85   1.2  christos 	DPRINTF("SS=%#" PRIxREGISTER "\n", r.r_ss);
     86   1.2  christos 	DPRINTF("DS=%#" PRIxREGISTER "\n", r.r_ds);
     87   1.2  christos 	DPRINTF("ES=%#" PRIxREGISTER "\n", r.r_es);
     88   1.2  christos 	DPRINTF("FS=%#" PRIxREGISTER "\n", r.r_fs);
     89   1.2  christos 	DPRINTF("GS=%#" PRIxREGISTER "\n", r.r_gs);
     90   1.1     kamil 
     91   1.2  christos 	DPRINTF("Before resuming the child process where it left off and "
     92   1.1     kamil 	    "without signal to be sent\n");
     93   1.2  christos 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
     94   1.1     kamil 
     95   1.2  christos 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
     96   1.1     kamil 	TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
     97   1.1     kamil 
     98   1.1     kamil 	validate_status_exited(status, exitval);
     99   1.1     kamil 
    100   1.2  christos 	DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
    101   1.1     kamil 	TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
    102   1.1     kamil }
    103   1.6    mgorny 
    104   1.1     kamil #define ATF_TP_ADD_TCS_PTRACE_WAIT_I386() \
    105  1.10    mgorny 	ATF_TP_ADD_TC_HAVE_GPREGS(tp, i386_regs1);
    106   1.1     kamil #else
    107   1.1     kamil #define ATF_TP_ADD_TCS_PTRACE_WAIT_I386()
    108   1.1     kamil #endif
    109