]> granicus.if.org Git - strace/commitdiff
Clean up mmap decoding
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 19 Feb 2013 10:28:20 +0000 (11:28 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 19 Feb 2013 10:54:36 +0000 (11:54 +0100)
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>
21 files changed:
linux/arm/syscallent.h
linux/avr32/syscallent.h
linux/bfin/syscallent.h
linux/hppa/syscallent.h
linux/i386/syscallent.h
linux/ia64/syscallent.h
linux/m68k/syscallent.h
linux/microblaze/syscallent.h
linux/mips/syscallent.h
linux/or1k/syscallent.h
linux/powerpc/syscallent.h
linux/s390/syscallent.h
linux/s390x/syscallent.h
linux/sh/syscallent.h
linux/sh64/syscallent.h
linux/sparc/syscallent1.h
linux/syscall.h
linux/tile/syscallent1.h
mem.c
pathtrace.c
test/mmap_offset_decode.c

index 123b910947a33753a2f0b631aaffb230cdf6ccf7..e3de1f5a4d6a736d8d3628c528b25d106ae311bc 100644 (file)
        { 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 */
        { 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 */
index b215cc17ce5dfd0129ab7cc226e153e80d2a5ef2..af8b524bf795ac921201239de9f79b331cf77bde 100644 (file)
        { 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 */
index 05194fb584a1e1c59d66f6767e7dc53b6bc863a6..be8f532fc7aada6f901f8a65ee38bff730f9548e 100644 (file)
        { 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 */
        { 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 */
index dc12299ad6b02530c864ea6b9a5a5b04fd743ae6..fafdfd24ab7d14244f21e7144937f45ddbfd1b55 100644 (file)
@@ -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 */
index ee61933c5b9ea841d6da4ea227b5b754192cbb5f..3d1e738f63ca1688a37c11360c0be9bca5e7de17 100644 (file)
        { 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 */
index 8e130ad54d69966270c4adb91f9a7f21bb43821e..6e74968dc83b73e7b863a6c732448521697dde57 100644 (file)
        { 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 */
index 184f01c8b7a762a0c840cf2d4ad1173655ff6971..165109b1a5ab721ca2cbb20dd12966a7c90e934f 100644 (file)
        { 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 */
        { 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 */
index c5a52fafbf034365cd8eaf83db9b4a27fa42b41e..0c8fbbd01dfe418862f4578fe4c601ca7e721802 100644 (file)
        { 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 */
        { 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 */
index 91efeb2c1d02494433b1a5de2097c7d13b09a1c5..085c0e290a36dbbd9f9102cac43cb21f0dc32fcc 100644 (file)
        { 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 */
        { 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 */
        { 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 */
        { 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 */
        { 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 */
        { 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 */
        { 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 */
        { 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 */
        { 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 */
        { 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 */
        { 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 */
index 24f50360629c26b926f54491fb219e56a09c7c47..3e7613f8bceda29e1c92abd2ca5b2ab82d729b66 100644 (file)
        {  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 */
index e61946e3ddfb322957f58c02060f838126e1b370..8cb9179b03b7c2bb5f723f24991bf67ac3ec7a3a 100644 (file)
        { 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 */
index 94f4d25633f5ed80d2a038aae1961d3b267026c2..709267b6aa3e68b41bebd5752792546cec7bae47 100644 (file)
        { 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 */
index ebf35d48baa6f7f0f3fae86c593a2e99af4fc727..32b75d9049748a242d88ed7a0d8c1b530e1d10b4 100644 (file)
        { 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 */
index 1546ff692a4ff154b18955b1e25efe516f08d029..b64704622eafdc643d2b19730f83b007fe62094a 100644 (file)
        { 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 */
        { 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 */
index 4e20c478f0f8e4c67b0f726d0726670ef98280cc..0591f07c017c387e8e67e0534a901633256ebc46 100644 (file)
        { 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 */
        { 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 */
index 5e9fe961e1d803d474005f98d564fe284faea556..9519e085ad3ea5871719e1505fa438b1a25376cb 100644 (file)
        { 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 */
index 010756498d199ef95d2e2b7507590dc3a3004555..39c0ff26ee7e71c4c24d1aba20a85f90682d21dd 100644 (file)
@@ -138,6 +138,8 @@ int sys_mknod();
 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_munmap();
 int sys_nanosleep();
 int sys_newfstatat();
 int sys_old_mmap();
+int sys_old_mmap_pgoff();
 int sys_oldfstat();
 int sys_oldlstat();
 int sys_oldselect();
index 50481f8ff3bdd91c1a9f1acaf40a11f0fd8f5040..05dab40ab231ab7e8e5a07d590463ef8af716f3b 100644 (file)
        { 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 b67a1b6509208c57ba4a9b517429007855f9d7ef..6f22922d623e3e871c01933413cabe0be9ad9aed 100644 (file)
--- a/mem.c
+++ b/mem.c
 #  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 @@ print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
        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);
 }
 
index 1a7d1db0c17cca32b8f24ad232483c380cc55437..33c9b75d78a17a5b7ca46e28b9642972a2bff8aa 100644 (file)
@@ -231,7 +231,13 @@ pathtrace_match(struct tcb *tcp)
 
        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]);
        }
index 875ea9cca9fcb4135a1ce3ca1c23aa9934a43bca..34a708e22bad64eee2ab26f3a645cd8ff9ffb38c 100644 (file)
@@ -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