syscall.c: split arch specific code into separate arch files
Split code that use arch-specific registers to separate arch files.
* syscall.c: Move definitions of variables containing fetched registers
to linux/*/arch_regs.c files.
[HAVE_GETRVAL2] (getrval2): Move arch-specific code
to linux/*/arch_getrval2.c, include "arch_getrval2.c".
(print_pc): Move arch-specific code to linux/*/print_pc.c files,
include "print_pc.c".
[X86_64] (x86_64_getregs_old): Rename to getregs_old, move to
linux/x86_64/getregs_old.c, include "getregs_old.c".
[POWERPC] (powerpc_getregs_old): Rename to getregs_old, move to
linux/powerpc/getregs_old.c, include "getregs_old.c".
(get_regs) [X86_64, POWERPC]: Update callers.
(get_scno): Move arch-specific code to linux/*/get_scno.c,
include "get_scno.c".
(get_syscall_args): Move arch-specific code
to linux/*/get_syscall_args.c, include "get_syscall_args.c".
(get_error): Move arch-specific code to linux/*/get_error.c,
include "get_error.c".
(get_syscall_result): Move arch-specific code
to linux/*/get_syscall_result.c, include "get_syscall_result.c".
* Makefile.am (EXTRA_DIST): Add new linux/*/*.c files.
diff --git a/Makefile.am b/Makefile.am
index 48fe1d7..27b6a12 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -164,77 +164,161 @@
linux/32/syscallent.h \
linux/64/ioctls_inc.h \
linux/64/syscallent.h \
+ linux/aarch64/arch_regs.c \
linux/aarch64/arch_regs.h \
linux/aarch64/errnoent1.h \
+ linux/aarch64/get_error.c \
+ linux/aarch64/get_scno.c \
+ linux/aarch64/get_syscall_args.c\
linux/aarch64/ioctls_arch0.h \
linux/aarch64/ioctls_arch1.h \
linux/aarch64/ioctls_inc0.h \
linux/aarch64/ioctls_inc1.h \
+ linux/aarch64/print_pc.c \
linux/aarch64/signalent1.h \
linux/aarch64/syscallent.h \
linux/aarch64/syscallent1.h \
+ linux/alpha/arch_getrval2.c \
+ linux/alpha/arch_regs.c \
linux/alpha/arch_regs.h \
linux/alpha/errnoent.h \
+ linux/alpha/get_error.c \
+ linux/alpha/get_scno.c \
+ linux/alpha/get_syscall_args.c \
+ linux/alpha/get_syscall_result.c\
linux/alpha/ioctls_arch0.h \
linux/alpha/ioctls_inc0.h \
+ linux/alpha/print_pc.c \
linux/alpha/signalent.h \
linux/alpha/syscallent.h \
linux/alpha/userent.h \
+ linux/arc/arch_regs.c \
+ linux/arc/get_error.c \
+ linux/arc/get_scno.c \
+ linux/arc/get_syscall_args.c \
linux/arc/ioctls_arch0.h \
linux/arc/ioctls_inc0.h \
+ linux/arc/print_pc.c \
linux/arc/syscallent.h \
linux/arch_regs.h \
+ linux/arm/arch_regs.c \
linux/arm/arch_regs.h \
+ linux/arm/get_error.c \
+ linux/arm/get_scno.c \
+ linux/arm/get_syscall_args.c \
linux/arm/ioctls_arch0.h \
linux/arm/ioctls_inc0.h \
+ linux/arm/print_pc.c \
linux/arm/syscallent.h \
linux/arm/userent.h \
+ linux/avr32/arch_regs.c \
+ linux/avr32/get_error.c \
+ linux/avr32/get_scno.c \
+ linux/avr32/get_syscall_args.c \
linux/avr32/ioctls_arch0.h \
linux/avr32/ioctls_inc0.h \
+ linux/avr32/print_pc.c \
linux/avr32/syscallent.h \
linux/avr32/userent.h \
+ linux/bfin/arch_regs.c \
+ linux/bfin/get_error.c \
+ linux/bfin/get_scno.c \
+ linux/bfin/get_syscall_args.c \
+ linux/bfin/get_syscall_result.c \
linux/bfin/ioctls_arch0.h \
linux/bfin/ioctls_inc0.h \
+ linux/bfin/print_pc.c \
linux/bfin/syscallent.h \
linux/bfin/userent.h \
+ linux/crisv10/arch_regs.c \
+ linux/crisv10/get_error.c \
+ linux/crisv10/get_scno.c \
+ linux/crisv10/get_syscall_args.c \
+ linux/crisv10/get_syscall_result.c \
+ linux/crisv10/print_pc.c \
linux/crisv10/userent.h \
+ linux/crisv32/arch_regs.c \
+ linux/crisv32/get_error.c \
+ linux/crisv32/get_scno.c \
+ linux/crisv32/get_syscall_args.c \
+ linux/crisv32/get_syscall_result.c \
+ linux/crisv32/print_pc.c \
linux/crisv32/userent.h \
linux/dummy.h \
linux/errnoent.h \
+ linux/hppa/arch_regs.c \
linux/hppa/arch_regs.h \
linux/hppa/errnoent.h \
+ linux/hppa/get_error.c \
+ linux/hppa/get_scno.c \
+ linux/hppa/get_syscall_args.c \
+ linux/hppa/get_syscall_result.c \
linux/hppa/ioctls_arch0.h \
linux/hppa/ioctls_inc0.h \
+ linux/hppa/print_pc.c \
linux/hppa/signalent.h \
linux/hppa/syscallent.h \
+ linux/i386/arch_regs.c \
linux/i386/arch_regs.h \
+ linux/i386/get_error.c \
+ linux/i386/get_scno.c \
+ linux/i386/get_syscall_args.c \
linux/i386/ioctls_arch0.h \
linux/i386/ioctls_inc0.h \
+ linux/i386/print_pc.c \
linux/i386/syscallent.h \
linux/i386/userent.h \
linux/i386/userent0.h \
+ linux/ia64/arch_getrval2.c \
+ linux/ia64/arch_regs.c \
linux/ia64/arch_regs.h \
+ linux/ia64/get_error.c \
+ linux/ia64/get_scno.c \
+ linux/ia64/get_syscall_args.c \
linux/ia64/ioctls_arch0.h \
linux/ia64/ioctls_inc0.h \
+ linux/ia64/print_pc.c \
linux/ia64/syscallent.h \
linux/ia64/userent.h \
linux/inet_diag.h \
+ linux/m68k/arch_regs.c \
+ linux/m68k/get_error.c \
+ linux/m68k/get_scno.c \
+ linux/m68k/get_syscall_args.c \
+ linux/m68k/get_syscall_result.c \
linux/m68k/ioctls_arch0.h \
linux/m68k/ioctls_inc0.h \
+ linux/m68k/print_pc.c \
linux/m68k/syscallent.h \
linux/m68k/userent.h \
+ linux/metag/arch_regs.c \
+ linux/metag/get_error.c \
+ linux/metag/get_scno.c \
+ linux/metag/get_syscall_args.c \
linux/metag/ioctls_arch0.h \
linux/metag/ioctls_inc0.h \
+ linux/metag/print_pc.c \
linux/metag/syscallent.h \
+ linux/microblaze/arch_regs.c \
+ linux/microblaze/get_error.c \
+ linux/microblaze/get_scno.c \
+ linux/microblaze/get_syscall_args.c \
+ linux/microblaze/get_syscall_result.c \
linux/microblaze/ioctls_arch0.h \
linux/microblaze/ioctls_inc0.h \
+ linux/microblaze/print_pc.c \
linux/microblaze/syscallent.h \
linux/microblaze/userent.h \
+ linux/mips/arch_regs.c \
linux/mips/arch_regs.h \
linux/mips/errnoent.h \
linux/mips/genstub.sh \
+ linux/mips/get_error.c \
+ linux/mips/get_scno.c \
+ linux/mips/get_syscall_args.c \
linux/mips/ioctls_arch0.h \
linux/mips/ioctls_inc0.h \
+ linux/mips/print_pc.c \
linux/mips/signalent.h \
linux/mips/syscallent-compat.h \
linux/mips/syscallent-n32.h \
@@ -243,77 +327,129 @@
linux/mips/syscallent.h \
linux/mips/userent.h \
linux/mtd-abi.h \
+ linux/or1k/arch_regs.c \
+ linux/or1k/get_error.c \
+ linux/or1k/get_scno.c \
+ linux/or1k/get_syscall_args.c \
linux/or1k/ioctls_arch0.h \
linux/or1k/ioctls_inc0.h \
+ linux/or1k/print_pc.c \
linux/or1k/syscallent.h \
linux/or1k/userent.h \
linux/personality.h \
+ linux/powerpc/arch_regs.c \
linux/powerpc/arch_regs.h \
linux/powerpc/errnoent.h \
+ linux/powerpc/get_error.c \
+ linux/powerpc/get_scno.c \
+ linux/powerpc/get_syscall_args.c \
+ linux/powerpc/getregs_old.c \
linux/powerpc/ioctls_arch0.h \
linux/powerpc/ioctls_inc0.h \
+ linux/powerpc/print_pc.c \
linux/powerpc/syscallent.h \
linux/powerpc/userent.h \
+ linux/powerpc64/arch_regs.c \
linux/powerpc64/arch_regs.h \
linux/powerpc64/errnoent.h \
linux/powerpc64/errnoent1.h \
+ linux/powerpc64/get_error.c \
+ linux/powerpc64/get_scno.c \
+ linux/powerpc64/get_syscall_args.c \
+ linux/powerpc64/getregs_old.c \
linux/powerpc64/ioctls_arch0.h \
linux/powerpc64/ioctls_arch1.h \
linux/powerpc64/ioctls_inc0.h \
linux/powerpc64/ioctls_inc1.h \
+ linux/powerpc64/print_pc.c \
linux/powerpc64/signalent1.h \
linux/powerpc64/syscallent.h \
linux/powerpc64/syscallent1.h \
linux/powerpc64/userent.h \
linux/ptp_clock.h \
+ linux/s390/arch_regs.c \
linux/s390/arch_regs.h \
+ linux/s390/get_error.c \
+ linux/s390/get_scno.c \
+ linux/s390/get_syscall_args.c \
linux/s390/ioctls_arch0.h \
linux/s390/ioctls_inc0.h \
+ linux/s390/print_pc.c \
linux/s390/syscallent.h \
linux/s390/userent.h \
linux/s390/userent0.h \
linux/s390/userent1.h \
+ linux/s390x/arch_regs.c \
linux/s390x/arch_regs.h \
+ linux/s390x/get_error.c \
+ linux/s390x/get_scno.c \
+ linux/s390x/get_syscall_args.c \
linux/s390x/ioctls_arch0.h \
linux/s390x/ioctls_inc0.h \
+ linux/s390x/print_pc.c \
linux/s390x/syscallent.h \
linux/s390x/userent.h \
+ linux/sh/arch_getrval2.c \
+ linux/sh/arch_regs.c \
+ linux/sh/get_error.c \
+ linux/sh/get_scno.c \
+ linux/sh/get_syscall_args.c \
+ linux/sh/get_syscall_result.c \
linux/sh/ioctls_arch0.h \
linux/sh/ioctls_inc0.h \
+ linux/sh/print_pc.c \
linux/sh/syscallent.h \
linux/sh/userent.h \
linux/sh/userent0.h \
+ linux/sh64/arch_regs.c \
linux/sh64/arch_regs.h \
+ linux/sh64/get_error.c \
+ linux/sh64/get_scno.c \
+ linux/sh64/get_syscall_args.c \
+ linux/sh64/get_syscall_result.c \
linux/sh64/ioctls_arch0.h \
linux/sh64/ioctls_inc0.h \
+ linux/sh64/print_pc.c \
linux/sh64/syscallent.h \
linux/sh64/userent.h \
linux/signalent.h \
linux/sock_diag.h \
+ linux/sparc/arch_getrval2.c \
+ linux/sparc/arch_regs.c \
linux/sparc/arch_regs.h \
linux/sparc/dummy2.h \
linux/sparc/errnoent.h \
linux/sparc/errnoent1.h \
linux/sparc/gen.pl \
+ linux/sparc/get_error.c \
+ linux/sparc/get_scno.c \
+ linux/sparc/get_syscall_args.c \
linux/sparc/ioctlent1.h \
linux/sparc/ioctls_arch0.h \
linux/sparc/ioctls_inc0.h \
+ linux/sparc/print_pc.c \
linux/sparc/signalent.h \
linux/sparc/signalent1.h \
linux/sparc/syscall1.h \
linux/sparc/syscallent.h \
linux/sparc/syscallent1.h \
linux/sparc/userent.h \
+ linux/sparc64/arch_getrval2.c \
+ linux/sparc64/arch_regs.c \
linux/sparc64/arch_regs.h \
linux/sparc64/dummy2.h \
linux/sparc64/errnoent.h \
linux/sparc64/errnoent1.h \
linux/sparc64/errnoent2.h \
+ linux/sparc64/get_error.c \
+ linux/sparc64/get_scno.c \
+ linux/sparc64/get_syscall_args.c\
linux/sparc64/ioctlent1.h \
linux/sparc64/ioctls_arch0.h \
linux/sparc64/ioctls_arch2.h \
linux/sparc64/ioctls_inc0.h \
linux/sparc64/ioctls_inc2.h \
+ linux/sparc64/print_pc.c \
linux/sparc64/signalent.h \
linux/sparc64/signalent1.h \
linux/sparc64/signalent2.h \
@@ -324,12 +460,17 @@
linux/sparc64/userent.h \
linux/subcall.h \
linux/syscall.h \
+ linux/tile/arch_regs.c \
linux/tile/arch_regs.h \
linux/tile/errnoent1.h \
+ linux/tile/get_error.c \
+ linux/tile/get_scno.c \
+ linux/tile/get_syscall_args.c \
linux/tile/ioctls_arch0.h \
linux/tile/ioctls_arch1.h \
linux/tile/ioctls_inc0.h \
linux/tile/ioctls_inc1.h \
+ linux/tile/print_pc.c \
linux/tile/signalent1.h \
linux/tile/syscallent.h \
linux/tile/syscallent1.h \
@@ -338,34 +479,51 @@
linux/unix_diag.h \
linux/userent.h \
linux/userent0.h \
+ linux/x32/arch_regs.c \
linux/x32/arch_regs.h \
linux/x32/errnoent1.h \
+ linux/x32/get_error.c \
+ linux/x32/get_scno.c \
+ linux/x32/get_syscall_args.c \
linux/x32/ioctls_arch0.h \
linux/x32/ioctls_arch1.h \
linux/x32/ioctls_inc0.h \
linux/x32/ioctls_inc1.h \
+ linux/x32/print_pc.c \
linux/x32/signalent1.h \
linux/x32/syscallent.h \
linux/x32/syscallent1.h \
linux/x32/userent.h \
+ linux/x86_64/arch_regs.c \
linux/x86_64/arch_regs.h \
linux/x86_64/errnoent1.h \
linux/x86_64/errnoent2.h \
linux/x86_64/gentab.pl \
+ linux/x86_64/get_error.c \
+ linux/x86_64/get_scno.c \
+ linux/x86_64/get_syscall_args.c \
+ linux/x86_64/getregs_old.c \
linux/x86_64/ioctls_arch0.h \
linux/x86_64/ioctls_arch1.h \
linux/x86_64/ioctls_arch2.h \
linux/x86_64/ioctls_inc0.h \
linux/x86_64/ioctls_inc1.h \
linux/x86_64/ioctls_inc2.h \
+ linux/x86_64/print_pc.c \
linux/x86_64/signalent1.h \
linux/x86_64/signalent2.h \
linux/x86_64/syscallent.h \
linux/x86_64/syscallent1.h \
linux/x86_64/syscallent2.h \
linux/x86_64/userent.h \
+ linux/xtensa/arch_regs.c \
+ linux/xtensa/get_error.c \
+ linux/xtensa/get_scno.c \
+ linux/xtensa/get_syscall_args.c \
+ linux/xtensa/get_syscall_result.c \
linux/xtensa/ioctls_arch0.h \
linux/xtensa/ioctls_inc0.h \
+ linux/xtensa/print_pc.c \
linux/xtensa/syscallent.h \
linux/xtensa/userent.h \
maint/ioctls_gen.sh \
diff --git a/linux/aarch64/arch_regs.c b/linux/aarch64/arch_regs.c
new file mode 100644
index 0000000..3b9c2f6
--- /dev/null
+++ b/linux/aarch64/arch_regs.c
@@ -0,0 +1,37 @@
+struct arm_pt_regs {
+ int uregs[18];
+};
+#define ARM_cpsr uregs[16]
+#define ARM_pc uregs[15]
+#define ARM_lr uregs[14]
+#define ARM_sp uregs[13]
+#define ARM_ip uregs[12]
+#define ARM_fp uregs[11]
+#define ARM_r10 uregs[10]
+#define ARM_r9 uregs[9]
+#define ARM_r8 uregs[8]
+#define ARM_r7 uregs[7]
+#define ARM_r6 uregs[6]
+#define ARM_r5 uregs[5]
+#define ARM_r4 uregs[4]
+#define ARM_r3 uregs[3]
+#define ARM_r2 uregs[2]
+#define ARM_r1 uregs[1]
+#define ARM_r0 uregs[0]
+#define ARM_ORIG_r0 uregs[17]
+
+static union {
+ struct user_pt_regs aarch64_r;
+ struct arm_pt_regs arm_r;
+} arm_regs_union;
+#define aarch64_regs arm_regs_union.aarch64_r
+#define arm_regs arm_regs_union.arm_r
+
+uint64_t *const aarch64_sp_ptr = (uint64_t *) &aarch64_regs.sp;
+uint32_t *const arm_sp_ptr = (uint32_t *) &arm_regs.ARM_sp;
+static struct iovec aarch64_io = {
+ .iov_base = &arm_regs_union
+};
+
+#define ARCH_REGS_FOR_GETREGSET arm_regs_union
+#define ARCH_IOVEC_FOR_GETREGSET aarch64_io
diff --git a/linux/aarch64/get_error.c b/linux/aarch64/get_error.c
new file mode 100644
index 0000000..7dd6779
--- /dev/null
+++ b/linux/aarch64/get_error.c
@@ -0,0 +1,10 @@
+if (tcp->currpers == 1) {
+ if (check_errno && is_negated_errno(aarch64_regs.regs[0])) {
+ tcp->u_rval = -1;
+ tcp->u_error = -aarch64_regs.regs[0];
+ } else {
+ tcp->u_rval = aarch64_regs.regs[0];
+ }
+} else {
+#include "arm/get_error.c"
+}
diff --git a/linux/aarch64/get_scno.c b/linux/aarch64/get_scno.c
new file mode 100644
index 0000000..610b38d
--- /dev/null
+++ b/linux/aarch64/get_scno.c
@@ -0,0 +1,14 @@
+switch (aarch64_io.iov_len) {
+ case sizeof(aarch64_regs):
+ /* We are in 64-bit mode */
+ scno = aarch64_regs.regs[8];
+ update_personality(tcp, 1);
+ break;
+ case sizeof(arm_regs):
+ /* We are in 32-bit mode */
+ /* Note: we don't support OABI, unlike 32-bit ARM build */
+ scno = arm_regs.ARM_r7;
+ scno = shuffle_scno(scno);
+ update_personality(tcp, 0);
+ break;
+}
diff --git a/linux/aarch64/get_syscall_args.c b/linux/aarch64/get_syscall_args.c
new file mode 100644
index 0000000..41ce8b4
--- /dev/null
+++ b/linux/aarch64/get_syscall_args.c
@@ -0,0 +1,10 @@
+if (tcp->currpers == 1) {
+ tcp->u_arg[0] = aarch64_regs.regs[0];
+ tcp->u_arg[1] = aarch64_regs.regs[1];
+ tcp->u_arg[2] = aarch64_regs.regs[2];
+ tcp->u_arg[3] = aarch64_regs.regs[3];
+ tcp->u_arg[4] = aarch64_regs.regs[4];
+ tcp->u_arg[5] = aarch64_regs.regs[5];
+} else {
+#include "arm/get_syscall_args.c"
+}
diff --git a/linux/aarch64/print_pc.c b/linux/aarch64/print_pc.c
new file mode 100644
index 0000000..23c0e5c
--- /dev/null
+++ b/linux/aarch64/print_pc.c
@@ -0,0 +1,4 @@
+if (aarch64_io.iov_len == sizeof(arm_regs))
+ tprintf(fmt, (unsigned long) arm_regs.ARM_pc);
+else
+ tprintf(fmt, (unsigned long) aarch64_regs.pc);
diff --git a/linux/alpha/arch_getrval2.c b/linux/alpha/arch_getrval2.c
new file mode 100644
index 0000000..90ee392
--- /dev/null
+++ b/linux/alpha/arch_getrval2.c
@@ -0,0 +1,8 @@
+long
+getrval2(struct tcb *tcp)
+{
+ long r20;
+ if (upeek(tcp->pid, 20, &r20) < 0)
+ return -1;
+ return r20;
+}
diff --git a/linux/alpha/arch_regs.c b/linux/alpha/arch_regs.c
new file mode 100644
index 0000000..e2783ca
--- /dev/null
+++ b/linux/alpha/arch_regs.c
@@ -0,0 +1,2 @@
+static long alpha_r0;
+static long alpha_a3;
diff --git a/linux/alpha/get_error.c b/linux/alpha/get_error.c
new file mode 100644
index 0000000..5b615a5
--- /dev/null
+++ b/linux/alpha/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && alpha_a3) {
+ tcp->u_rval = -1;
+ tcp->u_error = alpha_r0;
+} else {
+ tcp->u_rval = alpha_r0;
+}
diff --git a/linux/alpha/get_scno.c b/linux/alpha/get_scno.c
new file mode 100644
index 0000000..4959e15
--- /dev/null
+++ b/linux/alpha/get_scno.c
@@ -0,0 +1,16 @@
+if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0)
+ return -1;
+if (upeek(tcp->pid, REG_R0, &scno) < 0)
+ return -1;
+
+/*
+ * Do some sanity checks to figure out if it's
+ * really a syscall entry
+ */
+if (!SCNO_IN_RANGE(scno)) {
+ if (alpha_a3 == 0 || alpha_a3 == -1) {
+ if (debug_flag)
+ fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
+ return 0;
+ }
+}
diff --git a/linux/alpha/get_syscall_args.c b/linux/alpha/get_syscall_args.c
new file mode 100644
index 0000000..7f7d493
--- /dev/null
+++ b/linux/alpha/get_syscall_args.c
@@ -0,0 +1,5 @@
+unsigned int i;
+
+for (i = 0; i < tcp->s_ent->nargs; ++i)
+ if (upeek(tcp->pid, REG_A0+i, &tcp->u_arg[i]) < 0)
+ return -1;
diff --git a/linux/alpha/get_syscall_result.c b/linux/alpha/get_syscall_result.c
new file mode 100644
index 0000000..11e2736
--- /dev/null
+++ b/linux/alpha/get_syscall_result.c
@@ -0,0 +1,4 @@
+if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0)
+ return -1;
+if (upeek(tcp->pid, REG_R0, &alpha_r0) < 0)
+ return -1;
diff --git a/linux/alpha/print_pc.c b/linux/alpha/print_pc.c
new file mode 100644
index 0000000..c0232e5
--- /dev/null
+++ b/linux/alpha/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, REG_PC, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/linux/arc/arch_regs.c b/linux/arc/arch_regs.c
new file mode 100644
index 0000000..0d57ae4
--- /dev/null
+++ b/linux/arc/arch_regs.c
@@ -0,0 +1,2 @@
+static struct user_regs_struct arc_regs;
+#define ARCH_REGS_FOR_GETREGSET arc_regs
diff --git a/linux/arc/get_error.c b/linux/arc/get_error.c
new file mode 100644
index 0000000..1741c17
--- /dev/null
+++ b/linux/arc/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(arc_regs.scratch.r0)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -arc_regs.scratch.r0;
+} else {
+ tcp->u_rval = arc_regs.scratch.r0;
+}
diff --git a/linux/arc/get_scno.c b/linux/arc/get_scno.c
new file mode 100644
index 0000000..cc45d46
--- /dev/null
+++ b/linux/arc/get_scno.c
@@ -0,0 +1 @@
+scno = arc_regs.scratch.r8;
diff --git a/linux/arc/get_syscall_args.c b/linux/arc/get_syscall_args.c
new file mode 100644
index 0000000..bb003c8
--- /dev/null
+++ b/linux/arc/get_syscall_args.c
@@ -0,0 +1,5 @@
+long *arc_args = &arc_regs.scratch.r0;
+unsigned int i;
+
+for (i = 0; i < MAX_ARGS; ++i)
+ tcp->u_arg[i] = *arc_args--;
diff --git a/linux/arc/print_pc.c b/linux/arc/print_pc.c
new file mode 100644
index 0000000..f904544
--- /dev/null
+++ b/linux/arc/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, arc_regs.efa);
diff --git a/linux/arm/arch_regs.c b/linux/arm/arch_regs.c
new file mode 100644
index 0000000..ca1fb6d
--- /dev/null
+++ b/linux/arm/arch_regs.c
@@ -0,0 +1,4 @@
+static struct pt_regs arm_regs;
+long *const arm_sp_ptr = &arm_regs.ARM_sp;
+
+#define ARCH_REGS_FOR_GETREGS arm_regs
diff --git a/linux/arm/get_error.c b/linux/arm/get_error.c
new file mode 100644
index 0000000..d2ae09b
--- /dev/null
+++ b/linux/arm/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(arm_regs.ARM_r0)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -arm_regs.ARM_r0;
+} else {
+ tcp->u_rval = arm_regs.ARM_r0;
+}
diff --git a/linux/arm/get_scno.c b/linux/arm/get_scno.c
new file mode 100644
index 0000000..6122d39
--- /dev/null
+++ b/linux/arm/get_scno.c
@@ -0,0 +1,41 @@
+if (arm_regs.ARM_ip != 0) {
+ /* It is not a syscall entry */
+ fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid);
+ tcp->flags |= TCB_INSYSCALL;
+ return 0;
+}
+
+/* Note: we support only 32-bit CPUs, not 26-bit */
+
+#if !defined(__ARM_EABI__) || ENABLE_ARM_OABI
+if (arm_regs.ARM_cpsr & 0x20) {
+ /* Thumb mode */
+ goto scno_in_r7;
+}
+/* ARM mode */
+/* Check EABI/OABI by examining SVC insn's low 24 bits */
+errno = 0;
+scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL);
+if (errno)
+ return -1;
+/* EABI syscall convention? */
+if ((unsigned long) scno != 0xef000000) {
+ /* No, it's OABI */
+ if ((scno & 0x0ff00000) != 0x0f900000) {
+ fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n",
+ tcp->pid, scno);
+ return -1;
+ }
+ /* Fixup the syscall number */
+ scno &= 0x000fffff;
+} else {
+scno_in_r7:
+ scno = arm_regs.ARM_r7;
+}
+#else /* __ARM_EABI__ || !ENABLE_ARM_OABI */
+
+scno = arm_regs.ARM_r7;
+
+#endif
+
+scno = shuffle_scno(scno);
diff --git a/linux/arm/get_syscall_args.c b/linux/arm/get_syscall_args.c
new file mode 100644
index 0000000..1bd4faf
--- /dev/null
+++ b/linux/arm/get_syscall_args.c
@@ -0,0 +1,6 @@
+tcp->u_arg[0] = arm_regs.uregs[0];
+tcp->u_arg[1] = arm_regs.uregs[1];
+tcp->u_arg[2] = arm_regs.uregs[2];
+tcp->u_arg[3] = arm_regs.uregs[3];
+tcp->u_arg[4] = arm_regs.uregs[4];
+tcp->u_arg[5] = arm_regs.uregs[5];
diff --git a/linux/arm/print_pc.c b/linux/arm/print_pc.c
new file mode 100644
index 0000000..b9d9622
--- /dev/null
+++ b/linux/arm/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, arm_regs.ARM_pc);
diff --git a/linux/avr32/arch_regs.c b/linux/avr32/arch_regs.c
new file mode 100644
index 0000000..aab0338
--- /dev/null
+++ b/linux/avr32/arch_regs.c
@@ -0,0 +1,2 @@
+static struct pt_regs avr32_regs;
+#define ARCH_REGS_FOR_GETREGS avr32_regs
diff --git a/linux/avr32/get_error.c b/linux/avr32/get_error.c
new file mode 100644
index 0000000..ef44584
--- /dev/null
+++ b/linux/avr32/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(avr32_regs.r12)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -avr32_regs.r12;
+} else {
+ tcp->u_rval = avr32_regs.r12;
+}
diff --git a/linux/avr32/get_scno.c b/linux/avr32/get_scno.c
new file mode 100644
index 0000000..0142329
--- /dev/null
+++ b/linux/avr32/get_scno.c
@@ -0,0 +1 @@
+scno = avr32_regs.r8;
diff --git a/linux/avr32/get_syscall_args.c b/linux/avr32/get_syscall_args.c
new file mode 100644
index 0000000..2e3cd3b
--- /dev/null
+++ b/linux/avr32/get_syscall_args.c
@@ -0,0 +1,6 @@
+tcp->u_arg[0] = avr32_regs.r12;
+tcp->u_arg[1] = avr32_regs.r11;
+tcp->u_arg[2] = avr32_regs.r10;
+tcp->u_arg[3] = avr32_regs.r9;
+tcp->u_arg[4] = avr32_regs.r5;
+tcp->u_arg[5] = avr32_regs.r3;
diff --git a/linux/avr32/print_pc.c b/linux/avr32/print_pc.c
new file mode 100644
index 0000000..ca293e6
--- /dev/null
+++ b/linux/avr32/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, avr32_regs.pc);
diff --git a/linux/bfin/arch_regs.c b/linux/bfin/arch_regs.c
new file mode 100644
index 0000000..f6f4204
--- /dev/null
+++ b/linux/bfin/arch_regs.c
@@ -0,0 +1 @@
+static long bfin_r0;
diff --git a/linux/bfin/get_error.c b/linux/bfin/get_error.c
new file mode 100644
index 0000000..d7ff247
--- /dev/null
+++ b/linux/bfin/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(bfin_r0)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -bfin_r0;
+} else {
+ tcp->u_rval = bfin_r0;
+}
diff --git a/linux/bfin/get_scno.c b/linux/bfin/get_scno.c
new file mode 100644
index 0000000..dfdb0a7
--- /dev/null
+++ b/linux/bfin/get_scno.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, PT_ORIG_P0, &scno))
+ return -1;
diff --git a/linux/bfin/get_syscall_args.c b/linux/bfin/get_syscall_args.c
new file mode 100644
index 0000000..ac6e6cd
--- /dev/null
+++ b/linux/bfin/get_syscall_args.c
@@ -0,0 +1,6 @@
+static const int argreg[MAX_ARGS] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 };
+unsigned int i;
+
+for (i = 0; i < tcp->s_ent->nargs; ++i)
+ if (upeek(tcp->pid, argreg[i], &tcp->u_arg[i]) < 0)
+ return -1;
diff --git a/linux/bfin/get_syscall_result.c b/linux/bfin/get_syscall_result.c
new file mode 100644
index 0000000..c9d94d4
--- /dev/null
+++ b/linux/bfin/get_syscall_result.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, PT_R0, &bfin_r0) < 0)
+ return -1;
diff --git a/linux/bfin/print_pc.c b/linux/bfin/print_pc.c
new file mode 100644
index 0000000..b1eef14
--- /dev/null
+++ b/linux/bfin/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, PT_PC, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/linux/crisv10/arch_regs.c b/linux/crisv10/arch_regs.c
new file mode 100644
index 0000000..573f593
--- /dev/null
+++ b/linux/crisv10/arch_regs.c
@@ -0,0 +1 @@
+static long cris_r10;
diff --git a/linux/crisv10/get_error.c b/linux/crisv10/get_error.c
new file mode 100644
index 0000000..3f947ae
--- /dev/null
+++ b/linux/crisv10/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(cris_r10)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -cris_r10;
+} else {
+ tcp->u_rval = cris_r10;
+}
diff --git a/linux/crisv10/get_scno.c b/linux/crisv10/get_scno.c
new file mode 100644
index 0000000..5bbbe8b
--- /dev/null
+++ b/linux/crisv10/get_scno.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, 4*PT_R9, &scno) < 0)
+ return -1;
diff --git a/linux/crisv10/get_syscall_args.c b/linux/crisv10/get_syscall_args.c
new file mode 100644
index 0000000..66b5ac7
--- /dev/null
+++ b/linux/crisv10/get_syscall_args.c
@@ -0,0 +1,9 @@
+static const int crisregs[MAX_ARGS] = {
+ 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12,
+ 4*PT_R13 , 4*PT_MOF, 4*PT_SRP
+};
+unsigned int i;
+
+for (i = 0; i < tcp->s_ent->nargs; ++i)
+ if (upeek(tcp->pid, crisregs[i], &tcp->u_arg[i]) < 0)
+ return -1;
diff --git a/linux/crisv10/get_syscall_result.c b/linux/crisv10/get_syscall_result.c
new file mode 100644
index 0000000..53b087a
--- /dev/null
+++ b/linux/crisv10/get_syscall_result.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, 4*PT_R10, &cris_r10) < 0)
+ return -1;
diff --git a/linux/crisv10/print_pc.c b/linux/crisv10/print_pc.c
new file mode 100644
index 0000000..cc76216
--- /dev/null
+++ b/linux/crisv10/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, 4*PT_IRP, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/linux/crisv32/arch_regs.c b/linux/crisv32/arch_regs.c
new file mode 100644
index 0000000..a088e17
--- /dev/null
+++ b/linux/crisv32/arch_regs.c
@@ -0,0 +1 @@
+#include "crisv10/arch_regs.c"
diff --git a/linux/crisv32/get_error.c b/linux/crisv32/get_error.c
new file mode 100644
index 0000000..f7bb1e0
--- /dev/null
+++ b/linux/crisv32/get_error.c
@@ -0,0 +1 @@
+#include "crisv10/get_error.c"
diff --git a/linux/crisv32/get_scno.c b/linux/crisv32/get_scno.c
new file mode 100644
index 0000000..edfd60f
--- /dev/null
+++ b/linux/crisv32/get_scno.c
@@ -0,0 +1 @@
+#include "crisv10/get_scno.c"
diff --git a/linux/crisv32/get_syscall_args.c b/linux/crisv32/get_syscall_args.c
new file mode 100644
index 0000000..4d98465
--- /dev/null
+++ b/linux/crisv32/get_syscall_args.c
@@ -0,0 +1 @@
+#include "crisv10/get_syscall_args.c"
diff --git a/linux/crisv32/get_syscall_result.c b/linux/crisv32/get_syscall_result.c
new file mode 100644
index 0000000..ebefdb2
--- /dev/null
+++ b/linux/crisv32/get_syscall_result.c
@@ -0,0 +1 @@
+#include "crisv10/get_syscall_result.c"
diff --git a/linux/crisv32/print_pc.c b/linux/crisv32/print_pc.c
new file mode 100644
index 0000000..b4af692
--- /dev/null
+++ b/linux/crisv32/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, 4*PT_ERP, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/linux/hppa/arch_regs.c b/linux/hppa/arch_regs.c
new file mode 100644
index 0000000..56d1ee3
--- /dev/null
+++ b/linux/hppa/arch_regs.c
@@ -0,0 +1 @@
+static long hppa_r28;
diff --git a/linux/hppa/get_error.c b/linux/hppa/get_error.c
new file mode 100644
index 0000000..901aa54
--- /dev/null
+++ b/linux/hppa/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(hppa_r28)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -hppa_r28;
+} else {
+ tcp->u_rval = hppa_r28;
+}
diff --git a/linux/hppa/get_scno.c b/linux/hppa/get_scno.c
new file mode 100644
index 0000000..0dc1a46
--- /dev/null
+++ b/linux/hppa/get_scno.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, PT_GR20, &scno) < 0)
+ return -1;
diff --git a/linux/hppa/get_syscall_args.c b/linux/hppa/get_syscall_args.c
new file mode 100644
index 0000000..117b68b
--- /dev/null
+++ b/linux/hppa/get_syscall_args.c
@@ -0,0 +1,5 @@
+unsigned int i;
+
+for (i = 0; i < tcp->s_ent->nargs; ++i)
+ if (upeek(tcp->pid, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
+ return -1;
diff --git a/linux/hppa/get_syscall_result.c b/linux/hppa/get_syscall_result.c
new file mode 100644
index 0000000..d929b9f
--- /dev/null
+++ b/linux/hppa/get_syscall_result.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, PT_GR28, &hppa_r28) < 0)
+ return -1;
diff --git a/linux/hppa/print_pc.c b/linux/hppa/print_pc.c
new file mode 100644
index 0000000..7656346
--- /dev/null
+++ b/linux/hppa/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, PT_IAOQ0, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/linux/i386/arch_regs.c b/linux/i386/arch_regs.c
new file mode 100644
index 0000000..15b5615
--- /dev/null
+++ b/linux/i386/arch_regs.c
@@ -0,0 +1,4 @@
+static struct user_regs_struct i386_regs;
+long *const i386_esp_ptr = &i386_regs.esp;
+
+#define ARCH_REGS_FOR_GETREGS i386_regs
diff --git a/linux/i386/get_error.c b/linux/i386/get_error.c
new file mode 100644
index 0000000..465118b
--- /dev/null
+++ b/linux/i386/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(i386_regs.eax)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -i386_regs.eax;
+} else {
+ tcp->u_rval = i386_regs.eax;
+}
diff --git a/linux/i386/get_scno.c b/linux/i386/get_scno.c
new file mode 100644
index 0000000..fa22fa6
--- /dev/null
+++ b/linux/i386/get_scno.c
@@ -0,0 +1 @@
+scno = i386_regs.orig_eax;
diff --git a/linux/i386/get_syscall_args.c b/linux/i386/get_syscall_args.c
new file mode 100644
index 0000000..30cce6a
--- /dev/null
+++ b/linux/i386/get_syscall_args.c
@@ -0,0 +1,6 @@
+tcp->u_arg[0] = i386_regs.ebx;
+tcp->u_arg[1] = i386_regs.ecx;
+tcp->u_arg[2] = i386_regs.edx;
+tcp->u_arg[3] = i386_regs.esi;
+tcp->u_arg[4] = i386_regs.edi;
+tcp->u_arg[5] = i386_regs.ebp;
diff --git a/linux/i386/print_pc.c b/linux/i386/print_pc.c
new file mode 100644
index 0000000..0d5c957
--- /dev/null
+++ b/linux/i386/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, i386_regs.eip);
diff --git a/linux/ia64/arch_getrval2.c b/linux/ia64/arch_getrval2.c
new file mode 100644
index 0000000..7a6875f
--- /dev/null
+++ b/linux/ia64/arch_getrval2.c
@@ -0,0 +1,5 @@
+long
+getrval2(struct tcb *tcp)
+{
+ return ia64_regs.gr[9];
+}
diff --git a/linux/ia64/arch_regs.c b/linux/ia64/arch_regs.c
new file mode 100644
index 0000000..d7de201
--- /dev/null
+++ b/linux/ia64/arch_regs.c
@@ -0,0 +1,7 @@
+static struct pt_all_user_regs ia64_regs;
+unsigned long *const ia64_frame_ptr = &ia64_regs.gr[12];
+
+#define IA64_PSR_IS ((long)1 << 34)
+#define ia64_ia32mode (ia64_regs.cr_ipsr & IA64_PSR_IS)
+
+#define ARCH_REGS_FOR_GETREGS ia64_regs
diff --git a/linux/ia64/get_error.c b/linux/ia64/get_error.c
new file mode 100644
index 0000000..fb6b9f4
--- /dev/null
+++ b/linux/ia64/get_error.c
@@ -0,0 +1,16 @@
+if (ia64_ia32mode) {
+ int err = ia64_regs.gr[8];
+ if (check_errno && is_negated_errno(err)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -err;
+ } else {
+ tcp->u_rval = err;
+ }
+} else {
+ if (check_errno && ia64_regs.gr[10]) {
+ tcp->u_rval = -1;
+ tcp->u_error = ia64_regs.gr[8];
+ } else {
+ tcp->u_rval = ia64_regs.gr[8];
+ }
+}
diff --git a/linux/ia64/get_scno.c b/linux/ia64/get_scno.c
new file mode 100644
index 0000000..86333fd
--- /dev/null
+++ b/linux/ia64/get_scno.c
@@ -0,0 +1,5 @@
+if (ia64_ia32mode) {
+ scno = ia64_regs.gr[0];
+} else {
+ scno = ia64_regs.gr[15];
+}
diff --git a/linux/ia64/get_syscall_args.c b/linux/ia64/get_syscall_args.c
new file mode 100644
index 0000000..9527396
--- /dev/null
+++ b/linux/ia64/get_syscall_args.c
@@ -0,0 +1,22 @@
+if (!ia64_ia32mode) {
+ unsigned long *rbs_end =
+ (unsigned long *) ia64_regs.ar[PT_AUR_BSP];
+ unsigned long sof = (ia64_regs.cfm >> 0) & 0x7f;
+ unsigned long sol = (ia64_regs.cfm >> 7) & 0x7f;
+ unsigned long *out0 = ia64_rse_skip_regs(rbs_end, -sof + sol);
+ unsigned int i;
+
+ for (i = 0; i < tcp->s_ent->nargs; ++i) {
+ if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
+ sizeof(long), &tcp->u_arg[i]) < 0)
+ return -1;
+ }
+} else {
+ /* truncate away IVE sign-extension */
+ tcp->u_arg[0] = 0xffffffff & ia64_regs.gr[11]; /* EBX */
+ tcp->u_arg[1] = 0xffffffff & ia64_regs.gr[ 9]; /* ECX */
+ tcp->u_arg[2] = 0xffffffff & ia64_regs.gr[10]; /* EDX */
+ tcp->u_arg[3] = 0xffffffff & ia64_regs.gr[14]; /* ESI */
+ tcp->u_arg[4] = 0xffffffff & ia64_regs.gr[15]; /* EDI */
+ tcp->u_arg[5] = 0xffffffff & ia64_regs.gr[13]; /* EBP */
+}
diff --git a/linux/ia64/print_pc.c b/linux/ia64/print_pc.c
new file mode 100644
index 0000000..fe96780
--- /dev/null
+++ b/linux/ia64/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, ia64_regs.br[0]);
diff --git a/linux/m68k/arch_regs.c b/linux/m68k/arch_regs.c
new file mode 100644
index 0000000..5d41825
--- /dev/null
+++ b/linux/m68k/arch_regs.c
@@ -0,0 +1 @@
+static long m68k_d0;
diff --git a/linux/m68k/get_error.c b/linux/m68k/get_error.c
new file mode 100644
index 0000000..8bf5359
--- /dev/null
+++ b/linux/m68k/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(m68k_d0)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -m68k_d0;
+} else {
+ tcp->u_rval = m68k_d0;
+}
diff --git a/linux/m68k/get_scno.c b/linux/m68k/get_scno.c
new file mode 100644
index 0000000..1a6d28e
--- /dev/null
+++ b/linux/m68k/get_scno.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, 4*PT_ORIG_D0, &scno) < 0)
+ return -1;
diff --git a/linux/m68k/get_syscall_args.c b/linux/m68k/get_syscall_args.c
new file mode 100644
index 0000000..bdffcb1
--- /dev/null
+++ b/linux/m68k/get_syscall_args.c
@@ -0,0 +1,5 @@
+unsigned int i;
+
+for (i = 0; i < tcp->s_ent->nargs; ++i)
+ if (upeek(tcp->pid, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0)
+ return -1;
diff --git a/linux/m68k/get_syscall_result.c b/linux/m68k/get_syscall_result.c
new file mode 100644
index 0000000..fc452b4
--- /dev/null
+++ b/linux/m68k/get_syscall_result.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, 4*PT_D0, &m68k_d0) < 0)
+ return -1;
diff --git a/linux/m68k/print_pc.c b/linux/m68k/print_pc.c
new file mode 100644
index 0000000..aa4497d
--- /dev/null
+++ b/linux/m68k/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/linux/metag/arch_regs.c b/linux/metag/arch_regs.c
new file mode 100644
index 0000000..b7923ba
--- /dev/null
+++ b/linux/metag/arch_regs.c
@@ -0,0 +1,2 @@
+static struct user_gp_regs metag_regs;
+#define ARCH_REGS_FOR_GETREGSET metag_regs
diff --git a/linux/metag/get_error.c b/linux/metag/get_error.c
new file mode 100644
index 0000000..809eec5
--- /dev/null
+++ b/linux/metag/get_error.c
@@ -0,0 +1,7 @@
+/* result pointer in D0Re0 (D0.0) */
+if (check_errno && is_negated_errno(metag_regs.dx[0][0])) {
+ tcp->u_rval = -1;
+ tcp->u_error = -metag_regs.dx[0][0];
+} else {
+ tcp->u_rval = metag_regs.dx[0][0];
+}
diff --git a/linux/metag/get_scno.c b/linux/metag/get_scno.c
new file mode 100644
index 0000000..45cfa48
--- /dev/null
+++ b/linux/metag/get_scno.c
@@ -0,0 +1 @@
+scno = metag_regs.dx[0][1]; /* syscall number in D1Re0 (D1.0) */
diff --git a/linux/metag/get_syscall_args.c b/linux/metag/get_syscall_args.c
new file mode 100644
index 0000000..269f4eb
--- /dev/null
+++ b/linux/metag/get_syscall_args.c
@@ -0,0 +1,5 @@
+unsigned int i;
+
+for (i = 0; i < MAX_ARGS; i++)
+ /* arguments go backwards from D1Ar1 (D1.3) */
+ tcp->u_arg[i] = ((unsigned long *)&metag_regs.dx[3][1])[-i];
diff --git a/linux/metag/print_pc.c b/linux/metag/print_pc.c
new file mode 100644
index 0000000..4415f67
--- /dev/null
+++ b/linux/metag/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, metag_regs.pc);
diff --git a/linux/microblaze/arch_regs.c b/linux/microblaze/arch_regs.c
new file mode 100644
index 0000000..9c26aad
--- /dev/null
+++ b/linux/microblaze/arch_regs.c
@@ -0,0 +1 @@
+static long microblaze_r3;
diff --git a/linux/microblaze/get_error.c b/linux/microblaze/get_error.c
new file mode 100644
index 0000000..d36e281
--- /dev/null
+++ b/linux/microblaze/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(microblaze_r3)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -microblaze_r3;
+} else {
+ tcp->u_rval = microblaze_r3;
+}
diff --git a/linux/microblaze/get_scno.c b/linux/microblaze/get_scno.c
new file mode 100644
index 0000000..cf1d919
--- /dev/null
+++ b/linux/microblaze/get_scno.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, 0, &scno) < 0)
+ return -1;
diff --git a/linux/microblaze/get_syscall_args.c b/linux/microblaze/get_syscall_args.c
new file mode 100644
index 0000000..373911c
--- /dev/null
+++ b/linux/microblaze/get_syscall_args.c
@@ -0,0 +1,5 @@
+unsigned int i;
+
+for (i = 0; i < tcp->s_ent->nargs; ++i)
+ if (upeek(tcp->pid, (5 + i) * 4, &tcp->u_arg[i]) < 0)
+ return -1;
diff --git a/linux/microblaze/get_syscall_result.c b/linux/microblaze/get_syscall_result.c
new file mode 100644
index 0000000..b7ec27f
--- /dev/null
+++ b/linux/microblaze/get_syscall_result.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, 3 * 4, µblaze_r3) < 0)
+ return -1;
diff --git a/linux/microblaze/print_pc.c b/linux/microblaze/print_pc.c
new file mode 100644
index 0000000..b1eef14
--- /dev/null
+++ b/linux/microblaze/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, PT_PC, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/linux/mips/arch_regs.c b/linux/mips/arch_regs.c
new file mode 100644
index 0000000..c46e6eb
--- /dev/null
+++ b/linux/mips/arch_regs.c
@@ -0,0 +1,3 @@
+struct mips_regs mips_regs; /* not static */
+/* PTRACE_GETREGS on MIPS is available since linux v2.6.15. */
+#define ARCH_REGS_FOR_GETREGS mips_regs
diff --git a/linux/mips/get_error.c b/linux/mips/get_error.c
new file mode 100644
index 0000000..e934af0
--- /dev/null
+++ b/linux/mips/get_error.c
@@ -0,0 +1,9 @@
+if (check_errno && mips_REG_A3) {
+ tcp->u_rval = -1;
+ tcp->u_error = mips_REG_V0;
+} else {
+# if defined LINUX_MIPSN32
+ tcp->u_lrval = mips_REG_V0;
+# endif
+ tcp->u_rval = mips_REG_V0;
+}
diff --git a/linux/mips/get_scno.c b/linux/mips/get_scno.c
new file mode 100644
index 0000000..967235d
--- /dev/null
+++ b/linux/mips/get_scno.c
@@ -0,0 +1,9 @@
+scno = mips_REG_V0;
+
+if (!SCNO_IN_RANGE(scno)) {
+ if (mips_REG_A3 == 0 || mips_REG_A3 == (uint64_t) -1) {
+ if (debug_flag)
+ fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
+ return 0;
+ }
+}
diff --git a/linux/mips/get_syscall_args.c b/linux/mips/get_syscall_args.c
new file mode 100644
index 0000000..4e4a22b
--- /dev/null
+++ b/linux/mips/get_syscall_args.c
@@ -0,0 +1,27 @@
+#if defined LINUX_MIPSN64
+ tcp->u_arg[0] = mips_REG_A0;
+ tcp->u_arg[1] = mips_REG_A1;
+ tcp->u_arg[2] = mips_REG_A2;
+ tcp->u_arg[3] = mips_REG_A3;
+ tcp->u_arg[4] = mips_REG_A4;
+ tcp->u_arg[5] = mips_REG_A5;
+#elif defined LINUX_MIPSN32
+ tcp->u_arg[0] = tcp->ext_arg[0] = mips_REG_A0;
+ tcp->u_arg[1] = tcp->ext_arg[1] = mips_REG_A1;
+ tcp->u_arg[2] = tcp->ext_arg[2] = mips_REG_A2;
+ tcp->u_arg[3] = tcp->ext_arg[3] = mips_REG_A3;
+ tcp->u_arg[4] = tcp->ext_arg[4] = mips_REG_A4;
+ tcp->u_arg[5] = tcp->ext_arg[5] = mips_REG_A5;
+#elif defined LINUX_MIPSO32
+ tcp->u_arg[0] = mips_REG_A0;
+ tcp->u_arg[1] = mips_REG_A1;
+ tcp->u_arg[2] = mips_REG_A2;
+ tcp->u_arg[3] = mips_REG_A3;
+ if (tcp->s_ent->nargs > 4) {
+ umoven(tcp, mips_REG_SP + 4 * 4,
+ (tcp->s_ent->nargs - 4) * sizeof(tcp->u_arg[0]),
+ &tcp->u_arg[4]);
+ }
+#else
+# error unsupported mips abi
+#endif
diff --git a/linux/mips/print_pc.c b/linux/mips/print_pc.c
new file mode 100644
index 0000000..569b0b6
--- /dev/null
+++ b/linux/mips/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, (unsigned long) mips_REG_EPC);
diff --git a/linux/or1k/arch_regs.c b/linux/or1k/arch_regs.c
new file mode 100644
index 0000000..7415e08
--- /dev/null
+++ b/linux/or1k/arch_regs.c
@@ -0,0 +1,2 @@
+static struct user_regs_struct or1k_regs;
+#define ARCH_REGS_FOR_GETREGSET or1k_regs
diff --git a/linux/or1k/get_error.c b/linux/or1k/get_error.c
new file mode 100644
index 0000000..cbf9a6e
--- /dev/null
+++ b/linux/or1k/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(or1k_regs.gpr[11])) {
+ tcp->u_rval = -1;
+ tcp->u_error = -or1k_regs.gpr[11];
+} else {
+ tcp->u_rval = or1k_regs.gpr[11];
+}
diff --git a/linux/or1k/get_scno.c b/linux/or1k/get_scno.c
new file mode 100644
index 0000000..99fada2
--- /dev/null
+++ b/linux/or1k/get_scno.c
@@ -0,0 +1 @@
+scno = or1k_regs.gpr[11];
diff --git a/linux/or1k/get_syscall_args.c b/linux/or1k/get_syscall_args.c
new file mode 100644
index 0000000..751cba0
--- /dev/null
+++ b/linux/or1k/get_syscall_args.c
@@ -0,0 +1,6 @@
+tcp->u_arg[0] = or1k_regs.gpr[3 + 0];
+tcp->u_arg[1] = or1k_regs.gpr[3 + 1];
+tcp->u_arg[2] = or1k_regs.gpr[3 + 2];
+tcp->u_arg[3] = or1k_regs.gpr[3 + 3];
+tcp->u_arg[4] = or1k_regs.gpr[3 + 4];
+tcp->u_arg[5] = or1k_regs.gpr[3 + 5];
diff --git a/linux/or1k/print_pc.c b/linux/or1k/print_pc.c
new file mode 100644
index 0000000..3fe4a1a
--- /dev/null
+++ b/linux/or1k/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, or1k_regs.pc);
diff --git a/linux/powerpc/arch_regs.c b/linux/powerpc/arch_regs.c
new file mode 100644
index 0000000..cd92d21
--- /dev/null
+++ b/linux/powerpc/arch_regs.c
@@ -0,0 +1,3 @@
+struct pt_regs ppc_regs; /* not static */
+
+#define ARCH_REGS_FOR_GETREGS ppc_regs
diff --git a/linux/powerpc/get_error.c b/linux/powerpc/get_error.c
new file mode 100644
index 0000000..f0f0a4e
--- /dev/null
+++ b/linux/powerpc/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && (ppc_regs.ccr & 0x10000000)) {
+ tcp->u_rval = -1;
+ tcp->u_error = ppc_regs.gpr[3];
+} else {
+ tcp->u_rval = ppc_regs.gpr[3];
+}
diff --git a/linux/powerpc/get_scno.c b/linux/powerpc/get_scno.c
new file mode 100644
index 0000000..a311734
--- /dev/null
+++ b/linux/powerpc/get_scno.c
@@ -0,0 +1 @@
+scno = ppc_regs.gpr[0];
diff --git a/linux/powerpc/get_syscall_args.c b/linux/powerpc/get_syscall_args.c
new file mode 100644
index 0000000..237cf77
--- /dev/null
+++ b/linux/powerpc/get_syscall_args.c
@@ -0,0 +1,6 @@
+tcp->u_arg[0] = ppc_regs.orig_gpr3;
+tcp->u_arg[1] = ppc_regs.gpr[4];
+tcp->u_arg[2] = ppc_regs.gpr[5];
+tcp->u_arg[3] = ppc_regs.gpr[6];
+tcp->u_arg[4] = ppc_regs.gpr[7];
+tcp->u_arg[5] = ppc_regs.gpr[8];
diff --git a/linux/powerpc/getregs_old.c b/linux/powerpc/getregs_old.c
new file mode 100644
index 0000000..22167cb
--- /dev/null
+++ b/linux/powerpc/getregs_old.c
@@ -0,0 +1,35 @@
+/*
+ * PTRACE_GETREGS was added to the PowerPC kernel in v2.6.23,
+ * we provide a slow fallback for old kernels.
+ */
+static int
+getregs_old(pid_t pid)
+{
+ int i;
+ long r;
+
+ if (iflag) {
+ r = upeek(pid, sizeof(long) * PT_NIP, (long *)&ppc_regs.nip);
+ if (r)
+ goto out;
+ }
+#ifdef POWERPC64 /* else we never use it */
+ r = upeek(pid, sizeof(long) * PT_MSR, (long *)&ppc_regs.msr);
+ if (r)
+ goto out;
+#endif
+ r = upeek(pid, sizeof(long) * PT_CCR, (long *)&ppc_regs.ccr);
+ if (r)
+ goto out;
+ r = upeek(pid, sizeof(long) * PT_ORIG_R3, (long *)&ppc_regs.orig_gpr3);
+ if (r)
+ goto out;
+ for (i = 0; i <= 8; i++) {
+ r = upeek(pid, sizeof(long) * (PT_R0 + i),
+ (long *)&ppc_regs.gpr[i]);
+ if (r)
+ goto out;
+ }
+ out:
+ return r;
+}
diff --git a/linux/powerpc/print_pc.c b/linux/powerpc/print_pc.c
new file mode 100644
index 0000000..34112fb
--- /dev/null
+++ b/linux/powerpc/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, ppc_regs.nip);
diff --git a/linux/powerpc64/arch_regs.c b/linux/powerpc64/arch_regs.c
new file mode 100644
index 0000000..b5c572d
--- /dev/null
+++ b/linux/powerpc64/arch_regs.c
@@ -0,0 +1 @@
+#include "powerpc/arch_regs.c"
diff --git a/linux/powerpc64/get_error.c b/linux/powerpc64/get_error.c
new file mode 100644
index 0000000..209bfd8
--- /dev/null
+++ b/linux/powerpc64/get_error.c
@@ -0,0 +1 @@
+#include "powerpc/get_error.c"
diff --git a/linux/powerpc64/get_scno.c b/linux/powerpc64/get_scno.c
new file mode 100644
index 0000000..1e67010
--- /dev/null
+++ b/linux/powerpc64/get_scno.c
@@ -0,0 +1,11 @@
+scno = ppc_regs.gpr[0];
+unsigned int currpers;
+
+/*
+ * Check for 64/32 bit mode.
+ * Embedded implementations covered by Book E extension of PPC use
+ * bit 0 (CM) of 32-bit Machine state register (MSR).
+ * Other implementations use bit 0 (SF) of 64-bit MSR.
+ */
+currpers = (ppc_regs.msr & 0x8000000080000000) ? 0 : 1;
+update_personality(tcp, currpers);
diff --git a/linux/powerpc64/get_syscall_args.c b/linux/powerpc64/get_syscall_args.c
new file mode 100644
index 0000000..5561a55
--- /dev/null
+++ b/linux/powerpc64/get_syscall_args.c
@@ -0,0 +1 @@
+#include "powerpc/get_syscall_args.c"
diff --git a/linux/powerpc64/getregs_old.c b/linux/powerpc64/getregs_old.c
new file mode 100644
index 0000000..177ff74
--- /dev/null
+++ b/linux/powerpc64/getregs_old.c
@@ -0,0 +1 @@
+#include "powerpc/getregs_old.c"
diff --git a/linux/powerpc64/print_pc.c b/linux/powerpc64/print_pc.c
new file mode 100644
index 0000000..ddaf880
--- /dev/null
+++ b/linux/powerpc64/print_pc.c
@@ -0,0 +1 @@
+#include "powerpc/print_pc.c"
diff --git a/linux/s390/arch_regs.c b/linux/s390/arch_regs.c
new file mode 100644
index 0000000..32c50a1
--- /dev/null
+++ b/linux/s390/arch_regs.c
@@ -0,0 +1,4 @@
+/* PTRACE_GETREGSET on S390 is available since linux v2.6.27. */
+static struct user_regs_struct s390_regset;
+unsigned long *const s390_frame_ptr = &s390_regset.gprs[15];
+#define ARCH_REGS_FOR_GETREGSET s390_regset
diff --git a/linux/s390/get_error.c b/linux/s390/get_error.c
new file mode 100644
index 0000000..29fffbd
--- /dev/null
+++ b/linux/s390/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(s390_regset.gprs[2])) {
+ tcp->u_rval = -1;
+ tcp->u_error = -s390_regset.gprs[2];
+} else {
+ tcp->u_rval = s390_regset.gprs[2];
+}
diff --git a/linux/s390/get_scno.c b/linux/s390/get_scno.c
new file mode 100644
index 0000000..b9e1c19
--- /dev/null
+++ b/linux/s390/get_scno.c
@@ -0,0 +1 @@
+scno = s390_regset.gprs[2];
diff --git a/linux/s390/get_syscall_args.c b/linux/s390/get_syscall_args.c
new file mode 100644
index 0000000..85f2585
--- /dev/null
+++ b/linux/s390/get_syscall_args.c
@@ -0,0 +1,6 @@
+tcp->u_arg[0] = s390_regset.orig_gpr2;
+tcp->u_arg[1] = s390_regset.gprs[3];
+tcp->u_arg[2] = s390_regset.gprs[4];
+tcp->u_arg[3] = s390_regset.gprs[5];
+tcp->u_arg[4] = s390_regset.gprs[6];
+tcp->u_arg[5] = s390_regset.gprs[7];
diff --git a/linux/s390/print_pc.c b/linux/s390/print_pc.c
new file mode 100644
index 0000000..f92ccd4
--- /dev/null
+++ b/linux/s390/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, s390_regset.psw.addr);
diff --git a/linux/s390x/arch_regs.c b/linux/s390x/arch_regs.c
new file mode 100644
index 0000000..62aece7
--- /dev/null
+++ b/linux/s390x/arch_regs.c
@@ -0,0 +1 @@
+#include "s390/arch_regs.c"
diff --git a/linux/s390x/get_error.c b/linux/s390x/get_error.c
new file mode 100644
index 0000000..8e3944c
--- /dev/null
+++ b/linux/s390x/get_error.c
@@ -0,0 +1 @@
+#include "s390/get_error.c"
diff --git a/linux/s390x/get_scno.c b/linux/s390x/get_scno.c
new file mode 100644
index 0000000..71816fb
--- /dev/null
+++ b/linux/s390x/get_scno.c
@@ -0,0 +1 @@
+#include "s390/get_scno.c"
diff --git a/linux/s390x/get_syscall_args.c b/linux/s390x/get_syscall_args.c
new file mode 100644
index 0000000..4ded41d
--- /dev/null
+++ b/linux/s390x/get_syscall_args.c
@@ -0,0 +1 @@
+#include "s390/get_syscall_args.c"
diff --git a/linux/s390x/print_pc.c b/linux/s390x/print_pc.c
new file mode 100644
index 0000000..9a445f7
--- /dev/null
+++ b/linux/s390x/print_pc.c
@@ -0,0 +1 @@
+#include "s390/print_pc.c"
diff --git a/linux/sh/arch_getrval2.c b/linux/sh/arch_getrval2.c
new file mode 100644
index 0000000..8f60de7
--- /dev/null
+++ b/linux/sh/arch_getrval2.c
@@ -0,0 +1,8 @@
+long
+getrval2(struct tcb *tcp)
+{
+ long val;
+ if (upeek(tcp->pid, 4*(REG_REG0+1), &val) < 0)
+ return -1;
+ return val;
+}
diff --git a/linux/sh/arch_regs.c b/linux/sh/arch_regs.c
new file mode 100644
index 0000000..9d24ee7
--- /dev/null
+++ b/linux/sh/arch_regs.c
@@ -0,0 +1 @@
+static long sh_r0;
diff --git a/linux/sh/get_error.c b/linux/sh/get_error.c
new file mode 100644
index 0000000..2375e3c
--- /dev/null
+++ b/linux/sh/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(sh_r0)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -sh_r0;
+} else {
+ tcp->u_rval = sh_r0;
+}
diff --git a/linux/sh/get_scno.c b/linux/sh/get_scno.c
new file mode 100644
index 0000000..90dbf0f
--- /dev/null
+++ b/linux/sh/get_scno.c
@@ -0,0 +1,19 @@
+/*
+ * In the new syscall ABI, the system call number is in R3.
+ */
+if (upeek(tcp->pid, 4*(REG_REG0+3), &scno) < 0)
+ return -1;
+
+if (scno < 0) {
+ /* Odd as it may seem, a glibc bug has been known to cause
+ glibc to issue bogus negative syscall numbers. So for
+ our purposes, make strace print what it *should* have been */
+ long correct_scno = (scno & 0xff);
+ if (debug_flag)
+ fprintf(stderr,
+ "Detected glibc bug: bogus system call"
+ " number = %ld, correcting to %ld\n",
+ scno,
+ correct_scno);
+ scno = correct_scno;
+}
diff --git a/linux/sh/get_syscall_args.c b/linux/sh/get_syscall_args.c
new file mode 100644
index 0000000..7c94f48
--- /dev/null
+++ b/linux/sh/get_syscall_args.c
@@ -0,0 +1,10 @@
+static const int syscall_regs[MAX_ARGS] = {
+ 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6),
+ 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1)
+};
+
+unsigned int i;
+
+for (i = 0; i < tcp->s_ent->nargs; ++i)
+ if (upeek(tcp->pid, syscall_regs[i], &tcp->u_arg[i]) < 0)
+ return -1;
diff --git a/linux/sh/get_syscall_result.c b/linux/sh/get_syscall_result.c
new file mode 100644
index 0000000..3ee0546
--- /dev/null
+++ b/linux/sh/get_syscall_result.c
@@ -0,0 +1,3 @@
+/* new syscall ABI returns result in R0 */
+if (upeek(tcp->pid, 4*REG_REG0, (long *)&sh_r0) < 0)
+ return -1;
diff --git a/linux/sh/print_pc.c b/linux/sh/print_pc.c
new file mode 100644
index 0000000..2f43eff
--- /dev/null
+++ b/linux/sh/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, 4*REG_PC, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/linux/sh64/arch_regs.c b/linux/sh64/arch_regs.c
new file mode 100644
index 0000000..e09cac5
--- /dev/null
+++ b/linux/sh64/arch_regs.c
@@ -0,0 +1 @@
+static long sh64_r9;
diff --git a/linux/sh64/get_error.c b/linux/sh64/get_error.c
new file mode 100644
index 0000000..9e8aeaf
--- /dev/null
+++ b/linux/sh64/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(sh64_r9)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -sh64_r9;
+} else {
+ tcp->u_rval = sh64_r9;
+}
diff --git a/linux/sh64/get_scno.c b/linux/sh64/get_scno.c
new file mode 100644
index 0000000..9e7ecd4
--- /dev/null
+++ b/linux/sh64/get_scno.c
@@ -0,0 +1,3 @@
+if (upeek(tcp->pid, REG_SYSCALL, &scno) < 0)
+ return -1;
+scno &= 0xFFFF;
diff --git a/linux/sh64/get_syscall_args.c b/linux/sh64/get_syscall_args.c
new file mode 100644
index 0000000..dcc8967
--- /dev/null
+++ b/linux/sh64/get_syscall_args.c
@@ -0,0 +1,7 @@
+/* Registers used by SH5 Linux system calls for parameters */
+static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 };
+unsigned int i;
+
+for (i = 0; i < tcp->s_ent->nargs; ++i)
+ if (upeek(tcp->pid, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
+ return -1;
diff --git a/linux/sh64/get_syscall_result.c b/linux/sh64/get_syscall_result.c
new file mode 100644
index 0000000..e53bd0f
--- /dev/null
+++ b/linux/sh64/get_syscall_result.c
@@ -0,0 +1,3 @@
+/* ABI defines result returned in r9 */
+if (upeek(tcp->pid, REG_GENERAL(9), (long *)&sh64_r9) < 0)
+ return -1;
diff --git a/linux/sh64/print_pc.c b/linux/sh64/print_pc.c
new file mode 100644
index 0000000..c0232e5
--- /dev/null
+++ b/linux/sh64/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, REG_PC, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/linux/sparc/arch_getrval2.c b/linux/sparc/arch_getrval2.c
new file mode 100644
index 0000000..9079482
--- /dev/null
+++ b/linux/sparc/arch_getrval2.c
@@ -0,0 +1,5 @@
+long
+getrval2(struct tcb *tcp)
+{
+ return sparc_regs.u_regs[U_REG_O1];
+}
diff --git a/linux/sparc/arch_regs.c b/linux/sparc/arch_regs.c
new file mode 100644
index 0000000..ed13029
--- /dev/null
+++ b/linux/sparc/arch_regs.c
@@ -0,0 +1,2 @@
+struct pt_regs sparc_regs; /* not static */
+#define ARCH_REGS_FOR_GETREGS sparc_regs
diff --git a/linux/sparc/get_error.c b/linux/sparc/get_error.c
new file mode 100644
index 0000000..3531f01
--- /dev/null
+++ b/linux/sparc/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && sparc_regs.psr & PSR_C) {
+ tcp->u_rval = -1;
+ tcp->u_error = sparc_regs.u_regs[U_REG_O0];
+} else {
+ tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
+}
diff --git a/linux/sparc/get_scno.c b/linux/sparc/get_scno.c
new file mode 100644
index 0000000..d083bf4
--- /dev/null
+++ b/linux/sparc/get_scno.c
@@ -0,0 +1,62 @@
+/* Disassemble the syscall trap. */
+/* Retrieve the syscall trap instruction. */
+unsigned long trap;
+
+errno = 0;
+
+#ifdef SPARC64
+trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.tpc, 0);
+trap >>= 32;
+#else
+trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.pc, 0);
+#endif
+
+if (errno)
+ return -1;
+
+/* Disassemble the trap to see what personality to use. */
+switch (trap) {
+case 0x91d02010:
+ /* Linux/SPARC syscall trap. */
+ update_personality(tcp, 0);
+ break;
+case 0x91d0206d:
+ /* Linux/SPARC64 syscall trap. */
+ update_personality(tcp, 2);
+ break;
+case 0x91d02000:
+ /* SunOS syscall trap. (pers 1) */
+ fprintf(stderr, "syscall: SunOS no support\n");
+ return -1;
+case 0x91d02008:
+ /* Solaris 2.x syscall trap. (per 2) */
+ update_personality(tcp, 1);
+ break;
+case 0x91d02009:
+ /* NetBSD/FreeBSD syscall trap. */
+ fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n");
+ return -1;
+case 0x91d02027:
+ /* Solaris 2.x gettimeofday */
+ update_personality(tcp, 1);
+ break;
+default:
+#ifdef SPARC64
+ fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, sparc_regs.tpc);
+#else
+ fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, sparc_regs.pc);
+#endif
+ return -1;
+}
+
+/* Extract the system call number from the registers. */
+if (trap == 0x91d02027) {
+ scno = 156;
+} else {
+ scno = sparc_regs.u_regs[U_REG_G1];
+}
+
+if (scno == 0) {
+ scno = sparc_regs.u_regs[U_REG_O0];
+ memmove(&sparc_regs.u_regs[U_REG_O0], &sparc_regs.u_regs[U_REG_O1], 7*sizeof(sparc_regs.u_regs[0]));
+}
diff --git a/linux/sparc/get_syscall_args.c b/linux/sparc/get_syscall_args.c
new file mode 100644
index 0000000..14bce8f
--- /dev/null
+++ b/linux/sparc/get_syscall_args.c
@@ -0,0 +1,6 @@
+tcp->u_arg[0] = sparc_regs.u_regs[U_REG_O0 + 0];
+tcp->u_arg[1] = sparc_regs.u_regs[U_REG_O0 + 1];
+tcp->u_arg[2] = sparc_regs.u_regs[U_REG_O0 + 2];
+tcp->u_arg[3] = sparc_regs.u_regs[U_REG_O0 + 3];
+tcp->u_arg[4] = sparc_regs.u_regs[U_REG_O0 + 4];
+tcp->u_arg[5] = sparc_regs.u_regs[U_REG_O0 + 5];
diff --git a/linux/sparc/print_pc.c b/linux/sparc/print_pc.c
new file mode 100644
index 0000000..683e3b1
--- /dev/null
+++ b/linux/sparc/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, sparc_regs.pc);
diff --git a/linux/sparc64/arch_getrval2.c b/linux/sparc64/arch_getrval2.c
new file mode 100644
index 0000000..81f1556
--- /dev/null
+++ b/linux/sparc64/arch_getrval2.c
@@ -0,0 +1 @@
+#include "sparc/arch_getrval2.c"
diff --git a/linux/sparc64/arch_regs.c b/linux/sparc64/arch_regs.c
new file mode 100644
index 0000000..db38d88
--- /dev/null
+++ b/linux/sparc64/arch_regs.c
@@ -0,0 +1 @@
+#include "sparc/arch_regs.c"
diff --git a/linux/sparc64/get_error.c b/linux/sparc64/get_error.c
new file mode 100644
index 0000000..ee3a7e5
--- /dev/null
+++ b/linux/sparc64/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && sparc_regs.tstate & 0x1100000000UL) {
+ tcp->u_rval = -1;
+ tcp->u_error = sparc_regs.u_regs[U_REG_O0];
+} else {
+ tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
+}
diff --git a/linux/sparc64/get_scno.c b/linux/sparc64/get_scno.c
new file mode 100644
index 0000000..dbb0afa
--- /dev/null
+++ b/linux/sparc64/get_scno.c
@@ -0,0 +1 @@
+#include "sparc/get_scno.c"
diff --git a/linux/sparc64/get_syscall_args.c b/linux/sparc64/get_syscall_args.c
new file mode 100644
index 0000000..821c331
--- /dev/null
+++ b/linux/sparc64/get_syscall_args.c
@@ -0,0 +1 @@
+#include "sparc/get_syscall_args.c"
diff --git a/linux/sparc64/print_pc.c b/linux/sparc64/print_pc.c
new file mode 100644
index 0000000..11c0ac4
--- /dev/null
+++ b/linux/sparc64/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, sparc_regs.tpc);
diff --git a/linux/tile/arch_regs.c b/linux/tile/arch_regs.c
new file mode 100644
index 0000000..455077c
--- /dev/null
+++ b/linux/tile/arch_regs.c
@@ -0,0 +1,2 @@
+struct pt_regs tile_regs; /* not static */
+#define ARCH_REGS_FOR_GETREGS tile_regs
diff --git a/linux/tile/get_error.c b/linux/tile/get_error.c
new file mode 100644
index 0000000..8b73dfa
--- /dev/null
+++ b/linux/tile/get_error.c
@@ -0,0 +1,12 @@
+/*
+ * The standard tile calling convention returns the value (or negative
+ * errno) in r0, and zero (or positive errno) in r1.
+ * Until at least kernel 3.8, however, the r1 value is not reflected
+ * in ptregs at this point, so we use r0 here.
+ */
+if (check_errno && is_negated_errno(tile_regs.regs[0])) {
+ tcp->u_rval = -1;
+ tcp->u_error = -tile_regs.regs[0];
+} else {
+ tcp->u_rval = tile_regs.regs[0];
+}
diff --git a/linux/tile/get_scno.c b/linux/tile/get_scno.c
new file mode 100644
index 0000000..1ae65c9
--- /dev/null
+++ b/linux/tile/get_scno.c
@@ -0,0 +1,17 @@
+unsigned int currpers;
+
+scno = tile_regs.regs[10];
+
+#ifdef __tilepro__
+currpers = 1;
+#else
+# ifndef PT_FLAGS_COMPAT
+# define PT_FLAGS_COMPAT 0x10000 /* from Linux 3.8 on */
+# endif
+if (tile_regs.flags & PT_FLAGS_COMPAT)
+ currpers = 1;
+else
+ currpers = 0;
+#endif
+
+update_personality(tcp, currpers);
diff --git a/linux/tile/get_syscall_args.c b/linux/tile/get_syscall_args.c
new file mode 100644
index 0000000..33371d5
--- /dev/null
+++ b/linux/tile/get_syscall_args.c
@@ -0,0 +1,6 @@
+tcp->u_arg[0] = tile_regs.regs[0];
+tcp->u_arg[1] = tile_regs.regs[1];
+tcp->u_arg[2] = tile_regs.regs[2];
+tcp->u_arg[3] = tile_regs.regs[3];
+tcp->u_arg[4] = tile_regs.regs[4];
+tcp->u_arg[5] = tile_regs.regs[5];
diff --git a/linux/tile/print_pc.c b/linux/tile/print_pc.c
new file mode 100644
index 0000000..8a6894f
--- /dev/null
+++ b/linux/tile/print_pc.c
@@ -0,0 +1 @@
+tprintf(fmt, (unsigned long) tile_regs.pc);
diff --git a/linux/x32/arch_regs.c b/linux/x32/arch_regs.c
new file mode 100644
index 0000000..62c70be
--- /dev/null
+++ b/linux/x32/arch_regs.c
@@ -0,0 +1 @@
+#include "x86_64/arch_regs.c"
diff --git a/linux/x32/get_error.c b/linux/x32/get_error.c
new file mode 100644
index 0000000..6c6fbaf
--- /dev/null
+++ b/linux/x32/get_error.c
@@ -0,0 +1 @@
+#include "x86_64/get_error.c"
diff --git a/linux/x32/get_scno.c b/linux/x32/get_scno.c
new file mode 100644
index 0000000..492863f
--- /dev/null
+++ b/linux/x32/get_scno.c
@@ -0,0 +1 @@
+#include "x86_64/get_scno.c"
diff --git a/linux/x32/get_syscall_args.c b/linux/x32/get_syscall_args.c
new file mode 100644
index 0000000..6cdb465
--- /dev/null
+++ b/linux/x32/get_syscall_args.c
@@ -0,0 +1 @@
+#include "x86_64/get_syscall_args.c"
diff --git a/linux/x32/print_pc.c b/linux/x32/print_pc.c
new file mode 100644
index 0000000..13ccdc2
--- /dev/null
+++ b/linux/x32/print_pc.c
@@ -0,0 +1 @@
+#include "x86_64/print_pc.c"
diff --git a/linux/x86_64/arch_regs.c b/linux/x86_64/arch_regs.c
new file mode 100644
index 0000000..1925dad
--- /dev/null
+++ b/linux/x86_64/arch_regs.c
@@ -0,0 +1,40 @@
+/*
+ * On i386, pt_regs and user_regs_struct are the same,
+ * but on 64 bit x86, user_regs_struct has six more fields:
+ * fs_base, gs_base, ds, es, fs, gs.
+ * PTRACE_GETREGS fills them too, so struct pt_regs would overflow.
+ */
+struct i386_user_regs_struct {
+ uint32_t ebx;
+ uint32_t ecx;
+ uint32_t edx;
+ uint32_t esi;
+ uint32_t edi;
+ uint32_t ebp;
+ uint32_t eax;
+ uint32_t xds;
+ uint32_t xes;
+ uint32_t xfs;
+ uint32_t xgs;
+ uint32_t orig_eax;
+ uint32_t eip;
+ uint32_t xcs;
+ uint32_t eflags;
+ uint32_t esp;
+ uint32_t xss;
+};
+static union {
+ struct user_regs_struct x86_64_r;
+ struct i386_user_regs_struct i386_r;
+} x86_regs_union;
+#define x86_64_regs x86_regs_union.x86_64_r
+#define i386_regs x86_regs_union.i386_r
+
+uint32_t *const i386_esp_ptr = &i386_regs.esp;
+uint64_t *const x86_64_rsp_ptr = (uint64_t *) &x86_64_regs.rsp;
+static struct iovec x86_io = {
+ .iov_base = &x86_regs_union
+};
+
+#define ARCH_REGS_FOR_GETREGSET x86_regs_union
+#define ARCH_IOVEC_FOR_GETREGSET x86_io
diff --git a/linux/x86_64/get_error.c b/linux/x86_64/get_error.c
new file mode 100644
index 0000000..29b7816
--- /dev/null
+++ b/linux/x86_64/get_error.c
@@ -0,0 +1,23 @@
+/*
+ * In X32, return value is 64-bit (llseek uses one).
+ * Using merely "long rax" would not work.
+ */
+long long rax;
+
+if (x86_io.iov_len == sizeof(i386_regs)) {
+ /* Sign extend from 32 bits */
+ rax = (int32_t) i386_regs.eax;
+} else {
+ rax = x86_64_regs.rax;
+}
+
+if (check_errno && is_negated_errno(rax)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -rax;
+} else {
+ tcp->u_rval = rax;
+# ifdef X32
+ /* tcp->u_rval contains a truncated value */
+ tcp->u_lrval = rax;
+# endif
+}
diff --git a/linux/x86_64/get_scno.c b/linux/x86_64/get_scno.c
new file mode 100644
index 0000000..2eb0d5d
--- /dev/null
+++ b/linux/x86_64/get_scno.c
@@ -0,0 +1,107 @@
+#ifndef __X32_SYSCALL_BIT
+# define __X32_SYSCALL_BIT 0x40000000
+#endif
+
+unsigned int currpers;
+
+#if 1
+/* GETREGSET of NT_PRSTATUS tells us regset size,
+ * which unambiguously detects i386.
+ *
+ * Linux kernel distinguishes x86-64 and x32 processes
+ * solely by looking at __X32_SYSCALL_BIT:
+ * arch/x86/include/asm/compat.h::is_x32_task():
+ * if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
+ * return true;
+ */
+if (x86_io.iov_len == sizeof(i386_regs)) {
+ scno = i386_regs.orig_eax;
+ currpers = 1;
+} else {
+ scno = x86_64_regs.orig_rax;
+ currpers = 0;
+ if (scno & __X32_SYSCALL_BIT) {
+ /*
+ * Syscall number -1 requires special treatment:
+ * it might be a side effect of SECCOMP_RET_ERRNO
+ * filtering that sets orig_rax to -1
+ * in some versions of linux kernel.
+ * If that is the case, then
+ * __X32_SYSCALL_BIT logic does not apply.
+ */
+ if ((long long) x86_64_regs.orig_rax != -1) {
+ scno -= __X32_SYSCALL_BIT;
+ currpers = 2;
+ } else {
+# ifdef X32
+ currpers = 2;
+# endif
+ }
+ }
+}
+
+#elif 0
+/* cs = 0x33 for long mode (native 64 bit and x32)
+ * cs = 0x23 for compatibility mode (32 bit)
+ * ds = 0x2b for x32 mode (x86-64 in 32 bit)
+ */
+scno = x86_64_regs.orig_rax;
+switch (x86_64_regs.cs) {
+ case 0x23: currpers = 1; break;
+ case 0x33:
+ if (x86_64_regs.ds == 0x2b) {
+ currpers = 2;
+ scno &= ~__X32_SYSCALL_BIT;
+ } else
+ currpers = 0;
+ break;
+ default:
+ fprintf(stderr, "Unknown value CS=0x%08X while "
+ "detecting personality of process "
+ "PID=%d\n", (int)x86_64_regs.cs, tcp->pid);
+ currpers = current_personality;
+ break;
+}
+#elif 0
+/* This version analyzes the opcode of a syscall instruction.
+ * (int 0x80 on i386 vs. syscall on x86-64)
+ * It works, but is too complicated, and strictly speaking, unreliable.
+ */
+unsigned long call, rip = x86_64_regs.rip;
+/* sizeof(syscall) == sizeof(int 0x80) == 2 */
+rip -= 2;
+errno = 0;
+call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0);
+if (errno)
+ fprintf(stderr, "ptrace_peektext failed: %s\n",
+ strerror(errno));
+switch (call & 0xffff) {
+ /* x86-64: syscall = 0x0f 0x05 */
+ case 0x050f: currpers = 0; break;
+ /* i386: int 0x80 = 0xcd 0x80 */
+ case 0x80cd: currpers = 1; break;
+ default:
+ currpers = current_personality;
+ fprintf(stderr,
+ "Unknown syscall opcode (0x%04X) while "
+ "detecting personality of process "
+ "PID=%d\n", (int)call, tcp->pid);
+ break;
+}
+#endif
+
+#ifdef X32
+/* If we are built for a x32 system, then personality 0 is x32
+ * (not x86_64), and stracing of x86_64 apps is not supported.
+ * Stracing of i386 apps is still supported.
+ */
+if (currpers == 0) {
+ fprintf(stderr, "syscall_%lu(...) in unsupported "
+ "64-bit mode of process PID=%d\n",
+ scno, tcp->pid);
+ return 0;
+}
+currpers &= ~2; /* map 2,1 to 0,1 */
+#endif /* X32 */
+
+update_personality(tcp, currpers);
diff --git a/linux/x86_64/get_syscall_args.c b/linux/x86_64/get_syscall_args.c
new file mode 100644
index 0000000..0ccecdf
--- /dev/null
+++ b/linux/x86_64/get_syscall_args.c
@@ -0,0 +1,29 @@
+if (x86_io.iov_len != sizeof(i386_regs)) {
+ /* x86-64 or x32 ABI */
+ tcp->u_arg[0] = x86_64_regs.rdi;
+ tcp->u_arg[1] = x86_64_regs.rsi;
+ tcp->u_arg[2] = x86_64_regs.rdx;
+ tcp->u_arg[3] = x86_64_regs.r10;
+ tcp->u_arg[4] = x86_64_regs.r8;
+ tcp->u_arg[5] = x86_64_regs.r9;
+#ifdef X32
+ tcp->ext_arg[0] = x86_64_regs.rdi;
+ tcp->ext_arg[1] = x86_64_regs.rsi;
+ tcp->ext_arg[2] = x86_64_regs.rdx;
+ tcp->ext_arg[3] = x86_64_regs.r10;
+ tcp->ext_arg[4] = x86_64_regs.r8;
+ tcp->ext_arg[5] = x86_64_regs.r9;
+#endif
+} else {
+ /* i386 ABI */
+ /* Zero-extend from 32 bits */
+ /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers
+ * if you need to use *sign-extended* parameter.
+ */
+ tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx;
+ tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx;
+ tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx;
+ tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi;
+ tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi;
+ tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp;
+}
diff --git a/linux/x86_64/getregs_old.c b/linux/x86_64/getregs_old.c
new file mode 100644
index 0000000..6911eee
--- /dev/null
+++ b/linux/x86_64/getregs_old.c
@@ -0,0 +1,39 @@
+/*
+ * PTRACE_GETREGSET was added to the kernel in v2.6.25,
+ * a PTRACE_GETREGS based fallback is provided for old kernels.
+ */
+static void
+getregs_old(pid_t pid)
+{
+ /* Use old method, with unreliable heuristical detection of 32-bitness. */
+ get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &x86_64_regs);
+ if (get_regs_error)
+ return;
+
+ if (x86_64_regs.cs == 0x23) {
+ x86_io.iov_len = sizeof(i386_regs);
+ /*
+ * The order is important: i386_regs and x86_64_regs
+ * are overlaid in memory!
+ */
+ i386_regs.ebx = x86_64_regs.rbx;
+ i386_regs.ecx = x86_64_regs.rcx;
+ i386_regs.edx = x86_64_regs.rdx;
+ i386_regs.esi = x86_64_regs.rsi;
+ i386_regs.edi = x86_64_regs.rdi;
+ i386_regs.ebp = x86_64_regs.rbp;
+ i386_regs.eax = x86_64_regs.rax;
+ /* i386_regs.xds = x86_64_regs.ds; unused by strace */
+ /* i386_regs.xes = x86_64_regs.es; ditto... */
+ /* i386_regs.xfs = x86_64_regs.fs; */
+ /* i386_regs.xgs = x86_64_regs.gs; */
+ i386_regs.orig_eax = x86_64_regs.orig_rax;
+ i386_regs.eip = x86_64_regs.rip;
+ /* i386_regs.xcs = x86_64_regs.cs; */
+ /* i386_regs.eflags = x86_64_regs.eflags; */
+ i386_regs.esp = x86_64_regs.rsp;
+ /* i386_regs.xss = x86_64_regs.ss; */
+ } else {
+ x86_io.iov_len = sizeof(x86_64_regs);
+ }
+}
diff --git a/linux/x86_64/print_pc.c b/linux/x86_64/print_pc.c
new file mode 100644
index 0000000..71b080a
--- /dev/null
+++ b/linux/x86_64/print_pc.c
@@ -0,0 +1,4 @@
+if (x86_io.iov_len == sizeof(i386_regs))
+ tprintf(fmt, (unsigned long) i386_regs.eip);
+else
+ tprintf(fmt, (unsigned long) x86_64_regs.rip);
diff --git a/linux/xtensa/arch_regs.c b/linux/xtensa/arch_regs.c
new file mode 100644
index 0000000..1114cab
--- /dev/null
+++ b/linux/xtensa/arch_regs.c
@@ -0,0 +1 @@
+static long xtensa_a2;
diff --git a/linux/xtensa/get_error.c b/linux/xtensa/get_error.c
new file mode 100644
index 0000000..6efbb6e
--- /dev/null
+++ b/linux/xtensa/get_error.c
@@ -0,0 +1,6 @@
+if (check_errno && is_negated_errno(xtensa_a2)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -xtensa_a2;
+} else {
+ tcp->u_rval = xtensa_a2;
+}
diff --git a/linux/xtensa/get_scno.c b/linux/xtensa/get_scno.c
new file mode 100644
index 0000000..4299163
--- /dev/null
+++ b/linux/xtensa/get_scno.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, SYSCALL_NR, &scno) < 0)
+ return -1;
diff --git a/linux/xtensa/get_syscall_args.c b/linux/xtensa/get_syscall_args.c
new file mode 100644
index 0000000..dca8788
--- /dev/null
+++ b/linux/xtensa/get_syscall_args.c
@@ -0,0 +1,7 @@
+/* arg0: a6, arg1: a3, arg2: a4, arg3: a5, arg4: a8, arg5: a9 */
+static const int xtensaregs[MAX_ARGS] = { 6, 3, 4, 5, 8, 9 };
+unsigned int i;
+
+for (i = 0; i < tcp->s_ent->nargs; ++i)
+ if (upeek(tcp->pid, REG_A_BASE + xtensaregs[i], &tcp->u_arg[i]) < 0)
+ return -1;
diff --git a/linux/xtensa/get_syscall_result.c b/linux/xtensa/get_syscall_result.c
new file mode 100644
index 0000000..0d2e697
--- /dev/null
+++ b/linux/xtensa/get_syscall_result.c
@@ -0,0 +1,2 @@
+if (upeek(tcp->pid, REG_A_BASE + 2, &xtensa_a2) < 0)
+ return -1;
diff --git a/linux/xtensa/print_pc.c b/linux/xtensa/print_pc.c
new file mode 100644
index 0000000..c0232e5
--- /dev/null
+++ b/linux/xtensa/print_pc.c
@@ -0,0 +1,6 @@
+long pc;
+if (upeek(tcp->pid, REG_PC, &pc) < 0) {
+ PRINTBADPC;
+ return;
+}
+tprintf(fmt, pc);
diff --git a/syscall.c b/syscall.c
index 3c5f4ba..435dc80 100644
--- a/syscall.c
+++ b/syscall.c
@@ -1127,166 +1127,10 @@
return val >= max;
}
-
-#if defined(I386)
-static struct user_regs_struct i386_regs;
-long *const i386_esp_ptr = &i386_regs.esp;
-# define ARCH_REGS_FOR_GETREGS i386_regs
-#elif defined(X86_64) || defined(X32)
-/*
- * On i386, pt_regs and user_regs_struct are the same,
- * but on 64 bit x86, user_regs_struct has six more fields:
- * fs_base, gs_base, ds, es, fs, gs.
- * PTRACE_GETREGS fills them too, so struct pt_regs would overflow.
- */
-struct i386_user_regs_struct {
- uint32_t ebx;
- uint32_t ecx;
- uint32_t edx;
- uint32_t esi;
- uint32_t edi;
- uint32_t ebp;
- uint32_t eax;
- uint32_t xds;
- uint32_t xes;
- uint32_t xfs;
- uint32_t xgs;
- uint32_t orig_eax;
- uint32_t eip;
- uint32_t xcs;
- uint32_t eflags;
- uint32_t esp;
- uint32_t xss;
-};
-static union {
- struct user_regs_struct x86_64_r;
- struct i386_user_regs_struct i386_r;
-} x86_regs_union;
-# define x86_64_regs x86_regs_union.x86_64_r
-# define i386_regs x86_regs_union.i386_r
-uint32_t *const i386_esp_ptr = &i386_regs.esp;
-uint64_t *const x86_64_rsp_ptr = (uint64_t *) &x86_64_regs.rsp;
-static struct iovec x86_io = {
- .iov_base = &x86_regs_union
-};
-# define ARCH_REGS_FOR_GETREGSET x86_regs_union
-# define ARCH_IOVEC_FOR_GETREGSET x86_io
-#elif defined(IA64)
-static struct pt_all_user_regs ia64_regs;
-unsigned long *const ia64_frame_ptr = &ia64_regs.gr[12];
-# define IA64_PSR_IS ((long)1 << 34)
-# define ia64_ia32mode (ia64_regs.cr_ipsr & IA64_PSR_IS)
-# define ARCH_REGS_FOR_GETREGS ia64_regs
-#elif defined(POWERPC)
-struct pt_regs ppc_regs; /* not static */
-# define ARCH_REGS_FOR_GETREGS ppc_regs
-#elif defined(M68K)
-static long m68k_d0;
-#elif defined(BFIN)
-static long bfin_r0;
-#elif defined(ARM)
-static struct pt_regs arm_regs;
-long *const arm_sp_ptr = &arm_regs.ARM_sp;
-# define ARCH_REGS_FOR_GETREGS arm_regs
-#elif defined(AARCH64)
-struct arm_pt_regs {
- int uregs[18];
-};
-# define ARM_cpsr uregs[16]
-# define ARM_pc uregs[15]
-# define ARM_lr uregs[14]
-# define ARM_sp uregs[13]
-# define ARM_ip uregs[12]
-# define ARM_fp uregs[11]
-# define ARM_r10 uregs[10]
-# define ARM_r9 uregs[9]
-# define ARM_r8 uregs[8]
-# define ARM_r7 uregs[7]
-# define ARM_r6 uregs[6]
-# define ARM_r5 uregs[5]
-# define ARM_r4 uregs[4]
-# define ARM_r3 uregs[3]
-# define ARM_r2 uregs[2]
-# define ARM_r1 uregs[1]
-# define ARM_r0 uregs[0]
-# define ARM_ORIG_r0 uregs[17]
-static union {
- struct user_pt_regs aarch64_r;
- struct arm_pt_regs arm_r;
-} arm_regs_union;
-# define aarch64_regs arm_regs_union.aarch64_r
-# define arm_regs arm_regs_union.arm_r
-uint64_t *const aarch64_sp_ptr = (uint64_t *) &aarch64_regs.sp;
-uint32_t *const arm_sp_ptr = (uint32_t *) &arm_regs.ARM_sp;
-static struct iovec aarch64_io = {
- .iov_base = &arm_regs_union
-};
-# define ARCH_REGS_FOR_GETREGSET arm_regs_union
-# define ARCH_IOVEC_FOR_GETREGSET aarch64_io
-#elif defined(ALPHA)
-static long alpha_r0;
-static long alpha_a3;
-#elif defined(AVR32)
-static struct pt_regs avr32_regs;
-# define ARCH_REGS_FOR_GETREGS avr32_regs
-#elif defined(SPARC) || defined(SPARC64)
-struct pt_regs sparc_regs; /* not static */
-# define ARCH_REGS_FOR_GETREGS sparc_regs
-#elif defined(MIPS)
-struct mips_regs mips_regs; /* not static */
-/* PTRACE_GETREGS on MIPS is available since linux v2.6.15. */
-# define ARCH_REGS_FOR_GETREGS mips_regs
-#elif defined(S390) || defined(S390X)
-/* PTRACE_GETREGSET on S390 is available since linux v2.6.27. */
-static struct user_regs_struct s390_regset;
-unsigned long *const s390_frame_ptr = &s390_regset.gprs[15];
-# define ARCH_REGS_FOR_GETREGSET s390_regset
-#elif defined(HPPA)
-static long hppa_r28;
-#elif defined(SH)
-static long sh_r0;
-#elif defined(SH64)
-static long sh64_r9;
-#elif defined(CRISV10) || defined(CRISV32)
-static long cris_r10;
-#elif defined(TILE)
-struct pt_regs tile_regs; /* not static */
-# define ARCH_REGS_FOR_GETREGS tile_regs
-#elif defined(MICROBLAZE)
-static long microblaze_r3;
-#elif defined(OR1K)
-static struct user_regs_struct or1k_regs;
-# define ARCH_REGS_FOR_GETREGSET or1k_regs
-#elif defined(METAG)
-static struct user_gp_regs metag_regs;
-# define ARCH_REGS_FOR_GETREGSET metag_regs
-#elif defined(XTENSA)
-static long xtensa_a2;
-# elif defined(ARC)
-static struct user_regs_struct arc_regs;
-# define ARCH_REGS_FOR_GETREGSET arc_regs
-#endif
+#include "arch_regs.c"
#ifdef HAVE_GETRVAL2
-long
-getrval2(struct tcb *tcp)
-{
- long val;
-
-# if defined(SPARC) || defined(SPARC64)
- val = sparc_regs.u_regs[U_REG_O1];
-# elif defined(SH)
- if (upeek(tcp->pid, 4*(REG_REG0+1), &val) < 0)
- return -1;
-# elif defined ALPHA
- if (upeek(tcp->pid, 20, &val) < 0)
- return -1;
-# elif defined(IA64)
- val = ia64_regs.gr[9];
-# endif
-
- return val;
-}
+# include "arch_getrval2.c"
#endif
void
@@ -1317,189 +1161,11 @@
return;
}
-#if defined(I386)
- tprintf(fmt, i386_regs.eip);
-#elif defined(X86_64) || defined(X32)
- if (x86_io.iov_len == sizeof(i386_regs))
- tprintf(fmt, (unsigned long) i386_regs.eip);
- else
- tprintf(fmt, (unsigned long) x86_64_regs.rip);
-#elif defined(S390) || defined(S390X)
- tprintf(fmt, s390_regset.psw.addr);
-#elif defined(IA64)
- tprintf(fmt, ia64_regs.br[0]);
-#elif defined(POWERPC)
- tprintf(fmt, ppc_regs.nip);
-#elif defined(M68K)
- long pc;
- if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) {
- PRINTBADPC;
- return;
- }
- tprintf(fmt, pc);
-#elif defined(ALPHA)
- long pc;
- if (upeek(tcp->pid, REG_PC, &pc) < 0) {
- PRINTBADPC;
- return;
- }
- tprintf(fmt, pc);
-#elif defined(SPARC)
- tprintf(fmt, sparc_regs.pc);
-#elif defined(SPARC64)
- tprintf(fmt, sparc_regs.tpc);
-#elif defined(HPPA)
- long pc;
- if (upeek(tcp->pid, PT_IAOQ0, &pc) < 0) {
- PRINTBADPC;
- return;
- }
- tprintf(fmt, pc);
-#elif defined MIPS
- tprintf(fmt, (unsigned long) mips_REG_EPC);
-#elif defined(SH)
- long pc;
- if (upeek(tcp->pid, 4*REG_PC, &pc) < 0) {
- PRINTBADPC;
- return;
- }
- tprintf(fmt, pc);
-#elif defined(SH64)
- long pc;
- if (upeek(tcp->pid, REG_PC, &pc) < 0) {
- PRINTBADPC;
- return;
- }
- tprintf(fmt, pc);
-#elif defined(AARCH64)
- if (aarch64_io.iov_len == sizeof(arm_regs))
- tprintf(fmt, (unsigned long) arm_regs.ARM_pc);
- else
- tprintf(fmt, (unsigned long) aarch64_regs.pc);
-#elif defined(ARM)
- tprintf(fmt, arm_regs.ARM_pc);
-#elif defined(AVR32)
- tprintf(fmt, avr32_regs.pc);
-#elif defined(BFIN)
- long pc;
- if (upeek(tcp->pid, PT_PC, &pc) < 0) {
- PRINTBADPC;
- return;
- }
- tprintf(fmt, pc);
-#elif defined(CRISV10)
- long pc;
- if (upeek(tcp->pid, 4*PT_IRP, &pc) < 0) {
- PRINTBADPC;
- return;
- }
- tprintf(fmt, pc);
-#elif defined(CRISV32)
- long pc;
- if (upeek(tcp->pid, 4*PT_ERP, &pc) < 0) {
- PRINTBADPC;
- return;
- }
- tprintf(fmt, pc);
-#elif defined(TILE)
- tprintf(fmt, (unsigned long) tile_regs.pc);
-#elif defined(OR1K)
- tprintf(fmt, or1k_regs.pc);
-#elif defined(METAG)
- tprintf(fmt, metag_regs.pc);
-#elif defined(XTENSA)
- long pc;
- if (upeek(tcp->pid, REG_PC, &pc) < 0) {
- PRINTBADPC;
- return;
- }
- tprintf(fmt, pc);
-#elif defined(ARC)
- tprintf(fmt, arc_regs.efa);
-#else
-# warning print_pc is not implemented for this architecture
- PRINTBADPC;
-#endif /* architecture */
+#include "print_pc.c"
}
-#ifdef X86_64
-/*
- * PTRACE_GETREGSET was added to the kernel in v2.6.25,
- * a PTRACE_GETREGS based fallback is provided for old kernels.
- */
-static void
-x86_64_getregs_old(pid_t pid)
-{
- /* Use old method, with unreliable heuristical detection of 32-bitness. */
- get_regs_error = ptrace(PTRACE_GETREGS, pid, NULL, &x86_64_regs);
- if (get_regs_error)
- return;
-
- if (x86_64_regs.cs == 0x23) {
- x86_io.iov_len = sizeof(i386_regs);
- /*
- * The order is important: i386_regs and x86_64_regs
- * are overlaid in memory!
- */
- i386_regs.ebx = x86_64_regs.rbx;
- i386_regs.ecx = x86_64_regs.rcx;
- i386_regs.edx = x86_64_regs.rdx;
- i386_regs.esi = x86_64_regs.rsi;
- i386_regs.edi = x86_64_regs.rdi;
- i386_regs.ebp = x86_64_regs.rbp;
- i386_regs.eax = x86_64_regs.rax;
- /* i386_regs.xds = x86_64_regs.ds; unused by strace */
- /* i386_regs.xes = x86_64_regs.es; ditto... */
- /* i386_regs.xfs = x86_64_regs.fs; */
- /* i386_regs.xgs = x86_64_regs.gs; */
- i386_regs.orig_eax = x86_64_regs.orig_rax;
- i386_regs.eip = x86_64_regs.rip;
- /* i386_regs.xcs = x86_64_regs.cs; */
- /* i386_regs.eflags = x86_64_regs.eflags; */
- i386_regs.esp = x86_64_regs.rsp;
- /* i386_regs.xss = x86_64_regs.ss; */
- } else {
- x86_io.iov_len = sizeof(x86_64_regs);
- }
-}
-#endif /* X86_64 */
-
-#ifdef POWERPC
-/*
- * PTRACE_GETREGS was added to the PowerPC kernel in v2.6.23,
- * we provide a slow fallback for old kernels.
- */
-static int
-powerpc_getregs_old(pid_t pid)
-{
- int i;
- long r;
-
- if (iflag) {
- r = upeek(pid, sizeof(long) * PT_NIP, (long *)&ppc_regs.nip);
- if (r)
- goto out;
- }
-#ifdef POWERPC64 /* else we never use it */
- r = upeek(pid, sizeof(long) * PT_MSR, (long *)&ppc_regs.msr);
- if (r)
- goto out;
-#endif
- r = upeek(pid, sizeof(long) * PT_CCR, (long *)&ppc_regs.ccr);
- if (r)
- goto out;
- r = upeek(pid, sizeof(long) * PT_ORIG_R3, (long *)&ppc_regs.orig_gpr3);
- if (r)
- goto out;
- for (i = 0; i <= 8; i++) {
- r = upeek(pid, sizeof(long) * (PT_R0 + i),
- (long *)&ppc_regs.gpr[i]);
- if (r)
- goto out;
- }
- out:
- return r;
-}
+#if defined X86_64 || defined POWERPC
+# include "getregs_old.c"
#endif
#if defined ARCH_REGS_FOR_GETREGSET
@@ -1543,7 +1209,7 @@
return;
getregset_support = -1;
}
- x86_64_getregs_old(pid);
+ getregs_old(pid);
# else /* !X86_64 */
/* Assume that PTRACE_GETREGSET works. */
get_regs_error = get_regset(pid);
@@ -1560,7 +1226,7 @@
if (get_regs_error && errno == EIO) {
old_kernel = 1;
old:
- get_regs_error = powerpc_getregs_old(pid);
+ get_regs_error = getregs_old(pid);
}
# else
/* Assume that PTRACE_GETREGS works. */
@@ -1587,337 +1253,7 @@
long scno = 0;
-#if defined(S390) || defined(S390X)
- scno = s390_regset.gprs[2];
-#elif defined(POWERPC)
- scno = ppc_regs.gpr[0];
-# ifdef POWERPC64
- unsigned int currpers;
-
- /*
- * Check for 64/32 bit mode.
- * Embedded implementations covered by Book E extension of PPC use
- * bit 0 (CM) of 32-bit Machine state register (MSR).
- * Other implementations use bit 0 (SF) of 64-bit MSR.
- */
- currpers = (ppc_regs.msr & 0x8000000080000000) ? 0 : 1;
- update_personality(tcp, currpers);
-# endif
-#elif defined(AVR32)
- scno = avr32_regs.r8;
-#elif defined(BFIN)
- if (upeek(tcp->pid, PT_ORIG_P0, &scno))
- return -1;
-#elif defined(I386)
- scno = i386_regs.orig_eax;
-#elif defined(X86_64) || defined(X32)
-# ifndef __X32_SYSCALL_BIT
-# define __X32_SYSCALL_BIT 0x40000000
-# endif
- unsigned int currpers;
-# if 1
- /* GETREGSET of NT_PRSTATUS tells us regset size,
- * which unambiguously detects i386.
- *
- * Linux kernel distinguishes x86-64 and x32 processes
- * solely by looking at __X32_SYSCALL_BIT:
- * arch/x86/include/asm/compat.h::is_x32_task():
- * if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
- * return true;
- */
- if (x86_io.iov_len == sizeof(i386_regs)) {
- scno = i386_regs.orig_eax;
- currpers = 1;
- } else {
- scno = x86_64_regs.orig_rax;
- currpers = 0;
- if (scno & __X32_SYSCALL_BIT) {
- /*
- * Syscall number -1 requires special treatment:
- * it might be a side effect of SECCOMP_RET_ERRNO
- * filtering that sets orig_rax to -1
- * in some versions of linux kernel.
- * If that is the case, then
- * __X32_SYSCALL_BIT logic does not apply.
- */
- if ((long long) x86_64_regs.orig_rax != -1) {
- scno -= __X32_SYSCALL_BIT;
- currpers = 2;
- } else {
-# ifdef X32
- currpers = 2;
-# endif
- }
- }
- }
-# elif 0
- /* cs = 0x33 for long mode (native 64 bit and x32)
- * cs = 0x23 for compatibility mode (32 bit)
- * ds = 0x2b for x32 mode (x86-64 in 32 bit)
- */
- scno = x86_64_regs.orig_rax;
- switch (x86_64_regs.cs) {
- case 0x23: currpers = 1; break;
- case 0x33:
- if (x86_64_regs.ds == 0x2b) {
- currpers = 2;
- scno &= ~__X32_SYSCALL_BIT;
- } else
- currpers = 0;
- break;
- default:
- fprintf(stderr, "Unknown value CS=0x%08X while "
- "detecting personality of process "
- "PID=%d\n", (int)x86_64_regs.cs, tcp->pid);
- currpers = current_personality;
- break;
- }
-# elif 0
- /* This version analyzes the opcode of a syscall instruction.
- * (int 0x80 on i386 vs. syscall on x86-64)
- * It works, but is too complicated, and strictly speaking, unreliable.
- */
- unsigned long call, rip = x86_64_regs.rip;
- /* sizeof(syscall) == sizeof(int 0x80) == 2 */
- rip -= 2;
- errno = 0;
- call = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)rip, (char *)0);
- if (errno)
- fprintf(stderr, "ptrace_peektext failed: %s\n",
- strerror(errno));
- switch (call & 0xffff) {
- /* x86-64: syscall = 0x0f 0x05 */
- case 0x050f: currpers = 0; break;
- /* i386: int 0x80 = 0xcd 0x80 */
- case 0x80cd: currpers = 1; break;
- default:
- currpers = current_personality;
- fprintf(stderr,
- "Unknown syscall opcode (0x%04X) while "
- "detecting personality of process "
- "PID=%d\n", (int)call, tcp->pid);
- break;
- }
-# endif
-
-# ifdef X32
- /* If we are built for a x32 system, then personality 0 is x32
- * (not x86_64), and stracing of x86_64 apps is not supported.
- * Stracing of i386 apps is still supported.
- */
- if (currpers == 0) {
- fprintf(stderr, "syscall_%lu(...) in unsupported "
- "64-bit mode of process PID=%d\n",
- scno, tcp->pid);
- return 0;
- }
- currpers &= ~2; /* map 2,1 to 0,1 */
-# endif
- update_personality(tcp, currpers);
-#elif defined(IA64)
- if (ia64_ia32mode) {
- scno = ia64_regs.gr[0];
- } else {
- scno = ia64_regs.gr[15];
- }
-#elif defined(AARCH64)
- switch (aarch64_io.iov_len) {
- case sizeof(aarch64_regs):
- /* We are in 64-bit mode */
- scno = aarch64_regs.regs[8];
- update_personality(tcp, 1);
- break;
- case sizeof(arm_regs):
- /* We are in 32-bit mode */
- /* Note: we don't support OABI, unlike 32-bit ARM build */
- scno = arm_regs.ARM_r7;
- scno = shuffle_scno(scno);
- update_personality(tcp, 0);
- break;
- }
-#elif defined(ARM)
- if (arm_regs.ARM_ip != 0) {
- /* It is not a syscall entry */
- fprintf(stderr, "pid %d stray syscall exit\n", tcp->pid);
- tcp->flags |= TCB_INSYSCALL;
- return 0;
- }
- /* Note: we support only 32-bit CPUs, not 26-bit */
-
-# if !defined(__ARM_EABI__) || ENABLE_ARM_OABI
- if (arm_regs.ARM_cpsr & 0x20)
- /* Thumb mode */
- goto scno_in_r7;
- /* ARM mode */
- /* Check EABI/OABI by examining SVC insn's low 24 bits */
- errno = 0;
- scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL);
- if (errno)
- return -1;
- /* EABI syscall convention? */
- if ((unsigned long) scno != 0xef000000) {
- /* No, it's OABI */
- if ((scno & 0x0ff00000) != 0x0f900000) {
- fprintf(stderr, "pid %d unknown syscall trap 0x%08lx\n",
- tcp->pid, scno);
- return -1;
- }
- /* Fixup the syscall number */
- scno &= 0x000fffff;
- } else {
- scno_in_r7:
- scno = arm_regs.ARM_r7;
- }
-# else /* __ARM_EABI__ || !ENABLE_ARM_OABI */
- scno = arm_regs.ARM_r7;
-# endif
- scno = shuffle_scno(scno);
-#elif defined(M68K)
- if (upeek(tcp->pid, 4*PT_ORIG_D0, &scno) < 0)
- return -1;
-#elif defined(MIPS)
- scno = mips_REG_V0;
-
- if (!SCNO_IN_RANGE(scno)) {
- if (mips_REG_A3 == 0 || mips_REG_A3 == (uint64_t) -1) {
- if (debug_flag)
- fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
- return 0;
- }
- }
-#elif defined(ALPHA)
- if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0)
- return -1;
- if (upeek(tcp->pid, REG_R0, &scno) < 0)
- return -1;
-
- /*
- * Do some sanity checks to figure out if it's
- * really a syscall entry
- */
- if (!SCNO_IN_RANGE(scno)) {
- if (alpha_a3 == 0 || alpha_a3 == -1) {
- if (debug_flag)
- fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
- return 0;
- }
- }
-#elif defined(SPARC) || defined(SPARC64)
- /* Disassemble the syscall trap. */
- /* Retrieve the syscall trap instruction. */
- unsigned long trap;
- errno = 0;
-# if defined(SPARC64)
- trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.tpc, 0);
- trap >>= 32;
-# else
- trap = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)sparc_regs.pc, 0);
-# endif
- if (errno)
- return -1;
-
- /* Disassemble the trap to see what personality to use. */
- switch (trap) {
- case 0x91d02010:
- /* Linux/SPARC syscall trap. */
- update_personality(tcp, 0);
- break;
- case 0x91d0206d:
- /* Linux/SPARC64 syscall trap. */
- update_personality(tcp, 2);
- break;
- case 0x91d02000:
- /* SunOS syscall trap. (pers 1) */
- fprintf(stderr, "syscall: SunOS no support\n");
- return -1;
- case 0x91d02008:
- /* Solaris 2.x syscall trap. (per 2) */
- update_personality(tcp, 1);
- break;
- case 0x91d02009:
- /* NetBSD/FreeBSD syscall trap. */
- fprintf(stderr, "syscall: NetBSD/FreeBSD not supported\n");
- return -1;
- case 0x91d02027:
- /* Solaris 2.x gettimeofday */
- update_personality(tcp, 1);
- break;
- default:
-# if defined(SPARC64)
- fprintf(stderr, "syscall: unknown syscall trap %08lx %016lx\n", trap, sparc_regs.tpc);
-# else
- fprintf(stderr, "syscall: unknown syscall trap %08lx %08lx\n", trap, sparc_regs.pc);
-# endif
- return -1;
- }
-
- /* Extract the system call number from the registers. */
- if (trap == 0x91d02027)
- scno = 156;
- else
- scno = sparc_regs.u_regs[U_REG_G1];
- if (scno == 0) {
- scno = sparc_regs.u_regs[U_REG_O0];
- memmove(&sparc_regs.u_regs[U_REG_O0], &sparc_regs.u_regs[U_REG_O1], 7*sizeof(sparc_regs.u_regs[0]));
- }
-#elif defined(HPPA)
- if (upeek(tcp->pid, PT_GR20, &scno) < 0)
- return -1;
-#elif defined(SH)
- /*
- * In the new syscall ABI, the system call number is in R3.
- */
- if (upeek(tcp->pid, 4*(REG_REG0+3), &scno) < 0)
- return -1;
-
- if (scno < 0) {
- /* Odd as it may seem, a glibc bug has been known to cause
- glibc to issue bogus negative syscall numbers. So for
- our purposes, make strace print what it *should* have been */
- long correct_scno = (scno & 0xff);
- if (debug_flag)
- fprintf(stderr,
- "Detected glibc bug: bogus system call"
- " number = %ld, correcting to %ld\n",
- scno,
- correct_scno);
- scno = correct_scno;
- }
-#elif defined(SH64)
- if (upeek(tcp->pid, REG_SYSCALL, &scno) < 0)
- return -1;
- scno &= 0xFFFF;
-#elif defined(CRISV10) || defined(CRISV32)
- if (upeek(tcp->pid, 4*PT_R9, &scno) < 0)
- return -1;
-#elif defined(TILE)
- unsigned int currpers;
- scno = tile_regs.regs[10];
-# ifdef __tilepro__
- currpers = 1;
-# else
-# ifndef PT_FLAGS_COMPAT
-# define PT_FLAGS_COMPAT 0x10000 /* from Linux 3.8 on */
-# endif
- if (tile_regs.flags & PT_FLAGS_COMPAT)
- currpers = 1;
- else
- currpers = 0;
-# endif
- update_personality(tcp, currpers);
-#elif defined(MICROBLAZE)
- if (upeek(tcp->pid, 0, &scno) < 0)
- return -1;
-#elif defined(OR1K)
- scno = or1k_regs.gpr[11];
-#elif defined(METAG)
- scno = metag_regs.dx[0][1]; /* syscall number in D1Re0 (D1.0) */
-#elif defined(XTENSA)
- if (upeek(tcp->pid, SYSCALL_NR, &scno) < 0)
- return -1;
-# elif defined(ARC)
- scno = arc_regs.scratch.r8;
-#endif
+#include "get_scno.c"
tcp->scno = scno;
if (SCNO_IS_VALID(tcp->scno)) {
@@ -1940,463 +1276,17 @@
static int
get_syscall_args(struct tcb *tcp)
{
- int i, nargs;
-
- nargs = tcp->s_ent->nargs;
-
-#if defined(S390) || defined(S390X)
- (void)i;
- (void)nargs;
- tcp->u_arg[0] = s390_regset.orig_gpr2;
- tcp->u_arg[1] = s390_regset.gprs[3];
- tcp->u_arg[2] = s390_regset.gprs[4];
- tcp->u_arg[3] = s390_regset.gprs[5];
- tcp->u_arg[4] = s390_regset.gprs[6];
- tcp->u_arg[5] = s390_regset.gprs[7];
-#elif defined(ALPHA)
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, REG_A0+i, &tcp->u_arg[i]) < 0)
- return -1;
-#elif defined(IA64)
- if (!ia64_ia32mode) {
- unsigned long *rbs_end =
- (unsigned long *) ia64_regs.ar[PT_AUR_BSP];
- unsigned long sof = (ia64_regs.cfm >> 0) & 0x7f;
- unsigned long sol = (ia64_regs.cfm >> 7) & 0x7f;
- unsigned long *out0 = ia64_rse_skip_regs(rbs_end, -sof + sol);
-
- for (i = 0; i < nargs; ++i) {
- if (umoven(tcp, (unsigned long) ia64_rse_skip_regs(out0, i),
- sizeof(long), &tcp->u_arg[i]) < 0)
- return -1;
- }
- } else {
- (void)i;
- (void)nargs;
- /* truncate away IVE sign-extension */
- tcp->u_arg[0] = 0xffffffff & ia64_regs.gr[11]; /* EBX */
- tcp->u_arg[1] = 0xffffffff & ia64_regs.gr[ 9]; /* ECX */
- tcp->u_arg[2] = 0xffffffff & ia64_regs.gr[10]; /* EDX */
- tcp->u_arg[3] = 0xffffffff & ia64_regs.gr[14]; /* ESI */
- tcp->u_arg[4] = 0xffffffff & ia64_regs.gr[15]; /* EDI */
- tcp->u_arg[5] = 0xffffffff & ia64_regs.gr[13]; /* EBP */
- }
-#elif defined LINUX_MIPSN64
- (void)i;
- (void)nargs;
- tcp->u_arg[0] = mips_REG_A0;
- tcp->u_arg[1] = mips_REG_A1;
- tcp->u_arg[2] = mips_REG_A2;
- tcp->u_arg[3] = mips_REG_A3;
- tcp->u_arg[4] = mips_REG_A4;
- tcp->u_arg[5] = mips_REG_A5;
-#elif defined LINUX_MIPSN32
- (void)i;
- (void)nargs;
- tcp->u_arg[0] = tcp->ext_arg[0] = mips_REG_A0;
- tcp->u_arg[1] = tcp->ext_arg[1] = mips_REG_A1;
- tcp->u_arg[2] = tcp->ext_arg[2] = mips_REG_A2;
- tcp->u_arg[3] = tcp->ext_arg[3] = mips_REG_A3;
- tcp->u_arg[4] = tcp->ext_arg[4] = mips_REG_A4;
- tcp->u_arg[5] = tcp->ext_arg[5] = mips_REG_A5;
-#elif defined LINUX_MIPSO32
- (void)i;
- (void)nargs;
- tcp->u_arg[0] = mips_REG_A0;
- tcp->u_arg[1] = mips_REG_A1;
- tcp->u_arg[2] = mips_REG_A2;
- tcp->u_arg[3] = mips_REG_A3;
- if (nargs > 4) {
- umoven(tcp, mips_REG_SP + 4 * 4,
- (nargs - 4) * sizeof(tcp->u_arg[0]),
- &tcp->u_arg[4]);
- }
-#elif defined(POWERPC)
- (void)i;
- (void)nargs;
- tcp->u_arg[0] = ppc_regs.orig_gpr3;
- tcp->u_arg[1] = ppc_regs.gpr[4];
- tcp->u_arg[2] = ppc_regs.gpr[5];
- tcp->u_arg[3] = ppc_regs.gpr[6];
- tcp->u_arg[4] = ppc_regs.gpr[7];
- tcp->u_arg[5] = ppc_regs.gpr[8];
-#elif defined(SPARC) || defined(SPARC64)
- for (i = 0; i < nargs; ++i)
- tcp->u_arg[i] = sparc_regs.u_regs[U_REG_O0 + i];
-#elif defined(HPPA)
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, PT_GR26-4*i, &tcp->u_arg[i]) < 0)
- return -1;
-#elif defined(ARM) || defined(AARCH64)
-# if defined(AARCH64)
- if (tcp->currpers == 1)
- for (i = 0; i < nargs; ++i)
- tcp->u_arg[i] = aarch64_regs.regs[i];
- else
-# endif
- for (i = 0; i < nargs; ++i)
- tcp->u_arg[i] = arm_regs.uregs[i];
-#elif defined(AVR32)
- (void)i;
- (void)nargs;
- tcp->u_arg[0] = avr32_regs.r12;
- tcp->u_arg[1] = avr32_regs.r11;
- tcp->u_arg[2] = avr32_regs.r10;
- tcp->u_arg[3] = avr32_regs.r9;
- tcp->u_arg[4] = avr32_regs.r5;
- tcp->u_arg[5] = avr32_regs.r3;
-#elif defined(BFIN)
- static const int argreg[MAX_ARGS] = { PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5 };
-
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, argreg[i], &tcp->u_arg[i]) < 0)
- return -1;
-#elif defined(SH)
- static const int syscall_regs[MAX_ARGS] = {
- 4 * (REG_REG0+4), 4 * (REG_REG0+5), 4 * (REG_REG0+6),
- 4 * (REG_REG0+7), 4 * (REG_REG0 ), 4 * (REG_REG0+1)
- };
-
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, syscall_regs[i], &tcp->u_arg[i]) < 0)
- return -1;
-#elif defined(SH64)
- int i;
- /* Registers used by SH5 Linux system calls for parameters */
- static const int syscall_regs[MAX_ARGS] = { 2, 3, 4, 5, 6, 7 };
-
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
- return -1;
-#elif defined(I386)
- (void)i;
- (void)nargs;
- tcp->u_arg[0] = i386_regs.ebx;
- tcp->u_arg[1] = i386_regs.ecx;
- tcp->u_arg[2] = i386_regs.edx;
- tcp->u_arg[3] = i386_regs.esi;
- tcp->u_arg[4] = i386_regs.edi;
- tcp->u_arg[5] = i386_regs.ebp;
-#elif defined(X86_64) || defined(X32)
- (void)i;
- (void)nargs;
- if (x86_io.iov_len != sizeof(i386_regs)) {
- /* x86-64 or x32 ABI */
- tcp->u_arg[0] = x86_64_regs.rdi;
- tcp->u_arg[1] = x86_64_regs.rsi;
- tcp->u_arg[2] = x86_64_regs.rdx;
- tcp->u_arg[3] = x86_64_regs.r10;
- tcp->u_arg[4] = x86_64_regs.r8;
- tcp->u_arg[5] = x86_64_regs.r9;
-# ifdef X32
- tcp->ext_arg[0] = x86_64_regs.rdi;
- tcp->ext_arg[1] = x86_64_regs.rsi;
- tcp->ext_arg[2] = x86_64_regs.rdx;
- tcp->ext_arg[3] = x86_64_regs.r10;
- tcp->ext_arg[4] = x86_64_regs.r8;
- tcp->ext_arg[5] = x86_64_regs.r9;
-# endif
- } else {
- /* i386 ABI */
- /* Zero-extend from 32 bits */
- /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers
- * if you need to use *sign-extended* parameter.
- */
- tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx;
- tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx;
- tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx;
- tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi;
- tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi;
- tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp;
- }
-#elif defined(MICROBLAZE)
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, (5 + i) * 4, &tcp->u_arg[i]) < 0)
- return -1;
-#elif defined(CRISV10) || defined(CRISV32)
- static const int crisregs[MAX_ARGS] = {
- 4*PT_ORIG_R10, 4*PT_R11, 4*PT_R12,
- 4*PT_R13 , 4*PT_MOF, 4*PT_SRP
- };
-
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, crisregs[i], &tcp->u_arg[i]) < 0)
- return -1;
-#elif defined(TILE)
- for (i = 0; i < nargs; ++i)
- tcp->u_arg[i] = tile_regs.regs[i];
-#elif defined(M68K)
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, (i < 5 ? i : i + 2)*4, &tcp->u_arg[i]) < 0)
- return -1;
-#elif defined(OR1K)
- (void)nargs;
- for (i = 0; i < 6; ++i)
- tcp->u_arg[i] = or1k_regs.gpr[3 + i];
-#elif defined(METAG)
- for (i = 0; i < nargs; i++)
- /* arguments go backwards from D1Ar1 (D1.3) */
- tcp->u_arg[i] = ((unsigned long *)&metag_regs.dx[3][1])[-i];
-#elif defined(XTENSA)
- /* arg0: a6, arg1: a3, arg2: a4, arg3: a5, arg4: a8, arg5: a9 */
- static const int xtensaregs[MAX_ARGS] = { 6, 3, 4, 5, 8, 9 };
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, REG_A_BASE + xtensaregs[i], &tcp->u_arg[i]) < 0)
- return -1;
-# elif defined(ARC)
- long *arc_args = &arc_regs.scratch.r0;
- for (i = 0; i < nargs; ++i)
- tcp->u_arg[i] = *arc_args--;
-
-#else /* Other architecture (32bits specific) */
- for (i = 0; i < nargs; ++i)
- if (upeek(tcp->pid, i*4, &tcp->u_arg[i]) < 0)
- return -1;
-#endif
+#include "get_syscall_args.c"
return 1;
}
static void
get_error(struct tcb *tcp)
{
- int u_error = 0;
- int check_errno = 1;
- if (tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS) {
- check_errno = 0;
- }
-#if defined(S390) || defined(S390X)
- if (check_errno && is_negated_errno(s390_regset.gprs[2])) {
- tcp->u_rval = -1;
- u_error = -s390_regset.gprs[2];
- }
- else {
- tcp->u_rval = s390_regset.gprs[2];
- }
-#elif defined(I386)
- if (check_errno && is_negated_errno(i386_regs.eax)) {
- tcp->u_rval = -1;
- u_error = -i386_regs.eax;
- }
- else {
- tcp->u_rval = i386_regs.eax;
- }
-#elif defined(X86_64) || defined(X32)
- /*
- * In X32, return value is 64-bit (llseek uses one).
- * Using merely "long rax" would not work.
- */
- long long rax;
+ const bool check_errno = !(tcp->s_ent->sys_flags & SYSCALL_NEVER_FAILS);
+ tcp->u_error = 0;
- if (x86_io.iov_len == sizeof(i386_regs)) {
- /* Sign extend from 32 bits */
- rax = (int32_t) i386_regs.eax;
- } else {
- rax = x86_64_regs.rax;
- }
- if (check_errno && is_negated_errno(rax)) {
- tcp->u_rval = -1;
- u_error = -rax;
- }
- else {
- tcp->u_rval = rax;
-# ifdef X32
- /* tcp->u_rval contains a truncated value */
- tcp->u_lrval = rax;
-# endif
- }
-#elif defined(IA64)
- if (ia64_ia32mode) {
- int err = ia64_regs.gr[8];
- if (check_errno && is_negated_errno(err)) {
- tcp->u_rval = -1;
- u_error = -err;
- }
- else {
- tcp->u_rval = err;
- }
- } else {
- if (check_errno && ia64_regs.gr[10]) {
- tcp->u_rval = -1;
- u_error = ia64_regs.gr[8];
- } else {
- tcp->u_rval = ia64_regs.gr[8];
- }
- }
-#elif defined(MIPS)
- if (check_errno && mips_REG_A3) {
- tcp->u_rval = -1;
- u_error = mips_REG_V0;
- } else {
-# if defined LINUX_MIPSN32
- tcp->u_lrval = mips_REG_V0;
-# endif
- tcp->u_rval = mips_REG_V0;
- }
-#elif defined(POWERPC)
- if (check_errno && (ppc_regs.ccr & 0x10000000)) {
- tcp->u_rval = -1;
- u_error = ppc_regs.gpr[3];
- }
- else {
- tcp->u_rval = ppc_regs.gpr[3];
- }
-#elif defined(M68K)
- if (check_errno && is_negated_errno(m68k_d0)) {
- tcp->u_rval = -1;
- u_error = -m68k_d0;
- }
- else {
- tcp->u_rval = m68k_d0;
- }
-#elif defined(ARM) || defined(AARCH64)
-# if defined(AARCH64)
- if (tcp->currpers == 1) {
- if (check_errno && is_negated_errno(aarch64_regs.regs[0])) {
- tcp->u_rval = -1;
- u_error = -aarch64_regs.regs[0];
- }
- else {
- tcp->u_rval = aarch64_regs.regs[0];
- }
- }
- else
-# endif
- {
- if (check_errno && is_negated_errno(arm_regs.ARM_r0)) {
- tcp->u_rval = -1;
- u_error = -arm_regs.ARM_r0;
- }
- else {
- tcp->u_rval = arm_regs.ARM_r0;
- }
- }
-#elif defined(AVR32)
- if (check_errno && avr32_regs.r12 && (unsigned) -avr32_regs.r12 < nerrnos) {
- tcp->u_rval = -1;
- u_error = -avr32_regs.r12;
- }
- else {
- tcp->u_rval = avr32_regs.r12;
- }
-#elif defined(BFIN)
- if (check_errno && is_negated_errno(bfin_r0)) {
- tcp->u_rval = -1;
- u_error = -bfin_r0;
- } else {
- tcp->u_rval = bfin_r0;
- }
-#elif defined(ALPHA)
- if (check_errno && alpha_a3) {
- tcp->u_rval = -1;
- u_error = alpha_r0;
- }
- else {
- tcp->u_rval = alpha_r0;
- }
-#elif defined(SPARC)
- if (check_errno && sparc_regs.psr & PSR_C) {
- tcp->u_rval = -1;
- u_error = sparc_regs.u_regs[U_REG_O0];
- }
- else {
- tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
- }
-#elif defined(SPARC64)
- if (check_errno && sparc_regs.tstate & 0x1100000000UL) {
- tcp->u_rval = -1;
- u_error = sparc_regs.u_regs[U_REG_O0];
- }
- else {
- tcp->u_rval = sparc_regs.u_regs[U_REG_O0];
- }
-#elif defined(HPPA)
- if (check_errno && is_negated_errno(hppa_r28)) {
- tcp->u_rval = -1;
- u_error = -hppa_r28;
- }
- else {
- tcp->u_rval = hppa_r28;
- }
-#elif defined(SH)
- if (check_errno && is_negated_errno(sh_r0)) {
- tcp->u_rval = -1;
- u_error = -sh_r0;
- }
- else {
- tcp->u_rval = sh_r0;
- }
-#elif defined(SH64)
- if (check_errno && is_negated_errno(sh64_r9)) {
- tcp->u_rval = -1;
- u_error = -sh64_r9;
- }
- else {
- tcp->u_rval = sh64_r9;
- }
-#elif defined(METAG)
- /* result pointer in D0Re0 (D0.0) */
- if (check_errno && is_negated_errno(metag_regs.dx[0][0])) {
- tcp->u_rval = -1;
- u_error = -metag_regs.dx[0][0];
- }
- else {
- tcp->u_rval = metag_regs.dx[0][0];
- }
-#elif defined(CRISV10) || defined(CRISV32)
- if (check_errno && cris_r10 && (unsigned) -cris_r10 < nerrnos) {
- tcp->u_rval = -1;
- u_error = -cris_r10;
- }
- else {
- tcp->u_rval = cris_r10;
- }
-#elif defined(TILE)
- /*
- * The standard tile calling convention returns the value (or negative
- * errno) in r0, and zero (or positive errno) in r1.
- * Until at least kernel 3.8, however, the r1 value is not reflected
- * in ptregs at this point, so we use r0 here.
- */
- if (check_errno && is_negated_errno(tile_regs.regs[0])) {
- tcp->u_rval = -1;
- u_error = -tile_regs.regs[0];
- } else {
- tcp->u_rval = tile_regs.regs[0];
- }
-#elif defined(MICROBLAZE)
- if (check_errno && is_negated_errno(microblaze_r3)) {
- tcp->u_rval = -1;
- u_error = -microblaze_r3;
- }
- else {
- tcp->u_rval = microblaze_r3;
- }
-#elif defined(OR1K)
- if (check_errno && is_negated_errno(or1k_regs.gpr[11])) {
- tcp->u_rval = -1;
- u_error = -or1k_regs.gpr[11];
- }
- else {
- tcp->u_rval = or1k_regs.gpr[11];
- }
-#elif defined(XTENSA)
- if (check_errno && is_negated_errno(xtensa_a2)) {
- tcp->u_rval = -1;
- u_error = -xtensa_a2;
- }
- else {
- tcp->u_rval = xtensa_a2;
- }
-#elif defined(ARC)
- if (check_errno && is_negated_errno(arc_regs.scratch.r0)) {
- tcp->u_rval = -1;
- u_error = -arc_regs.scratch.r0;
- }
- else {
- tcp->u_rval = arc_regs.scratch.r0;
- }
-#endif
- tcp->u_error = u_error;
+#include "get_error.c"
}
/* Returns:
@@ -2409,39 +1299,8 @@
{
#if defined ARCH_REGS_FOR_GETREGSET || defined ARCH_REGS_FOR_GETREGS
/* already done by get_regs */
-#elif defined(BFIN)
- if (upeek(tcp->pid, PT_R0, &bfin_r0) < 0)
- return -1;
-#elif defined(M68K)
- if (upeek(tcp->pid, 4*PT_D0, &m68k_d0) < 0)
- return -1;
-#elif defined(ALPHA)
- if (upeek(tcp->pid, REG_A3, &alpha_a3) < 0)
- return -1;
- if (upeek(tcp->pid, REG_R0, &alpha_r0) < 0)
- return -1;
-#elif defined(HPPA)
- if (upeek(tcp->pid, PT_GR28, &hppa_r28) < 0)
- return -1;
-#elif defined(SH)
- /* new syscall ABI returns result in R0 */
- if (upeek(tcp->pid, 4*REG_REG0, (long *)&sh_r0) < 0)
- return -1;
-#elif defined(SH64)
- /* ABI defines result returned in r9 */
- if (upeek(tcp->pid, REG_GENERAL(9), (long *)&sh64_r9) < 0)
- return -1;
-#elif defined(CRISV10) || defined(CRISV32)
- if (upeek(tcp->pid, 4*PT_R10, &cris_r10) < 0)
- return -1;
-#elif defined(MICROBLAZE)
- if (upeek(tcp->pid, 3 * 4, µblaze_r3) < 0)
- return -1;
-#elif defined(XTENSA)
- if (upeek(tcp->pid, REG_A_BASE + 2, &xtensa_a2) < 0)
- return -1;
#else
-# error get_syscall_result is not implemented for this architecture
+# include "get_syscall_result.c"
#endif
get_error(tcp);
return 1;