]> granicus.if.org Git - psmisc/commitdiff
ppc patch for peekfd
authorCraig Small <csmall@users.sourceforge.net>
Wed, 4 Jul 2007 02:25:00 +0000 (02:25 +0000)
committerCraig Small <csmall@users.sourceforge.net>
Wed, 4 Jul 2007 02:25:00 +0000 (02:25 +0000)
ChangeLog
configure.ac
src/Makefile.am
src/peekfd.c

index 5a73d667de3282016a472bda04f519f6e566cfda..04df2ab9127141606aa705b32e19667192b3bf46 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 Changes in ??
 =============
+2007-07-04 Tomas Smetana
+       * Added support for PPC architecture for peekfd
+
 2007-06-25 Craig Small
        * Updated the Chinese simplified po file
 
index 98d567f254eaf5efa69b846db92ce0e65058f986..0bd43f346e120b9b27bcac038fbd31ec2ea70bb8 100644 (file)
@@ -68,6 +68,8 @@ AC_CHECK_MEMBERS([struct user_regs_struct.orig_eax,
                struct user_regs_struct.rdi,
                struct user_regs_struct.rsi,
                struct user_regs_struct.rdx], [],[], [#include <linux/user.h>])
+AC_CHECK_MEMBERS([struct pt_regs.orig_gpr3,
+               struct pt_regs.gpr], [],[], [#include <linux/ptrace.h>])
 AM_CONDITIONAL(WANT_PEEKFD_I386,
  test $ac_cv_member_struct_user_regs_struct_orig_eax = yes &&
    test $ac_cv_member_struct_user_regs_struct_eax = yes &&
@@ -80,6 +82,9 @@ AM_CONDITIONAL(WANT_PEEKFD_X86_64,
    test $ac_cv_member_struct_user_regs_struct_rdi = yes &&
    test $ac_cv_member_struct_user_regs_struct_rsi = yes &&
    test $ac_cv_member_struct_user_regs_struct_rdx = yes )
+AM_CONDITIONAL(WANT_PEEKFD_PPC,
+   test $ac_cv_member_struct_pt_regs_orig_gpr3 = yes &&
+   test $ac_cv_member_struct_pt_regs_gpr = yes )
 
 dnl Check for language stuff
 AM_GNU_GETTEXT([external])
index 22cb39cdb887b13f4ec0ac89201cd14fc460f4cb..8eb661b4fc0b658c7742d8ab8f8c089c5c983dfa 100644 (file)
@@ -10,6 +10,10 @@ if WANT_PEEKFD_X86_64
   bin_PROGRAMS += peekfd
   AM_CFLAGS += -DX86_64
 endif
+if WANT_PEEKFD_PPC
+  bin_PROGRAMS += peekfd
+  AM_CFLAGS += -DPPC
+endif
 
 oldfuser_SOURCES = oldfuser.c comm.h signals.c signals.h loop.h i18n.h
 
index cfcfb1893fe35a9ee881144f9e600fc2ecefe573..9262304c98523078c7fa1b4134d2bc4e952db71e 100644 (file)
@@ -27,6 +27,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/syscall.h>
+#include <byteswap.h>
+#include <endian.h>
 #include <linux/user.h>
 #include <stdlib.h>
 #include <getopt.h>
        #define REG_PARAM1 rdi
        #define REG_PARAM2 rsi
        #define REG_PARAM3 rdx
+#elif PPC
+       #define REG_ORIG_ACCUM gpr[0]
+       #define REG_ACCUM gpr[3]
+       #define REG_PARAM1 orig_gpr3
+       #define REG_PARAM2 gpr[4]
+       #define REG_PARAM3 gpr[5]
+#ifndef PT_ORIG_R3
+       #define PT_ORIG_R3 34
+#endif
 #endif
 
 #define MAX_ATTACHED_PIDS 1024
@@ -188,9 +199,17 @@ int main(int argc, char **argv)
                int status;
                int pid = wait(&status);
                if (WIFSTOPPED(status)) {
+#ifdef PPC
+                       struct pt_regs regs;
+                       regs.gpr[0] = ptrace(PTRACE_PEEKUSER, pid, 4 * PT_R0, 0);
+                       regs.gpr[3] = ptrace(PTRACE_PEEKUSER, pid, 4 * PT_R3, 0);
+                       regs.gpr[4] = ptrace(PTRACE_PEEKUSER, pid, 4 * PT_R4, 0);
+                       regs.gpr[5] = ptrace(PTRACE_PEEKUSER, pid, 4 * PT_R5, 0);
+                       regs.orig_gpr3 = ptrace(PTRACE_PEEKUSER, pid, 4 * PT_ORIG_R3, 0);
+#else
                        struct user_regs_struct regs;
                        ptrace(PTRACE_GETREGS, pid, 0, &regs);
-               
+#endif         
                        /*unsigned int b = ptrace(PTRACE_PEEKTEXT, pid, regs.eip, 0);*/
                        if (follow_forks && (regs.REG_ORIG_ACCUM == SYS_fork || regs.REG_ORIG_ACCUM == SYS_clone)) {
                                if (regs.REG_ACCUM > 0)
@@ -219,7 +238,11 @@ int main(int argc, char **argv)
                                                }
 
                                                for (i = 0; i < regs.REG_PARAM3; i++) {
+#ifdef _BIG_ENDIAN
+                                                       unsigned int a = bswap_32(ptrace(PTRACE_PEEKTEXT, pid, regs.REG_PARAM2 + i, 0));
+#else
                                                        unsigned int a = ptrace(PTRACE_PEEKTEXT, pid, regs.REG_PARAM2 + i, 0);
+#endif
                                                        if (remove_duplicates)
                                                                lastbuf[i] = a & 0xff;