Clean up mmap decoding
Previous code merges too many similar, but different ways
of decoding mmap. For example, sys_old_mmap is "params in memory"
API... except SH[64], where it is "params in regs",
i.e. what sys_mmap ("new mmap") function does on other arches!
It's much simpler when every mmap handler has same API regardless
of arch. Where API means whether params are in regs or in memory,
and whether offset is in bytes, pages, or 4k blocks.
Then we just insert correct function pointers into
arch syscall tables.
It turns out there are four common mmap APIs over
all architectures which exist in Linux kernel,
and one outlier for S390.
A number of mmap decoders were plain wrong in arch tables.
For example, BFIN has no old_mmap. It returns ENOSYS.
I checked kernel sources for all arches nad fixed the tables.
There was dead code for x86_64 for old_mmap:
x86_64 has no old_mmap.
* mem.c: Refactor mmap functions so that we have five mmap syscall
handlers, each with the fixed API (not varying by arch).
* pathtrace.c (pathtrace_match): Adjust sys_func == mmap_func checks.
* linux/syscall.h: Declare new mmap syscall handler functions.
* linux/arm/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/avr32/syscallent.h: mmap is sys_mmap_pgoff.
* linux/bfin/syscallent.h: old_mmap is ENOSYS, mmap2 is sys_mmap_pgoff.
* linux/hppa/syscallent.h: mmap2 is sys_mmap_4koff.
* linux/i386/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/ia64/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/m68k/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/microblaze/syscallent.h: old_mmap is sys_mmap, mmap2 is sys_mmap_pgoff.
* linux/mips/syscallent.h: mmap is sys_mmap_4kgoff.
* linux/or1k/syscallent.h: mmap2 is sys_mmap_pgoff.
* linux/powerpc/syscallent.h: mmap2 is sys_mmap_4kgoff.
* linux/s390/syscallent.h: mmap2 is sys_old_mmap_pgoff.
* linux/s390x/syscallent.h: mmap is sys_old_mmap and thus has 1 arg.
* linux/sh/syscallent.h: old_mmap2 is sys_mmap, mmap2 is sys_mmap_4koff.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent1.h: mmap is TD|TM.
* linux/tile/syscallent1.h: mmap2 is sys_mmap_4koff.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/linux/arm/syscallent.h b/linux/arm/syscallent.h
index 123b910..e3de1f5 100644
--- a/linux/arm/syscallent.h
+++ b/linux/arm/syscallent.h
@@ -116,7 +116,7 @@
{ 2, TF, sys_swapon, "swapon" }, /* 87 */
{ 4, 0, sys_reboot, "reboot" }, /* 88 */
{ 3, 0, sys_readdir, "readdir" }, /* 89 */
- { 6, TD|TM, sys_old_mmap, "old_mmap" }, /* 90 */
+ { 1, TD|TM, sys_old_mmap, "old_mmap" }, /* 90 */
{ 2, TM, sys_munmap, "munmap" }, /* 91 */
{ 2, TF, sys_truncate, "truncate" }, /* 92 */
{ 2, 0, sys_ftruncate, "ftruncate" }, /* 93 */
@@ -219,7 +219,7 @@
{ 5, 0, sys_putpmsg, "putpmsg" }, /* 189 */
{ 0, TP, sys_vfork, "vfork" }, /* 190 */
{ 2, 0, sys_getrlimit, "getrlimit" }, /* 191 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 192 */
+ { 6, TD|TM, sys_mmap_pgoff, "mmap2" }, /* 192 */
{ 4, TF, sys_truncate64, "truncate64" }, /* 193 */
{ 4, TF, sys_ftruncate64, "ftruncate64" }, /* 194 */
{ 2, TF, sys_stat64, "stat64" }, /* 195 */
diff --git a/linux/avr32/syscallent.h b/linux/avr32/syscallent.h
index b215cc1..af8b524 100644
--- a/linux/avr32/syscallent.h
+++ b/linux/avr32/syscallent.h
@@ -115,7 +115,7 @@
{ 5, TD, sys_pwrite, "pwrite" }, /* 87 */
{ 2, TF, sys_swapon, "swapon" }, /* 88 */
{ 4, 0, sys_reboot, "reboot" }, /* 89 */
- { 6, TD|TM, sys_mmap, "mmap" }, /* 90 */
+ { 6, TD|TM, sys_mmap_pgoff, "mmap" }, /* 90 */
{ 2, TM, sys_munmap, "munmap" }, /* 91 */
{ 2, TF, sys_truncate, "truncate" }, /* 92 */
{ 2, TD, sys_ftruncate, "ftruncate" }, /* 93 */
diff --git a/linux/bfin/syscallent.h b/linux/bfin/syscallent.h
index 05194fb..be8f532 100644
--- a/linux/bfin/syscallent.h
+++ b/linux/bfin/syscallent.h
@@ -116,7 +116,7 @@
{ 2, TF, sys_swapon, "swapon" }, /* 87 */
{ 4, 0, sys_reboot, "reboot" }, /* 88 */
{ 3, TD, sys_readdir, "readdir" }, /* 89 */
- { 6, TD|TM, sys_old_mmap, "old_mmap" }, /* 90 */
+ { 6, TD|TM, printargs, "old_mmap" }, /* 90: not implemented in kernel */
{ 2, TM, sys_munmap, "munmap" }, /* 91 */
{ 2, TF, sys_truncate, "truncate" }, /* 92 */
{ 2, TD, sys_ftruncate, "ftruncate" }, /* 93 */
@@ -218,7 +218,7 @@
{ 5, 0, sys_putpmsg, "putpmsg" }, /* 189 */
{ 0, TP, sys_vfork, "vfork" }, /* 190 */
{ 2, 0, sys_getrlimit, "getrlimit" }, /* 191 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 192 */
+ { 6, TD|TM, sys_mmap_pgoff, "mmap2" }, /* 192 */
{ 3, TF, sys_truncate64, "truncate64" }, /* 193 */
{ 3, TD, sys_ftruncate64, "ftruncate64" }, /* 194 */
{ 2, TF, sys_stat64, "stat64" }, /* 195 */
diff --git a/linux/hppa/syscallent.h b/linux/hppa/syscallent.h
index dc12299..fafdfd2 100644
--- a/linux/hppa/syscallent.h
+++ b/linux/hppa/syscallent.h
@@ -91,7 +91,7 @@
{ 1, 0, sys_uselib, "uselib" }, /* 86 */
{ 2, TF, sys_swapon, "swapon" }, /* 87 */
{ 4, 0, sys_reboot, "reboot" }, /* 88 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 89 */
+ { 6, TD|TM, sys_mmap_4koff, "mmap2" }, /* 89 */
{ 6, TD|TM, sys_mmap, "mmap" }, /* 90 */
{ 2, TM, sys_munmap, "munmap" }, /* 91 */
{ 2, TF, sys_truncate, "truncate" }, /* 92 */
diff --git a/linux/i386/syscallent.h b/linux/i386/syscallent.h
index ee61933..3d1e738 100644
--- a/linux/i386/syscallent.h
+++ b/linux/i386/syscallent.h
@@ -219,7 +219,7 @@
{ 5, 0, sys_putpmsg, "putpmsg" }, /* 189 */
{ 0, TP, sys_vfork, "vfork" }, /* 190 */
{ 2, 0, sys_getrlimit, "getrlimit" }, /* 191 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 192 */
+ { 6, TD|TM, sys_mmap_pgoff, "mmap2" }, /* 192 */
{ 3, TF, sys_truncate64, "truncate64" }, /* 193 */
{ 3, TD, sys_ftruncate64, "ftruncate64" }, /* 194 */
{ 2, TF, sys_stat64, "stat64" }, /* 195 */
diff --git a/linux/ia64/syscallent.h b/linux/ia64/syscallent.h
index 8e130ad..6e74968 100644
--- a/linux/ia64/syscallent.h
+++ b/linux/ia64/syscallent.h
@@ -960,7 +960,7 @@
{ 3, 0, sys_nfsservctl, "nfsservctl" }, /* 1169 */
{ 5, 0, sys_prctl, "prctl" }, /* 1170 */
{ 1, 0, sys_getpagesize, "getpagesize" }, /* 1171 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 1172 */
+ { 6, TD|TM, sys_mmap_pgoff, "mmap2" }, /* 1172 */
{ 5, 0, printargs, "pciconfig_read"}, /* 1173 */
{ 5, 0, printargs, "pciconfig_write"}, /* 1174 */
{ MA, 0, printargs, "perfmonctl" }, /* 1175 */
diff --git a/linux/m68k/syscallent.h b/linux/m68k/syscallent.h
index 184f01c..165109b 100644
--- a/linux/m68k/syscallent.h
+++ b/linux/m68k/syscallent.h
@@ -116,7 +116,7 @@
{ 2, TF, sys_swapon, "swapon" }, /* 87 */
{ 4, 0, sys_reboot, "reboot" }, /* 88 */
{ 3, 0, sys_readdir, "readdir" }, /* 89 */
- { 6, TD|TM, sys_old_mmap, "old_mmap" }, /* 90 */
+ { 1, TD|TM, sys_old_mmap, "old_mmap" }, /* 90 */
{ 2, TM, sys_munmap, "munmap" }, /* 91 */
{ 2, TF, sys_truncate, "truncate" }, /* 92 */
{ 2, 0, sys_ftruncate, "ftruncate" }, /* 93 */
@@ -218,7 +218,7 @@
{ 5, 0, sys_putpmsg, "putpmsg" }, /* 189 */
{ 0, TP, sys_vfork, "vfork" }, /* 190 */
{ 2, 0, sys_getrlimit, "getrlimit" }, /* 191 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 192 */
+ { 6, TD|TM, sys_mmap_pgoff, "mmap2" }, /* 192 */
{ 3, TF, sys_truncate64, "truncate64" }, /* 193 */
{ 3, TF, sys_ftruncate64, "ftruncate64" }, /* 194 */
{ 2, TF, sys_stat64, "stat64" }, /* 195 */
diff --git a/linux/microblaze/syscallent.h b/linux/microblaze/syscallent.h
index c5a52fa..0c8fbbd 100644
--- a/linux/microblaze/syscallent.h
+++ b/linux/microblaze/syscallent.h
@@ -116,7 +116,7 @@
{ 2, TF, sys_swapon, "swapon" }, /* 87 */
{ 4, 0, sys_reboot, "reboot" }, /* 88 */
{ 3, 0, sys_readdir, "readdir" }, /* 89 */
- { 6, TD|TM, sys_old_mmap, "old_mmap" }, /* 90 */
+ { 6, TD|TM, sys_mmap, "old_mmap" }, /* 90 */
{ 2, TM, sys_munmap, "munmap" }, /* 91 */
{ 2, TF, sys_truncate, "truncate" }, /* 92 */
{ 2, 0, sys_ftruncate, "ftruncate" }, /* 93 */
@@ -218,7 +218,7 @@
{ 5, 0, sys_putpmsg, "putpmsg" }, /* 189 */
{ 0, TP, sys_vfork, "vfork" }, /* 190 */
{ 2, 0, sys_getrlimit, "getrlimit" }, /* 191 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 192 */
+ { 6, TD|TM, sys_mmap_pgoff, "mmap2" }, /* 192 */
{ 3, TF, sys_truncate64, "truncate64" }, /* 193 */
{ 3, TF, sys_ftruncate64, "ftruncate64" }, /* 194 */
{ 2, TF, sys_stat64, "stat64" }, /* 195 */
diff --git a/linux/mips/syscallent.h b/linux/mips/syscallent.h
index 91efeb2..085c0e2 100644
--- a/linux/mips/syscallent.h
+++ b/linux/mips/syscallent.h
@@ -115,7 +115,7 @@
{ 0, 0, printargs, "svr4_priocntlset" }, /* 0112 */
{ 0, 0, printargs, "svr4_pathconf" }, /* 0113 */
{ 0, TM, printargs, "svr4_mincore" }, /* 0114 */
- { 0, TM, printargs, "svr4_mmap" }, /* 0115 */
+ { 0, TD|TM, printargs, "svr4_mmap" }, /* 0115 */
{ 0, TM, printargs, "svr4_mprotect" }, /* 0116 */
{ 0, TM, printargs, "svr4_munmap" }, /* 0117 */
{ 0, 0, printargs, "svr4_fpathconf" }, /* 0118 */
@@ -346,7 +346,7 @@
{ 0, 0, printargs, "sysv_procblk" }, /* 1131 */
{ 0, 0, printargs, "sysv_sprocsp" }, /* 1132 */
{ 0, 0, printargs, "sysv_sgigsc" }, /* 1133 */
- { 0, TM, printargs, "sysv_mmap" }, /* 1134 */
+ { 0, TD|TM, printargs, "sysv_mmap" }, /* 1134 */
{ 0, TM, printargs, "sysv_munmap" }, /* 1135 */
{ 0, TM, printargs, "sysv_mprotect" }, /* 1136 */
{ 0, TM, printargs, "sysv_msync" }, /* 1137 */
@@ -397,7 +397,7 @@
{ 0, 0, printargs, "sysv_writev" }, /* 1182 */
{ 0, 0, printargs, "sysv_truncate64" }, /* 1183 */
{ 0, 0, printargs, "sysv_ftruncate64" }, /* 1184 */
- { 0, TM, printargs, "sysv_mmap64" }, /* 1185 */
+ { 0, TD|TM, printargs, "sysv_mmap64" }, /* 1185 */
{ 0, 0, printargs, "sysv_dmi" }, /* 1186 */
{ 0, 0, printargs, "sysv_pread" }, /* 1187 */
{ 0, 0, printargs, "sysv_pwrite" }, /* 1188 */
@@ -475,7 +475,7 @@
{ 0, 0, printargs, "bsd43_vwrite" }, /* 2068 */
{ 0, TM, printargs, "bsd43_sbrk" }, /* 2069 */
{ 0, 0, printargs, "bsd43_sstk" }, /* 2070 */
- { 0, TM, printargs, "bsd43_mmap" }, /* 2071 */
+ { 0, TD|TM, printargs, "bsd43_mmap" }, /* 2071 */
{ 0, 0, printargs, "bsd43_vadvise" }, /* 2072 */
{ 0, TM, printargs, "bsd43_munmap" }, /* 2073 */
{ 0, TM, printargs, "bsd43_mprotect" }, /* 2074 */
@@ -733,7 +733,7 @@
{ 0, 0, printargs, "posix_SGI_blkproc" }, /* 3131 */
{ 0, 0, NULL, NULL }, /* 3132 */
{ 0, 0, printargs, "posix_SGI_sgigsc" }, /* 3133 */
- { 0, TM, printargs, "posix_SGI_mmap" }, /* 3134 */
+ { 0, TD|TM, printargs, "posix_SGI_mmap" }, /* 3134 */
{ 0, TM, printargs, "posix_SGI_munmap" }, /* 3135 */
{ 0, TM, printargs, "posix_SGI_mprotect" }, /* 3136 */
{ 0, TM, printargs, "posix_SGI_msync" }, /* 3137 */
@@ -754,7 +754,7 @@
{ 0, 0, printargs, "posix_fchown" }, /* 3152 */
{ 0, 0, printargs, "posix_fchmod" }, /* 3153 */
{ 0, 0, printargs, "posix_wait3" }, /* 3154 */
- { 0, TM, printargs, "posix_mmap" }, /* 3155 */
+ { 0, TD|TM, printargs, "posix_mmap" }, /* 3155 */
{ 0, TM, printargs, "posix_munmap" }, /* 3156 */
{ 0, TM, printargs, "posix_madvise" }, /* 3157 */
{ 0, 0, printargs, "posix_BSD_getpagesize" }, /* 3158 */
@@ -1083,7 +1083,7 @@
{ 4, TD|TN, sys_sendfile, "sendfile" }, /* 4207 */
{ 0, 0, NULL, NULL }, /* 4208 */
{ 0, 0, NULL, NULL }, /* 4209 */
- { 6, TD|TM, sys_mmap, "mmap" }, /* 4210 */
+ { 6, TD|TM, sys_mmap_4koff, "mmap" }, /* 4210 */
{ 4, TF, sys_truncate64, "truncate64" }, /* 4211 */
{ 4, TD, sys_ftruncate64, "ftruncate64" }, /* 4212 */
{ 2, TF, sys_stat64, "stat64" }, /* 4213 */
@@ -1311,7 +1311,7 @@
{ 0, 0, printargs, "o32_swapon" }, /* 4087 */
{ 0, 0, printargs, "o32_reboot" }, /* 4088 */
{ 0, 0, printargs, "o32_readdir" }, /* 4089 */
- { 0, TM, printargs, "o32_old_mmap" }, /* 4090 */
+ { 0, TD|TM, printargs, "o32_old_mmap" }, /* 4090 */
{ 0, TM, printargs, "o32_munmap" }, /* 4091 */
{ 0, 0, printargs, "o32_truncate" }, /* 4092 */
{ 0, 0, printargs, "o32_ftruncate" }, /* 4093 */
@@ -1431,7 +1431,7 @@
{ 0, 0, printargs, "o32_sendfile" }, /* 4207 */
{ 0, 0, NULL, NULL }, /* 4208 */
{ 0, 0, NULL, NULL }, /* 4209 */
- { 0, TM, printargs, "o32_mmap" }, /* 4210 */
+ { 0, TD|TM, printargs, "o32_mmap" }, /* 4210 */
{ 0, 0, printargs, "o32_truncate64" }, /* 4211 */
{ 0, 0, printargs, "o32_ftruncate64" }, /* 4212 */
{ 0, 0, printargs, "o32_stat64" }, /* 4213 */
@@ -1890,7 +1890,7 @@
{ 0, 0, printargs, "n64_lstat" }, /* 5006 */
{ 0, 0, printargs, "n64_poll" }, /* 5007 */
{ 0, 0, printargs, "n64_lseek" }, /* 5008 */
- { 0, TM, printargs, "n64_mmap" }, /* 5009 */
+ { 0, TD|TM, printargs, "n64_mmap" }, /* 5009 */
{ 0, TM, printargs, "n64_mprotect" }, /* 5010 */
{ 0, TM, printargs, "n64_munmap" }, /* 5011 */
{ 0, TM, printargs, "n64_brk" }, /* 5012 */
@@ -2514,7 +2514,7 @@
{ 0, 0, printargs, "n32_lstat" }, /* 6006 */
{ 0, 0, printargs, "n32_poll" }, /* 6007 */
{ 0, 0, printargs, "n32_lseek" }, /* 6008 */
- { 0, TM, printargs, "n32_mmap" }, /* 6009 */
+ { 0, TD|TM, printargs, "n32_mmap" }, /* 6009 */
{ 0, TM, printargs, "n32_mprotect" }, /* 6010 */
{ 0, TM, printargs, "n32_munmap" }, /* 6011 */
{ 0, TM, printargs, "n32_brk" }, /* 6012 */
diff --git a/linux/or1k/syscallent.h b/linux/or1k/syscallent.h
index 24f5036..3e7613f 100644
--- a/linux/or1k/syscallent.h
+++ b/linux/or1k/syscallent.h
@@ -220,7 +220,7 @@
{ 5, 0, sys_keyctl, "keyctl" }, /* 219 */
{ 5, TP, sys_clone, "clone" }, /* 220 */
{ 3, TF|TP, sys_execve, "execve" }, /* 221 */
- { 6, TD, sys_mmap, "mmap2" }, /* 222 */
+ { 6, TD|TM, sys_mmap_pgoff, "mmap2" }, /* 222 */
{ 6, TD, sys_fadvise64_64, "fadvise64_64" }, /* 223 */
{ 2, TF, sys_swapon, "swapon" }, /* 224 */
{ 1, TF, sys_swapoff, "swapoff" }, /* 225 */
diff --git a/linux/powerpc/syscallent.h b/linux/powerpc/syscallent.h
index e61946e..8cb9179 100644
--- a/linux/powerpc/syscallent.h
+++ b/linux/powerpc/syscallent.h
@@ -218,7 +218,7 @@
{ 0, TP, sys_vfork, "vfork" }, /* 189 */
{ 2, 0, sys_getrlimit, "getrlimit" }, /* 190 */
{ 5, TD, sys_readahead, "readahead" }, /* 190 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 192 */
+ { 6, TD|TM, sys_mmap_4koff, "mmap2" }, /* 192 */
{ 4, TF, sys_truncate64, "truncate64" }, /* 193 */
{ 4, TD, sys_ftruncate64, "ftruncate64" }, /* 194 */
{ 2, TF, sys_stat64, "stat64" }, /* 195 */
diff --git a/linux/s390/syscallent.h b/linux/s390/syscallent.h
index 94f4d25..709267b 100644
--- a/linux/s390/syscallent.h
+++ b/linux/s390/syscallent.h
@@ -220,7 +220,7 @@
{ 5, 0, sys_putpmsg, "putpmsg" }, /* 189 */
{ 0, TP, sys_vfork, "vfork" }, /* 190 */
{ 2, 0, sys_getrlimit, "getrlimit" }, /* 191 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 192 */
+ { 1, TD|TM, sys_old_mmap_pgoff, "mmap2" }, /* 192 */
{ 2, TF, sys_truncate64, "truncate64" }, /* 193 */
{ 2, TD, sys_ftruncate64, "ftruncate64" }, /* 194 */
{ 2, TF, sys_stat64, "stat64" }, /* 195 */
diff --git a/linux/s390x/syscallent.h b/linux/s390x/syscallent.h
index ebf35d4..32b75d9 100644
--- a/linux/s390x/syscallent.h
+++ b/linux/s390x/syscallent.h
@@ -117,7 +117,7 @@
{ 2, TF, sys_swapon, "swapon" }, /* 87 */
{ 4, 0, sys_reboot, "reboot" }, /* 88 */
{ MA, 0, NULL, NULL }, /* 89 */
- { 6, TD|TM, sys_old_mmap, "mmap" }, /* 90 */
+ { 1, TD|TM, sys_old_mmap, "mmap" }, /* 90 */
{ 2, TM, sys_munmap, "munmap" }, /* 91 */
{ 2, TF, sys_truncate, "truncate" }, /* 92 */
{ 2, TD, sys_ftruncate, "ftruncate" }, /* 93 */
diff --git a/linux/sh/syscallent.h b/linux/sh/syscallent.h
index 1546ff6..b647046 100644
--- a/linux/sh/syscallent.h
+++ b/linux/sh/syscallent.h
@@ -118,7 +118,7 @@
{ 2, TF, sys_swapon, "swapon" }, /* 87 */
{ 4, 0, sys_reboot, "reboot" }, /* 88 */
{ 3, TD, sys_readdir, "readdir" }, /* 89 */
- { 6, TD|TM, sys_old_mmap, "old_mmap" }, /* 90 */
+ { 6, TD|TM, sys_mmap, "old_mmap" }, /* 90 */
{ 2, TM, sys_munmap, "munmap" }, /* 91 */
{ 2, TF, sys_truncate, "truncate" }, /* 92 */
{ 2, TD, sys_ftruncate, "ftruncate" }, /* 93 */
@@ -221,7 +221,7 @@
{ 5, 0, NULL, NULL }, /* 189 */
{ 0, TP, sys_vfork, "vfork" }, /* 190 */
{ 5, 0, printargs, "getrlimit" }, /* 191 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 192 */
+ { 6, TD|TM, sys_mmap_4koff, "mmap2" }, /* 192 */
{ 5, 0, sys_truncate64, "truncate64" }, /* 193 */
{ 5, TD, sys_ftruncate64, "ftruncate64" }, /* 194 */
{ 2, TF, sys_stat64, "stat64" }, /* 195 */
diff --git a/linux/sh64/syscallent.h b/linux/sh64/syscallent.h
index 4e20c47..0591f07 100644
--- a/linux/sh64/syscallent.h
+++ b/linux/sh64/syscallent.h
@@ -116,7 +116,7 @@
{ 2, TF, sys_swapon, "swapon" }, /* 87 */
{ 4, 0, sys_reboot, "reboot" }, /* 88 */
{ 3, TD, sys_readdir, "readdir" }, /* 89 */
- { 6, TD|TM, sys_old_mmap, "old_mmap" }, /* 90 */
+ { 6, TD|TM, sys_mmap, "old_mmap" }, /* 90 */
{ 2, TM, sys_munmap, "munmap" }, /* 91 */
{ 2, TF, sys_truncate, "truncate" }, /* 92 */
{ 2, TD, sys_ftruncate, "ftruncate" }, /* 93 */
@@ -218,7 +218,7 @@
{ 5, 0, NULL, NULL }, /* 189 */
{ 0, TP, sys_vfork, "vfork" }, /* 190 */
{ 2, 0, printargs, "getrlimit" }, /* 191 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 192 */
+ { 6, TD|TM, sys_mmap_4koff, "mmap2" }, /* 192 */
{ 2, TF, sys_truncate64, "truncate64" }, /* 193 */
{ 2, TD, sys_ftruncate64, "ftruncate64" }, /* 194 */
{ 2, TF, sys_stat64, "stat64" }, /* 195 */
diff --git a/linux/sparc/syscallent1.h b/linux/sparc/syscallent1.h
index 5e9fe96..9519e08 100644
--- a/linux/sparc/syscallent1.h
+++ b/linux/sparc/syscallent1.h
@@ -140,7 +140,7 @@
{ 6, 0, solaris_priocntlsys, "priocntlsys" }, /* 112 */
{ 6, TF, solaris_pathconf, "pathconf" }, /* 113 */
{ 6, 0, solaris_mincore, "mincore" }, /* 114 */
- { 6, TD, solaris_mmap, "mmap" }, /* 115 */
+ { 6, TD|TM, solaris_mmap, "mmap" }, /* 115 */
{ 6, 0, solaris_mprotect, "mprotect" }, /* 116 */
{ 6, 0, solaris_munmap, "munmap" }, /* 117 */
{ 6, 0, solaris_fpathconf, "fpathconf" }, /* 118 */
diff --git a/linux/syscall.h b/linux/syscall.h
index 0107564..39c0ff2 100644
--- a/linux/syscall.h
+++ b/linux/syscall.h
@@ -138,6 +138,8 @@
int sys_mknodat();
int sys_mlockall();
int sys_mmap();
+int sys_mmap_pgoff();
+int sys_mmap_4koff();
int sys_modify_ldt();
int sys_mount();
int sys_move_pages();
@@ -157,6 +159,7 @@
int sys_nanosleep();
int sys_newfstatat();
int sys_old_mmap();
+int sys_old_mmap_pgoff();
int sys_oldfstat();
int sys_oldlstat();
int sys_oldselect();
diff --git a/linux/tile/syscallent1.h b/linux/tile/syscallent1.h
index 50481f8..05dab40 100644
--- a/linux/tile/syscallent1.h
+++ b/linux/tile/syscallent1.h
@@ -220,7 +220,7 @@
{ 5, 0, sys_keyctl, "keyctl" }, /* 219 */
{ 5, TP, sys_clone, "clone" }, /* 220 */
{ 3, TF|TP, sys_execve, "execve" }, /* 221 */
- { 6, TD|TM, sys_mmap, "mmap2" }, /* 222 */
+ { 6, TD|TM, sys_mmap_4koff, "mmap2" }, /* 222 */
{ 6, TD, sys_fadvise64, "fadvise64" }, /* 223 */
{ 1, TF, sys_swapon, "swapon" }, /* 224 */
{ 1, TF, sys_swapoff, "swapoff" }, /* 225 */
diff --git a/mem.c b/mem.c
index b67a1b6..6f22922 100644
--- a/mem.c
+++ b/mem.c
@@ -39,8 +39,14 @@
# define modify_ldt_ldt_s user_desc
# endif
#endif
+
+#include <sys/user.h> /* for PAGE_SHIFT */
#if defined(SH64)
-# include <asm/page.h> /* for PAGE_SHIFT */
+# include <asm/page.h> /* for PAGE_SHIFT */
+#endif
+#if !defined(PAGE_SHIFT)
+# warning Failed to get PAGE_SHIFT, assuming 12
+# define PAGE_SHIFT 12
#endif
int
@@ -236,67 +242,99 @@
return RVAL_HEX;
}
-int sys_old_mmap(struct tcb *tcp)
+/* Syscall name<->function correspondence is messed up on many arches.
+ * For example:
+ * i386 has __NR_mmap == 90, and it is "old mmap", and
+ * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
+ * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
+ * Confused? Me too!
+ */
+
+/* Params are pointed to by u_arg[0], offset is in bytes */
+int
+sys_old_mmap(struct tcb *tcp)
{
+ long u_arg[6];
#if defined(IA64)
/*
* IA64 processes never call this routine, they only use the
- * new `sys_mmap' interface.
- * For IA32 processes, this code converts the integer arguments
- * that they pushed onto the stack, into longs.
+ * new 'sys_mmap' interface. Only IA32 processes come here.
*/
int i;
- long u_arg[6];
unsigned narrow_arg[6];
if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
return 0;
for (i = 0; i < 6; i++)
- u_arg[i] = narrow_arg[i];
-#elif defined(SH) || defined(SH64)
- /* SH has always passed the args in registers */
- long *u_arg = tcp->u_arg;
+ u_arg[i] = (unsigned long) narrow_arg[i];
#elif defined(X86_64)
- long u_arg[6];
- if (current_personality == 1) {
- int i;
- unsigned narrow_arg[6];
- if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
- return 0;
- for (i = 0; i < 6; ++i)
- u_arg[i] = narrow_arg[i];
- } else {
- if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
- return 0;
- }
+ /* We are here only in personality 1 (i386) */
+ int i;
+ unsigned narrow_arg[6];
+ if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
+ return 0;
+ for (i = 0; i < 6; ++i)
+ u_arg[i] = (unsigned long) narrow_arg[i];
#else
- long u_arg[6];
if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
return 0;
#endif
- return print_mmap(tcp, u_arg, (unsigned long)u_arg[5]);
+ return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
}
+#if defined(S390)
+/* Params are pointed to by u_arg[0], offset is in pages */
+int
+sys_old_mmap_pgoff(struct tcb *tcp)
+{
+ long u_arg[5];
+ int i;
+ unsigned narrow_arg[6];
+ unsigned long long offset;
+ if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
+ return 0;
+ for (i = 0; i < 5; i++)
+ u_arg[i] = (unsigned long) narrow_arg[i];
+ offset = narrow_arg[5];
+ offset <<= PAGE_SHIFT;
+ return print_mmap(tcp, u_arg, offset);
+}
+#endif
+
+/* Params are passed directly, offset is in bytes */
int
sys_mmap(struct tcb *tcp)
{
unsigned long long offset = (unsigned long) tcp->u_arg[5];
-
-#if defined(SH64)
- /*
- * Old mmap differs from new mmap in specifying the
- * offset in units of bytes rather than pages. We
- * pretend it's in byte units so the user only ever
- * sees bytes in the printout.
- */
- offset <<= PAGE_SHIFT;
-#elif defined(I386)
- /* Try test/mmap_offset_decode.c */
- offset <<= 12; /* 4096 byte pages */
-#elif defined(LINUX_MIPSN32) || defined(X32)
+#if defined(LINUX_MIPSN32) || defined(X32)
/* Try test/x32_mmap.c */
- /* At least for X32 it definitely should not be page-shifted! */
offset = tcp->ext_arg[5];
#endif
+ /* Example of kernel-side handling of this variety of mmap:
+ * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
+ * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
+ * since the above code converts off to pages.
+ */
+ return print_mmap(tcp, tcp->u_arg, offset);
+}
+
+/* Params are passed directly, offset is in pages */
+int
+sys_mmap_pgoff(struct tcb *tcp)
+{
+ /* Try test/mmap_offset_decode.c */
+ unsigned long long offset;
+ offset = (unsigned long) tcp->u_arg[5];
+ offset <<= PAGE_SHIFT;
+ return print_mmap(tcp, tcp->u_arg, offset);
+}
+
+/* Params are passed directly, offset is in 4k units */
+int
+sys_mmap_4koff(struct tcb *tcp)
+{
+ unsigned long long offset;
+ offset = (unsigned long) tcp->u_arg[5];
+ offset <<= 12;
return print_mmap(tcp, tcp->u_arg, offset);
}
diff --git a/pathtrace.c b/pathtrace.c
index 1a7d1db..33c9b75 100644
--- a/pathtrace.c
+++ b/pathtrace.c
@@ -231,7 +231,13 @@
if (
s->sys_func == sys_old_mmap ||
- s->sys_func == sys_mmap) {
+#if defined(S390)
+ s->sys_func == sys_old_mmap_pgoff ||
+#endif
+ s->sys_func == sys_mmap ||
+ s->sys_func == sys_mmap_pgoff ||
+ s->sys_func == sys_mmap_4koff
+ ) {
/* x, x, x, x, fd */
return fdmatch(tcp, tcp->u_arg[4]);
}
diff --git a/test/mmap_offset_decode.c b/test/mmap_offset_decode.c
index 875ea9c..34a708e 100644
--- a/test/mmap_offset_decode.c
+++ b/test/mmap_offset_decode.c
@@ -15,8 +15,8 @@
* $ strace ./mmap_offset_decode
*
* As of today (2011-08), on i386 strace prints page offset.
+ * Fixed 2013-02-19. Now all mmaps on all arches should show byte offsets.
*/
-
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64