]> granicus.if.org Git - strace/commitdiff
Move change_syscall() to its only user and make it static
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 17 Mar 2012 01:17:51 +0000 (02:17 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 17 Mar 2012 01:17:51 +0000 (02:17 +0100)
* defs.h: Remove declaration of change_syscall().
* process.c (change_syscall): Remove definition of this function.
* util.c (change_syscall): Add definition of change_syscall().

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
defs.h
process.c
util.c

diff --git a/defs.h b/defs.h
index 3f60d1614a3870a0751665d510ee054e53b00034..89ccf54d2f29f72adc7df0e41551a43612bd621c 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -524,7 +524,6 @@ extern int is_restart_error(struct tcb *);
 extern int pathtrace_select(const char *);
 extern int pathtrace_match(struct tcb *);
 
-extern int change_syscall(struct tcb *, int);
 extern int internal_fork(struct tcb *);
 extern int internal_exec(struct tcb *);
 
index d44796312063b5b8d141758581cd74721c09efe6..ac184fa7aefe280efd97804a68f3362dc52b7128 100644 (file)
--- a/process.c
+++ b/process.c
@@ -530,124 +530,6 @@ sys_unshare(struct tcb *tcp)
        return 0;
 }
 
-int
-sys_fork(struct tcb *tcp)
-{
-       if (exiting(tcp))
-               return RVAL_UDECIMAL;
-       return 0;
-}
-
-int
-change_syscall(struct tcb *tcp, int new)
-{
-#if defined(I386)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
-               return -1;
-       return 0;
-#elif defined(X86_64)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
-               return -1;
-       return 0;
-#elif defined(POWERPC)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid,
-                  (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
-               return -1;
-       return 0;
-#elif defined(S390) || defined(S390X)
-       /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new) < 0)
-               return -1;
-       return 0;
-#elif defined(M68K)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new) < 0)
-               return -1;
-       return 0;
-#elif defined(SPARC) || defined(SPARC64)
-       struct pt_regs regs;
-       if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0) < 0)
-               return -1;
-       regs.u_regs[U_REG_G1] = new;
-       if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0) < 0)
-               return -1;
-       return 0;
-#elif defined(MIPS)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new) < 0)
-               return -1;
-       return 0;
-#elif defined(ALPHA)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new) < 0)
-               return -1;
-       return 0;
-#elif defined(AVR32)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_R8), new) < 0)
-               return -1;
-       return 0;
-#elif defined(BFIN)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_P0), new) < 0)
-               return -1;
-       return 0;
-#elif defined(IA64)
-       if (ia32) {
-               switch (new) {
-               case 2:
-                       break;  /* x86 SYS_fork */
-               case SYS_clone:
-                       new = 120;
-                       break;
-               default:
-                       fprintf(stderr, "%s: unexpected syscall %d\n",
-                               __FUNCTION__, new);
-                       return -1;
-               }
-               if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new) < 0)
-                       return -1;
-       } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new) < 0)
-               return -1;
-       return 0;
-#elif defined(HPPA)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new) < 0)
-               return -1;
-       return 0;
-#elif defined(SH)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new) < 0)
-               return -1;
-       return 0;
-#elif defined(SH64)
-       /* Top half of reg encodes the no. of args n as 0x1n.
-          Assume 0 args as kernel never actually checks... */
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
-                               0x100000 | new) < 0)
-               return -1;
-       return 0;
-#elif defined(CRISV10) || defined(CRISV32)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R9), new) < 0)
-               return -1;
-       return 0;
-#elif defined(ARM)
-       /* Some kernels support this, some (pre-2.6.16 or so) don't.  */
-# ifndef PTRACE_SET_SYSCALL
-#  define PTRACE_SET_SYSCALL 23
-# endif
-       if (ptrace(PTRACE_SET_SYSCALL, tcp->pid, 0, new & 0xffff) != 0)
-               return -1;
-       return 0;
-#elif defined(TILE)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid,
-                  (char*)PTREGS_OFFSET_REG(0),
-                  new) != 0)
-               return -1;
-       return 0;
-#elif defined(MICROBLAZE)
-       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR(0)), new) < 0)
-               return -1;
-       return 0;
-#else
-#warning Do not know how to handle change_syscall for this architecture
-#endif /* architecture */
-       return -1;
-}
-
 int
 internal_fork(struct tcb *tcp)
 {
@@ -676,6 +558,14 @@ internal_fork(struct tcb *tcp)
        return 0;
 }
 
+int
+sys_fork(struct tcb *tcp)
+{
+       if (exiting(tcp))
+               return RVAL_UDECIMAL;
+       return 0;
+}
+
 int
 sys_vfork(struct tcb *tcp)
 {
diff --git a/util.c b/util.c
index 88765ca274b349f00ceac10caa8e27ed0091f72f..18d29b74dc440bc32fb45cb6eaac24604e28f9f6 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1169,6 +1169,116 @@ printcall(struct tcb *tcp)
 # define CLONE_STOPPED   0x02000000
 #endif
 
+static int
+change_syscall(struct tcb *tcp, int new)
+{
+#if defined(I386)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
+               return -1;
+       return 0;
+#elif defined(X86_64)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_RAX * 8), new) < 0)
+               return -1;
+       return 0;
+#elif defined(POWERPC)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid,
+                  (char*)(sizeof(unsigned long)*PT_R0), new) < 0)
+               return -1;
+       return 0;
+#elif defined(S390) || defined(S390X)
+       /* s390 linux after 2.4.7 has a hook in entry.S to allow this */
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR2), new) < 0)
+               return -1;
+       return 0;
+#elif defined(M68K)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_ORIG_D0), new) < 0)
+               return -1;
+       return 0;
+#elif defined(SPARC) || defined(SPARC64)
+       struct pt_regs regs;
+       if (ptrace(PTRACE_GETREGS, tcp->pid, (char*)&regs, 0) < 0)
+               return -1;
+       regs.u_regs[U_REG_G1] = new;
+       if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)&regs, 0) < 0)
+               return -1;
+       return 0;
+#elif defined(MIPS)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_V0), new) < 0)
+               return -1;
+       return 0;
+#elif defined(ALPHA)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_A3), new) < 0)
+               return -1;
+       return 0;
+#elif defined(AVR32)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_R8), new) < 0)
+               return -1;
+       return 0;
+#elif defined(BFIN)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_P0), new) < 0)
+               return -1;
+       return 0;
+#elif defined(IA64)
+       if (ia32) {
+               switch (new) {
+               case 2:
+                       break;  /* x86 SYS_fork */
+               case SYS_clone:
+                       new = 120;
+                       break;
+               default:
+                       fprintf(stderr, "%s: unexpected syscall %d\n",
+                               __FUNCTION__, new);
+                       return -1;
+               }
+               if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R1), new) < 0)
+                       return -1;
+       } else if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_R15), new) < 0)
+               return -1;
+       return 0;
+#elif defined(HPPA)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GR20), new) < 0)
+               return -1;
+       return 0;
+#elif defined(SH)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*(REG_REG0+3)), new) < 0)
+               return -1;
+       return 0;
+#elif defined(SH64)
+       /* Top half of reg encodes the no. of args n as 0x1n.
+          Assume 0 args as kernel never actually checks... */
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(REG_SYSCALL),
+                               0x100000 | new) < 0)
+               return -1;
+       return 0;
+#elif defined(CRISV10) || defined(CRISV32)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*PT_R9), new) < 0)
+               return -1;
+       return 0;
+#elif defined(ARM)
+       /* Some kernels support this, some (pre-2.6.16 or so) don't.  */
+# ifndef PTRACE_SET_SYSCALL
+#  define PTRACE_SET_SYSCALL 23
+# endif
+       if (ptrace(PTRACE_SET_SYSCALL, tcp->pid, 0, new & 0xffff) != 0)
+               return -1;
+       return 0;
+#elif defined(TILE)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid,
+                  (char*)PTREGS_OFFSET_REG(0),
+                  new) != 0)
+               return -1;
+       return 0;
+#elif defined(MICROBLAZE)
+       if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(PT_GPR(0)), new) < 0)
+               return -1;
+       return 0;
+#else
+#warning Do not know how to handle change_syscall for this architecture
+#endif /* architecture */
+       return -1;
+}
+
 #ifdef IA64
 
 typedef unsigned long *arg_setup_state;