From 84a5ca8d8e06059e31984d023dad57b91ea618fd Mon Sep 17 00:00:00 2001 From: Craig Small Date: Wed, 4 Jul 2007 02:25:00 +0000 Subject: [PATCH] ppc patch for peekfd --- ChangeLog | 3 +++ configure.ac | 5 +++++ src/Makefile.am | 4 ++++ src/peekfd.c | 25 ++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5a73d66..04df2ab 100644 --- 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 diff --git a/configure.ac b/configure.ac index 98d567f..0bd43f3 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ]) +AC_CHECK_MEMBERS([struct pt_regs.orig_gpr3, + struct pt_regs.gpr], [],[], [#include ]) 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]) diff --git a/src/Makefile.am b/src/Makefile.am index 22cb39c..8eb661b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/peekfd.c b/src/peekfd.c index cfcfb18..9262304 100644 --- a/src/peekfd.c +++ b/src/peekfd.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include #include @@ -46,6 +48,15 @@ #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, ®s); - +#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; -- 2.40.0