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 9fdbe4d..61ff149 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -6,6 +6,8 @@
 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 930f6d9..b8475ac 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,8 @@
 	ipc_msg \
 	ipc_sem \
 	ipc_shm \
+	mmap \
+	mmap64 \
 	mmsg \
 	net-accept-connect \
 	netlink_inet_diag \
@@ -36,6 +38,7 @@
 	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 @@
 	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 0000000..d4d3e66
--- /dev/null
+++ b/tests/mmap.c
@@ -0,0 +1,46 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sys/mman.h>
+
+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 0000000..e9c9b3a
--- /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 0000000..b31ce42
--- /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 0000000..51f1896
--- /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"