Commit Graph

6540 Commits

Author SHA1 Message Date
Eugene Syromyatnikov
a465477fc7 ipc: use printxval for printing key
Convert explicit constant printing logic into a printxval call in order
to account for xlat style setting.

* defs.h (ipc_private): New xlat array declaration.
* ipc_msg.c (SYS_FUNC(msgget)): Use printxval for printing IPC_PRIVATE.
* ipc_sem.c (SYS_FUNC(semtimedop)): Likewise.
* ipc_shm.c (SYS_FUNC(shmget)): Likewise.
* xlat/ipc_private.in: New file.
2018-04-13 01:00:09 +02:00
Eugene Syromyatnikov
b416f61c3e mount: use print_xlat for printing MS_MGC_VAL
* mount.c (SYS_FUNC(mount)): Use print_xlat for printing MS_MGC_VAL
named constant.
2018-04-13 00:25:13 +02:00
Eugene Syromyatnikov
6ece6574d2 Introduce print_xlat and print_xlat_ex
print_xlat_ex prints a named constant in accordance with xlat style
provided, print_xlat is a thin wrapper around print_xlat_ex that passes
stringified constant name as a string and XLAT_STYLE_DEFAULT as a style.

* defs.h (print_xlat_ex): New function prototype.
(print_xlat): New macro, a thin wrapper around print_xlat_ex.
* xlat.c (print_xlat_ex): New function.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-13 00:25:13 +02:00
Eugene Syromyatnikov
b9fcbe6112 Introduce XLAT_STYLE_DEFAULT
This will be needed later, with the introduction of user-configurable
xlat style setting (stored in xlat_verbosity variable).

* defs.h (XLAT_STYLE_VERBOSITY_MASK): New macro constant.
(enum xlat_style) <XLAT_STYLE_DEFAULT>: New enumeration entity.
(xlat_verbosity): New external declaration.
(printxvals, printxval_searchn, printxval_search_ex, sprintxval,
sprintflags, printflags64): Use XLAT_STYLE_DEFAULT instead of
XLAT_STYLE_ABBREV.
* strace.c (xlat_verbosity): New variable.
* xlat.c (get_xlat_style): New function.
(printxvals_ex, sprintxval_ex, printxval_searchn_ex, sprintflags_ex,
printflags_ex): Use it.
2018-04-13 00:25:13 +02:00
Eugene Syromyatnikov
e8c3f34edd Introduce xlat verbosity styles
* defs.h (printxvals_ex): Rename from printxvals, add style argument.
(enum xlat_style): New enumeration.
(printxvals): New macro, a wrapper for printxvals_ex.
(printxval_searchn_ex): Rename from printxval_searchn, add style
argument.
(printxval_searchn): New macro, a wrapper for printxval_searchn_ex.
(printxval_search_ex): New macro, a wrapper for printxval_searchn_ex.
(sprintxval_ex): Rename from sprintxval, add style argument.
(sprintxval): New macro, a wrapper for sprintxval_ex.
(printflags_ex): Add style argument.
(sprintflags_ex): Rename from sprintflags, add style argument.
(sprintflags): New macro, a wrapper for sprintflags_ex.
(printflags64): Pass XLAT_STYLE_ABBREV as a style in printflags_ex call.
* netlink.c (decode_nlmsg_flags): Pass XLAT_STYLE_ABBREV as a style in
printflags_ex call.
* xlat.c (printxvals_ex): Rename from printxvals, add style argument,
handle it.
(sprintxval_ex): Rename from sprintxval, add style argument, handle it.
(printxval_searchn_ex): Rename from printxval_searchn, add style
argument, handle it.
(sprintflags_ex): Rename from sprintflags, add style argument,
handle it.
(printflags_ex): Add style argument, handle it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
References: https://github.com/strace/strace/issues/27
2018-04-13 00:25:13 +02:00
34c7794cc1 tests: robustify signal delivery test against kernel bugs
Recent kernel siginfo changes, namely, v4.14-rc1~60^2^2~1,
v4.16-rc1~159^2~37, and v4.16-rc1~159^2~39, introduced ABI regressions
that render the whole siginfo interface unreliable.

Looks like the kernel side is not eager to fix the breakage,
so here is a workaround.

* tests/signal_receive.c (s_sig, s_code, s_pid, s_uid): New volatile
variables.
(handler): Add siginfo_t parameter, save siginfo_t fields.
(sig_print): Remove.
(main): Rewrite.  Use variables saved by handler to print expected
siginfo output. Print diagnostics in case of siginfo mismatch.
* strace.spec.in (%check): Extract the diagnostics.

Closes: https://github.com/strace/strace/issues/21
2018-04-11 22:01:37 +00:00
ecf5284f7d Lift experimental status from stack tracing feature
* strace.1.in (.SH OPTIONS) <.B \-k>: Remove " (experimental)".
* strace.c (usage) [ENABLE_STACKTRACE]: Likewise.
2018-04-11 22:01:37 +00:00
dfd58df4a7 Enable stack tracing in packages on all architectures
The stack tracing feature used to be enabled in packages on x86_64 only.
This change enables -k option on all architectures.

* debian/control (Build-Depends) [!amd64]: Add pkg-config, libdw-dev,
and libiberty-dev.
* strace.spec.in (BuildRequires) [!x86_64]: Add
%buildrequires_stacktrace.
2018-04-11 22:01:37 +00:00
9165da9f68 Use libdw-based unwinder in ci and packages
* ci/install-dependencies.sh (common_packages): Add pkg-config,
replace libunwind8-dev with libdw-dev.
* debian/control (Build-Depends) [amd64]: Add pkg-config,
replace libunwind-dev with libdw-dev.
* debian/rules (build-udeb/Makefile): Replace --without-libunwind
with --without-stacktrace.
* strace.spec.in (buildrequires_libunwind_devel): Rename
to buildrequires_stacktrace, replace libunwind-devel with
either elfutils-devel or libdw-devel.
2018-04-11 22:01:37 +00:00
fd4a485828 tests: skip -k tests on unsupported architectures
* tests/strace-k.test: When actual strace -k output doesn't match the
expected output because of limited architecture support, skip the test
on architectures that are not currently supported by libdw.
2018-04-11 22:01:37 +00:00
Masatake YAMATO
ddb5a4ba73 unwind: add libdw as an unwinder
Implement alternative libdw-based unwinder for stack tracing.
Add --with-libdw configure option to control whether libdw can be used
as an unwinder.

* m4/st_libdw.m4: New file.
* m4/st_stacktrace.m4 (st_STACKTRACE): Invoke st_ARG_LIBDW and st_LIBDW,
check for mutually exclusive configure options,
(AM_CONDITIONAL): Add USE_LIBDW.
* unwind-libdw.c: New file.
* Makefile.am [USE_LIBDW] (strace_SOURCES): Append unwind-libdw.c.
[USE_LIBDW] (strace_CPPFLAGS): Append $(libdw_CPPFLAGS).
[USE_LIBDW] (strace_CFLAGS): Append $(libdw_CFLAGS).
[USE_LIBDW] (strace_LDFLAGS): Append $(libdw_LDFLAGS).
[USE_LIBDW] (strace_LDADD): Append $(libdw_LIBS).
* NEWS: Mention this improvement.

Closes: https://github.com/strace/strace/issues/12
Closes: https://github.com/strace/strace/issues/13
Co-Authored-by: Mark Wielaard <mjw@redhat.com>
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2018-04-11 22:01:37 +00:00
c78af2c9cf tests: check corner cases of udev_monitor_netlink_header decoding
* tests/netlink_kobject_uevent.c (test_nlmsg_type_kernel): Create
a tail-allocated udev_monitor_netlink_header object and pass it
to sys_send.
(test_nlmsg_type_udev): Likewise.  Check decoding of
udev_monitor_netlink_header object that ends in unmapped memory region.
2018-04-11 22:01:37 +00:00
Harsha Sharma
968a545ab7 tests: check decoding of udev_monitor_netlink_header
* tests/netlink_kobject_uevent.c: Include <string.h>, <arpa/inet.h>,
and "netlink_kobject_uevent.h".
(test_nlmsg_type_udev, test_nlmsg_type_kernel): New functions.
(main): Use them.
2018-04-11 22:01:37 +00:00
Harsha Sharma
c9694f85ed netlink: decode libudev netlink header
* defs.h (decode_netlink_kobject_uevent): New prototype.
* netlink.c (decode_netlink): Decode family kobject_uevent.
* netlink_kobject_uevent.h: New file.
* netlink_kobject_uevent.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
2018-04-11 22:01:37 +00:00
Harsha Sharma
d94871775a tests: check basic decoding of PTP_* ioctl commands
* tests/ioctl_ptp.c: New file.
* tests/gen_tests.in (ioctl_ptp): New entry.
* tests/pure_executables.list: Add ioctl_ptp.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-11 15:41:40 +00:00
Eugene Syromyatnikov
39f61ef513 bpf: decode BPF_PROG_QUERY command
BPF_PROG_QUERY was introduced in Linux commit v4.15-rc1~84^2~558^2~6.

* xlat/bpf_commands.in (BPF_PROG_QUERY): New constant.
* xlat/bpf_query_flags.in: New file.
* bpf.c: Include it.
(DECL_BPF_CMD_DECODER): Add priv argument for passing tcb private data.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): New function.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Add BPF_PROG_QUERY entry.
(SYS_FUNC(bpf)): Fetch buf on entering and exiting, pass buf on exiting,
retrieve private data on exiting, pass it to decoder as well, explicitly
rework rc handling logic for size argument printing.
* bpf_attr.h (struct BPF_PROG_QUERY_struct): New structure declaration.
(BPF_PROG_QUERY_struct_size, expected_BPF_PROG_QUERY_struct_size): New
macro.
* tests/bpf.c: Add checks for BPF_PROG_QUERY command.
2018-04-10 03:38:10 +00:00
Eugene Syromyatnikov
459ea39686 Make print_uint64 from btrfs.c globally available
And rename it to print_uint64_array_member to make the name sensible
without additional context.

* defs.h (print_uint64_array_member): New function prototype.
* btrfs.c (print_uint64): Move...
* util.c (print_uint64_array_member): ...here, drop "static" qualifier.
2018-04-10 03:38:10 +00:00
Eugene Syromyatnikov
1aee6198c7 Introduce umoven_or_printaddr64* functions
Counterparts for umoven_or_printaddr/umoven_or_printaddr_ignore_syserror
that always print 64 bits of addr (as this is needed in bpf and btrfs
decoders).

* util.c (umoven_or_printaddr64): Rename from umoven_or_printaddr,
change addr argument type to uint64_t, call printaddr64 instead of
printaddr.
(umoven_or_printaddr64_ignore_syserror): Rename from
umoven_or_printaddr_ignore_syserror, change addr argument type to
uint64_t, call printaddr64 instead of printaddr.
* defs.h (umoven_or_printaddr64): Rename from umoven_or_printaddr,
change addr argument type to uint64_t.
(umoven_or_printaddr64_ignore_syserror): Rename from
umoven_or_printaddr_ignore_syserror, change addr argument type to
uint64_t.
(umove_or_printaddr64): New macro, a wrapper for umoven_or_printaddr64.
(umoven_or_printaddr): New function, a wrapper for
umoven_or_printaddr64.
(umoven_or_printaddr_ignore_syserror): New function, a wrapper for
umoven_or_printaddr64_ignore_syserror.
2018-04-10 03:38:10 +00:00
Eugene Syromyatnikov
94ea427a31 bpf_filter.c: add support for decoding eBPF instruction codes
* bpf_filter.c (print_bpf_filter_code): Add extended argument, remove
static qualifier.  Add support for decoding eBPF instruction code.
* defs.h (print_bpf_filter_code): New declaration.
* xlat/ebpf_class.in: New file.
* xlat/ebpf_mode.in: Likewise.
* xlat/ebpf_op_alu.in: Likewise.
* xlat/ebpf_op_jmp.in: Likewise.
* xlat/ebpf_size.in: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-10 03:38:10 +00:00
2713444cb7 unwind: prepare configure subsystem for alternative unwinders
Introduce --enable-stacktrace configure option to control whether
-k option support is compiled in, --with-libunwind option remains
available to control whether libunwind can be used as an unwinder.

* m4/st_demangle.m4: New file.
* m4/st_libunwind.m4: Likewise.
* m4/st_stacktrace.m4: Likewise.
* configure.ac: Replace all libunwind and libiberty checks
with a single st_STACKTRACE invocation.
* Makefile.am: Conditionalize checks for USE_LIBUNWIND and USE_DEMANGLE
on ENABLE_STACKTRACE.
[ENABLE_STACKTRACE] (strace_SOURCES): Append unwind.c and unwind.h.
* strace.1.in: Replace libunwind with an unwinder-agnostic wording.
* defs.h: Replace USE_LIBUNWIND with ENABLE_STACKTRACE.
* strace.c: Likewise.
(print_version): Print stack-trace instead of stack-unwind.
* syscall.c: Replace USE_LIBUNWIND with ENABLE_STACKTRACE.
* tests/Makefile.am: Likewise.  Replace LIBUNWIND_TESTS
with STACKTRACE_TESTS.
* tests/strace-V.test: Update expected output.
2018-04-08 22:01:12 +00:00
Eugene Syromyatnikov
cbaa5db24d bpf: implement decoding of prog_name and prog_ifindex fields
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Add support for decoding
of prog_name (introduced in Linux commit v4.15-rc1~84^2~605^2~4) and
prog_ifindex (introduced as prog_target_ifindex in v4.15-rc1~84^2~127^2~13,
renamed in v4.15-rc1~15^2~5^2~3^2~7).
* bpf_attr.h [!BPF_OBJ_NAME_LEN] (BPF_OBJ_NAME_LEN): New macro constant.
[BPF_OBJ_NAME_LEN]: Check that BPF_OBJ_NAME_LEN is equal to 16.
(struct BPF_PROG_LOAD_struct): Add prog_name and prog_ifindex fields.
(BPF_PROG_LOAD_struct_size, expected_BPF_PROG_LOAD_struct_size): Update.
* tests/bpf.c (init_BPF_PROG_LOAD_attr): Rename
to init_BPF_PROG_LOAD_attr3.
(print_BPF_PROG_LOAD_attr): Rename to print_BPF_PROG_LOAD_attr3.
(init_BPF_PROG_LOAD_attr4, print_BPF_PROG_LOAD_attr4): New functions.
(BPF_PROG_LOAD_checks): Check new decoding features.
2018-04-08 22:01:12 +00:00
Eugene Syromyatnikov
a3509bac24 bpf: add support for array fields
* gen_bpf_attr_check.sh: Ignore field array size definition.
* m4/gen_bpf_attr_m4.sh (filter_entries): Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-08 22:01:12 +00:00
958cb40a6e tests: robustify strace -k tests
Allow __getpid as an alternative name for getpid,
allow __kernel_vsyscall after getpid.

* tests/strace-k.expected: New file.
* tests/strace-k-demangle.expected: Likewise.
* tests/Makefile.am (EXTRA_DIST): Add them.
* tests/strace-k-demangle.test (expected): Remove.
* tests/strace-k.test: Likewise.  Use grep to check the output.
2018-04-07 23:35:45 +00:00
Eugene Syromyatnikov
9574a6e231 ipc_msg: sign extend msgtyp in m32 personality
msgtyp has to be treated as a signed type all the way from fetching
to printing.

* ipc_msg.c (fetch_msgrcv_args): Sign extend msgtyp when fetching.
2018-04-07 02:39:09 +00:00
535a07503e strace.spec.in: update Source URL
* strace.spec.in (Source): Change to https://strace.io/files/.
2018-04-05 19:35:58 +00:00
2dad13a0bd debian: enable mpers support for ppc64el and s390x
* debian/control (Build-Depends) [ppc64el, s390x]: Add gcc-multilib.
2018-04-05 19:35:58 +00:00
3154e6de55 Post-release administrivia
* NEWS: Add a header line for the next release.
* debian/changelog.in: Add a changelog entry for 4.22-1.
* strace.spec.in: Likewise.
2018-04-05 12:13:14 +00:00
9630646cfa Prepare for 4.22 release
* NEWS: Update for 4.22 release.
2018-04-05 04:05:06 +00:00
6bc832e2bc Update copyright headers
Headers updated automatically using maint/update_copyright_years.sh
script.
2018-04-05 01:40:00 +00:00
Eugene Syromyatnikov
3b01ac5cd3 Update NEWS 2018-04-05 01:40:00 +00:00
Masatake YAMATO
dd7e62f1e7 unwind: split unwind code into front-end and back-end
This opens the way for alternative unwinder back-ends.

* unwind.h: New file, defines the unwinder back-end interface.
* unwind.c: Move all libunwind related code ...
* unwind-libunwind.c: ... here.
* Makefile.am [USE_LIBUNWIND] (strace_SOURCES): Add unwind.h
and unwind-libunwind.c.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-05 01:40:00 +00:00
Masatake YAMATO
6b94271548 unwind: rename public functions in an object-oriented fashion
This change renames functions exported to strace core part from unwind
subsystem.

The new names imply that unwind subsystem exports two types of
functions.  One is for manipulating back-end itself, "unwind_" prefix
is used for this type.  Another is for manipulating back-end private data
structure (unwind_ctx) attached to tcb, "unwind_tcb_" is used for this
type.

This naming should help people to understand unwind subsystem
and the relation between unwind subsystem and back-ends.

* defs.h (unwind_print_stacktrace): Rename to unwind_tcb_print.
(unwind_capture_stacktrace): Rename to unwind_tcb_capture.
* unwind.c: Ditto.
* syscall.c (syscall_entering_trace, syscall_exiting_trace): Use
new names.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-05 01:40:00 +00:00
Masatake YAMATO
9f5e1d113e unwind: add unwind_ prefix to struct tcb.queue field and its type
The names given to struct tcb.queue field and its type are too common,
this may cause conflicts in the future if new fields are added
to struct tcb.

* defs.h (struct tcb): Rename queue field to unwind_queue,
rename its type queue_t to unwind_queue_t.
* unwind.c (struct unwind_queue_t): Rename to unwind_queue_t.
All users updated.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-05 01:40:00 +00:00
Masatake YAMATO
51e81014e9 unwind: make the field type of struct tcb independent from libunwind
Narrowing the area where the code refers to names associated with
libunwind is needed to utilize libdw of elfutils as an alternative
unwinder.

* defs.h (struct tcb): Rename libunwind_ui field to unwind_ctx, change
its type to "void *".
* unwind.c (unwind_tcb_init, unwind_tcb_fin, stracetrace_walk): Reflect
* the above field renaming.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-05 01:40:00 +00:00
4eeba4e60f tests: robustify options-syntax.test against ash
* tests/options-syntax.test: Do not assume that shell provides $UID,
use "id -u" if it doesn't.
2018-04-04 21:36:07 +00:00
Eugene Syromyatnikov
be55c1c61a strace.c: add support for opening output file in append mode
* strace.c (open_append): New variable.
(init): Handle -A option.
(strace_fopen): Open file in "a" mode if open_append is set to true.
* strace.1.in: Document this.
* NEWS: Mention this.

Suggested-by: Philipp Marek <philipp.marek@emerion.com>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528488
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
698e9c30d4 strace.c: support simultaneous usage of -r and -t options
* strace.c (init): Do not set tflag when rflag is set.
(printleader): Handle rflag and tflag separately.
* strace.1.in (.SH OPTIONS): Add a note about differences between
the monotonic clock time  and the wall clock time.
* tests/options-syntax.test: Remove the check for
"-tt has no effect with -r" warning.
* NEWS: Mention this.

Suggested-by: Josh Triplett <josh@freedesktop.org>
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466195
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
bed7622d49 syscall.c: dump write I/O even if error is returned
It makes sense to try to dump the argument of write syscalls as they can
be readily available despite the fact that error has been returned.

* syscall.c (dumpio): Move check for syserror and check for fd in
read_set to the end of the function.
* tests/read-write.c: Add a check for this behaviour.
* tests/pread64-pwrite64.c: Update expected output.
* NEWS: Mention this.

Suggested-by: J. Bruce Fields <bfields@fieldses.org>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=436284
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
a02a583b3f strace: handle possible NULL from localtime() call
* strace.c (printleader): Print raw tv_sec value if localtime() returned
NULL.
* tests/localtime.c: New file.
* tests/localtime.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add localtime.
(MISC_TESTS): Add localtime.test.
(localtime_LDADD): New variable.
* tests/.gitignore: Add localtime.
* ci/install-dependencies.sh (common_packages): Add faketime.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Closes: https://github.com/strace/strace/issues/42
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
b7154bf146 Return RVAL_STR unconditionally
There is no reason to check for auxstr being non-NULL
because syscall_exiting_trace already does the check.

* sched.c (SYS_FUNC(sched_getscheduler)): Do not check tcp->auxstr,
return RVAL_STR unconditionally.
* time.c (do_adjtimex): Likewise.
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
0f368cd8cb dist/README: s/linux/Linux/
* dist/README: Replace "linux" with "Linux".
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
8ef2b2ad6e strace.1.in: fix formatting of -e trace class descriptions
Use .TP instead .PP as it is ought to be.

* strace.1.in (.SS Filtering): Use .TP instead .PP as it is ought to be.
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
834318eb15 nlattr: check NLA_TYPE_MASK at compile time
* nlattr.c: Include "static_assert.h"
(print_nlattr): Check the expectations about NLA_TYPE_MASK.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
b10995d982 bpf: add a comment about bpf_attr decoding
* bpf.c: Add comment.
2018-04-04 20:32:42 +00:00
a2e4217c95 tests: check decoding of bpf_attr of size 1
* tests/bpf.c (BPF_PROG_GET_NEXT_ID_checks): New entry.
2018-04-04 16:33:19 +00:00
Eugene Syromyatnikov
c5efe0a896 bpf: use print_big_u64_addr
Since pointers stored in the bpf_attr union are 64-bit regardless
of architecture bitness.

* bpf.c (DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)): Call print_big_u64_addr
for attr.license.
(DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Call print_big_u64_addr
for attr.pathname.
* tests/bpf.c (BPF_OBJ_PIN_checks): Check it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-04 16:33:19 +00:00
Eugene Syromyatnikov
8e439e10f0 bpf: add support for file mode flags
These were introduced by Linux commit v4.15-rc1~84^2~384^2~4.

* bpf_attr.h (struct BPF_OBJ_PIN_struct): Add file_flags field.
(struct BPF_PROG_GET_NEXT_ID_struct, struct BPF_PROG_GET_FD_BY_ID_struct,
struct BPF_MAP_GET_FD_BY_ID_struct): Add open_flags field.
(BPF_OBJ_PIN_struct_size, expected_BPF_OBJ_PIN_struct_size,
expected_BPF_PROG_GET_NEXT_ID_struct_size,
expected_BPF_PROG_GET_FD_BY_ID_struct_size,
expected_BPF_MAP_GET_FD_BY_ID_struct_size): Update.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the bpf_fd field, print file_flags field otherwise.
(DEF_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
DEF_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
DEF_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the next_id field, print open_flags field otherwise.
* xlat/bpf_file_mode_flags.in: New file.
* tests/bpf.c (BPF_OBJ_PIN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks): Check it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-04 16:33:19 +00:00
Eugene Syromyatnikov
737762cb85 tests: refactor bpf test
The aim of this change is to introduce an ability to perform multiple
checks for a specific bpf command.  In order to achieve so, all the
related data is stored in check descriptor, and test_bpf iterates over
it.  There are also some provisions made in regard to future changes
(specifically, the way bpf_attr_data union is defined).

* tests/bpf.c (print_bpf_attr): New function, a wrapper around
struct bpf_check.printer.
(test_bpf_): Rename to...
(test_bpf): ...this.  Replace arguments with struct bpf_check pointer.
Iterate over possible attribute variants. Account for changes in
attribute initialisation routine: provide a pointer to locally defined
union bpf_attr_data and perform memcpy afterwards. Initialise memory
from data each time before a bpf call.
(TEST_BPF, DEF_*, init_*, print_*): Remove.
(init_BPF_PROG_LOAD_attr, print_BPF_PROG_LOAD_attr,
init_BPF_OBJ_PIN_attr): New functions.
(license, pathname): New variables.
(BPF_MAP_CREATE_checks, BPF_MAP_LOOKUP_ELEM_checks,
BPF_MAP_UPDATE_ELEM_checks, BPF_MAP_DELETE_ELEM_checks,
BPF_MAP_GET_NEXT_KEY_checks, BPF_PROG_LOAD_checks, BPF_OBJ_PIN_checks,
BPF_PROG_ATTACH_checks, BPF_PROG_DETACH_checks,
BPF_PROG_TEST_RUN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks,
BPF_OBJ_GET_INFO_BY_FD_checks): New arrays.
(BPF_OBJ_GET_checks, BPF_MAP_GET_NEXT_ID_checks): New macros.
(CHK): New macro, a shorthand for initialising array of struct bpf_check.
(main): New static constant checks, iterate over checks and run test_bpf
with each element.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-04 16:33:19 +00:00
Eugene Syromyatnikov
82120681e3 print_fields.h: introduce PRINT_FIELD_ADDR and PRINT_FIELD_ADDR64 macros
* print_fields.h (PRINT_FIELD_ADDR, PRINT_FIELD_ADDR64): New macro.
2018-04-04 16:33:19 +00:00
Eugene Syromyatnikov
f54ab2c24a print_fields.h: introduce PRINT_FIELD_CSTRING_SZ macro
A variant of PRINT_FIELD_CSTRING with an ability to pass string size
explicitly.

* print_fields.h (PRINT_FIELD_CSTRING_SZ): New macro.
2018-04-04 16:33:19 +00:00