From 53af66a660dc7f66ec52ac9c2dab1f74bea279be Mon Sep 17 00:00:00 2001 From: Martin Cermak Date: Tue, 9 Jun 2015 08:32:41 +0200 Subject: [PATCH] PR18501: Add tapset support and test coverage for the kcmp syscall * tapset/linux/aux_syscalls.stp: New function _kcmp_type_str() * tapset/linux/nd_syscalls.stp: New probe nd_syscall.kcmp * tapset/linux/syscalls.stp: New probe syscall.kcmp * testsuite/buildok/aux_syscalls-embedded.stp: New subtest * testsuite/buildok/nd_syscalls-detailed.stp: Ditto * testsuite/buildok/syscalls-detailed.stp: Ditto * testsuite/systemtap.syscall/kcmp.c: New testcase --- tapset/linux/aux_syscalls.stp | 28 ++++++++ tapset/linux/nd_syscalls.stp | 20 ++++++ tapset/linux/syscalls.stp | 20 ++++++ testsuite/buildok/aux_syscalls-embedded.stp | 1 + testsuite/buildok/nd_syscalls-detailed.stp | 10 +++ testsuite/buildok/syscalls-detailed.stp | 10 +++ testsuite/systemtap.syscall/kcmp.c | 73 +++++++++++++++++++++ 7 files changed, 162 insertions(+) create mode 100644 testsuite/systemtap.syscall/kcmp.c diff --git a/tapset/linux/aux_syscalls.stp b/tapset/linux/aux_syscalls.stp index 3abf0deef..4f3fc33a5 100644 --- a/tapset/linux/aux_syscalls.stp +++ b/tapset/linux/aux_syscalls.stp @@ -5858,3 +5858,31 @@ function _perf_event_open_flags_str:string(flags:long) STAP_RETVALUE, MAXSTRINGLEN); #endif %} + +%{ +#ifdef CONFIG_CHECKPOINT_RESTORE +#include +#endif + +static const _stp_val_array const _stp_kcmp_type_list[] = { +#ifdef CONFIG_CHECKPOINT_RESTORE + V(KCMP_FILE), + V(KCMP_VM), + V(KCMP_FILES), + V(KCMP_FS), + V(KCMP_SIGHAND), + V(KCMP_IO), + V(KCMP_SYSVSEM), + V(KCMP_TYPES), +#endif + {0, NULL} +}; +%} + +function _kcmp_type_str:string(type:long) +%{ + unsigned long type = (unsigned long)STAP_ARG_type; + _stp_lookup_str(_stp_kcmp_type_list, (unsigned int)STAP_ARG_type, + STAP_RETVALUE, MAXSTRINGLEN); +%} + diff --git a/tapset/linux/nd_syscalls.stp b/tapset/linux/nd_syscalls.stp index 065adcdc7..921c290d3 100644 --- a/tapset/linux/nd_syscalls.stp +++ b/tapset/linux/nd_syscalls.stp @@ -3202,6 +3202,26 @@ probe nd_syscall.ioprio_set.return = kprobe.function("sys_ioprio_set").return ? retstr = returnstr(1) } +# kcmp _______________________________________________________ +# SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type, +# unsigned long, idx1, unsigned long, idx2) +probe nd_syscall.kcmp = kprobe.function("sys_kcmp") ? +{ + name = "kcmp" + pid1 = int_arg(1) + pid2 = int_arg(2) + type = int_arg(3) + type_str = _kcmp_type_str(type) + idx1 = ulong_arg(4) + idx2 = ulong_arg(5) + argstr = sprintf("%d, %d, %s, %u, %u", pid1, pid2, type_str, idx1, idx2) +} +probe nd_syscall.kcmp.return = kprobe.function("sys_kcmp").return ? +{ + name = "kcmp" + retstr = returnstr(1) +} + # kexec_file_load ____________________________________________ # The kexec_file_load() system call first appeared in Linux 3.17 # SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, diff --git a/tapset/linux/syscalls.stp b/tapset/linux/syscalls.stp index 1433f898a..fb277c62b 100644 --- a/tapset/linux/syscalls.stp +++ b/tapset/linux/syscalls.stp @@ -2979,6 +2979,26 @@ probe syscall.ioprio_set.return = kernel.function("sys_ioprio_set").return ? retstr = return_str(1, $return) } +# kcmp _______________________________________________________ +# SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type, +# unsigned long, idx1, unsigned long, idx2) +probe syscall.kcmp = kernel.function("sys_kcmp") ? +{ + name = "kcmp" + pid1 = __int32($pid1) + pid2 = __int32($pid2) + type = __int32($type) + type_str = _kcmp_type_str(type) + idx1 = @__compat_ulong($idx1) + idx2 = @__compat_ulong($idx2) + argstr = sprintf("%d, %d, %s, %u, %u", pid1, pid2, type_str, idx1, idx2) +} +probe syscall.kcmp.return = kernel.function("sys_kcmp").return ? +{ + name = "kcmp" + retstr = return_str(1, $return) +} + # kexec_file_load ____________________________________________ # The kexec_file_load() system call first appeared in Linux 3.17 # SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, diff --git a/testsuite/buildok/aux_syscalls-embedded.stp b/testsuite/buildok/aux_syscalls-embedded.stp index bc1450939..9f1c10437 100755 --- a/testsuite/buildok/aux_syscalls-embedded.stp +++ b/testsuite/buildok/aux_syscalls-embedded.stp @@ -207,4 +207,5 @@ probe begin { print (_fanotify_mark_flags_str(0)) print (_fanotify_mark_mask_str(0)) print (_perf_event_open_flags_str(0)) + print (_kcmp_type_str(0)) } diff --git a/testsuite/buildok/nd_syscalls-detailed.stp b/testsuite/buildok/nd_syscalls-detailed.stp index d45f0d23d..33d43fa43 100755 --- a/testsuite/buildok/nd_syscalls-detailed.stp +++ b/testsuite/buildok/nd_syscalls-detailed.stp @@ -1086,6 +1086,16 @@ probe nd_syscall.ioprio_set.return ? printf("%s, %s\n", name, retstr) } +probe nd_syscall.kcmp ? +{ + printf("%s, %s\n", name, argstr) + printf("%d, %d, %s, %u, %u", pid1, pid2, type_str, idx1, idx2) +} +probe nd_syscall.kcmp.return ? +{ + printf("%s, %s\n", name, retstr) +} + probe nd_syscall.kexec_file_load ? { printf("%s, %s\n", name, argstr) diff --git a/testsuite/buildok/syscalls-detailed.stp b/testsuite/buildok/syscalls-detailed.stp index b2d9c052d..72d0e9a99 100755 --- a/testsuite/buildok/syscalls-detailed.stp +++ b/testsuite/buildok/syscalls-detailed.stp @@ -1084,6 +1084,16 @@ probe syscall.ioprio_set.return ? printf("%s, %s\n", name, retstr) } +probe syscall.kcmp ? +{ + printf("%s, %s\n", name, argstr) + printf("%d, %d, %s, %u, %u", pid1, pid2, type_str, idx1, idx2) +} +probe syscall.kcmp.return ? +{ + printf("%s, %s\n", name, retstr) +} + probe syscall.kexec_file_load ? { printf("%s, %s\n", name, argstr) diff --git a/testsuite/systemtap.syscall/kcmp.c b/testsuite/systemtap.syscall/kcmp.c new file mode 100644 index 000000000..5789e7aae --- /dev/null +++ b/testsuite/systemtap.syscall/kcmp.c @@ -0,0 +1,73 @@ +/* COVERAGE: kcmp */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#ifdef __NR_kcmp +// The kernel-headers-3.13.9-200.fc20 doesn't have linux/kcmp.h, +// thus defining needed enum here: +enum kcmp_type { + KCMP_FILE, + KCMP_VM, + KCMP_FILES, + KCMP_FS, + KCMP_SIGHAND, + KCMP_IO, + KCMP_SYSVSEM, + KCMP_TYPES, +}; + +static inline int __kcmp(pid_t pid1, pid_t pid2, int type, + unsigned long idx1, unsigned long idx2) +{ + return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2); +} + +int main() +{ + int mypid = getpid(); + unsigned long fd = open("kcmp_testfile", O_CREAT); + + __kcmp(mypid, mypid, KCMP_FILE, fd, fd); + //staptest// [[[[kcmp (NNNN, NNNN, KCMP_FILE, NNNN, NNNN) = 0!!!!ni_syscall () = -38 (ENOSYS)]]]] + + // Limit testing + + __kcmp(-1, 0, 0, 0, 0); + //staptest// [[[[kcmp (-1, 0, KCMP_FILE, 0, 0)!!!!ni_syscall ()]]]] = -NNNN + + __kcmp(0, -1, 0, 0, 0); + //staptest// [[[[kcmp (0, -1, KCMP_FILE, 0, 0)!!!!ni_syscall ()]]]] = -NNNN + + __kcmp(0, 0, -1, 0, 0); + //staptest// [[[[kcmp (0, 0, 0x[f]+, 0, 0)!!!!ni_syscall ()]]]] = -NNNN + + __kcmp(0, 0, 0, -1, 0); +#if __WORDSIZE == 64 + //staptest// [[[[kcmp (0, 0, KCMP_FILE, 18446744073709551615, 0)!!!!ni_syscall ()]]]] = -NNNN +#else + //staptest// [[[[kcmp (0, 0, KCMP_FILE, 4294967295, 0)!!!!ni_syscall ()]]]] = -NNNN +#endif + + __kcmp(0, 0, 0, 0, -1); +#if __WORDSIZE == 64 + //staptest// [[[[kcmp (0, 0, KCMP_FILE, 0, 18446744073709551615)!!!!ni_syscall ()]]]] = -NNNN +#else + //staptest// [[[[kcmp (0, 0, KCMP_FILE, 0, 4294967295)!!!!ni_syscall ()]]]] = -NNNN +#endif + + + close(fd); + unlink("kcmp_testfile"); + return 0; +} +#else +int main() +{ + return 0; +} +#endif /* ifdef __NR_kcmp */ -- 2.43.5