Commit Graph

5150 Commits

Author SHA1 Message Date
84ecd63651 sg_io: decode structures on exiting syscall in case of syserror
The SCSI driver, starting with kernel commit v2.6.25-rc1~1230^2~78,
translates its "struct request.errors" to ioctl errors after
filling in all the output members of the SG_IO header structure.

As there is no easy way to tell SCSI layer errors from other syscall
errors, decode the structure on exiting syscall in case of syserror,
too.

* scsi.c (scsi_ioctl): Do not call set_tcb_priv_ulong, use
get_tcb_priv_data instead of get_tcb_priv_ulong, call decode_sg_io
unconditionally.
* sg_io_v3.c (decode_request): Save a copy of struct_sg_io_hdr using
set_tcb_priv_data.
(decode_response): Restore it using get_tcb_priv_data.  Print its i/o
fields when umove call fails.  Pass IOV_DECODE_STR to tprint_iov_upto
unconditionally.
* sg_io_v4.c (decode_request): Save a copy of struct sg_io_v4 using
set_tcb_priv_data.
(decode_response): Restore it using get_tcb_priv_data.  Print its i/o
fields when umove call fails.  Pass IOV_DECODE_STR to tprint_iov_upto
unconditionally.
2017-01-10 00:05:17 +00:00
f18b0ae42c sg_io: reorder printing of fields to follow structure order
* sg_io_v4.c (decode_request): Print timeout, flags, and usr_ptr fields
after dout_xferp field.
2017-01-08 16:55:48 +00:00
e2de9acdbc sg_io_v3: print sg_io_hdr.duration field as unsigned integer
* sg_io_v3.c (decode_response): Print duration field using %u format.
2017-01-08 19:53:53 +03:00
16d336702f sg_io_v3: print msg_status field
* sg_io_v3.c (decode_response): Print msg_status field.
2017-01-08 19:52:05 +03:00
1538b9dff3 sg_io: print names of array fields and corresponding length fields
* sg_io_v3.c (decode_request): Print names of cmd_len, cmdp,
and dxferp fields.
(decode_response): Print names of dxferp, sb_len_wr, and sbp fields.
* sg_io_v4.c (decode_request): Print names of request_len, request,
dout_xfer_len, and dout_xferp fields.
(decode_response): Print names of response_len, response,
and din_xferp fields.
2017-01-08 16:00:01 +00:00
e257082643 sg_io_v3: print status fields using %#x format specifier
The formerly used format string %02x led to misleading output as there
was no clear indication sometimes whether the printed integer was
decimal or hexadecimal.

* sg_io_v3.c (decode_response): Print status and masked_status fields
using %#x format specifier instead of %02x.
2017-01-08 15:51:59 +00:00
90bcf10061 sg_io_v4: print status fields in a hexadecimal form
The tradition is to print scsi status codes in a hexadecimal form.

* sg_io_v4.c (decode_response): Print driver_status, transport_status,
and device_status fields using %#x format specifier instead of %u.
2017-01-08 15:51:59 +00:00
11defb56a4 sg_io_v4: print request_tag and generated_tag fields in hex
The tradition is to print scsi tags in a hexadecimal form.

* sg_io_v4.c (decode_request): Print request_tag field
using ("%#" PRI__x64) format string.
(decode_response): Print generated_tag field using ("%#" PRI__x64)
format string.
2017-01-08 15:51:58 +00:00
653b9a6f95 sg_io_v4: print usr_ptr field in a hexadecimal form
As the nature of this field is pointer-like, print it
in a hexadecimal form.

* sg_io_v4.c (decode_request): Print usr_ptr field
using ("%#" PRI__x64) format string.
2017-01-08 15:36:42 +00:00
fb39d06748 sg_io_v4: do not print spare_in and spare_out fields
As the kernel does not touch these fields, there is no use
to print them.

* sg_io_v4.c (decode_request): Do not print spare_in field.
(decode_response): Do not print spare_out field.
2017-01-08 15:33:30 +00:00
0503b69486 sg_io: decode struct sg_io_hdr.info and struct sg_io_v4.info
Print struct sg_io_hdr.info and struct sg_io_v4.info using printflags.

* xlat/sg_io_info.in: New file.
* defs.h (sg_io_info): New xlat prototype.
* sg_io_v3.c: Include "xlat/sg_io_info.h".
(decode_response): Print struct_sg_io_hdr.info using printflags.
* sg_io_v4.c: (decode_response): Print struct sg_io_v4.info
using printflags.
2017-01-08 03:30:23 +00:00
0f774151a4 sg_io: decode struct sg_io_hdr.flags and struct sg_io_v4.flags
Print struct sg_io_hdr.flags and struct sg_io_v4.flags using printflags.

* xlat/sg_io_flags.in: New file.
* sg_io_v3.c: Include "xlat/sg_io_flags.h".
(decode_request): Print struct_sg_io_hdr.flags using printflags.
* xlat/bsg_flags.in: New file.
* sg_io_v4.c: Include "xlat/bsg_flags.h".
(decode_request): Print struct sg_io_v4.flags using printflags.
2017-01-08 03:30:02 +00:00
d30a9bf779 Mpersify struct sg_io_hdr
struct sg_io_hdr contains pointers and therefore has to be mpersified.

* defs.h (decode_sg_io_v3): Remove prototype.
* sg_io_v3.c (struct_sg_io_hdr): Typedef to struct sg_io_hdr.
Mpersify it.
(decode_sg_io_v3): Wrap into MPERS_PRINTER_DECL.
2017-01-08 01:05:50 +00:00
768d7cb78f Split scsi.c
Move decoders of SG_IO v3 and v4 APIs into separate files,
compile generic SG_IO decoder unconditionally.

* sg_io_v3.c: New file.
* sg_io_v4.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* defs.h (decode_sg_io_v3, decode_sg_io_v4): New prototypes.
* ioctl.c (ioctl_decode): Remove [HAVE_SCSI_SG_H] condition.
* scsi.c: (print_sg_io_res): Remove.
(print_sg_io_req): Rename to decode_sg_io, replace print_sg_io_v3_req
with decode_sg_io_v3, replace print_sg_io_v4_req with decode_sg_io_v4,
compile uncoditionally.
(scsi_ioctl): Replace print_sg_io_req and print_sg_io_res
with decode_sg_io, compile uncoditionally.
Move [HAVE_SCSI_SG_H] code to sg_io_v3.c.
Move [HAVE_LINUX_BSG_H] code to sg_io_v4.c.
2017-01-08 00:01:03 +00:00
cdd27d2088 scsi: detect and print changes of interface id
* scsi.c (print_sg_io_v3_res): Detect and print changes
of struct sg_io_hdr.interface_id field between entering and exiting
syscall.
(print_sg_io_v4_res): Detect and print changes of struct sg_io_v4.guard
field between entering and exiting syscall.
2017-01-07 19:09:37 +00:00
ff96efe158 scsi: print field names of all fields being printed
* scsi.c (print_sg_io_v3_req): Always print the name
of struct sg_io_hdr.interface_id field.
(print_sg_io_v4_req): Always print the name of struct sg_io_v4.guard
field.
(print_sg_io_req): Print unknown interface id as an integer.
(scsi_ioctl): Save interface id on entering syscall and use it
on exiting syscall.
2017-01-07 22:01:27 +03:00
ce616808a6 scsi: print struct sg_io_hdr.dxfer_direction field name
* scsi.c (print_sg_io_v3_req): Print struct sg_io_hdr.dxfer_direction
field name.
2017-01-07 21:55:40 +03:00
e95caf5505 scsi: print "protocol" and "subprotocol" field names of struct sg_io_v4
* scsi.c (print_sg_io_v4_req): Print field names
of struct sg_io_v4.protocol and struct sg_io_v4.subprotocol.
2017-01-07 21:45:48 +03:00
600457fa9d Print hexadecimal integer in error diagnostics using %#x
The formerly used format string %x led to misleading output as there was
no clear indication sometimes whether the printed integer was decimal or
hexadecimal.

* aio.c (startup_child, test_ptrace_seize): Print status
using %#x format specifier instead of %x.
2017-01-07 16:44:44 +00:00
a286680b04 aio: print hexadecimal integer using %#x
The formerly used format string %x led to misleading output as there was
no clear indication sometimes whether the printed integer was decimal or
hexadecimal.

* aio.c (print_common_flags): Print struct iocb.aio_flags using %#x
format specifier instead of %x.
* tests/aio.c (main): Likewise.
2017-01-07 16:44:44 +00:00
601a324df2 scsi: rewrite print_sg_io_buffer using printstr_ex(QUOTE_FORCE_HEX)
As printstr_ex has got QUOTE_FORCE_HEX flag support, there is no need
to implement it manually any longer.

* scsi.c (print_uchar): Remove.
(print_sg_io_buffer): Rewrite using printstr_ex(QUOTE_FORCE_HEX).
2017-01-06 16:31:35 +00:00
Eugene Syromyatnikov
c119a6da7c getrandom: print string as hex-escaped
Since there is no reason to interpret the value returned by getrandom as
ASCII string, it makes sense to always print it as a hex-escaped string.

* getrandom.c (SYS_FUNC(getrandom)): Use printstr_ex instead
of printstrn, set QUOTE_FORCE_HEX in user_style parameter in order
to force hex-escaped string formatting.
* tests/getrandom.test: Remove no longer needed -xx flag as the string
is always printed in hexadecimal format now.

Suggested-by: JingPiao Chen <chenjingpiao@gmail.com>
2017-01-06 11:43:50 +00:00
Eugene Syromyatnikov
34a920baad util: add support for forcing printing string as hex-escaped
This could be useful in cases when some binary data should not be
interpreted as an ASCII string, but rather as an array of byte values.

* defs.h (QUOTE_FORCE_HEX): New macro constant.
* util.c (quote_string): Enable use_hex when QUOTE_FORCE_HEX is set
in user_style parameter.
2017-01-06 11:39:54 +00:00
Eugene Syromyatnikov
a8f0442fd7 term: do not abort decoding in case of non-verbose output
The case of unset verbose is handled by umoven_or_printaddr, moreover,
exiting at this point is plain wrong and leads to last argument not
being printed while it should be.

* term.c (decode_termios, decode_termio, decode_winsize, decode_ttysize,
decode_modem_flags): Do not check verbose flags explicitly and do not
exit early if it is not set.
2017-01-06 11:39:33 +00:00
ae663f17fe tests: skip fault injection tests on hppa if the kernel is too old
* tests/fault_injection.sh: Add the minimal kernel version for hppa.
2017-01-05 20:46:48 +00:00
e752ef61c3 tests: skip readahead.test on MIPS n64 when built with glibc < 2.25
Due to a bug in glibc readahead syscall wrapper on MIPS n64,
this wrapper cannot be used in readahead.test.

* tests/readahead.c [HAVE_READAHEAD && LINUX_MIPSN64 && glibc < 2.25]:
Undefine HAVE_READAHEAD.

Reported-by: James Cowgill <james410@cowgill.org.uk>
2017-01-05 18:20:57 +00:00
92ac6131a1 tests: replace init_magic with fill_memory
Use the same fill_memory/fill_memory_ex interface in all affected tests.

* tests/ioctl_block.c (init_magic): Remove.
(main): Replace init_magic with fill_memory.
* tests/ioctl_evdev.c: Likewise.
* tests/ioctl_v4l2.c: Likewise.
* tests/ioctl_mtd.c (magic, init_magic): Remove.
(main): Replace init_magic with fill_memory.
* tests/ioctl_rtc.c: Likewise.
2017-01-05 01:34:24 +00:00
ff9f61dce9 tests: rewrite ioctl_v4l2 test without reliance on init_magic
* tests/ioctl_v4l2.c (cc0, cc1, cc2, cc3, fourcc): New macros.
(main): Use them.  Rewrite expected output without assumptions
on any particular magic data.
2017-01-05 01:34:24 +00:00
84e3de2018 tests: remove redundant casts in fill_memory{,_ex} invocations
* tests/ioctl_loop.c (main): Remove redundant casts of fill_memory
first argument.
* tests/kexec_load.c (main): Likewise.
* tests/perf_event_open.c (main): Likewise.
* tests/quotactl.c (main): Likewise.
* tests/mq_sendrecv.c (main): Remove redundant casts of fill_memory_ex
first argument.
* tests/quotactl-xfs.c (main): Likewise.
2017-01-04 22:17:26 +00:00
801d42d947 tests: change the type of fill_memory{,_ex} first argument to void *
As these functions behave like memset, it's more convenient to have
the first argument of type void * like memset.

* tests/fill_memory.c (fill_memory, fill_memory_ex): Change the type
of first argument from "char *" to "void *".
* tests/tests.h (fill_memory, fill_memory_ex): Likewise.
2017-01-04 22:08:32 +00:00
Eugene Syromyatnikov
23287f11fe tests: check non-verbose decoding of LOOP_* ioctls
* tests/ioctl_loop-nv.c: New file.
* tests/ioctl_loop-nv.test: New test.
* tests/ioctl_loop.c [!ABBREV] (ABBREV): Define to 0.
(print_loop_info, print_loop_info64): Handle [ABBREV != 0] case.
* tests/.gitignore: Add ioctl_loop-nv.
* tests/Makefile.am (check_PROGRAMS): Likewise.
2017-01-04 22:00:38 +00:00
Eugene Syromyatnikov
2acabfe47a tests: add more checks of LOOP_* ioctls decoding
* tests/ioctl_loop.c: Include <linux/ioctl.h>.
(magic, lmagic): Move static constants ...
(main): ... here.  Change types of magic constants to kernel_ulong_t.
Add more checks.
2017-01-04 21:53:00 +00:00
JingPiao Chen
3127a6a275 tests: check decoding of LOOP_* ioctls
* tests/ioctl_loop.c: New file.
* tests/ioctl_loop-v.c: Likewise.
* tests/ioctl_loop.test: New test.
* tests/ioctl_loop-v.test: Likewise.
* tests/.gitignore: Add ioctl_loop and ioctl_loop-v.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add ioctl_loop.test and ioctl_loop-v.test.

Co-authored-by: Eugene Syromyatnikov <evgsyr@gmail.com>
2017-01-04 19:59:27 +00:00
17a2ba8415 Drop vsprintf.c
Drop custom vfprintf implementation that was disabled by default.
Apparently nobody tests strace with this vfprintf enabled, otherwise
multiple uses of format specifiers not supported by this custom vfprintf
would not left unnoticed.

The GNU C library is not the only libc available, so those who want
faster implementations of libc functions are encouraged to try building
strace with other libc implementations.

* vsprintf.c: Remove.
* Makefile.am (strace_SOURCES): Remove vsprintf.c.
* defs.h (USE_CUSTOM_PRINTF, strace_vfprintf): Remove.
* strace.c (tprintf): Replace strace_vfprintf with vfprintf.
2017-01-04 13:22:19 +00:00
Eugene Syromyatnikov
297f570c2d loop: remove unnecessary verbose check
The verbose flag is responsible for dereferencing of addresses, and it
is perfectly handled by umove_or_printaddr; moreover, this early exit
leads to incorrect formatting of last argument.

* loop.c (loop_ioctl): Do not check verbose flag explicitly and do not
exit early if it is not set.
2017-01-04 13:22:19 +00:00
Eugene Syromyatnikov
0fbbe358ee loop: fix lo_encrypt_key field output
lo_encrypt_key is a sized string with its size specified by
lo_encrypt_key_size field, so take lo_encrypt_key_size into account.

* loop.c (decode_loop_info, decode_loop_info64): Use minimum of
LO_KEY_SIZE and lo_encrypt_key_size field value as lo_encrypt_key size.
2017-01-04 13:22:19 +00:00
Eugene Syromyatnikov
426b63f3fa loop: print lo_encrypt_key_size field of struct loop_info as unsigned
It is converted to an unsigned value in kernel (see loop_info64_from_old
in drivers/block/loop.c), so let's print it that way despite its type.

* loop.c (decode_loop_info): Print lo_encrypt_key_size as an uint32_t
value.
2017-01-04 13:22:19 +00:00
Eugene Syromyatnikov
1ccc55eed2 tests: add more checks of unknown ioctl command formatting
* tests/ioctl.c (main): Additional check for unknown ioctl command
decoding.
* tests/ioctl_evdev.c (main): Likewise.
* tests/ioctl_dm.c: Include <linux/ioctl.h> for _IOC_SIZE and _IOC_NR.
(main) <dummy_dm_ioctl1, dummy_dm_ioctl2, dummy_dm_arg>: New constants.
Add more checks for unknown command formatting.
2017-01-04 13:22:19 +00:00
Eugene Syromyatnikov
b00f54e881 ioctl: do not print explicit 0x prefix and do not specify minimum width
Specifying output width for size argument is rather misleading - it can
be up to 14 bits in size.  The use of explicit "0x" prefix is
discouraged because 0x0 looks ugly.  Usage of width specification along
with alternate form flag leads to inconsistent output for 0.
Let's use just plain %#x qualifiers instead.

* ioctl.c (ioctl_print_code): Change printf qualifiers for ioctl command
type, number and size to "%#x".
* tests/ioctl.c (main): Update expected test output.
* tests/ioctl_dm.c (main): Likewise.
* tests/ioctl_evdev.c (main): Likewise.
2017-01-04 13:22:19 +00:00
Eugene Syromyatnikov
7ba63db908 loop: fix printing of the reserved field array items
They are of char type, so "hh" length modifier should be used (otherwise
they are printed incorrectly as they are sign extended implicitly when
passed as printf arguments in case char is a signed type which is true
for most compilers).

* loop.c (decode_loop_info): Change "%#x" printf qualifier to "%#hhx"
in printing routine for array elements of the "reserved" field of
loop_info structure.
2017-01-04 13:22:19 +00:00
Eugene Syromyatnikov
589e3285d5 tests: check ioctl(SIOCGIFCONF) decoding
* tests/ioctl_sock_gifconf.c: New file.
* tests/ioctl_sock_gifconf.test: New test.
* tests/.gitignore: Add ioctl_sock_gifconf.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add ioctl_sock_gifconf.test.
2017-01-04 11:48:11 +00:00
Eugene Syromyatnikov
5882b169a0 dm.c: add copyright notice 2017-01-04 11:46:20 +00:00
71a69a36f8 Add scno.h and syscallent.i to .gitignore files
* .gitignore: Add /scno.h and /syscallent.i.
* tests/.gitignore: Add scno.h and syscallent.i.
2017-01-04 11:29:32 +00:00
JingPiao Chen
f2d80518f7 tests/.gitignore: add generated files that should be ignored
* tests/.gitignore: Replace addkey with add_key, add attach-f-p-cmd.
2017-01-04 11:28:48 +00:00
b58f75c5d4 Remove checks of __NR_* availability from strace source code
* strace.c: Remove __NR_tkill checks, assume it is always defined.
* util.c: Remove __NR_process_vm_readv checks and fallback definitions,
assume it is always defined.
2017-01-03 13:46:26 +00:00
2dd365f912 Include "scno.h" in files that check __NR_* constants
* strace.c: Include "scno.h".
* util.c: Likewise.
2017-01-03 11:27:35 +00:00
d6ea0d0204 Generate scno.h for use during the build of strace itself
* Makefile.am: Include scno.am.
($(strace_OBJECTS)): New rule.
2017-01-03 11:27:35 +00:00
cae1252903 Generate scno.h without invoking a generated executable helper
Generate scno.h using only those tools that are available for cross
build.  This allows to use scno.h during the build of strace itself.

* scno.am: New file.
* scno.head: New file.
* Makefile.am (EXTRA_DIST): Add it.
* tests/generate_scno.c: Remove.
* tests/.gitignore: Remove generate_scno.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(CLEANFILES): Remove scno.h.
(scno.h, $(scno_dependants)): Remove rules.
(scno_dependants): Remove.
($(objects)): New rule.
Include ../scno.am.
2017-01-01 20:59:11 +00:00
9eeb033ea6 Update all publicly shown copyright year number ranges
* COPYING: Update copyright year number range.
* configure.ac: Likewise.
* strace.c: Likewise.
* tests/strace-V.test: Use the current year for the check.
2017-01-01 11:33:40 +00:00
326b98927a defs.h: stop including <asm/unistd.h>
Limit the number of files where <asm/unistd.h> is included
to only those few that need it.

* defs.h: Do not include <asm/unistd.h>.
* clone.c: Include <asm/unistd.h>.
* strace.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.
2016-12-31 22:12:08 +00:00