mirror of
https://sourceware.org/git/glibc.git
synced 2025-04-26 15:09:05 +03:00
This patch removes PTRACE_GETREGS, PTRACE_SETREGS, PTRACE_GETFPREGS and PTRACE_SETFPREGS as these requests does not exist on s390 kernel. But the kernel has support for PTRACE_SINGLEBLOCK, PTRACE_SECCOMP_GET_FILTER, PTRACE_PEEKUSR_AREA, PTRACE_POKEUSR_AREA, PTRACE_GET_LAST_BREAK, PTRACE_ENABLE_TE, PTRACE_DISABLE_TE and PTRACE_TE_ABORT_RAND. Thus those are defined now. The current kernel s390 specific ptrace.h file also defines PTRACE_PEEKTEXT_AREA, PTRACE_PEEKDATA_AREA, PTRACE_POKETEXT_AREA, PTRACE_POKEDATA_AREA, PTRACE_PEEK_SYSTEM_CALL, PTRACE_POKE_SYSTEM_CALL and PTRACE_PROT, but those requests are not supported. Thus those defines are skipped in glibc ptrace.h. There were old includes of ptrace.h in sysdeps/s390/fpu/fesetenv.c. The ptrace feature isn't used there anymore, thus I removed the includes. Before this patch, <glibc>/sysdeps/unix/sysv/linux/s390/sys/ptrace.h uses ptrace-request 12 for PTRACE_GETREGS, but <kernel>/include/uapi/linux/ptrace.h uses 12 for PTRACE_SINGLEBLOCK. The s390 kernel has never had support for PTRACE_GETREGS! Thus glibc ptrace.h is adjusted to match kernel ptrace.h. The new s390 specific test ensures, that PTRACE_SINGLEBLOCK defined in glibc works as expected. If the kernel would interpret it as PTRACE_GETREGS, then the testcase will not make any progress and will time out. ChangeLog: [BZ #21539] * NEWS: Mention s390 ptrace request changes. * sysdeps/unix/sysv/linux/s390/sys/ptrace.h (PTRACE_GETREGS, PTRACE_SETREGS, PTRACE_GETFPREGS, PTRACE_SETFPREGS): Remove enum constant. (PT_GETREGS, PT_SETREGS, PT_GETFPREGS, T_SETFPREGS): Remove defines. (PTRACE_SINGLEBLOCK): New enum constant. (PT_STEPBLOCK): New define. (PTRACE_PEEKUSR_AREA, PTRACE_POKEUSR_AREA, PTRACE_GET_LAST_BREAK, PTRACE_ENABLE_TE, PTRACE_DISABLE_TE, PTRACE_TE_ABORT_RAND): New enum constant and define. * sysdeps/s390/fpu/fesetenv.c: Remove ptrace.h includes. * sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c: New file. * sysdeps/unix/sysv/linux/s390/Makefile: Add test.
129 lines
3.8 KiB
C
129 lines
3.8 KiB
C
/* Testing s390x PTRACE_SINGLEBLOCK ptrace request.
|
|
Copyright (C) 2017 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
#include <sys/types.h>
|
|
#include <sys/uio.h>
|
|
#include <elf.h>
|
|
#include <support/xunistd.h>
|
|
#include <support/check.h>
|
|
|
|
/* Ensure that we use the PTRACE_SINGLEBLOCK definition from glibc ptrace.h
|
|
in tracer_func. We need the kernel ptrace.h for structs ptrace_area
|
|
and gregset_t. */
|
|
#include <sys/ptrace.h>
|
|
static const enum __ptrace_request req_singleblock = PTRACE_SINGLEBLOCK;
|
|
#include <asm/ptrace.h>
|
|
|
|
static void
|
|
tracee_func (int pid)
|
|
{
|
|
/* Dump the mapping information for manual inspection of the printed
|
|
tracee addresses. */
|
|
char str[80];
|
|
sprintf (str, "cat /proc/%d/maps", pid);
|
|
puts (str);
|
|
system (str);
|
|
fflush (stdout);
|
|
|
|
TEST_VERIFY_EXIT (ptrace (PTRACE_TRACEME) == 0);
|
|
/* Stop tracee. Afterwards the tracer_func can operate. */
|
|
kill (pid, SIGSTOP);
|
|
|
|
puts ("The PTRACE_SINGLEBLOCK of the tracer will stop after: "
|
|
"brasl %r14,<puts@plt>!");
|
|
}
|
|
|
|
static void
|
|
tracer_func (int pid)
|
|
{
|
|
unsigned long last_break;
|
|
ptrace_area parea;
|
|
gregset_t regs;
|
|
struct iovec parea2;
|
|
gregset_t regs2;
|
|
|
|
int status;
|
|
|
|
while (1)
|
|
{
|
|
/* Wait for the tracee to be stopped or exited. */
|
|
wait (&status);
|
|
if (WIFEXITED (status))
|
|
break;
|
|
|
|
/* Get information about tracee: gprs, last breaking address. */
|
|
parea.len = sizeof (regs);
|
|
parea.process_addr = (unsigned long) ®s;
|
|
parea.kernel_addr = 0;
|
|
TEST_VERIFY_EXIT (ptrace (PTRACE_PEEKUSR_AREA, pid, &parea) == 0);
|
|
TEST_VERIFY_EXIT (ptrace (PTRACE_GET_LAST_BREAK, pid, NULL, &last_break)
|
|
== 0);
|
|
|
|
parea2.iov_len = sizeof (regs2);
|
|
parea2.iov_base = ®s2;
|
|
TEST_VERIFY_EXIT (ptrace (PTRACE_GETREGSET, pid, NT_PRSTATUS, &parea2)
|
|
== 0);
|
|
TEST_VERIFY_EXIT (parea2.iov_len == sizeof (regs2));
|
|
|
|
/* Test if gprs obtained by PTRACE_PEEKUSR_AREA and PTRACE_GETREGESET
|
|
have the same values. */
|
|
TEST_VERIFY_EXIT (memcmp (®s, ®s2, sizeof (regs)) == 0);
|
|
|
|
printf ("child IA: %p last_break: %p\n",
|
|
(void *) regs[1], (void *) last_break);
|
|
|
|
/* Execute tracee until next taken branch.
|
|
|
|
Note:
|
|
Before the commit which introduced this testcase,
|
|
<glibc>/sysdeps/unix/sysv/linux/s390/sys/ptrace.h
|
|
uses ptrace-request 12 for PTRACE_GETREGS,
|
|
but <kernel>/include/uapi/linux/ptrace.h
|
|
uses 12 for PTRACE_SINGLEBLOCK.
|
|
|
|
The s390 kernel has no support for PTRACE_GETREGS!
|
|
Thus glibc ptrace.h is adjusted to match kernel ptrace.h.
|
|
|
|
This test ensures, that PTRACE_SINGLEBLOCK defined in glibc
|
|
works as expected. If the kernel would interpret it as
|
|
PTRACE_GETREGS, then the tracee will not make any progress
|
|
and this testcase will time out. */
|
|
TEST_VERIFY_EXIT (ptrace (req_singleblock, pid, NULL, NULL) == 0);
|
|
}
|
|
}
|
|
|
|
static int
|
|
do_test (void)
|
|
{
|
|
int pid;
|
|
pid = xfork ();
|
|
if (pid)
|
|
tracer_func (pid);
|
|
else
|
|
tracee_func (getpid ());
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
#include <support/test-driver.c>
|