* print_kernel_version.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (print_kernel_version): New prototype.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)):
Use print_kernel_version.
* tests/kernel_version.c: New file.
* tests/kernel_version-Xabbrev.c: Likewise.
* tests/kernel_version-Xraw.c: Likewise.
* tests/kernel_version-Xverbose.c: Likewise.
* tests/gen_tests.in (kernel_version, kernel_version-Xabbrev,
kernel_version-Xraw, kernel_version-Xverbose): New tests.
* tests/pure_executables.list: Add kernel_version,
kernel_version-Xabbrev, kernel_version-Xraw, and kernel_version-Xverbose.
* tests/.gitignore: Likewise.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
print_fields.h \
print_ifindex.c \
print_instruction_pointer.c \
+ print_kernel_version.c \
print_mac.c \
print_mq_attr.c \
print_msgbuf.c \
/* kern_version field was added in Linux commit v4.1-rc1~84^2~50. */
if (len <= offsetof(struct BPF_PROG_LOAD_struct, kern_version))
break;
- tprintf(", kern_version=KERNEL_VERSION(%u, %u, %u)",
- attr.kern_version >> 16,
- (attr.kern_version >> 8) & 0xFF,
- attr.kern_version & 0xFF);
-
+ tprints(", kern_version=");
+ print_kernel_version(attr.kern_version);
/* prog_flags field was added in Linux commit v4.12-rc2~34^2~29^2~2. */
if (len <= offsetof(struct BPF_PROG_LOAD_struct, prog_flags))
break;
extern void print_numeric_umode_t(unsigned short);
extern void print_numeric_long_umask(unsigned long);
extern void print_dev_t(unsigned long long dev);
+extern void print_kernel_version(unsigned long version);
extern void print_abnormal_hi(kernel_ulong_t);
extern bool print_int32_array_member(struct tcb *, void *elem_buf,
--- /dev/null
+/*
+ * Kernel version printing routine.
+ *
+ * Copyright (c) 2018 The strace developers.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "defs.h"
+
+void
+print_kernel_version(const unsigned long version)
+{
+ if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
+ tprintf("%#lx", version);
+
+ if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
+ return;
+
+ if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
+ tprints(" /* ");
+
+ tprintf("KERNEL_VERSION(%lu, %lu, %lu)",
+ version >> 16,
+ (version >> 8) & 0xFF,
+ version & 0xFF);
+
+ if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
+ tprints(" */");
+}
kcmp
kcmp-y
kern_features
+kernel_version
+kernel_version-Xabbrev
+kernel_version-Xraw
+kernel_version-Xverbose
kexec_file_load
kexec_load
keyctl
ipc_shm-Xverbose +ipc.sh -Xverbose -a36
kcmp -a22
kcmp-y -a22 -y -e trace=kcmp
+kernel_version -a16 -v -e trace=bpf
+kernel_version-Xabbrev -a16 -Xabbrev -v -e trace=bpf
+kernel_version-Xraw -a16 -Xraw -v -e trace=bpf
+kernel_version-Xverbose -a16 -Xverbose -v -e trace=bpf
kern_features -a16
kexec_file_load -s9
kexec_load -s9
--- /dev/null
+#include "kernel_version.c"
--- /dev/null
+#define XLAT_RAW 1
+#include "kernel_version.c"
--- /dev/null
+#define XLAT_VERBOSE 1
+#include "kernel_version.c"
--- /dev/null
+/*
+ * Check kernel version decoding.
+ *
+ * Copyright (c) 2015-2018 The strace developers.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <asm/unistd.h>
+#include "scno.h"
+
+#ifdef HAVE_LINUX_BPF_H
+# include <linux/bpf.h>
+#endif
+
+#include "bpf_attr.h"
+#include "print_fields.h"
+
+#include "xlat.h"
+#include "xlat/bpf_commands.h"
+
+#define CMD_STR(x) #x
+static const char *errstr;
+
+static void
+print_bpf_attr(void)
+{
+#if XLAT_RAW
+ printf("{prog_type=0x15"
+#else
+ printf("{prog_type=0x15 /* BPF_PROG_TYPE_??? */"
+#endif
+ ", insn_cnt=3134983661"
+ ", insns=NULL"
+ ", license=NULL"
+ ", log_level=24"
+ ", log_size=3141592653"
+ ", log_buf=NULL"
+#if XLAT_RAW
+ ", kern_version=0xcafef00d"
+#elif XLAT_VERBOSE
+ ", kern_version=0xcafef00d"
+ " /* KERNEL_VERSION(51966, 240, 13) */"
+#else
+ ", kern_version=KERNEL_VERSION(51966, 240, 13)"
+#endif
+ ", prog_flags=0"
+ ", prog_name=\"\""
+ ", prog_ifindex=0"
+ ", expected_attach_type="
+#if XLAT_RAW
+ "0}"
+#elif XLAT_VERBOSE
+ "0 /* BPF_CGROUP_INET_INGRESS */}"
+#else /* XLAT_ABBREV */
+ "BPF_CGROUP_INET_INGRESS}"
+#endif
+ );
+}
+
+int
+main(void)
+{
+ long ret;
+ struct BPF_PROG_LOAD_struct prog = {
+ .prog_type = 21,
+ .insn_cnt = 0xbadc0ded,
+ .insns = 0,
+ .license = 0,
+ .log_level = 24,
+ .log_size = 3141592653U,
+ .log_buf = 0,
+ .kern_version = 0xcafef00d,
+ .prog_flags = 0,
+ };
+ ret = syscall(__NR_bpf, BPF_PROG_LOAD, &prog, sizeof(prog));
+ errstr = sprintrc(ret);
+#if XLAT_RAW
+ printf("bpf(%#x, ", BPF_PROG_LOAD);
+#elif XLAT_VERBOSE
+ printf("bpf(%#x /* %s */, ", BPF_PROG_LOAD, CMD_STR(BPF_PROG_LOAD));
+#else
+ printf("bpf(%s, ", CMD_STR(BPF_PROG_LOAD));
+#endif
+ print_bpf_attr();
+ printf(", %u) = %s\n", (unsigned int) sizeof(prog), errstr);
+ puts("+++ exited with 0 +++");
+ return 0;
+}
kcmp
kcmp-y
kern_features
+kernel_version
+kernel_version-Xabbrev
+kernel_version-Xraw
+kernel_version-Xverbose
kexec_file_load
kexec_load
keyctl