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