Commit Graph

298 Commits

Author SHA1 Message Date
0601cf5939 dumpiov_upto: change size types from unsigned long to kernel_ureg_t
* defs.h (dumpiov_upto): Change data_size argument type
from unsigned long to kernel_ureg_t.
* util.c (dumpiov_upto): Change the type of data_size argument
and iov_len variable from unsigned long to kernel_ureg_t.
2016-12-25 11:32:45 +00:00
00785bf73a printstr*: change len argument type from long to kernel_ureg_t
* defs.h (printstr_ex, printstrn): Change len argument type from long
to kernel_ureg_t.
* util.c (printstr_ex): Likewise.
2016-12-25 11:32:45 +00:00
a3c2e4e20b printstr_ex: fix decoding of non-NUL-terminated strings when len == -1
Do not treat len == -1 in any special way.  All users who need the
string to be handled as a NUL-terminated string set QUOTE_0_TERMINATED
bit in user_style flags already.

* util.c (printstr_ex): Remove (len == -1) check.
* tests/printstr.c: New file.
* tests/printstr.test: New test.
* tests/.gitignore: Add printstr.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add printstr.test.
2016-12-25 11:32:45 +00:00
cdf05fb392 dump*: change address argument type from long to kernel_ureg_t
* defs.h (dumpiov_in_msghdr, dumpiov_in_mmsghdr, dumpiov_upto, dumpstr):
Change address argument type from long to kernel_ureg_t.
* mmsghdr.c (dumpiov_in_mmsghdr): Likewise.
* msghdr.c (fetch_msghdr_namelen, decode_msghdr, dumpiov_in_msghdr):
Likewise.
* util.c (dumpiov_upto, dumpstr): Likewise.
2016-12-25 11:32:44 +00:00
bf20786de2 printnum_*, printpair_*: change address argument type from long to kernel_ureg_t
* defs.h (DECL_PRINTNUM, DECL_PRINTPAIR, printnum_long_int): Change
address argument type from long to kernel_ureg_t.
* util.c (DEF_PRINTNUM, DEF_PRINTPAIR, printnum_long_int): Likewise.
2016-12-25 11:32:43 +00:00
78b02c928a printpath*: change address argument type from long to kernel_ureg_t
* defs.h (printpath, printpathn): Change address argument type
from long to kernel_ureg_t.
* util.c (printpath, printpathn): Likewise.
2016-12-25 11:32:43 +00:00
5e4019c3bc printstr*: change address argument type from long to kernel_ureg_t
* defs.h (printstr_ex, printstr_ex): Change address argument type
from long to kernel_ureg_t.
* util.c (printstr_ex): Likewise.
2016-12-25 11:32:43 +00:00
956e3a34a3 umove*: change tracee address argument type from long to kernel_ureg_t
* defs.h (umovestr, umoven, umoven_or_printaddr,
umoven_or_printaddr_ignore_syserror): Change tracee address argument
type from long to kernel_ureg_t.
(print_array): Change the type of tracee address argument of umoven_func
from long to kernel_ureg_t.
* util.c (vm_read_mem, umovestr, umoven, umoven_or_printaddr,
umoven_or_printaddr_ignore_syserror): Change tracee address argument
type from long to kernel_ureg_t.
(print_array): Change the type of tracee address argument of umoven_func
from long to kernel_ureg_t.
* desc.c (umove_kulong_array_or_printaddr): Change tracee address
argument type from long to kernel_ureg_t.
* mmsghdr.c (fetch_struct_mmsghdr_or_printaddr): Likewise.
2016-12-25 11:32:43 +00:00
23cbf90c18 dumpiov_upto: cast pointers to kernel_ureg_t instead of long
* util.c  (dumpiov_upto): Cast iovec.iov_base pointer to kernel_ureg_t
instead of long.
2016-12-24 14:58:42 +00:00
399fceeb06 print_array: change tracee address type from unsigned long to kernel_ureg_t
* defs.h (print_array): Change start_addr type from unsigned long
to kernel_ureg_t.
* util.c (print_array): Likewise.  Change the type of all tracee
address variables from unsigned long to kernel_ureg_t.
2016-12-23 19:26:57 +00:00
c239ebc31b Rename LONG_LONG to ULONG_LONG and change it to return unsigned long long
In all places where LONG_LONG is used the destination already has type
unsigned long long, so it is quite natural to change LONG_LONG as well.

* defs.h (LONG_LONG): Rename to ULONG_LONG, change return type
from long long to unsigned long long.  All callers updated.
2016-12-23 19:26:57 +00:00
b3d82da686 Check for current_klongsize instead of current_personality where appropriate
current_klongsize checks are more universal, therefore they are usually
shorter and easier to comprehend.

* desc.c (umove_kulong_array_or_printaddr): Check for current_klongsize
instead of current_personality and current_wordsize.
* io.c (print_lld_from_low_high_val): Likewise.
* lseek.c (SYS_FUNC(lseek)): Likewise.
* resource.c (decode_rlimit): Likewise.
* syscall.c (is_negated_errno): Likewise.
* util.c (getllval, getarg_klu): Likewise.
2016-12-19 19:58:16 +00:00
a2485b86e7 Use kernel_ulong_t instead of unsigned long long where appropriate
* defs.h (printaddr_ull): Rename to printaddr_klu, change argument
type from unsigned long long to kernel_ulong_t.  All callers updated.
(getarg_ull): Rename to getarg_klu, change return value type
from unsigned long long to kernel_ulong_t.  All callers updated.
(PRI_kl, PRI_kld, PRI_klu, PRI_klx): New macros.
* bjm.c (SYS_FUNC(init_module)): Print kernel_ulong_t type using
PRI_klu format.
* desc.c (SYS_FUNC(pselect6)): Likewise.
* fadvise.c (SYS_FUNC(fadvise64)): Likewise.
* lookup_dcookie.c (SYS_FUNC(lookup_dcookie)): Likewise.
* mq.c (SYS_FUNC(mq_timedsend), SYS_FUNC(mq_timedreceive)): Likewise.
* kcmp.c (SYS_FUNC(kcmp)): Print kernel_ulong_t type using
PRI_klx format.
* keyctl.c (SYS_FUNC(keyctl)): Likewise.
* pkeys.c (SYS_FUNC(pkey_alloc)): Likewise.
* prctl.c (print_prctl_args, SYS_FUNC(prctl), SYS_FUNC(arch_prctl)):
Print kernel_ulong_t type using PRI_kld, PRI_klu, or PRI_klx format.
* util.c (printaddr_ull): Rename to printaddr_klu, change argument
type from unsigned long long to kernel_ulong_t, print it using
PRI_klx format.
(getarg_ull): Rename to getarg_klu, change return value type
from unsigned long long to kernel_ulong_t, print it using
PRI_klx format.
2016-12-19 19:58:16 +00:00
dfff7d5571 Remove getarg_ll
This function has never been used in the code, and in perspective
the whole ext_arg thing will go away.

* defs.h (getarg_ll): Remove prototype.
* util.c (getarg_ll): Remove.
2016-12-19 14:21:40 +00:00
fc346f1d91 struct tcb: make types of syscall arguments unsigned
This is the first step in the direction of revisiting current practice
of indiscriminate use of signed types for syscall arguments and memory
addresses.

* kernel_types.h (kernel_ureg_t): New type, typedef to unsigned long.
* defs.h (struct tcb): Change type of u_arg from long to kernel_ureg_t.
[HAVE_STRUCT_TCB_EXT_ARG]: Change type of ext_arg from long long
to unsigned long long.
* desc.c (decode_select): Change type of syscall arguments from long
to kernel_ureg_t.
(SYS_FUNC(oldselect)): Change type of select_args from long
to kernel_ureg_t.
* io.c (print_lld_from_low_high_val): Remove no longer needed cast
of syscall arguments to unsigned long.
* lseek.c (SYS_FUNC(lseek)): Cast syscall argument from unsigned long
to long.
* mem.c (print_mmap): Change type of syscall arguments from long
to kernel_ureg_t.
(SYS_FUNC(old_mmap), SYS_FUNC(old_mmap_pgoff)): Change type of u_arg
from long to kernel_ureg_t.
(SYS_FUNC(mmap), SYS_FUNC(mmap_pgoff), SYS_FUNC(mmap_pgoff)): Remove
no longer needed cast of syscall arguments to unsigned long.
* pathtrace.c (pathtrace_match): Change type of args and select_args
from long to kernel_ureg_t.
* util.c (getarg_ull): Remove no longer needed casts of syscall
arguments to unsigned types.
2016-12-19 12:38:29 +00:00
Eugene Syromyatnikov
f958b3ce5b util: simplify definitions of bit mask constants in umovestr
* util.c (umovestr): Do not check for SIZEOF_LONG in definitions
of bit mask constants.
2016-12-17 12:06:24 +00:00
9f2980bd2c util: fix integer overflow check in string_to_uint_ex
* util.c (string_to_uint_ex): Fix the check for integer overflow
on systems where LONG_MAX == INT_MAX.
2016-11-30 16:52:05 +00:00
Elvira Khabirova
ad53524377 Make date output format conform to ISO 8601
* util.c (sprinttime): Make date output conform to ISO 8601.
* tests/utime.c (print_tm): Update expected output.
* tests/xstatx.c (print_time): Likewise.
2016-11-29 10:05:16 +00:00
Eugene Syromyatnikov
a938b441d6 util: provide information whether xlat value has been found
This is necessary for the upcoming change in the output format
of the val3 argument of the FUTEX_WAKE_OP futex command.

* defs.h (printxvals, printxval_searchn): Change return type to int.
(printxval64, printxval, printxval_long): Likewise.  Forward the value
returned by printxvals call.
* util.c (printxvals, printxval_searchn): Change return type to int,
return 1 if xlat value has been found, 0 otherwise.
2016-11-29 00:23:13 +00:00
Eugene Syromyatnikov
c1271b7341 util: check dflt argument for NULL in printxvals
This is necessary for the upcoming change in the output format
of the val3 argument of the FUTEX_WAKE_OP futex command.

* util.c (printxvals): Do not print dflt if it is NULL.
2016-11-29 00:22:05 +00:00
37c4d4bcfc Change printargs to return RVAL_DECODED
As printargs is invoked as a generic syscall decoder only and
it is not supposed to print anything on exiting, change printargs
to return RVAL_DECODED so it would not be called on exiting at all.

* util.c (printargs): Print args unconditionally, return RVAL_DECODED.
2016-11-27 14:22:58 +00:00
52b85c6fdf printstr_ex: fix handling of last byte when QUOTE_0_TERMINATED bit set
* util.c (printstr_ex): Simplify handling of size == 0 case.
Do not artificially decrement size when QUOTE_0_TERMINATED bit is set.
Ensure that str[size] byte is non-zero if it hasn't been fetched.
2016-11-20 00:29:46 +00:00
03d65a05b9 printstr_ex: handle QUOTE_0_TERMINATED bit consistently
When user_style has QUOTE_0_TERMINATED bit set, printstr_ex prints
the fetched string as a NUL-terminated.
After this change, the string is being fetched as a NUL-terminated, too.

* util.c (printstr_ex): Use umovestr instead of umoven
if QUOTE_0_TERMINATED bit is set.
2016-11-19 21:01:03 +00:00
ead746af18 Cleanup fetch part of printstr_ex
* util.c (printstr_ex): Initialize "style" early, unify error handling.
2016-11-19 16:33:37 +00:00
081b2a821b Introduce string_to_uint_ex and string_to_uint_upto functions
* defs.h (string_to_uint_ex): New prototype.
(string_to_uint_upto): New function, a thin wrapper around
string_to_uint_ex.
* util.c (string_to_uint_ex): New function.
(string_to_uint): Change into a thin wrapper around string_to_uint_upto.
* strace.c (init): Use string_to_uint_upto.
* syscall.c (qualify_scno, qual_signal, qual_desc): Use
string_to_uint_upto instead of string_to_uint.
2016-11-16 01:41:51 +00:00
Eugene Syromyatnikov
fdd97aac53 util: add support for QUOTE_0_TERMINATED in user_style to ptrintstr_ex
This enables printing size-limited (expectedly) ASCIZ strings.

This is done by increasing umoven size limit for sized strings by one
byte above max_strlen (enabling copying possible NUL byte in case len is
greater than max_strlen) and decreasing size after copying by one byte
in case QUOTE_0_TERMINATED is set (due to user_style or usage of len of
-1).  As a result, there is one excess byte for string_quote in case
QUOTE_0_TERMINATED is set so string_quote can check for NUL termination
of strings up to size bytes in size (which is len or max_strlen, whatever
is greater).

The catch here is that when string is not properly NUL-terminated and
QUOTE_0_TERMINATED is provided in user_style and len is less than
max_strlen then last non-NUL byte is not printed.  But ellipsis is
printed instead, being indication that string is not terminated
properly.  QUOTE_OMIT_TRAILING_0 should be used instead in case this
behaviour is not intended.

* util.c (printstr_ex): Copy one excess byte in case of non-negative len
provided and it is more than max_strlen; handle case of max_strlen of 0
in case QUOTE_0_TERMINATED is set separately; check for need of printing
ellipsis by checking resulting style against QUOTE_0_TERMINATED.
2016-11-10 22:44:18 +03:00
Eugene Syromyatnikov
cdf0885fe0 util: add printing helper for sorted xlat arrays
* util.c (printxval_searchn): New function.
* defs.h (printxval_searchn): New prototype.
(printxval_search): New helper macro useful in conjunction with static
xlat arrays.
2016-10-31 00:49:28 +03:00
b61f3251c0 Add printaddr_ull, change printaddr into a thin wrapper around it
* defs.h (printaddr_ull): New prototype.
(printaddr): Change to a static inline wrapper around printaddr_ull.
* util.c (printaddr): Rename to printaddr_ull, change argument type
to unsigned long long, change print format to %#llx.
2016-10-29 02:54:01 +03:00
Eugene Syromyatnikov
a980c9ebbd Move umoven_or_printaddr_ignore_syserror to util.c
* defs.h (umoven_or_printaddr_ignore_syserror): New prototype.
* v4l2.c (umoven_or_printaddr_ignore_syserror): Move ...
* util.c: ... here.
2016-10-28 18:40:10 +00:00
Eugene Syromyatnikov
ee70a1baac Add printstr_ex which allows for providing user quotation style
This is useful for providing QUOTE_OMIT_TRAILING_0 and maybe other
flags.

* defs.h (printstr_ex): New prototype.
(printstr): Change to a wrapper around printstr_ex with zero user style.
* util.c (printstr): Rename to ...
(printstr_ex) ... new function, add user_style argument which is or'ed
with computed style.
2016-10-03 21:50:33 +00:00
Eugene Syromyatnikov
5cf68f97d5 util: add quote_string flag signalising that string is NUL-terminated
It is useful in cases strings with size provided are expected to be
NUL-terminated but are not trustworthy enough to call just plain
printstr(str, -1).

* defs.h (QUOTE_OMIT_TRAILING_0): New constant definition.
* util.c (string_quote): Swallow terminating NUL if
QUOTE_OMIT_TRAILING_0 is set.
2016-10-03 19:28:15 +00:00
Eugene Syromyatnikov
b93991d381 util: add getarg_ll and getarg_ull functions
These allow retrieving specific argument in full taking into account
peculiarities of runtimes which employ tcp->ext_arg (e.g. x32).

* defs.h (getarg_ll, getarg_ull): New prototypes.
* util.c (getarg_ll, getarg_ull): New functions.
(printargs): Use getarg_ull.
2016-09-28 03:00:10 +00:00
Eugene Syromyatnikov
714a162048 Move SH-specific argument number calculation to getllval
This change prevents scattering of ll-related hacks and simplifies
pread/pwrite syscalls parsers' logic a bit.

* util.c (getllval): Add fixup for arg_no for SuperH when argument
number is equal to 3.
* io.c (PREAD_OFFSET_ARG): Remove.
(SYS_FUNC(pread)): Always use argument number 3 for "count" argument
printing.
(SYS_FUNC(pwrite)): Likewise.
2016-08-21 22:02:20 +00:00
de5b0092a6 Fix one more code pattern that might break gcc strict aliasing rules
* btrfs.c (btrfs_ioctl): Add one more expicit cast to "void *",
to avoid breaking strict-aliasing rules reported by some gcc compilers.
* syscall.c (decode_socket_subcall): Likewise.
* util.c (next_set_bit): Likewise.
* tests/btrfs.c (btrfs_test_send_ioctl): Likewise.
2016-07-26 16:14:50 +00:00
82ffa78acd Fix casts of ptrace's third argument
* strace.c (maybe_allocate_tcb): Replace "(char *) 0" with NULL
as ptrace's third argument.
* linux/sparc64/get_scno.c (arch_get_scno): Cast third argument
of ptrace to "void *'.
* syscall.c (get_regs): Likewise.
* upeek.c (upeek): Likewise.
* util.c (umoven): Likewise.
2016-07-26 16:14:50 +00:00
9bd2382f21 x32, mips n32: make printargs print full 64-bit syscall arguments
As most of x32 syscalls are regular x86_64 syscalls, they should be
printed by default as 64-bit syscalls, and syscall parsers at their
discretion might print syscalls differently.  This is already
implemented in 64-bit strace tracing x32 personality processes,
and now x32 strace will also behave this way.

Similar reasoning applies to mips n32.

* util.c (printargs) [HAVE_STRUCT_TCB_EXT_ARG]: Print syscall arguments
from ext_arg array using %llx format.
2016-07-20 11:16:37 +00:00
Fabien Siron
2850f745ca Add a general netlink socket parser
Introduce a general socket netlink parser which prints the header and
a string for the remaining part of the buffer.  It doesn't handle all
the netlink flags and types yet because the parser needs more
information, this will be implemented later.

* net.c (decode_sockbuf): New function.
(SYS_FUNC(send), SYS_FUNC(sendto), SYS_FUNC(recv), SYS_FUNC(recvfrom)):
Use it instead of printstr.
* msghdr.c (print_msghdr): Pass IOV_DECODE_NETLINK to tprint_iov_upto()
for netlink sockets.
* netlink.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (decode_netlink, getfdproto): New prototypes.
(iov_decode): Add IOV_DECODER_NETLINK.
* io.c (print_iovec): Use decode_netlink().
* util.c (getfdproto): Remove static keyword.
* xlat/netlink_flags.in: New file.
* xlat/netlink_types.in: New file.
2016-07-07 09:46:51 +00:00
bf2698a6b8 msghdr.c: limit output when printing excessively large messages
Limit output of struct msghdr.msg_control when
struct msghdr.msg_controllen is greater than the maximum ancillary
buffer size specified in /proc/sys/net/core/optmem_max file.

* configure.ac (AC_CHECK_FUNCS): Add open64.
* defs.h (read_int_from_file): New prototype.
* util.c (read_int_from_file): New function.
* msghdr.c (get_optmem_max): New function based on read_int_from_file.
(decode_msg_control): Use it to check control_len argument.
* tests/msg_control.c (test_big_len): New function.
(main): Use it to test printing of excessively large messages.
2016-07-03 22:15:45 +00:00
Fabien Siron
802cc28f39 Make getfdproto return enum instead of string
Introduce a new enum type sock_proto and use it instead of strings for socket
protocols identification.

* defs.h (sock_proto): New enum.
(get_proto_by_name): New function.
* socketutils.c (protocols): New static table.
(print_sockaddr_by_inode): Use it.  Change type of "proto" argument
to sock_proto.
(get_proto_by_name): New function.
* util.c (getfdproto): Use it.  Change return type to sock_proto.
(printfd): Update.
2016-06-19 23:01:14 +00:00
b0c51131a3 Introduce HAVE_STRUCT_TCB_EXT_ARG macro
Check for "if HAVE_STRUCT_TCB_EXT_ARG" instead of
"if defined LINUX_MIPSN32 || defined X32".

* defs.h (HAVE_STRUCT_TCB_EXT_ARG): Define for LINUX_MIPSN32 || X32.
(struct tcb): Check it instead of LINUX_MIPSN32 || X32.
(RVAL_LUDECIMAL): Likewise.
* io.c (print_lld_from_low_high_val): Likewise.
* lseek.c (SYS_FUNC(lseek)): Likewise.
* mem.c (SYS_FUNC(mmap)): Likewise.
* syscall.c (trace_syscall_exiting): Likewise.
* util.c (getllval): Likewise.
2016-06-17 16:12:13 +00:00
Elvira Khabirova
3c1105d49c Move printargs* functions to util.c
* syscall.c (printargs, printargs_u, printargs_d): Move ...
* util.c: ... here.
2016-06-14 15:48:32 +00:00
484326dbd8 Consistently use printaddr for printing addresses
* bjm.c (SYS_FUNC(init_module)): Use printaddr.
* clone.c (SYS_FUNC(clone)): Likewise.
* evdev.c (ff_effect_ioctl): Likewise.
* mtd.c (decode_mtd_oob_buf): Likewise.
* net.c (SYS_FUNC(sendmmsg), SYS_FUNC(recvmmsg), SYS_FUNC(getsockopt)):
Likewise.
* print_sigevent.c (print_sigevent): Likewise.
* printsiginfo.c (printsigval, print_si_info): Likewise.
* signal.c (decode_new_sigaction): Likewise.
* sysmips.c (SYS_FUNC(sysmips)): Likewise.
* util.c (printpathn, printstr, umoven_or_printaddr): Likewise.
* v4l2.c (print_v4l2_buffer, print_v4l2_framebuffer,
umoven_or_printaddr_ignore_syserror): Likewise.
* tests/net-icmp_filter.c (main): Update.

Based on patch by Eugene Syromyatnikov <evgsyr@gmail.com>.
2016-06-11 09:26:49 +00:00
4811023e74 Rename sprintflags64 to sprintflags.
* defs.h (sprintflags): Remove.
(sprintflags64): Rename to sprintflags.
* util.c (sprintflags64): Rename to sprintflags.
2016-05-15 14:26:03 +00:00
c0db59b97b Rename xlookup64 to xlookup
* defs.h (xlookup): Remove.
(xlookup64): Rename to xlookup.
* util.c (xlookup64): Rename to xlookup.
2016-05-14 22:05:09 +00:00
dc0dcf90d6 Remove unused functions
* defs.h (umove_ulong_or_printaddr, umove_ulong_array_or_printaddr):
Remove.
* util.c (umove_ulong_or_printaddr, umove_ulong_array_or_printaddr):
Likewise.
2016-05-07 23:37:53 +00:00
72e4f7af56 Introduce print_array function for consistent decoding of arrays
* defs.h (print_array): New prototype.
* util.c (print_array): New function.
2016-05-07 13:08:36 +00:00
00beed61a4 Introduce printflags64 function
This is necessary for the upcoming change of xlat.val type.

* defs.h (printflags): Rename to printflags64, change type of integer
argument to uint64_t.
(printflags): New static inline function.
* util.c (printflags): Rename to printflags64, change type of integer
argument to uint64_t.  Print it using PRIx64 format.
Based on patch by Jeff Mahoney <jeffm@suse.com>.
2016-04-28 19:05:13 +00:00
01c910ccc3 Introduce sprintflags64 function
This is necessary for the upcoming change of xlat.val type.

* defs.h (sprintflags): Rename to sprintflags64, change type of integer
argument to uint64_t.
(sprintflags): New static inline function.
* util.c (sprintflags): Rename to sprintflags64, change type of integer
argument to uint64_t.  Print it using PRIx64 format.
Based on patch by Jeff Mahoney <jeffm@suse.com>.
2016-04-28 19:04:38 +00:00
c1328100d4 printxvals: change type of integer argument to uint64_t
This is necessary for the upcoming change of xlat.val type.
All users of printxvals are already prepared for this change.

* defs.h (printxvals): Change type of integer argument to uint64_t.
* util.c (printxvals): Likewise.  Print it using PRIx64 format.
Patch by Jeff Mahoney <jeffm@suse.com>.
2016-04-28 19:04:02 +00:00
43242e6656 xlat_search: change type of integer argument to uint64_t
This is necessary for the upcoming change of xlat.val type.
All users of addflags are already prepared for this change.

* defs.h (xlat_search): Change type of integer argument to uint64_t.
* util.c (xlat_search): Likewise.  Pass it by pointer.
(xlat_bsearch_compare): Treat first argument as a pointer.
Patch by Jeff Mahoney <jeffm@suse.com>.
2016-04-28 19:04:02 +00:00