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