[PATCH 01/11] tests: Additional getcwd checks
* tests/getcwd.c: Additional checks for getcwd arguments decoding. --- tests/getcwd.c |8 1 file changed, 8 insertions(+) diff --git a/tests/getcwd.c b/tests/getcwd.c index 704a315..e4a791f 100644 --- a/tests/getcwd.c +++ b/tests/getcwd.c @@ -13,6 +13,14 @@ main(void) { long res; char cur_dir[PATH_MAX + 1]; + static const size_t bogus_size = (size_t) 0xbadc0deddeadfaceULL; + + syscall(__NR_getcwd, NULL, bogus_size); + printf("getcwd(NULL, %zu) = -1 EFAULT (%m)\n", bogus_size); + + syscall(__NR_getcwd, (char *)-1L, sizeof(cur_dir)); + printf("getcwd(%p, %zu) = -1 EFAULT (%m)\n", + (char *)-1L, sizeof(cur_dir)); res = syscall(__NR_getcwd, cur_dir, sizeof(cur_dir)); -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH 00/11] Various minor tests
Hello. This patchset provides a set of some simple syscall decoders test along with fixes of minor issues discovered in the process. Eugene Syromyatnikov (11): tests: Additional getcwd checks tests: Avoid filling with the same values in ioctl_block test tests: check decoding of getcpu syscall xlat: Add values for falloc_flags constants fallocate: Change print format of offset and len arguments to signed fadvise: Change printing of len argument to unsigned in fadvise64 syscall util: Add getarg_ull/getarg_ll functions fadvise: Use getarg_ull for obtaining len argument of fadvise64 syscall Use sys_fadvise64 as a decoder for fadvise64 syscall on x32 tests: Add test for decoding fallocate syscall tests: Add test for decoding fadvise syscall configure.ac|1 + defs.h |2 ++ fadvise.c |2 +- fallocate.c |4 +-- linux/x32/syscallent.h |2 +- tests/.gitignore|4 +++ tests/Makefile.am |8 ++ tests/fadvise64.c | 71 +++ tests/fadvise64.test|6 tests/fadvise64_64.c| 59 +++ tests/fadvise64_64.test |6 tests/fallocate.c | 38 + tests/fallocate.test|6 tests/getcpu.c | 48 tests/getcpu.test |6 tests/getcwd.c |8 ++ tests/ioctl_block.c |2 +- util.c | 44 + xlat/falloc_flags.in| 12 19 files changed, 306 insertions(+), 23 deletions(-) create mode 100644 tests/fadvise64.c create mode 100755 tests/fadvise64.test create mode 100644 tests/fadvise64_64.c create mode 100755 tests/fadvise64_64.test create mode 100644 tests/fallocate.c create mode 100755 tests/fallocate.test create mode 100644 tests/getcpu.c create mode 100755 tests/getcpu.test -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH 03/11] tests: check decoding of getcpu syscall
* tests/getcpu.c: New file. * tests/getcpu.test: New test. * tests/.gitignore: Add getcpu. * tests/Makefile.am (check_PROGRAMS): Likewise. (DECODER_TESTS): Add getcpu.test. --- tests/.gitignore |1 + tests/Makefile.am |2 ++ tests/getcpu.c| 48 tests/getcpu.test |6 ++ 4 files changed, 57 insertions(+) create mode 100644 tests/getcpu.c create mode 100755 tests/getcpu.test diff --git a/tests/.gitignore b/tests/.gitignore index 2820b2b..bdb2d9a 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -70,6 +70,7 @@ ftruncate64 futex futimesat get_mempolicy +getcpu getcwd getdents getdents64 diff --git a/tests/Makefile.am b/tests/Makefile.am index f6f980a..ac579c7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -129,6 +129,7 @@ check_PROGRAMS = \ futex \ futimesat \ get_mempolicy \ + getcpu \ getcwd \ getdents \ getdents64 \ @@ -465,6 +466,7 @@ DECODER_TESTS = \ futex.test \ futimesat.test \ get_mempolicy.test \ + getcpu.test \ getcwd.test \ getdents.test \ getdents64.test \ diff --git a/tests/getcpu.c b/tests/getcpu.c new file mode 100644 index 000..a96fd49 --- /dev/null +++ b/tests/getcpu.c @@ -0,0 +1,48 @@ +#include "tests.h" + +#include + +#ifdef __NR_getcpu + +# include +# include + +int +main(void) +{ + static const unsigned *bogus_cpu = + (unsigned *) (unsigned long) 0xfeedfaceULL; + static const unsigned *bogus_node = + (unsigned *) (unsigned long) 0xfca7c0deULL; + static const unsigned *bogus_tcache = + (unsigned *) (unsigned long) 0xda7adeadULL; + + long res; + unsigned *cpu = tail_alloc(sizeof(*cpu)); + unsigned *node = tail_alloc(sizeof(*node)); + long * tcache = tail_alloc(128); + + res = syscall(__NR_getcpu, NULL, NULL, NULL); + printf("getcpu(NULL, NULL, NULL) = %s\n", sprintrc(res)); + + res = syscall(__NR_getcpu, bogus_cpu, bogus_node, bogus_tcache); + printf("getcpu(%p, %p, %p) = %s\n", + bogus_cpu, bogus_node, bogus_tcache, sprintrc(res)); + + res = syscall(__NR_getcpu, cpu, node, tcache); + if (res != 0) + perror_msg_and_skip("getcpu"); + + printf("getcpu([%u], [%u], %p) = 0\n", + *cpu, *node, tcache); + + puts("+++ exited with 0 +++"); + + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_getcpu"); + +#endif diff --git a/tests/getcpu.test b/tests/getcpu.test new file mode 100755 index 000..3dbe5e0 --- /dev/null +++ b/tests/getcpu.test @@ -0,0 +1,6 @@ +#!/bin/sh + +# Check getcwd syscall decoding. + +. "${srcdir=.}/init.sh" +run_strace_match_diff -a25 -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH 02/11] tests: Avoid filling with the same values in ioctl_block test
* tests/ioctl.block (init_magic): Add iterator value to fill magic value in order to enable detection of possible 4-byte aligned shifts. --- tests/ioctl_block.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ioctl_block.c b/tests/ioctl_block.c index 3dc030d..bac9f68 100644 --- a/tests/ioctl_block.c +++ b/tests/ioctl_block.c @@ -50,7 +50,7 @@ init_magic(void *addr, const unsigned int size) const unsigned int *end = addr + size - sizeof(int); for (; p <= end; ++p) - *(unsigned int *) p = magic; + *(unsigned int *) p = magic + (p - (unsigned int *)addr); } static struct xlat block_argless[] = { -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH 11/11] tests: Add test for decoding fadvise syscall
* tests/.gitignore: Add fadvise64, fadvise64_64. * tests/Makefile.am (check_PROGRAMS): Likewise. (DECODER_TESTS): Add fadvise64.test, fadvise64_64.test. * fadvise64.c: New file. * fadvise64_64.c: Likewise. * fadvise64.test: Likewise. * fadvise64_64.test: Likewise. --- tests/.gitignore|2 ++ tests/Makefile.am |4 +++ tests/fadvise64.c | 71 +++ tests/fadvise64.test|6 tests/fadvise64_64.c| 59 +++ tests/fadvise64_64.test |6 6 files changed, 148 insertions(+) create mode 100644 tests/fadvise64.c create mode 100755 tests/fadvise64.test create mode 100644 tests/fadvise64_64.c create mode 100755 tests/fadvise64_64.test diff --git a/tests/.gitignore b/tests/.gitignore index c3665c2..b41459a 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -44,6 +44,8 @@ execve-v execveat execveat-v faccessat +fadvise64 +fadvise64_64 fallocate fanotify_mark fchdir diff --git a/tests/Makefile.am b/tests/Makefile.am index 4fdc877..424c5bb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -103,6 +103,8 @@ check_PROGRAMS = \ execveat \ execveat-v \ faccessat \ + fadvise64 \ + fadvise64_64 \ fallocate \ fanotify_mark \ fchdir \ @@ -443,6 +445,8 @@ DECODER_TESTS = \ execveat-v.test \ execveat.test \ faccessat.test \ + fadvise64.test \ + fadvise64_64.test \ fallocate.test \ fanotify_mark.test \ fchdir.test \ diff --git a/tests/fadvise64.c b/tests/fadvise64.c new file mode 100644 index 000..812d4f3 --- /dev/null +++ b/tests/fadvise64.c @@ -0,0 +1,71 @@ +#include "tests.h" + +#include + +#if defined(__NR_fadvise64) + +# include +# include +# include +# include + +# include "xlat.h" +# include "xlat/advise.h" + +#if __BYTE_ORDER == __LITTLE_ENDIAN +# define __LONG_LONG_PAIR(HI, LO) LO, HI +#elif __BYTE_ORDER == __BIG_ENDIAN +# define __LONG_LONG_PAIR(HI, LO) HI, LO +#endif + +void do_fadvise64(int fd, long long offset, long long len, int advice) +{ + long ret; + +# if (LONG_MAX > INT_MAX) || defined(__x86_64__) && defined(__ILP32__) \ +|| defined(LINUX_MIPSN32) + ret = syscall(__NR_fadvise64, fd, offset, len, advice); + + printf("fadvise64(%d, %lld, %llu, ", fd, offset, len); +# else /* LONG_MAX > INT_MAX */ +# if defined(POWERPC) + ret = syscall(__NR_fadvise64, fd, 0, + __LONG_LONG_PAIR ((long) (offset >> 32), (long) offset), + (long) len, advice); + printf("fadvise64(%d, %lld, %lu, ", fd, offset, (long) len); +# elif defined(LINUX_MIPSO32) + ret = syscall(__NR_fadvise64, fd, 0, + __LONG_LONG_PAIR ((long) (offset >> 32), (long) offset), + __LONG_LONG_PAIR ((long) (len >> 32), (long) len), advice); + printf("fadvise64(%d, %lld, %lld, ", fd, offset, len); +# else + ret = syscall(__NR_fadvise64, fd, + __LONG_LONG_PAIR ((long) (offset >> 32), (long) offset), + (long) len, advice); + printf("fadvise64(%d, %lld, %lu, ", fd, offset, (long) len); +# endif +# endif /* LONG_MAX > INT_MAX */ + printxval(advise, (unsigned) advice, "POSIX_FADV_???"); + printf(") = %s\n", sprintrc(ret)); +} + +int +main(void) +{ + static const int bogus_fd = 0xbeefface; + static const long long bogus_offset = 0xbadc0dedda7a1057LLU; + static const long long bogus_len = (long) 0xbadfaceca7b0d1e5LLU; + static const int bogus_advice = 0xdeadca75; + + do_fadvise64(bogus_fd, bogus_offset, bogus_len, bogus_advice); + + puts("+++ exited with 0 +++"); + + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_fadvise64"); + +#endif diff --git a/tests/fadvise64.test b/tests/fadvise64.test new file mode 100755 index 000..46c5856 --- /dev/null +++ b/tests/fadvise64.test @@ -0,0 +1,6 @@ +#!/bin/sh + +# Check fadvise64 syscall decoding. + +. "${srcdir=.}/init.sh" +run_strace_match_diff -a18 diff --git a/tests/fadvise64_64.c b/tests/fadvise64_64.c new file mode 100644 index 000..35f64a0 --- /dev/null +++ b/tests/fadvise64_64.c @@ -0,0 +1,59 @@ +#include "tests.h" + +#include + +#if defined(__NR_fadvise64_64) || defined(__NR_arm_fadvise64_64) + +# include +# include +# include +# include + +# include "xlat.h" +# include "xlat/advise.h" + +#if __BYTE_ORDER == __LITTLE_ENDIAN +# define __LONG_LONG_PAIR(HI, LO) LO, HI +#elif __BYTE_ORDER == __BIG_ENDIAN +# define __LONG_LONG_PAIR(HI, LO) HI, LO +#endif + +void do_fadvise64_64(int fd, long long offset, long long len, int advice) +{ + long ret; + +# ifdef ARM + ret = syscall(__NR_arm_fadvise64_64, fd, advice, + __LONG_LONG_PAIR ((long) (offset >> 32), (long) offset), + __LONG_LONG_PAIR ((long) (len >> 32), (long)len)); +# else + ret = syscall(__NR_fadvise64_64, fd, + __LONG_LONG_PAIR
[PATCH 04/11] xlat: Add values for falloc_flags constants
In order to avoid dependence of declared constants to headers available on build system. * xlat/falloc_flags.in: Add values for constants. --- xlat/falloc_flags.in | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xlat/falloc_flags.in b/xlat/falloc_flags.in index 936e960..9d8ecf2 100644 --- a/xlat/falloc_flags.in +++ b/xlat/falloc_flags.in @@ -1,6 +1,6 @@ -FALLOC_FL_KEEP_SIZE -FALLOC_FL_PUNCH_HOLE -FALLOC_FL_NO_HIDE_STALE -FALLOC_FL_COLLAPSE_RANGE -FALLOC_FL_ZERO_RANGE -FALLOC_FL_INSERT_RANGE +FALLOC_FL_KEEP_SIZE 0x01 +FALLOC_FL_PUNCH_HOLE 0x02 +FALLOC_FL_NO_HIDE_STALE 0x04 +FALLOC_FL_COLLAPSE_RANGE 0x08 +FALLOC_FL_ZERO_RANGE 0x10 +FALLOC_FL_INSERT_RANGE 0x20 -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH 05/11] fallocate: Change print format of offset and len arguments to signed
Since types of these arguments is off_t and kernel actually expects signed values (in order to fail in case negative values are provided), it is reasonable to display these values as signed as well. * fallocate.c (SYS_FUNC(fallocate)): Change conversion specifier for printing "offset" and "len" syscall arguments from %llu to %lld. --- fallocate.c |4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fallocate.c b/fallocate.c index 0b1cfec..b707279 100644 --- a/fallocate.c +++ b/fallocate.c @@ -19,10 +19,10 @@ SYS_FUNC(fallocate) tprints(", "); /* offset */ - argn = printllval(tcp, "%llu, ", 2); + argn = printllval(tcp, "%lld, ", 2); /* len */ - printllval(tcp, "%llu", argn); + printllval(tcp, "%lld", argn); return RVAL_DECODED; } -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH 10/11] tests: Add test for decoding fallocate syscall
* tests/.gitignore: Add fallocate. * tests/Makefile.am (check_PROGRAMS): Likewise. (DECODER_TESTS): Add fallocate.test. * fallocate.c: New file. * fallocate.test: Likewise. --- configure.ac |1 + tests/.gitignore |1 + tests/Makefile.am|2 ++ tests/fallocate.c| 38 ++ tests/fallocate.test |6 ++ 5 files changed, 48 insertions(+) create mode 100644 tests/fallocate.c create mode 100755 tests/fallocate.test diff --git a/configure.ac b/configure.ac index 5c924e7..404dfb9 100644 --- a/configure.ac +++ b/configure.ac @@ -281,6 +281,7 @@ AC_TYPE_UID_T AC_CHECK_FUNCS(m4_normalize([ accept4 + fallocate fanotify_mark fopen64 fork diff --git a/tests/.gitignore b/tests/.gitignore index bdb2d9a..c3665c2 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -44,6 +44,7 @@ execve-v execveat execveat-v faccessat +fallocate fanotify_mark fchdir fchmod diff --git a/tests/Makefile.am b/tests/Makefile.am index ac579c7..4fdc877 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -103,6 +103,7 @@ check_PROGRAMS = \ execveat \ execveat-v \ faccessat \ + fallocate \ fanotify_mark \ fchdir \ fchmod \ @@ -442,6 +443,7 @@ DECODER_TESTS = \ execveat-v.test \ execveat.test \ faccessat.test \ + fallocate.test \ fanotify_mark.test \ fchdir.test \ fchmod.test \ diff --git a/tests/fallocate.c b/tests/fallocate.c new file mode 100644 index 000..563f2ec --- /dev/null +++ b/tests/fallocate.c @@ -0,0 +1,38 @@ +#include "tests.h" + +#include + +#if defined(__NR_fallocate) && defined(HAVE_FALLOCATE) && HAVE_FALLOCATE + +# include +# include + +# include "xlat.h" +# include "xlat/falloc_flags.h" + +int +main(void) +{ + static const int bogus_fd = 0xbeefface; + static const int bogus_mode = 0xdeadca75; + static const off_t bogus_offset = (off_t) 0xbadc0dedda7a1057LLU; + static const off_t bogus_len = (off_t) 0xbadfaceca7b0d1e5LLU; + + long rc; + + rc = fallocate(bogus_fd, bogus_mode, bogus_offset, bogus_len); + printf("fallocate(%d, ", bogus_fd); + printflags(falloc_flags, (unsigned) bogus_mode, "FALLOC_FL_???"); + printf(", %lld, %lld) = %s\n", + (long long) bogus_offset, (long long) bogus_len, sprintrc(rc)); + + puts("+++ exited with 0 +++"); + + return 0; +} + +#else + +SKIP_MAIN_UNDEFINED("__NR_fallocate && HAVE_FALLOCATE"); + +#endif diff --git a/tests/fallocate.test b/tests/fallocate.test new file mode 100755 index 000..405187e --- /dev/null +++ b/tests/fallocate.test @@ -0,0 +1,6 @@ +#!/bin/sh + +# Check getcwd syscall decoding. + +. "${srcdir=.}/init.sh" +run_strace_match_diff -a18 -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH 07/11] util: Add getarg_ull/getarg_ll functions
These allow retrieving specific argument in full taking into account peculiarities of runtimes which employ EXT_ARG (x32, for example). * defs.h: Add declarations of getarg_ull, getarg_ll. * util.c (getarg_ull): New function. (getarg_ll): Likewise. (printargs): Use getarg_ull for argument retrieval. --- defs.h |2 ++ util.c | 44 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/defs.h b/defs.h index 26dbf8e..593e316 100644 --- a/defs.h +++ b/defs.h @@ -546,6 +546,8 @@ extern int printllval(struct tcb *, const char *, int) extern void printaddr(long); extern void printxvals(const uint64_t, const char *, const struct xlat *, ...) ATTRIBUTE_SENTINEL; +extern unsigned long long getarg_ull(struct tcb *tcp, int argn); +extern long long getarg_ll(struct tcb *tcp, int argn); extern int printargs(struct tcb *); extern int printargs_u(struct tcb *); extern int printargs_d(struct tcb *); diff --git a/util.c b/util.c index 056711d..b17ab29 100644 --- a/util.c +++ b/util.c @@ -1413,24 +1413,44 @@ print_array(struct tcb *tcp, return cur >= end_addr; } -int -printargs(struct tcb *tcp) +unsigned long long +getarg_ull(struct tcb *tcp, int argn) { - if (entering(tcp)) { - int i; - int n = tcp->s_ent->nargs; - for (i = 0; i < n; i++) { #if HAVE_STRUCT_TCB_EXT_ARG # if SUPPORTED_PERSONALITIES > 1 - if (current_personality == 1) - tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]); - else + if (current_personality == 1) + return (unsigned long) tcp->u_arg[argn]; + else # endif - tprintf("%s%#llx", i ? ", " : "", tcp->ext_arg[i]); + return (unsigned long long) tcp->ext_arg[argn]; #else - tprintf("%s%#lx", i ? ", " : "", tcp->u_arg[i]); + return (unsigned long) tcp->u_arg[argn]; #endif - } +} + +long long +getarg_ll(struct tcb *tcp, int argn) +{ +#if HAVE_STRUCT_TCB_EXT_ARG +# if SUPPORTED_PERSONALITIES > 1 + if (current_personality == 1) + return (long) tcp->u_arg[argn]; + else +# endif + return (long long) tcp->ext_arg[argn]; +#else + return (long) tcp->u_arg[argn]; +#endif +} + +int +printargs(struct tcb *tcp) +{ + if (entering(tcp)) { + int i; + int n = tcp->s_ent->nargs; + for (i = 0; i < n; i++) + tprintf("%s%#llx", i ? ", " : "", getarg_ull(tcp, i)); } return 0; } -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH 08/11] fadvise: Use getarg_ull for obtaining len argument of fadvise64 syscall
Since it is size_t, it is 64-bit wide on x32 and special care should be made in order to obtain it. * fadvise.c (SYS_FUNC(fadvise64)): Use getarg_ull for obtaining value of the "len" syscall argument. --- fadvise.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fadvise.c b/fadvise.c index 208f533..34933f7 100644 --- a/fadvise.c +++ b/fadvise.c @@ -42,7 +42,7 @@ SYS_FUNC(fadvise64) printfd(tcp, tcp->u_arg[0]); argn = printllval(tcp, ", %lld", 1); - tprintf(", %lu, ", tcp->u_arg[argn++]); + tprintf(", %llu, ", getarg_ull(tcp, argn++)); printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???"); return RVAL_DECODED; -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH 06/11] fadvise: Change printing of len argument to unsigned in fadvise64 syscall
long sys_fadvise64(int fd, loff_t offset, size_t len, int advice); * fadvise.c (SYS_FUNC(fadvise64)): change conversion specifier from "%ld" to "%lu" for printing len argument since kernel expects argument of type size_t. --- fadvise.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fadvise.c b/fadvise.c index 2001394..208f533 100644 --- a/fadvise.c +++ b/fadvise.c @@ -42,7 +42,7 @@ SYS_FUNC(fadvise64) printfd(tcp, tcp->u_arg[0]); argn = printllval(tcp, ", %lld", 1); - tprintf(", %ld, ", tcp->u_arg[argn++]); + tprintf(", %lu, ", tcp->u_arg[argn++]); printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???"); return RVAL_DECODED; -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel