From: Dmitry V. Levin Date: Thu, 19 Mar 2015 22:03:32 +0000 (+0000) Subject: tests: add a test for mmap/mprotect/munmap decoding X-Git-Tag: v4.11~562 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7d671bd4a6345b41071633e79de17a6f3b88fde;p=strace tests: add a test for mmap/mprotect/munmap decoding * tests/mmap.c: New file. * tests/mmap64.c: New file. * tests/mmap.test: New test. * tests/mmap64.test: New test. * tests/Makefile.am (check_PROGRAMS): Add mmap and mmap64. (mmap64_CFLAGS): Define. (TESTS): Add mmap.test and mmap64.test. * tests/.gitignore: Add mmap and mmap64. --- diff --git a/tests/.gitignore b/tests/.gitignore index 9fdbe4d8..61ff1498 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -6,6 +6,8 @@ ioctl ipc_msg ipc_sem ipc_shm +mmap +mmap64 mmsg net-accept-connect netlink_inet_diag diff --git a/tests/Makefile.am b/tests/Makefile.am index 930f6d95..b8475acc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -15,6 +15,8 @@ check_PROGRAMS = \ ipc_msg \ ipc_sem \ ipc_shm \ + mmap \ + mmap64 \ mmsg \ net-accept-connect \ netlink_inet_diag \ @@ -36,6 +38,7 @@ check_PROGRAMS = \ uio \ unix-pair-send-recv +mmap64_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64 pc_LDADD = $(dl_LIBS) stat_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64 statfs_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64 @@ -65,6 +68,8 @@ TESTS = \ stat32-v.test \ stat64-v.test \ statfs.test \ + mmap.test \ + mmap64.test \ mmsg.test \ net.test \ net-fd.test \ diff --git a/tests/mmap.c b/tests/mmap.c new file mode 100644 index 00000000..d4d3e664 --- /dev/null +++ b/tests/mmap.c @@ -0,0 +1,46 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include + +int +main(void) +{ + const intmax_t pagesize = sysconf(_SC_PAGESIZE); + const unsigned long length = pagesize * 3; + const int fd = -1; + off_t offset; + void *addr, *p; + +#if ULONG_MAX > 4294967295UL + offset = 0xcafedeadbeef000 & -pagesize; + addr = (void *) (uintmax_t) (0xfacefeed000 & -pagesize); +#else + offset = 0xdeadbeef000 & -pagesize; + addr = (void *) (unsigned int) (0xfaced000 & -pagesize); +#endif + + p = mmap(addr, length, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, fd, offset); + if (p == MAP_FAILED || + mprotect(p, length, PROT_NONE) || + munmap(p, length)) + return 77; + + if (sizeof(offset) == sizeof(int)) + printf("(mmap2?|old_mmap)\\(%p, %lu, PROT_READ\\|PROT_WRITE, " + "MAP_PRIVATE\\|MAP_ANONYMOUS, %d, %#x\\) = %p\n", + addr, length, fd, (unsigned int) offset, p); + else + printf("(mmap2?|old_mmap)\\(%p, %lu, PROT_READ\\|PROT_WRITE, " + "MAP_PRIVATE\\|MAP_ANONYMOUS, %d, %#jx\\) = %p\n", + addr, length, fd, (uintmax_t) offset, p); + printf("mprotect\\(%p, %lu, PROT_NONE\\) += 0\n", p, length); + printf("munmap\\(%p, %lu\\) += 0\n", p, length); + return 0; +} diff --git a/tests/mmap.test b/tests/mmap.test new file mode 100755 index 00000000..e9c9b3ab --- /dev/null +++ b/tests/mmap.test @@ -0,0 +1,20 @@ +#!/bin/sh + +# Check mmap/mprotect/munmap syscalls decoding. + +. "${srcdir=.}/init.sh" + +syscall=mprotect,munmap +for n in mmap mmap2 old_mmap; do + $STRACE -e$n -h > /dev/null && syscall=$syscall,$n +done + +OUT="$LOG.out" + +run_prog > /dev/null +run_strace -e$syscall $args > "$OUT" +match_grep "$LOG" "$OUT" + +rm -f "$OUT" + +exit 0 diff --git a/tests/mmap64.c b/tests/mmap64.c new file mode 100644 index 00000000..b31ce427 --- /dev/null +++ b/tests/mmap64.c @@ -0,0 +1 @@ +#include "mmap.c" diff --git a/tests/mmap64.test b/tests/mmap64.test new file mode 100755 index 00000000..51f1896e --- /dev/null +++ b/tests/mmap64.test @@ -0,0 +1,6 @@ +#!/bin/sh + +# Check mmap/mprotect/munmap syscalls decoding. +# Target executable was compiled with -D_FILE_OFFSET_BITS=64. + +. "${srcdir=.}/mmap.test"