From: Denys Vlasenko Date: Sat, 17 Mar 2012 01:17:51 +0000 (+0100) Subject: Move change_syscall() to its only user and make it static X-Git-Tag: v4.7~72 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=081533c10048365a2a8ffd2456af81765d402810;p=strace Move change_syscall() to its only user and make it static * 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 --- diff --git a/defs.h b/defs.h index 3f60d161..89ccf54d 100644 --- 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 *); diff --git a/process.c b/process.c index d4479631..ac184fa7 100644 --- 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*)®s, 0) < 0) - return -1; - regs.u_regs[U_REG_G1] = new; - if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)®s, 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 88765ca2..18d29b74 100644 --- 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*)®s, 0) < 0) + return -1; + regs.u_regs[U_REG_G1] = new; + if (ptrace(PTRACE_SETREGS, tcp->pid, (char*)®s, 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;