summaryrefslogtreecommitdiff
path: root/syscall.c
Commit message (Collapse)AuthorAge
* Alias sys_vfork to sys_forkDmitry V. Levin2014-05-12
| | | | | | | | | * process.c (sys_vfork): Remove. * linux/syscall.h (sys_vfork): Likewise. * linux/dummy.h (sys_vfork): Alias to sys_fork. * linux/alpha/syscallent.h: Fix vfork entry. * util.c (setbpt): Do not check for sys_vfork. * syscall.c (syscall_fixup_for_fork_exec): Likewise.
* ARM EABI: disable OABI support by defaultDmitry V. Levin2014-03-20
| | | | | | | | | OABI is rarely used in ARM EABI systems nowadays, so disable its support by default. Add --enable-arm-oabi option to enable ARM OABI support. * configure.ac: New option --enable-arm-oabi. * syscall.c (get_scno) [ARM]: Check ENABLE_ARM_OABI macro defined by configure instead of undocumented STRACE_KNOWS_ONLY_EABI macro.
* aarch64: fix decoding of arm syscall numbersElliott Hughes2014-03-03
| | | | | | | | | | | If an aarch64 strace is tracing a process using the arm personality, it also needs to call the shuffle_scno function for the ARM-specific syscalls. * syscall.c (shuffle_scno): Define on AARCH64. (get_scno) [AARCH64]: Call shuffle_scno when the tracee is in 32-bit mode. Signed-off-by: Elliott Hughes <enh@google.com>
* powerpc64: fix 64-bit process detection on embeddedJames Yang2014-02-25
| | | | | | | | * syscall.c (get_scno) [POWERPC64]: Fix 64-bit process detection on embedded powerpc. Signed-off-by: James Yang <james.yang@freescale.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* Delete old PTRACE_{PEEK,POKE}USR logicMike Frysinger2013-12-31
| | | | | | | | | | | The code base has settled on PTRACE_{PEEK,POKE}USER (with an E) and has logic in defs.h to make sure it's set sanely. Delete this old logic as the defs.h takes care of it now. * process.c: Delete PTRACE_PEEKUSR/PTRACE_POKEUSR defines. * signal.c: Likewise. * syscall.c: Delete PTRACE_PEEKUSR define. * util.c: Likewise.
* Work around conflict between <sys/ptrace.h> and <linux/ptrace.h>Ali Polatel2013-09-26
| | | | | | | | | | | | | | | Since glibc-2.18~39 <sys/ptrace.h> defines ptrace_peeksiginfo_args which collides with <linux/ptrace.h>. * configure.ac: Check for `struct ptrace_peeksiginfo_args' in <sys/ptrace.h>. * process.c: Work around potential conflict between <sys/ptrace.h> and <linux/ptrace.h> by redefining ptrace_peeksiginfo_args. * signal.c: Likewise. * syscall.c: Likewise. * util.c: Likewise. Signed-off-by: Ali Polatel <alip@exherbo.org>
* Add support for ARC Cores from SynopsysVineet Gupta2013-09-11
| | | | | | | | | | | | | | | | | | | | | | | | | | Take #2 on mainlining strace support for ARC (last one was 4.6 based back in March 2011), see http://sourceforge.net/p/strace/mailman/message/27210168/ The syscall ABI is asm-generic/unistd.h based (so no legacy syscalls), hence very similar to metag port. test/* all seem to work well. * linux/arc/ioctlent.h.in: New file. * linux/arc/syscallent.h: Likewise. * Makefile.am (EXTRA_DIST): Add linux/arc/ioctlent.h.in and linux/arc/syscallent.h. * configure.ac: Add ARC to the list of supported architectures. * defs.h: Add ARC support. * process.c (struct_user_offsets): Likewise. * signal.c (sys_sigreturn): Likewise. * syscall.c (print_pc, get_regset, get_regs, get_scno, get_syscall_args, get_syscall_result, get_error): Likewise. * util.c (change_syscall): Likewise. Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Acked-by: Mike Frysinger <vapier@gentoo.org>
* I386: fix signedness mismatch warningDenys Vlasenko2013-07-18
| | | | | | | &i386_regs.esp is a pointer to long, not unsigned long. It needs a cast. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* ARM: remove wrong NSIG = 32 defineDenys Vlasenko2013-07-18
| | | | | | | | | | | | | | | | | | | | | | | | ARM in fact has 64 signals (1..64), and NSIG should be 65 (as usual, rememebr that NSIG_libc == NSIG_kernel+1). I carefully reviewed all usages of NSIG. In syscall.c, the only usage is: for (i = 0; i <= NSIG; i++) if (strcasecmp(s, signame(i) + 3) == 0)... which is safe even if NSIG is way too big - signame(i) returns a well-formed string for any i. In signal.c, memcpy(&sigset, &sc.sc_mask, NSIG / 8) is used by IA64 and TILE code, so ARM change can't affect it. And final usage is: struct new_sigaction::unsigned long sa_mask[NSIG / sizeof(long)]; It will grow on ARM (and become correct in the process). Its only use is memcpy(&sigset, &sa.sa_mask, NSIG / 8); printsigmask(&sigset, 1); which used to copy garbage in high bits, now it will copy actual data. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Improve sigreturn decoding on x86 to show RT signal bits too.Denys Vlasenko2013-07-16
| | | | | | | | | This includes decoding of 32-bit sigreturn by 64-bit strace, which previously wasn't done. Added a test for it. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* powerpc: fix some compiler warningsAnton Blanchard2013-07-12
| | | | | | | | Fix a number of differing signedness warnings when building on powerpc. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* s390[x]: get rid of syscall_mode, delete code which never triggersDenys Vlasenko2013-07-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change, the logic was as follows: syscall entry: get_scno: syscall_mode = GPR2 scno = syscall_mode unless syscall_mode == -ENOSYS (if -ENOSYS, scn is retrieved by decoding current insn) fixup: gpr2 = GPR2 syscall_mode = scno unless syscall_mode == -ENOSYS if (gpr2 != syscall_mode) stray_entry syscall exit: get_res: gpr2 = GRP2 fixup: syscall_mode = scno unless syscall_mode == -ENOSYS if (WAITEXECVE && gpr2 in (-ENOSYS, scno)) gpr2 = 0; get_error: gpr2 is retval Entry fixup's if() can never trigger: regardless whether GPR2 is -ENOSYS or not, syscall_mode is always equal to GRP2 value there. So it can be removed. On sysexit path, syscall mode is never used. Therefore, syscall_mode variable is deleted. grp2 is read from GPR2 register in get_scno, redundant read in entry fixup is removed. As a result, entry fixup's s390 code block vanishes completely. gpr2 variable is renamed s390_gpr2 to match the convention used by other arches. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* ARM: add STRACE_KNOWS_ONLY_EABI define which can be used to omit OABI supportDenys Vlasenko2013-07-04
| | | | Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Remove ia64-specific printing of current address on signal deliveryDenys Vlasenko2013-07-01
| | | | | | The address is printed anyway by printleader() if -i is active. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Rename ia32 to ia64_ia32mode, and make it bool, not longDenys Vlasenko2013-07-01
| | | | | | Grepping for just ia32 was turning up many false positives. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Fold is_restart_error() into its sole userDenys Vlasenko2013-06-30
| | | | Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* POWERPC: get rid of "static long ppc_result"Denys Vlasenko2013-06-28
| | | | Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* POWERPC: read ppc_regs.nip if -iDenys Vlasenko2013-06-28
| | | | Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* POWERPC: if GETREGS fails with EIO, don't try it againDenys Vlasenko2013-06-28
| | | | Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Get rid of powerpc_getreg(), it's a copy of upeek()Denys Vlasenko2013-06-28
| | | | Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Change upeek() to take pid, not full tcp.Denys Vlasenko2013-06-28
| | | | | | This will be used by next change. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* powerpc: Provide a fallback for old kernels without PTRACE_GETREGSAnton Blanchard2013-06-26
| | | | | | | | | | | | PTRACE_GETREGS was added to the ppc kernel in 2.6.23. In order to provide backward compatibility for very old kernels, add a manual fallback. * syscall.c (powerpc_getreg, powerpc_getregs_old): New functions. (get_regs): Call powerpc_getregs_old if PTRACE_GETREGS is not supported. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* powerpc: Use PTRACE_GETREGS to fetch all registersAnton Blanchard2013-06-26
| | | | | | | | | | | | * defs.h: declare ppc_regs and get_regs_error. * signal.c (sys_sigreturn): Use ppc_regs instead of upeek. * syscall.c: define ppc_regs. (printcall): Use ppc_regs instead of upeek. (get_scno): Replace multiple upeek calls with one PTRACE_GETREGS call. (get_syscall_result): Likewise. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Hide startup syscalls.Denys Vlasenko2013-05-14
| | | | | | | | | | | | | | | | | | | Tested with "./strace [-D] [-q] [-bexecve] env true", all cases seem to work. * defs.h: Declare new variable: bool hide_log_until_execve. * strace.c: Define hide_log_until_execve. Rename skip_startup_execve to skip_one_b_execve. (startup_child): Do not set skip_one_b_execve = 1 here. (init): If "strace PROG" case (as opposed to "strace -pPID"), set skip_one_b_execve and hide_log_until_execve to 1. (trace): Don't print signal messages if hide_log_until_execve == 1. * syscall.c (trace_syscall_entering): Skip syscall printing if hide_log_until_execve == 1. Reset hide_log_until_execve if we enter execve syscall. (trace_syscall_exiting): Skip syscall printing if hide_log_until_execve == 1. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Add support for the XTENSA architectureChris Zankel2013-03-25
| | | | | | | | | | | | | | * configure.ac: Add XTENSA to the list of supported architectures. * defs.h: Add XTENSA support. * linux/xtensa/syscallent.h: New file. * linux/xtensa/ioctlent.h.in: Likewise. * process.c (struct_user_offsets): Add XTENSA support. * signal.c (sys_sigreturn): Likewise. * syscall.c (printcall, get_scno, get_syscall_args, get_syscall_result, get_error): Likewise. * util.c (change_syscall): Likewise. Signed-off-by: Chris Zankel <chris@zankel.net>
* Reorganize get_regs code, hopefully without functional changesDmitry V. Levin2013-03-18
| | | | | | | * syscall.c [I386 || ARM || OR1K || METAG] (ARCH_REGS_FOR_GETREGSET): New macro. (get_regset): Implement for AARCH64, METAG, OR1K and X32. (get_regs) [AARCH64 || METAG || OR1K || X32]: Use it.
* arm, i386: use PTRACE_GETREGSET if availableDmitry V. Levin2013-03-18
| | | | | * syscall.c [ARM || I386 || X86_64] (get_regset): New function. (get_regs) [ARM || I386 || X86_64]: Use it.
* Include <sys/uio.h> and <elf.h> on all architecturesDmitry V. Levin2013-03-18
| | | | * syscall.c: Include <sys/uio.h> and <elf.h> on all architectures.
* x86-64: enhance PTRACE_GETREGSET testDmitry V. Levin2013-03-18
| | | | | * syscall.c (get_regs) [X86_64]: Check whether PTRACE_GETREGSET works regardless of the kernel version.
* x32: use PTRACE_GETREGSET unconditionallyDmitry V. Levin2013-03-18
| | | | | * syscall.c (get_regs) [X32]: Assume that PTRACE_GETREGSET always works regardless of the kernel version.
* x86-64, x32: do not include linux/ptrace.h unnecessarilyDmitry V. Levin2013-03-18
| | | | * syscall.c [X86_64 || X32]: Stop including linux/ptrace.h.
* Emit better message for ERESTARTNOHAND returnDenys Vlasenko2013-03-05
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Add support for Imagination Technologies MetaJames Hogan2013-03-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for Imagination Technologies Meta architecture (the architecture/ABI is usually referred to as metag in code). The Meta Linux kernel port is in the process of being upstreamed for v3.9 so it uses generic system call numbers. sys_lookup_dcookie writes a filename to buffer argument, so I've set TF flag. nfsservctl appears to be set to sys_ni_syscall in asm-generic/unistd.h so I've left it blank. truncate64/ftruncate64/pread64/pwrite64/readahead have unaligned 64bit args which are packed tightly on metag, so less arguments on metag. fchdir/llseek takes a file descriptor so s/TF/TD/ sync_file_range has 2 64bit args so uses 6 args, so s/4/6/ timerfd_create/msgget/msgctl/msgrcv/semget/segtimedop/semop/shmget/ shmctl/shmat/shmdt/recvmsg/migrate_pages have different number of args. oldgetrlimit is just getrlimit for metag. add TM flag to various memory syscalls. metag doesn't directly use sys_mmap_pgoff for mmap2. prlimit64/process_vm_readv/process_vm_writev take a pid so add TP flag. fanotify_init doesn't appear to take a file descriptor so remove TD. Add kcmp syscall. Signed-off-by: James Hogan <james.hogan@imgtec.com> Cc: Christian Svensson <blue@cmd.nu> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Fix trace=set regression introduced by commit v4.7-111-g9cbc15bDmitry V. Levin2013-03-01
| | | | | | | * syscall.c (qual_syscall, qualify): Pass personality down to qualify_one. * tests/qual_syscall: New test. * tests/Makefile.am (TESTS): Add qual_syscall.
* Fix compilation errors uncovered by -Werror=enum-compareDmitry V. Levin2013-02-26
| | | | | | | This fixes regression introduced by commit v4.7-111-g9cbc15b. * syscall.c: Merge all nsyscalls* enums into single enum. Likewise merge nerrnos*, nsignals*, and nioctlents* into single enums.
* Mass replace error_msg("%s", "literal") -> error_msg("literal")Denys Vlasenko2013-02-26
| | | | | | | There is no need to print literal strings through "%s". Only untrusted strings such as filenames need that. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Correct i > MAX_NSYSCALLS commparison: should be i >= MAX_NSYSCALLSDenys Vlasenko2013-02-23
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Eliminate MAX_QUALS, make qualifier array dynamicDenys Vlasenko2013-02-22
| | | | | | | | | | | | | | | | | | | | | | | MAX_QUALS was 2048, even though most arches used less than 500 entries in it. MAX_QUALS had to be maintained by hand to be higher than syscall count. It also limited the highest possible fd to track. This change makes qual_flagsN[] arrays start sized to the required minimum (number of syscalls) and grow dynamically if user requested -e read=BIGNUM. As a precaution, BIGNUM should be < 2^15, but this limit can be raised with no cost for normal strace invocations. qual_flags is now a define to qual_vec[current_personality]. As a bonus, this patch aliases sysent, errnoent, signalent, ioctlent names in one-personality arches to their corresponding <foo>0 arrays, removing one indirection level. text data bss dec hex filename 244471 700 12928 258099 3f033 strace.t7/strace 244627 680 10860 256167 3e8a7 strace.t8/strace Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Create and use struct_sysent and struct_ioctlent typedefs.Denys Vlasenko2013-02-22
| | | | | | | | | | This is a preparatory mass replace patch with no code changes. The future change will need to typedef sysent to sysent0, which results in compile failures when "struct sysent" string gets mangled into "struct sysent0". Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Remove unused QUAL_FAULT code (was used by non-Linux code only).Denys Vlasenko2013-02-21
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Use uint8_t for qual_flags[] instead of ints.Denys Vlasenko2013-02-21
| | | | | | | | | | Resulting bss reduction is ~6kbytes: text data bss dec hex filename 245703 700 19072 265475 40d03 strace.t4/strace 245687 700 12928 259315 3f4f3 strace.t5/strace Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Eliminate many SCNO_IS_VALID checksDenys Vlasenko2013-02-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By adding tcp->s_ent pointer tot syscall table entry, we can replace sysent[tcp->scno] references by tcp->s_ent. More importantly, we may ensure that tcp->s_ent is always valid, regardless of tcp->scno value. This allows us to drop SCNO_IS_VALID(tcp->scno) checks before we access syscall table entry. We can optimize (qual_flags[tcp->scno] & QUAL_foo) checks with a similar technique. Resulting code shrink: text data bss dec hex filename 245975 700 19072 265747 40e13 strace.t3/strace 245703 700 19072 265475 40d03 strace.t4/strace * count.c (count_syscall): Use cheaper SCNO_IN_RANGE() check. * defs.h: Add "int qual_flg" and "const struct sysent *s_ent" to struct tcb. Remove "int u_nargs" from it. Add UNDEFINED_SCNO constant which will mark undefined scnos in tcp->qual_flg. * pathtrace.c (pathtrace_match): Drop SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno]. * process.c (sys_prctl): Use tcp->s_ent->nargs instead of tcp->u_nargs. (sys_waitid): Likewise. * strace.c (init): Add compile-time check that DEFAULT_QUAL_FLAGS constant is consistent with init code. * syscall.c (decode_socket_subcall): Use tcp->s_ent->nargs instead of tcp->u_nargs. Set tcp->qual_flg and tcp->s_ent. (decode_ipc_subcall): Likewise. (printargs): Use tcp->s_ent->nargs instead of tcp->u_nargs. (printargs_lu): Likewise. (printargs_ld): Likewise. (get_scno): [MIPS,ALPHA] Use cheaper SCNO_IN_RANGE() check. If !SCNO_IS_VALID, set tcp->s_ent and tcp->qual_flg to default values. (internal_fork): Use tcp->s_ent instead of sysent[tcp->scno]. (syscall_fixup_for_fork_exec): Remove SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno]. (get_syscall_args): Likewise. (get_error): Drop SCNO_IS_VALID check where it is redundant. (dumpio): Drop SCNO_IS_VALID check where it is redundant. Use tcp->s_ent instead of sysent[tcp->scno]. (trace_syscall_entering): Use (tcp->qual_flg & UNDEFINED_SCNO) instead of SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno]. Drop SCNO_IS_VALID check where it is redundant. Print undefined syscall name with undefined_scno_name(tcp). (trace_syscall_exiting): Likewise. * util.c (setbpt): Use tcp->s_ent instead of sysent[tcp->scno]. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ARM: make it one-personality archDenys Vlasenko2013-02-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ARM in fact _is_ one personality. We had two personalities for it because it has a handful of syscalls with huge scnos (0x000f00xx). Extending syscall table to have [0x000f0005] index is of course not a good idea. Someone decided to handle that by having a separate personality just for these syscalls. But multi-personality arch does a bit more work in other parts. This patch is another alternative: "move" 0x000f00nn syscalls down to the entries just above last ordinary syscall, by manipulating scno if it falls into the 0x000f00xx range. In order to not worsen genuine undefined scnos' printing, the code remaps scno back to actual value before printing "syscall_NNN" string. * defs.h: Remove multi-reprsonality defines from ARM. * syscall.c (shuffle_scno): New function. (undefined_scno_name): New function. (get_scno): [ARM] Replace personality setting with scno shuffling. (trace_syscall_entering): Print unknown syscall name using undefined_scno_name(). (trace_syscall_exiting): Likewise. * linux/arm/syscallent.h: Add ARM specific syscalls at the end. * linux/arm/errnoent1.h: Deleted. * linux/arm/ioctlent1.h: Deleted. * linux/arm/signalent1.h: Deleted. * linux/arm/syscallent1.h: Deleted. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* arm: shorten syscall table for EABI - no point in storing NULL entriesDenys Vlasenko2013-02-20
| | | | | | | Also, reformatted ARM code in get_scno(), mostly improved comments, without code changes. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Fix compiler warningsDenys Vlasenko2013-02-19
| | | | | | | | | With constant current_wordsize == 4 and 32-bit longs, gcc was spooked by "1ul << (8 * current_wordsize)" = "1ul << 32". Make such places conditional on SIZEOF_LONG > 4. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Improve comment text. No code changesDenys Vlasenko2013-02-19
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Simple optimization in get_errorDenys Vlasenko2013-02-16
| | | | | | | | | * defs.h: Define SCNO_IN_RANGE(scno) macro. * syscall.c (get_error): Change return type to void. Use SCNO_IN_RANGE instead of SCNO_IS_VALID. (trace_syscall_exiting): Stop checking get_error() return value. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Mass rename of SCNO_IN_RANGE define to SCNO_IS_VALIDDenys Vlasenko2013-02-16
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Finish prefixing regs struct names with arch_Denys Vlasenko2013-02-16
| | | | | | | | | | * defs: Rename regs -> sparc_regs. * signal.c (sys_sigreturn): Use new variable name. * syscall.c: Rename regs -> sparc_regs, regs -> avr32_regs. (getrval2): Use new variable names. (printcall): Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Use the same type for i386_regs on 32-bit and 64-bit x86.Denys Vlasenko2013-02-15
| | | | | | | | * defs.h: Stop including <asm/ptrace.h> for x86. Change i386_regs from "struct pt_regs" to "struct user_regs_struct". * syscall.c: Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>