IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an
email to Administrator. User accounts are meant only to access repo
and report issues and/or generate pull requests.
This is a purpose-specific Git hosting for
BaseALT
projects. Thank you for your understanding!
Только зарегистрированные пользователи имеют доступ к сервису!
Для получения аккаунта, обратитесь к администратору.
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 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>
While at it, fix some comments which say
"we use i386 syscalls/ioctls/errnos" but in reality
common ones are used.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
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>
pathname[] was getting destroyed, execve of garbage pathname
failing, and to top it off, the tracer's stack was also
smashed and trecer segfaulted.
* strace.c (exec_or_die): New function.
(startup_child): Don't use pathname[] contents after vfork,
make a malloced copy instead. Explain "NOMMU + -D bug"
and how we work around it.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
And while using it, I discovered that -D doesn't work too well
on NOMMU. Added a comment about it.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Previous code merges too many similar, but different ways
of decoding mmap. For example, sys_old_mmap is "params in memory"
API... except SH[64], where it is "params in regs",
i.e. what sys_mmap ("new mmap") function does on other arches!
It's much simpler when every mmap handler has same API regardless
of arch. Where API means whether params are in regs or in memory,
and whether offset is in bytes, pages, or 4k blocks.
Then we just insert correct function pointers into
arch syscall tables.
It turns out there are four common mmap APIs over
all architectures which exist in Linux kernel,
and one outlier for S390.
A number of mmap decoders were plain wrong in arch tables.
For example, BFIN has no old_mmap. It returns ENOSYS.
I checked kernel sources for all arches nad fixed the tables.
There was dead code for x86_64 for old_mmap:
x86_64 has no old_mmap.
* mem.c: Refactor mmap functions so that we have five mmap syscall
handlers, each with the fixed API (not varying by arch).
* pathtrace.c (pathtrace_match): Adjust sys_func == mmap_func checks.
* linux/syscall.h: Declare new mmap syscall handler functions.
* linux/arm/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/avr32/syscallent.h: mmap is sys_mmap_pgoff.
* linux/bfin/syscallent.h: old_mmap is ENOSYS, mmap2 is sys_mmap_pgoff.
* linux/hppa/syscallent.h: mmap2 is sys_mmap_4koff.
* linux/i386/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/ia64/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/m68k/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/microblaze/syscallent.h: old_mmap is sys_mmap, mmap2 is sys_mmap_pgoff.
* linux/mips/syscallent.h: mmap is sys_mmap_4kgoff.
* linux/or1k/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/powerpc/syscallent.h: mmap2 is sys_mmap_4kgoff.
* linux/s390/syscallent.h: mmap2 is sys_old_mmap_pgoff.
* linux/s390x/syscallent.h: mmap is sys_old_mmap and thus has 1 arg.
* linux/sh/syscallent.h: old_mmap2 is sys_mmap, mmap2 is sys_mmap_4koff.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent1.h: mmap is TD|TM.
* linux/tile/syscallent1.h: mmap2 is sys_mmap_4koff.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
No wonder that it is unused.
It's code looked quite questionable.
* mem.c (sys_mmap64): Remove this function.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
While looking at mmap mess, did experimenting in order
to figure out what gets used when.
Tried building armv4tl, armv5l, armv6l, mips, mipsel, i686,
x86_64 and none of they have long long off_t,
which isn't suprprising: we aren't using glibc defines
which enable that.
Moreover, we SHOULD NOT use off_t in syscall decode!
Its size depends on libc, not on arch! I.e. it is essentially
unpredictable and can even in theory vary on the same arch
with different libc.
We should use longs or long longs, in a way which matches
architectural ABI for the given syscall. There are usually
*at most* two permutations, no need to add yet another variable
(sizeof(off_t)) to the mix.
This change removes almost all HAVE_LONG_LONG_OFF_T conditionals,
which will reveal further possible simplifications.
* mem.c: Remove code conditional on HAVE_LONG_LONG_OFF_T.
As a result, never remap sys_mmap64 to sys_mmap.
(print_mmap): Compile unconditionally.
(sys_old_mmap): Compile unconditionally.
(sys_mmap): Compile unconditionally.
* io.c (sys_sendfile): Add a FIXME comment.
* file.c: Remove code conditional on HAVE_LONG_LONG_OFF_T.
As a result, never remap sys_*stat64 to sys_*stat etc.
(sys_truncate): Compile unconditionally.
(realprintstat): Likewise.
(sys_stat): Likewise.
(sys_fstat): Likewise.
(sys_lstat): Likewise.
* desc.c (printflock): Likewise.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* mem.c (sys_mmap): Ensure unsigned expansion of tcp->u_arg[5].
Add page shift of offset for I386.
Use tcp->ext_arg[5] as offset for X32.
(sys_old_mmap): [X32] Remove this function, X32 doesn't use is.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* mem.c: Move "define sys_mmap64 sys_mmap" from the top
to the only place it affects.
(print_mmap): Make offset argument unsigned, for safer implicit conversions.
(sys_old_mmap): [IA64] use unsigned narrow_arg[].
Cast u_arg[5] (offset param) to unsigned long, to prevent erroneous signed
expansion.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
We use printllval without HAVE_LONG_LONG guards in many places,
but define it only if HAVE_LONG_LONG. This means that
on !HAVE_LONG_LONG systems we won't build for some time now.
* defs.h: Remove HAVE_LONG_LONG guard around LONG_LONG() macro
and printllval() function declaration.
* util.c: Remove HAVE_LONG_LONG guard around printllval()
function definition.
(printllval): Add compile-time error check for using wrong
if branch. Explain places where we deliberately use mismatched
types for printf formats.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
I found hard way why the code was using "_whence" name.
* file.c: Rename whence[] to whence_codes[].
(sys_lseek): Fix printxval() to use whence_codes[].
(sys_lseek32): Likewise.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The code doesn't look fully correct to me, but I need to experiment
on actual x32 machine before I start "fixing" things.
For now, add comments, and optimize out one tprints() call...
* file.c (sys_lseek): Rename '_whence' as 'whence'.
Merge printing of ", " into subsequent tprintf.
(sys_lseek32): Likewise.
(sys_llseek): Likewise.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* linux/mips/syscallent.h: Remove trailing empty elements.
Compactify huge stretches of NULL elements in the middle.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* syscall.c (get_scno): [TILE] Remove TCB_WAITEXECVE check,
it is never true on Tile, and stopped compiling when
TCB_WAITEXECVE define was removed for Tile.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Zero-extension is slightly more common that sign-extension:
all pointers are zero-extended, and some other params are unsigned.
Whereas signed ones (fds, pids, etc) are often treated as
_32-bit ints_ even by kernel, so just unconditionally casting
such tcp->u_arg[N] to int works.
* syscall.c (get_syscall_args): [X86] Zero-extend 32-bit args
instead of sign-extension.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* defs.h: Define widen_to_long() macro.
* signal.c (sys_kill): Use it instead of open-coding it.
(sys_tgkill): Use widen_to_long() on pids.
* resource.c (decode_rlimit): Formatting fix.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
On x86_64:
text data bss dec hex filename
435661 26628 47424 509713 7c711 strace_old
435501 26612 47440 509553 7c671 strace_new_clever_wordsize
On x32 and arm it should be even better, current_wordsize becomes
a constant there.
* defs.h: Declare current_wordsize as a variable if needed,
else declare as a constant define.
Remove declatation of personality_wordsize[].
* syscall.c: Make personality_wordsize[] static.
Declare current_wordsize as a variable if needed.
(set_personality): Set current_wordsize only if non-constant.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Unlike PTRACE_GETREGS, this new method detects 32-bit processes
reliably, without checking segment register values which
are undocumented and aren't part of any sort of API.
While at it, also fixed x32 detection to use __X32_SYSCALL_BIT,
as it should have been from the beginning.
* defs.h: Declare os_release and KERNEL_VERSION.
* strace.c: Make os_release non-static, remove KERNEL_VERSION define.
* syscall.c: New struct i386_user_regs_struct,
static union x86_regs_union and struct iovec x86_io.
(printcall): Use i386_regs or x86_64_regs depending on x86_io.iov_len.
(get_regs): On x86 and kernels 2.6.30+, use PTRACE_GETREGSET,
on earlier kernels fall back to old method.
(get_scno): [X86] Determine personality based on regset size
on scno & __X32_SYSCALL_BIT.
(syscall_fixup_on_sysenter): Use i386_regs or x86_64_regs depending
on x86_io.iov_len.
(get_syscall_args): Likewise.
(get_error): Likewise.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This makes it easier to grep for them.
* syscall.c: Rename variables:
r0 -> bfin_r0,alpha_r0,sh_r0.
a3 -> mips_a3.
r2 -> mips_r2.
(get_scno): Use new variable names.
(get_syscall_result): Likewise.
(get_error): Likewise.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* defs.h: Declare new function printsiginfo_at(tcp, addr).
* process.c (sys_waitid): Use printsiginfo_at().
(sys_ptrace): Likewise.
* signal.c: (printsiginfo_at): Implement this new function.
(sys_rt_sigsuspend): Use printsiginfo_at().
(sys_rt_sigtimedwait): Likewise.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* process.c: Add start_code and start_data members of struct user
in struct_user_offsets[], where appropriate.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* util.c (change_syscall): For MICROBLAZE, replace code
with dummy "return 0" and a comment explaining why that is ok
for this architecture.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This is a leftover from sysenter/sysexit split.
I can't run-test it, but from code inspection it seems to be correct.
* syscall.c (get_scno): Remove stray syscall result reading for s390[x].
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The maze of ifdefs/ifndefs was scaring new contributors.
Format it so that every arch has its own ifdef block.
* process.c: Deobfuscate definitions of struct user offsets.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* defs.h: Do not define TCB_WAITEXECVE for AARCH64.
* util.c (change_syscall): For AARCH64 and X32, replace code
with dummy "return 0" and a comment explaining why that is ok
for these architectures.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* defs.h: Do not define TCB_WAITEXECVE for AVR32, BFIN and TILE.
* util.c (change_syscall): For AVR32, BFIN and TILE, replace code
with dummy "return 0" and a comment explaining why that is ok
for these architectures.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* net.c (printmsghdr): If current_wordsize is 4 and long is wider than it,
read 32-bit struct msghdr and expand it into a native one before using it.
(printmmsghdr): Likewise for struct mmsghdr.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
X32's return value is 64-bit. We were truncating it to 32-bit long
before checking for -errno.
* syscall.c (is_negated_errno_x32): New function.
(get_error): Use is_negated_errno_x32 for X32 architecture.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
We sometimes use LINUXSPARC and sometimes (more often)
use "defined(SPARC) || defined(SPARC64)". Better to use
one construct consistently.
LINUX_MIPS64 is altogether unused.
* defs.h: Remove LINUXSPARC and LINUX_MIPS64 defines.
Move PTRACE_xxx compat defines up, before arch-specific
machinery. Use defined(SPARC) || defined(SPARC64)
instead of LINUXSPARC.
* file.c: Use defined(SPARC) || defined(SPARC64) instead of LINUXSPARC.
* signal.c: Likewise.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* syscall.c: Move PT_FLAGS_COMPAT define to its only user, get_scno().
Rename arm_regs_union's fields to names less likely to collide with
system defines.
(get_regs): Use sizeof(arm_regs_union) instead of sizeof(aarch64_regs).
This should be the same, but htis way it's cleaner.
Remove __X32_SYSCALL_MASK and use __X32_SYSCALL_BIT instead.
Explain 64-bit check in X32 build better.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>