psmisc/psmisc-22.13-ppc64.patch

54 lines
1.8 KiB
Diff

diff --git a/src/peekfd.c b/src/peekfd.c
index 6d759b9..c4a3474 100644
--- a/src/peekfd.c
+++ b/src/peekfd.c
@@ -55,6 +55,9 @@
#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
#elif defined(ARM)
#ifndef __ARM_EABI__
#error arm oabi not supported
@@ -73,9 +76,6 @@
#define REG_PARAM1 regs[4]
#define REG_PARAM2 regs[5]
#define REG_PARAM3 regs[6]
-#ifndef PT_ORIG_R3
- #define PT_ORIG_R3 34
-#endif
#endif
#define MAX_ATTACHED_PIDS 1024
@@ -222,11 +222,11 @@ int main(int argc, char **argv)
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);
+ regs.gpr[0] = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_R0, 0);
+ regs.gpr[3] = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_R3, 0);
+ regs.gpr[4] = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_R4, 0);
+ regs.gpr[5] = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_R5, 0);
+ regs.orig_gpr3 = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_ORIG_R3, 0);
#elif defined(ARM)
struct pt_regs regs;
ptrace(PTRACE_GETREGS, pid, 0, &regs);
@@ -271,7 +271,11 @@ int main(int argc, char **argv)
for (i = 0; i < regs.REG_PARAM3; i++) {
#ifdef _BIG_ENDIAN
+#if __WORDSIZE == 64
+ unsigned int a = bswap_64(ptrace(PTRACE_PEEKTEXT, pid, regs.REG_PARAM2 + i, 0));
+#else
unsigned int a = bswap_32(ptrace(PTRACE_PEEKTEXT, pid, regs.REG_PARAM2 + i, 0));
+#endif
#else
unsigned int a = ptrace(PTRACE_PEEKTEXT, pid, regs.REG_PARAM2 + i, 0);
#endif