powerpc: fix sysconf support for cache geometries
[glibc.git] / sysdeps / unix / sysv / linux / s390 / tst-ptrace-singleblock.c
blob95a2f55612088ce0266a3df5e9e7eacbe6034f6b
1 /* Testing s390x PTRACE_SINGLEBLOCK ptrace request.
2 Copyright (C) 2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <sys/wait.h>
24 #include <sys/types.h>
25 #include <sys/uio.h>
26 #include <elf.h>
27 #include <support/xunistd.h>
28 #include <support/check.h>
30 /* Ensure that we use the PTRACE_SINGLEBLOCK definition from glibc ptrace.h
31 in tracer_func. We need the kernel ptrace.h for structs ptrace_area
32 and gregset_t. */
33 #include <sys/ptrace.h>
34 static const enum __ptrace_request req_singleblock = PTRACE_SINGLEBLOCK;
35 #include <asm/ptrace.h>
37 static void
38 tracee_func (int pid)
40 /* Dump the mapping information for manual inspection of the printed
41 tracee addresses. */
42 char str[80];
43 sprintf (str, "cat /proc/%d/maps", pid);
44 puts (str);
45 system (str);
46 fflush (stdout);
48 TEST_VERIFY_EXIT (ptrace (PTRACE_TRACEME) == 0);
49 /* Stop tracee. Afterwards the tracer_func can operate. */
50 kill (pid, SIGSTOP);
52 puts ("The PTRACE_SINGLEBLOCK of the tracer will stop after: "
53 "brasl %r14,<puts@plt>!");
56 static void
57 tracer_func (int pid)
59 unsigned long last_break;
60 ptrace_area parea;
61 gregset_t regs;
62 struct iovec parea2;
63 gregset_t regs2;
65 int status;
67 while (1)
69 /* Wait for the tracee to be stopped or exited. */
70 wait (&status);
71 if (WIFEXITED (status))
72 break;
74 /* Get information about tracee: gprs, last breaking address. */
75 parea.len = sizeof (regs);
76 parea.process_addr = (unsigned long) &regs;
77 parea.kernel_addr = 0;
78 TEST_VERIFY_EXIT (ptrace (PTRACE_PEEKUSR_AREA, pid, &parea) == 0);
79 TEST_VERIFY_EXIT (ptrace (PTRACE_GET_LAST_BREAK, pid, NULL, &last_break)
80 == 0);
82 parea2.iov_len = sizeof (regs2);
83 parea2.iov_base = &regs2;
84 TEST_VERIFY_EXIT (ptrace (PTRACE_GETREGSET, pid, NT_PRSTATUS, &parea2)
85 == 0);
86 TEST_VERIFY_EXIT (parea2.iov_len == sizeof (regs2));
88 /* Test if gprs obtained by PTRACE_PEEKUSR_AREA and PTRACE_GETREGESET
89 have the same values. */
90 TEST_VERIFY_EXIT (memcmp (&regs, &regs2, sizeof (regs)) == 0);
92 printf ("child IA: %p last_break: %p\n",
93 (void *) regs[1], (void *) last_break);
95 /* Execute tracee until next taken branch.
97 Note:
98 Before the commit which introduced this testcase,
99 <glibc>/sysdeps/unix/sysv/linux/s390/sys/ptrace.h
100 uses ptrace-request 12 for PTRACE_GETREGS,
101 but <kernel>/include/uapi/linux/ptrace.h
102 uses 12 for PTRACE_SINGLEBLOCK.
104 The s390 kernel has no support for PTRACE_GETREGS!
105 Thus glibc ptrace.h is adjusted to match kernel ptrace.h.
107 This test ensures, that PTRACE_SINGLEBLOCK defined in glibc
108 works as expected. If the kernel would interpret it as
109 PTRACE_GETREGS, then the tracee will not make any progress
110 and this testcase will time out. */
111 TEST_VERIFY_EXIT (ptrace (req_singleblock, pid, NULL, NULL) == 0);
115 static int
116 do_test (void)
118 int pid;
119 pid = xfork ();
120 if (pid)
121 tracer_func (pid);
122 else
123 tracee_func (getpid ());
125 return EXIT_SUCCESS;
128 #include <support/test-driver.c>