Blame SOURCES/valgrind-3.14.0-ppc64-ptrace.patch

560544
commit 3967a99c26e8b314634a6b1fd8927cbb2bb5d060
560544
Author: Mark Wielaard <mark@klomp.org>
560544
Date:   Wed Dec 12 14:11:29 2018 +0100
560544
560544
    Implement minimal ptrace support for ppc64[le]-linux.
560544
560544
diff --git a/coregrind/m_syswrap/syswrap-ppc64-linux.c b/coregrind/m_syswrap/syswrap-ppc64-linux.c
560544
index 6549dd1..0fdcc8e 100644
560544
--- a/coregrind/m_syswrap/syswrap-ppc64-linux.c
560544
+++ b/coregrind/m_syswrap/syswrap-ppc64-linux.c
560544
@@ -388,6 +388,7 @@ DECL_TEMPLATE(ppc64_linux, sys_mmap);
560544
 //zz DECL_TEMPLATE(ppc64_linux, sys_sigreturn);
560544
 DECL_TEMPLATE(ppc64_linux, sys_rt_sigreturn);
560544
 DECL_TEMPLATE(ppc64_linux, sys_fadvise64);
560544
+DECL_TEMPLATE(ppc64_linux, sys_ptrace);
560544
 
560544
 PRE(sys_mmap)
560544
 {
560544
@@ -511,6 +512,72 @@ PRE(sys_rt_sigreturn)
560544
    *flags |= SfPollAfter;
560544
 }
560544
 
560544
+// ARG3 is only used for pointers into the traced process's address
560544
+// space and for offsets into the traced process's struct
560544
+// user_regs_struct. It is never a pointer into this process's memory
560544
+// space, and we should therefore not check anything it points to.
560544
+// powerpc does have other ways to get/set registers, we only support
560544
+// GET/SETREGSET for now.
560544
+PRE(sys_ptrace)
560544
+{
560544
+   PRINT("sys_ptrace ( %ld, %ld, %#lx, %#lx )", ARG1,ARG2,ARG3,ARG4);
560544
+   PRE_REG_READ4(int, "ptrace",
560544
+                 long, request, long, pid, long, addr, long, data);
560544
+   switch (ARG1) {
560544
+   case VKI_PTRACE_PEEKTEXT:
560544
+   case VKI_PTRACE_PEEKDATA:
560544
+   case VKI_PTRACE_PEEKUSR:
560544
+      PRE_MEM_WRITE( "ptrace(peek)", ARG4,
560544
+                     sizeof (long));
560544
+      break;
560544
+   case VKI_PTRACE_GETEVENTMSG:
560544
+      PRE_MEM_WRITE( "ptrace(geteventmsg)", ARG4, sizeof(unsigned long));
560544
+      break;
560544
+   case VKI_PTRACE_GETSIGINFO:
560544
+      PRE_MEM_WRITE( "ptrace(getsiginfo)", ARG4, sizeof(vki_siginfo_t));
560544
+      break;
560544
+   case VKI_PTRACE_SETSIGINFO:
560544
+      PRE_MEM_READ( "ptrace(setsiginfo)", ARG4, sizeof(vki_siginfo_t));
560544
+      break;
560544
+   case VKI_PTRACE_GETREGSET:
560544
+      ML_(linux_PRE_getregset)(tid, ARG3, ARG4);
560544
+      break;
560544
+   case VKI_PTRACE_SETREGSET:
560544
+      ML_(linux_PRE_setregset)(tid, ARG3, ARG4);
560544
+      break;
560544
+   default:
560544
+      break;
560544
+   }
560544
+}
560544
+
560544
+POST(sys_ptrace)
560544
+{
560544
+   switch (ARG1) {
560544
+   case VKI_PTRACE_TRACEME:
560544
+      ML_(linux_POST_traceme)(tid);
560544
+      break;
560544
+   case VKI_PTRACE_PEEKTEXT:
560544
+   case VKI_PTRACE_PEEKDATA:
560544
+   case VKI_PTRACE_PEEKUSR:
560544
+      POST_MEM_WRITE( ARG4, sizeof (long));
560544
+      break;
560544
+   case VKI_PTRACE_GETEVENTMSG:
560544
+      POST_MEM_WRITE( ARG4, sizeof(unsigned long));
560544
+      break;
560544
+   case VKI_PTRACE_GETSIGINFO:
560544
+      /* XXX: This is a simplification. Different parts of the
560544
+       * siginfo_t are valid depending on the type of signal.
560544
+       */
560544
+      POST_MEM_WRITE( ARG4, sizeof(vki_siginfo_t));
560544
+      break;
560544
+   case VKI_PTRACE_GETREGSET:
560544
+      ML_(linux_POST_getregset)(tid, ARG3, ARG4);
560544
+      break;
560544
+   default:
560544
+      break;
560544
+   }
560544
+}
560544
+
560544
 #undef PRE
560544
 #undef POST
560544
 
560544
@@ -562,8 +629,7 @@ static SyscallTableEntry syscall_table[] = {
560544
    GENX_(__NR_getuid,            sys_getuid),             //  24
560544
 
560544
 // _____(__NR_stime,             sys_stime),              //  25
560544
-// When ptrace is supported, memcheck/tests/linux/getregset should be enabled
560544
-// _____(__NR_ptrace,            sys_ptrace),             //  26
560544
+   PLAXY(__NR_ptrace,            sys_ptrace),             //  26
560544
    GENX_(__NR_alarm,             sys_alarm),              //  27
560544
 // _____(__NR_oldfstat,          sys_oldfstat),           //  28
560544
    GENX_(__NR_pause,             sys_pause),              //  29
560544
diff --git a/memcheck/tests/linux/getregset.vgtest b/memcheck/tests/linux/getregset.vgtest
560544
index 4c66108..c35be4c 100644
560544
--- a/memcheck/tests/linux/getregset.vgtest
560544
+++ b/memcheck/tests/linux/getregset.vgtest
560544
@@ -1,4 +1,4 @@
560544
 prog: getregset
560544
 vgopts: -q
560544
-prereq: ((../../../tests/os_test linux 2.6.33 && ! ../../../tests/arch_test mips32) || ../../../tests/os_test linux 3.10.0 ) && ! ../../../tests/arch_test ppc64
560544
+prereq: ((../../../tests/os_test linux 2.6.33 && ! ../../../tests/arch_test mips32) || ../../../tests/os_test linux 3.10.0 )
560544