* tests/ipc_msgbuf.c: Include <unistd.h> and <asm/unistd.h>.
(sys_msgrcv): New function.
(msgrcv): Use it instead of msgrcv. Add bits to mtype,
check for -mtype in msgrcv.
Regenerate xlat/sockoptions.in using the following script:
sed -n 's/^\(SO_[^[:space:]]*\).*/\1/p' xlat/sockoptions.in |
uniq |
while read name; do
sed -rn 's/#define[[:space:]]+('"$name"')[[:space:]]+([[:digit:]]+)$/\2\t\1/p' \
/path/to/linux/include/uapi/asm-generic/socket.h
done |
sort -n |
while read def name; do
grep -EH '#define[[:space:]]+'"$name"'[[:space:]]+(0x[[:xdigit:]]+|[[:digit:]]+)' \
/path/to/linux/arch/*/include/uapi/asm/socket.h |
sed -rn 's|^[^#]*/arch/([^/]+)/include/uapi/asm/socket\.h:#define[[:space:]]+'"$name"'[[:space:]]+([^[:space:]]+)([[:space:]].*)?$|\1\t\2|p' |
sed s/parisc/hppa/ |sort |
awk -vname="$name" -vdef="$def" '
{
i=strtonum($2)
if (i == def) next
if (a[i])
a[i]=a[i] " || defined __" $1 "__"
else
a[i]="defined __" $1 "__"
}
END {
iftext="#if"
for (i in a) {
printf("%s %s\n%s %u\n",iftext,a[i],name,i)
iftext="#elif"
}
if (iftext != "#if")
print "#else"
printf("%s %s\n", name, def)
if (iftext == "#if")
print ""
else
print "#endif\n"
}'
done
* xlat/sockoptions.in: Add fallback definitions.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
* xlat/socketlayers.in: Add a comment that the xlat is sorted.
* net.c (print_sockopt_fd_level_name): Use printxval_search
instead of printxval for decoding socket layer name.
net: decode Bluetooth protocol names unconditionally
As we have all BTPROTO_* constant definitions now, there is no need
to rely on bluetooth.h header anymore.
* net.c (AF_BLUETOOTH): Provide a fallback definition.
[HAVE_BLUETOOTH_BLUETOOTH_H]: Do not include <bluetooth/bluetooth.h>.
[!HAVE_BLUETOOTH_BLUETOOTH_H]: Include "xlat/bt_protocols.h".
[!HAVE_BLUETOOTH_BLUETOOTH_H] (decode_sockbuf): Decode AF_BLUETOOTH.
(decode_sockbuf) <case AF_BLUETOOTH>: Use printxval_index.
* xlat/bt_protocols.in: Add "#value_indexed" directive.
* xlat/sigfpe_codes.in (FPE_FLTUNK): New constant, introduced by Linux
commit v4.17-rc1~107^2~2.
(FPE_CONDTRAP): New constant, introduced by Linux commit
v4.17-rc1~31^2~3.
Synchronise v4l2_control_ids list with the one provided by kernel's
include/uapi/linux/v4l2-controls.h. A few notes:
- V4L2_CID_CHROMA_GAIN and V4L2_CID_COLORFX_CBCR moved in accordance
with their position/values.
- V4L2_CID_WHITENESS is removed as it has the same value as
V4L2_CID_GAMMA.
- V4L2_CID_PRIVATE_BASE is removed.
- V4L2_CID_HCENTER and V4L2_CID_VCENTER that were removed by Linux
commit v3.9-rc1~93^2~237, are retained for historical reasons.
* xlat/v4l2_control_classes.in (V4L2_CTRL_CLASS_DV): New constant,
introduced by Linux commit v3.7-rc1~101^2^2~322.
(V4L2_CTRL_CLASS_RF_TUNER): New constant, introduced by Linux commit
v3.15-rc1~85^2~192.
(V4L2_CTRL_CLASS_DETECT): New constant, introduced by Linux commit
v3.17-rc1~112^2~340.
Apparently, BPF_F_RDONLY and BPF_F_WRONLY are also used in map_flags.
Moreover, set of flags depends on the type of map, but let's leave that
for another day.
* xlat/bpf_map_flags.in (BPF_F_RDONLY, BPF_F_WRONLY): New constants.
(BPF_F_STACK_BUILD_ID): New constant, introduced by Linux commit
v4.17-rc1~148^2~156^2~3^2~1.
* xlat/bpf_map_flags.in: Update expected output.
* xlat/socksctpoptions.in (SCTP_AUTH_DEACTIVATE_KEY): New constant,
introduced by Linux commit v4.17-rc1~148^2~191^2~2.
(SCTP_SENDMSG_CONNECT): New constant, introduced by Linux commit
v4.17-rc1~96^2~9.
Dmitry V. Levin [Sat, 5 May 2018 14:38:38 +0000 (14:38 +0000)]
build: rewrite libdw detection without pkg-config
pkg-config expected to be more convenient way to configure libdw,
but in practice it appeared to be less portable than good old
AC_CHECK_HEADERS and AC_CHECK_LIB.
* ci/install-dependencies.sh (common_packages): Remove pkg-config.
(STACKTRACE == "libdw"): Do not install libz-dev and liblzma-dev.
* debian/control (Build-Depends): Remove pkg-config.
* m4/st_libdw.m4 (st_ARG_LIBDW, st_LIBDW): Rewrite without pkg-config.
Dmitry V. Levin [Fri, 4 May 2018 23:13:45 +0000 (23:13 +0000)]
ci: add more variants of unwinder to test matrices
Check x86_64 builds with libdw, with libunwind, and without stacktrace.
As Travis CI doesn't provide a suitable libdw, do not test libdw there.
* ci/install-dependencies.sh (common_packages): Remove libdw-dev.
Install libdw-dev or libunwind8-dev depending on $STACKTRACE.
* ci/run-build-and-tests.sh: Specify --with-libdw=yes,
--with-libunwind=yes, or --without-stacktrace depending on $STACKTRACE.
* .gitlab-ci.yml (gcc-x86_64): Rename to gcc-x86_64-libdw,
add STACKTRACE=libdw.
(gcc-x86): Rename to gcc-x86-nounwind, add STACKTRACE=no.
(clang-x86_64): Rename to clang-x86_64-libdw, add STACKTRACE=libdw.
(clang-x86): Rename to clang-x86-nounwind, add STACKTRACE=no.
(gcc-x86_64-libunwind, gcc-x86_64-nounwind, gcc-x86-nounwind,
clang-x86_64-libunwind, clang-x86_64-nounwind, clang-x86-nounwind):
New test matrix entries.
* .travis.yml: Add STACKTRACE=libunwind to all x86_64 test matrix
entries except musl-gcc, add STACKTRACE=no to other matrix entries,
add test matrix entries with STACKTRACE=no variants on x86_64.
* xlat/adjtimex_modes.in: Add values to constants.
(0): Remove.
(ADJ_OFFSET_SS_READ): Move to the first place.
(ADJ_OFFSET_SINGLESHOT): Move to the second place.
Dmitry V. Levin [Fri, 4 May 2018 14:45:44 +0000 (14:45 +0000)]
mmap_cache: do not activate unless requested
Do not call mmap_cache functions until mmap_cache_enable is invoked.
Change struct mmap_cache_t into a proxy structure, move all mmap_cache
data from struct tcb inside this new structure.
* Makefile.am (strace_SOURCES): Move mmap_cache.c and mmap_cache.h
to libstrace_a_SOURCES.
* defs.h (struct tcb): Remove mmap_cache_size and mmap_cache_generation
* fields.
* mmap_cache.h (struct mmap_cache_t): Rename
to struct mmap_cache_entry_t, create a new struct mmap_cache_t,
all users updated.
(mmap_cache_delete): Remove.
* mmap_cache.c (mmap_cache_delete): Rename to delete_mmap_cache,
add static qualifier.
(build_mmap_cache): Merge into mmap_cache_rebuild_if_invalid.
* strace.c (droptcb): Replace mmap_cache_delete invocation
with tcp->mmap_cache->free_fn.
The unwind subsystem uses the mmap_cache subsystem even it uses
unwind-libdw as backend. unwind-libdw doesn't need the full set of the
mmap_cache subsystem; libdw has a feature for caching a memory
mapping.
This commit does three things.
(1) Make the unwind subsystem not use the mmap_cache subsystem.
The unwind subsystem never concern the memory mapping of the target.
It becomes a thin layer.
(2) Make unwind-libunwind use the mmap_cache subsystem directly.
(3) Make unwind-libdw use the mmap_notify subsystem to know when it
should call dwfl_linux_proc_report/dwfl_report_end for updating the
cache.
Here is a subsystem structure that this patch
introduces:
* unwind.c: Don't include "mmap_cache.h".
(unwind_init): Don't call mmap_cache_enable.
(unwind_tcb_print, unwind_tcb_capture): Don't call mmap_cache related
functions, just invoke unwinder.tcb_walk.
* unwind.h (struct unwind_unwinder_t): Remove tcb_flush_cache field.
* unwind-libdw.c: Include "mmap_notify.h" instead of "mmap_cache.h".
(struct ctx): Add last_proc_updating field to record the generation
of memory mapping that is cached by dwfl_linux_proc_report
and dwfl_report_end.
(mapping_generation): A variable counting how many times the memory
mapping of targets has been changed.
(updating_mapping_generation): New utility function for updating
mapping_generation.
(init): New function for registering updating_mapping_generation
in the mmap_notify subsystem as a callback function.
(tcb_init): Initialize ctx::last_proc_updating.
(tcb_flush_cache): Rename to flush_cache_maybe. Rebuild the cache data
only if the data is stale.
(tcb_walk): Call flush_cache_maybe for avoiding referring staled cache data.
(unwinder): Set init function, remove tcb_flush_cache field.
* unwind-libunwind.c (init): Enable the mmap_cache subsystem.
(tcb_walk): Call mmap_cache_rebuild_if_invalid and unw_flush_cache for
updating the cache of the memory mapping before walking the stack.
(tcb_walk): Rename to walk.
(unwinder): Remove tcb_flush_cache field.
* mmap_cache.c: Include mmap_notify.h.
(mmap_cache_enable): Call mmap_notify_register_client to use
the mmap_notify subsystem, mmap_cache_invalidate is specified
to handle the change of memory mapping.
(mmap_cache_invalidate): Add static qualifier.
* mmap_cache.h (mmap_cache_invalidate): Remove.
* syscall.c: Include mmap_notify.h instead of mmap_cache.h.
(syscall_exiting_decode): Call mmap_notify_report instead
of mmap_cache_invalidate.
These missing va_end() calls are followed by die() calls that never
return, so the only practical effect of this change is appeasement
of code checking tools.
Dmitry V. Levin [Wed, 2 May 2018 15:23:46 +0000 (15:23 +0000)]
xlat: merge fcntl64cmds into fcntlcmds
Since we don't have to workaround old F_[GS]ETOWN_EX == F_[SG]ETLK64
kernel bug any longer, there is a room for cleanup.
* xlat/fcntlcmds.in (F_GETLK64, F_SETLK64, F_SETLKW64): Add from
xlat/fcntl64cmds.in.
* xlat/fcntl64cmds.in: Remove.
* fcntl.c: Do not include "xlat/fcntl64cmds.h".
(SYS_FUNC(fcntl), SYS_FUNC(fcntl64)): Do not use fcntl64cmds, call
printxval instead of printxvals.
Zhibin Li [Wed, 2 May 2018 15:16:57 +0000 (23:16 +0800)]
tests: check decoding of F_GETOWN_EX and F_SETOWN_EX fcntl commands
* tests/fcntl.c (TEST_F_OWNER_EX): New macro.
[TEST_F_OWNER_EX]: Include "f_owner_ex.h".
[TEST_F_OWNER_EX] (test_f_owner_ex_type_pid,
test_f_owner_ex_umove_or_printaddr, test_f_owner_ex): New functions.
(main) [TEST_F_OWNER_EX]: Use test_f_owner_ex.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Wed, 2 May 2018 15:23:46 +0000 (15:23 +0000)]
Introduce f_owner_ex.h
Some headers define struct f_owner_ex, some struct __kernel_f_owner_ex,
we have to support both variants.
* configure.ac (AC_CHECK_TYPES): Check for "struct f_owner_ex"
and "struct __kernel_f_owner_ex" in <linux/fcntl.h>.
* f_owner_ex.h: New file.
* Makefile.am (strace_SOURCES): Add it.
Masatake YAMATO [Wed, 2 May 2018 08:11:07 +0000 (17:11 +0900)]
tests/ioctl_kvm_run.c: handle cpuid at the end of vcpu dentry
Since Linux 4.16, kernel appends the cpuid as suffix to the entry
for a kvm vcpu in /proc/$pid/fd like:
anon_inode:kvm-vcpu:0
That was
anon_inode:kvm-vcpu
This kernel change causes the test case failure on newer kernels.
Update the test to deal with the new name as well as the old one.
* tests/ioctl_kvm_run.c: Include unistd.h for using readlink(2).
(vcpu_dev_should_have_cpuid): New function for detecting whether
a proc entry for given fd has the cpuid suffix or not.
(main): Trim vcpu_dev to remove the cpuid suffix if needed.
(vcpu_dev): Remove const modifier.
xlat: check that system definitions match fallback definitions
For each constant that is accompanied by a fallback definition,
generate a sanity check that the definition provided by system headers
matches the fallback definition.
* gcc_compat.h (DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE,
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE): New macros.
* xlat/gen.sh (cond_def): Generate a code that checks the system
definition against the default.
(gen_header): Generate a code that includes "gcc_compat.h" and
"static_assert.h".
xlat: override values of F_SETOWN_EX and F_GETOWN_EX constants
Linux kernel commit v2.6.32-rc7~23 has changed values of F_SETOWN_EX
and F_GETOWN_EX constants introduced by commit v2.6.32-rc1~96 to fix
the conflict with F_GETLK64 and F_SETLK64 constants.
Looks like the best way to handle this situation is to pretend that
old values of F_SETOWN_EX and F_GETOWN_EX didn't exist.
xlat: override values of KEY_RFKILL and KEY_BRIGHTNESS_MIN constants
KEY_RFKILL and KEY_NUMERIC_A constants were introduced by Linux kernel
commits v2.6.33~17^2~2 and v4.1-rc1~150^2~1^10~6, respectively.
Apparently, RHEL6 introduced an alternative KEY_RFKILL constant
with the same value as upstream KEY_NUMERIC_A.
KEY_BRIGHTNESS_MIN and KEY_BRIGHTNESS_MAX constants were introduced
by Linux kernel commit v3.16-rc1~30^2~6^2~1^2~7.
Apparently, RHEL7 introduced an alternative KEY_BRIGHTNESS_MIN constant
with the same value as upstream KEY_BRIGHTNESS_MAX.
Downstream vendors are *not* allowed to do this.
Ignore the system value of KEY_RFKILL and KEY_BRIGHTNESS_MIN.
Linux kernel commit v4.9-rc8~12^2 has changed the value of KEY_DATA
constant introduced by commit v4.7-rc6~32^2~6^2 because the old value
was already used by KEY_FASTREVERSE.
Looks like the best way to handle this situation is to pretend that
the old value of KEY_DATA didn't exist.
xlat: override the value of AUDIT_FEATURE_CHANGE constant
Linux kernel commit v3.15-rc1~18^2~1 has changed the value
of AUDIT_FEATURE_CHANGE constant introduced by commit v3.13-rc1~19^2~20
which is of course an ABI breakage that affected 3.13 and 3.14 kernel
releases as well as their LTS derivatives.
Linux kernel commit v3.15-rc1~18^2~1 also claims that the old value
of AUDIT_FEATURE_CHANGE was ignored by userspace because of the
established convention how netlink messages for the audit system
are divided into blocks.
Looks like the best way to handle this situation is to pretend that
the old value of AUDIT_FEATURE_CHANGE didn't exist.
build: try to use _Static_assert if static_assert is not available
* configure.ac: Check for _Static_assert if static_assert
is not available.
* static_assert.h [!HAVE_STATIC_ASSERT && HAVE__STATIC_ASSERT]
(static_assert): Define to _Static_assert.
evdev: support various types of xlats in decode_bitset
* evdev.c (enum xlat_type): New enumeration.
(printxval_dispatch): New function.
(decode_bitset_): Rename from decode_bitset, add decode_nr_size
and xt arguments, call printxval_dispatch instead of printxval.
(decode_bitset): Add a decode_bitset_ wrapper that derives
decode_nr_size from the ARRAY_SIZE of decode_nr.
(bit_ioctl, evdev_read_ioctl): Update decode_bitset calls.
There are quite a few xlats that start from 0 and not too sparse,
we can push the search time for them down to O(1).
* defs.h (printxval_indexn_ex): New declaration.
(printxval_indexn, printxval_index, printxval_index_ex): New macros.
* xlat.c (printxval_sized): Rename from printxval_searchn_ex,
add fn argument, call it instead of xlat_search.
(printxval_searchn_ex): Implement as a thin wrapper around
printxval_sized using xlat_search as a search function.
(xlat_idx): New function.
(printxval_indexn_ex): New function, a thin wrapper around
printxval_sized using xlat_idx as a search function.
* xlat/gen.sh: Add support for "#value_indexed" directive.
keyctl: use printxval_d for printing keyring serial number
* keyctl.c (print_keyring_serial_number): Use printxval_d instead of
looking up and printing xlat value manually.
* xlat/key_spec.in: Add "#val_type int" so the xlat values have sign
bit propagated.
ioprio: use sprintxval instead of xlookup and string/value printing
In order to respect current xlat style.
* ioprio.c (sprint_ioprio): Use sprintxval for producing string
representation of ioprio class, use the produced string representation
in resulting xsprintf.
tests/ioctl_evdev.c (TEST_NULL_ARG_EX): Rename from TEST_NULL_ARG, add
str argument, print it instead of #cmd.
(TEST_NULL_ARG): Implement as a TEST_NULL_ARG_EX wrapper.
(main): Add checks for EVIOCSABS and EVIOCGBIT ioctls.
* xlat/evdev_switch.in (SW_RADIO): Remove, as it was renamed to
SW_RFKILL_ALL and marked as deprecated by Linux commit v2.6.26-rc5~32^2.
(SW_PEN_INSERTED): New constant, was added by Linux commit v4.7~11^2~7.
* btrfs.c (btrfs_print_balance_args): Print devid field using
PRINT_FIELD_DEV.
(MPERS_PRINTER_DECL(btrfs_ioctl)) <case BTRFS_IOC_DEV_INFO,
case BTRFS_IOC_GET_DEV_STATS, case BTRFS_IOC_SCRUB,
case BTRFS_IOC_SCRUB_PROGRESS>: Likewise.
(MPERS_PRINTER_DECL(btrfs_ioctl)) <case BTRFS_IOC_DEV_REPLACE>: Print
start.srcdevid field using PRINT_FIELD_DEV.
* tests/btrfs.c: Update expected output.
btrfs: print cont_reading_from_srcdev_mode as xlat
* xlat/btrfs_cont_reading_from_srcdev_mode.in: New file.
* btrfs.c: Include "xlat/btrfs_cont_reading_from_srcdev_mode.h".
(MPERS_PRINTER_DECL(btrfs_ioctl)) <case BTRFS_IOC_DEV_REPLACE>: Print
named values for the
struct btrfs_ioctl_dev_replace_args.start.cont_reading_from_srcdev_mode
field.
* tests/btrfs.c: Include "xlat/btrfs_cont_reading_from_srcdev_mode.h".
(btrfs_test_dev_replace_ioctl): Update expected output.
btrfs: make BTRFS_IOC_GET_DEV_STATS error statistics output more structured
* btrfs.c (MPERS_PRINTER_DECL(btrfs_ioctl)) <case
BTRFS_IOC_GET_DEV_STATS>: Print array index in square brackets before
the value in order to avoid confusion.
* tests/btrfs.c (btrfs_test_get_dev_stats_ioctl): Update expected output.
ioctl: print ioctl number in accordance with xlat verbosity setting
* ioctl.c (SYS_FUNC(ioctl)): Print ioctl command name in accordance
with the current xlat_verbosity setting.
* tests/btrfs.c (sprint_xlat_): New function.
(ioc): New macro, a wrapper for sprint_xlat_.
Update expected output.
file_ioctl: make abbreviated output more structured
* file_ioctl.c (file_ioctl): Print fm_extents field name only in case
of non-abbreviated output.
* tests/btrfs.c (btrfs_test_ino_path_ioctls): Update expected output.