Browse Source

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>
Denys Vlasenko 7 years ago
parent
commit
1ba85436de

+ 2
- 2
linux/arm/syscallent.h View File

@@ -116,7 +116,7 @@
116 116
 	{ 2,	TF,	sys_swapon,		"swapon"	}, /* 87 */
117 117
 	{ 4,	0,	sys_reboot,		"reboot"	}, /* 88 */
118 118
 	{ 3,	0,	sys_readdir,		"readdir"	}, /* 89 */
119
-	{ 6,	TD|TM,	sys_old_mmap,		"old_mmap"	}, /* 90 */
119
+	{ 1,	TD|TM,	sys_old_mmap,		"old_mmap"	}, /* 90 */
120 120
 	{ 2,	TM,	sys_munmap,		"munmap"	}, /* 91 */
121 121
 	{ 2,	TF,	sys_truncate,		"truncate"	}, /* 92 */
122 122
 	{ 2,	0,	sys_ftruncate,		"ftruncate"	}, /* 93 */
@@ -219,7 +219,7 @@
219 219
 	{ 5,	0,	sys_putpmsg,		"putpmsg"	}, /* 189 */
220 220
 	{ 0,	TP,	sys_vfork,		"vfork"		}, /* 190 */
221 221
 	{ 2,	0,	sys_getrlimit,		"getrlimit"	}, /* 191 */
222
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"		}, /* 192 */
222
+	{ 6,	TD|TM,	sys_mmap_pgoff,		"mmap2"		}, /* 192 */
223 223
 	{ 4,	TF,	sys_truncate64,		"truncate64"	}, /* 193 */
224 224
 	{ 4,	TF,	sys_ftruncate64,	"ftruncate64"	}, /* 194 */
225 225
 	{ 2,	TF,	sys_stat64,		"stat64"	}, /* 195 */

+ 1
- 1
linux/avr32/syscallent.h View File

@@ -115,7 +115,7 @@
115 115
 	{ 5,	TD,	sys_pwrite,		"pwrite"	}, /* 87 */
116 116
 	{ 2,	TF,	sys_swapon,		"swapon"	}, /* 88 */
117 117
 	{ 4,	0,	sys_reboot,		"reboot"	}, /* 89 */
118
-	{ 6,	TD|TM,	sys_mmap,		"mmap"		}, /* 90 */
118
+	{ 6,	TD|TM,	sys_mmap_pgoff,		"mmap"		}, /* 90 */
119 119
 	{ 2,	TM,	sys_munmap,		"munmap"	}, /* 91 */
120 120
 	{ 2,	TF,	sys_truncate,		"truncate"	}, /* 92 */
121 121
 	{ 2,	TD,	sys_ftruncate,		"ftruncate"	}, /* 93 */

+ 2
- 2
linux/bfin/syscallent.h View File

@@ -116,7 +116,7 @@
116 116
 	{ 2,	TF,	sys_swapon,		"swapon"	}, /* 87 */
117 117
 	{ 4,	0,	sys_reboot,		"reboot"	}, /* 88 */
118 118
 	{ 3,	TD,	sys_readdir,		"readdir"	}, /* 89 */
119
-	{ 6,	TD|TM,	sys_old_mmap,		"old_mmap"	}, /* 90 */
119
+	{ 6,	TD|TM,	printargs,		"old_mmap"	}, /* 90: not implemented in kernel */
120 120
 	{ 2,	TM,	sys_munmap,		"munmap"	}, /* 91 */
121 121
 	{ 2,	TF,	sys_truncate,		"truncate"	}, /* 92 */
122 122
 	{ 2,	TD,	sys_ftruncate,		"ftruncate"	}, /* 93 */
@@ -218,7 +218,7 @@
218 218
 	{ 5,	0,	sys_putpmsg,		"putpmsg"	}, /* 189 */
219 219
 	{ 0,	TP,	sys_vfork,		"vfork"		}, /* 190 */
220 220
 	{ 2,	0,	sys_getrlimit,		"getrlimit"	}, /* 191 */
221
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"		}, /* 192 */
221
+	{ 6,	TD|TM,	sys_mmap_pgoff,		"mmap2"		}, /* 192 */
222 222
 	{ 3,	TF,	sys_truncate64,		"truncate64"	}, /* 193 */
223 223
 	{ 3,	TD,	sys_ftruncate64,	"ftruncate64"	}, /* 194 */
224 224
 	{ 2,	TF,	sys_stat64,		"stat64"	}, /* 195 */

+ 1
- 1
linux/hppa/syscallent.h View File

@@ -91,7 +91,7 @@
91 91
 	{ 1,	0,	sys_uselib,		"uselib"		}, /* 86 */
92 92
 	{ 2,	TF,	sys_swapon,		"swapon"		}, /* 87 */
93 93
 	{ 4,	0,	sys_reboot,		"reboot"		}, /* 88 */
94
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"			}, /* 89 */
94
+	{ 6,	TD|TM,	sys_mmap_4koff,		"mmap2"			}, /* 89 */
95 95
 	{ 6,	TD|TM,	sys_mmap,		"mmap"			}, /* 90 */
96 96
 	{ 2,	TM,	sys_munmap,		"munmap"		}, /* 91 */
97 97
 	{ 2,	TF,	sys_truncate,		"truncate"		}, /* 92 */

+ 1
- 1
linux/i386/syscallent.h View File

@@ -219,7 +219,7 @@
219 219
 	{ 5,	0,	sys_putpmsg,		"putpmsg"	}, /* 189 */
220 220
 	{ 0,	TP,	sys_vfork,		"vfork"		}, /* 190 */
221 221
 	{ 2,	0,	sys_getrlimit,		"getrlimit"	}, /* 191 */
222
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"		}, /* 192 */
222
+	{ 6,	TD|TM,	sys_mmap_pgoff,		"mmap2"		}, /* 192 */
223 223
 	{ 3,	TF,	sys_truncate64,		"truncate64"	}, /* 193 */
224 224
 	{ 3,	TD,	sys_ftruncate64,	"ftruncate64"	}, /* 194 */
225 225
 	{ 2,	TF,	sys_stat64,		"stat64"	}, /* 195 */

+ 1
- 1
linux/ia64/syscallent.h View File

@@ -960,7 +960,7 @@
960 960
 	{ 3,	0,	sys_nfsservctl,		"nfsservctl"	}, /* 1169 */
961 961
 	{ 5,	0,	sys_prctl,		"prctl"		}, /* 1170 */
962 962
 	{ 1,	0,	sys_getpagesize,	"getpagesize"	}, /* 1171 */
963
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"		}, /* 1172 */
963
+	{ 6,	TD|TM,	sys_mmap_pgoff,		"mmap2"		}, /* 1172 */
964 964
 	{ 5,	0,	printargs,		"pciconfig_read"}, /* 1173 */
965 965
 	{ 5,	0,	printargs,		"pciconfig_write"}, /* 1174 */
966 966
 	{ MA,	0,	printargs,		"perfmonctl"	}, /* 1175 */

+ 2
- 2
linux/m68k/syscallent.h View File

@@ -116,7 +116,7 @@
116 116
 	{ 2,	TF,	sys_swapon,		"swapon"	}, /* 87 */
117 117
 	{ 4,	0,	sys_reboot,		"reboot"	}, /* 88 */
118 118
 	{ 3,	0,	sys_readdir,		"readdir"	}, /* 89 */
119
-	{ 6,	TD|TM,	sys_old_mmap,		"old_mmap"	}, /* 90 */
119
+	{ 1,	TD|TM,	sys_old_mmap,		"old_mmap"	}, /* 90 */
120 120
 	{ 2,	TM,	sys_munmap,		"munmap"	}, /* 91 */
121 121
 	{ 2,	TF,	sys_truncate,		"truncate"	}, /* 92 */
122 122
 	{ 2,	0,	sys_ftruncate,		"ftruncate"	}, /* 93 */
@@ -218,7 +218,7 @@
218 218
 	{ 5,	0,	sys_putpmsg,		"putpmsg"	}, /* 189 */
219 219
 	{ 0,	TP,	sys_vfork,		"vfork"		}, /* 190 */
220 220
 	{ 2,	0,	sys_getrlimit,		"getrlimit"	}, /* 191 */
221
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"		}, /* 192 */
221
+	{ 6,	TD|TM,	sys_mmap_pgoff,		"mmap2"		}, /* 192 */
222 222
 	{ 3,	TF,	sys_truncate64,		"truncate64"	}, /* 193 */
223 223
 	{ 3,	TF,	sys_ftruncate64,	"ftruncate64"	}, /* 194 */
224 224
 	{ 2,	TF,	sys_stat64,		"stat64"	}, /* 195 */

+ 2
- 2
linux/microblaze/syscallent.h View File

@@ -116,7 +116,7 @@
116 116
 	{ 2,	TF,	sys_swapon,		"swapon"	}, /* 87 */
117 117
 	{ 4,	0,	sys_reboot,		"reboot"	}, /* 88 */
118 118
 	{ 3,	0,	sys_readdir,		"readdir"	}, /* 89 */
119
-	{ 6,	TD|TM,	sys_old_mmap,		"old_mmap"	}, /* 90 */
119
+	{ 6,	TD|TM,	sys_mmap,		"old_mmap"	}, /* 90 */
120 120
 	{ 2,	TM,	sys_munmap,		"munmap"	}, /* 91 */
121 121
 	{ 2,	TF,	sys_truncate,		"truncate"	}, /* 92 */
122 122
 	{ 2,	0,	sys_ftruncate,		"ftruncate"	}, /* 93 */
@@ -218,7 +218,7 @@
218 218
 	{ 5,	0,	sys_putpmsg,		"putpmsg"	}, /* 189 */
219 219
 	{ 0,	TP,	sys_vfork,		"vfork"		}, /* 190 */
220 220
 	{ 2,	0,	sys_getrlimit,		"getrlimit"	}, /* 191 */
221
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"		}, /* 192 */
221
+	{ 6,	TD|TM,	sys_mmap_pgoff,		"mmap2"		}, /* 192 */
222 222
 	{ 3,	TF,	sys_truncate64,		"truncate64"	}, /* 193 */
223 223
 	{ 3,	TF,	sys_ftruncate64,	"ftruncate64"	}, /* 194 */
224 224
 	{ 2,	TF,	sys_stat64,		"stat64"	}, /* 195 */

+ 11
- 11
linux/mips/syscallent.h View File

@@ -115,7 +115,7 @@
115 115
 	{ 0,	0,	printargs,		"svr4_priocntlset"	}, /*  0112 */
116 116
 	{ 0,	0,	printargs,		"svr4_pathconf"	}, /*  0113 */
117 117
 	{ 0,	TM,	printargs,		"svr4_mincore"	}, /*  0114 */
118
-	{ 0,	TM,	printargs,		"svr4_mmap"	}, /*  0115 */
118
+	{ 0,	TD|TM,	printargs,		"svr4_mmap"	}, /*  0115 */
119 119
 	{ 0,	TM,	printargs,		"svr4_mprotect"	}, /*  0116 */
120 120
 	{ 0,	TM,	printargs,		"svr4_munmap"	}, /*  0117 */
121 121
 	{ 0,	0,	printargs,		"svr4_fpathconf"	}, /*  0118 */
@@ -346,7 +346,7 @@
346 346
 	{ 0,	0,	printargs,		"sysv_procblk"	}, /* 1131 */
347 347
 	{ 0,	0,	printargs,		"sysv_sprocsp"	}, /* 1132 */
348 348
 	{ 0,	0,	printargs,		"sysv_sgigsc"	}, /* 1133 */
349
-	{ 0,	TM,	printargs,		"sysv_mmap"	}, /* 1134 */
349
+	{ 0,	TD|TM,	printargs,		"sysv_mmap"	}, /* 1134 */
350 350
 	{ 0,	TM,	printargs,		"sysv_munmap"	}, /* 1135 */
351 351
 	{ 0,	TM,	printargs,		"sysv_mprotect"	}, /* 1136 */
352 352
 	{ 0,	TM,	printargs,		"sysv_msync"	}, /* 1137 */
@@ -397,7 +397,7 @@
397 397
 	{ 0,	0,	printargs,		"sysv_writev"	}, /* 1182 */
398 398
 	{ 0,	0,	printargs,		"sysv_truncate64"	}, /* 1183 */
399 399
 	{ 0,	0,	printargs,		"sysv_ftruncate64"	}, /* 1184 */
400
-	{ 0,	TM,	printargs,		"sysv_mmap64"	}, /* 1185 */
400
+	{ 0,	TD|TM,	printargs,		"sysv_mmap64"	}, /* 1185 */
401 401
 	{ 0,	0,	printargs,		"sysv_dmi"	}, /* 1186 */
402 402
 	{ 0,	0,	printargs,		"sysv_pread"	}, /* 1187 */
403 403
 	{ 0,	0,	printargs,		"sysv_pwrite"	}, /* 1188 */
@@ -475,7 +475,7 @@
475 475
 	{ 0,	0,	printargs,		"bsd43_vwrite"	}, /* 2068 */
476 476
 	{ 0,	TM,	printargs,		"bsd43_sbrk"	}, /* 2069 */
477 477
 	{ 0,	0,	printargs,		"bsd43_sstk"	}, /* 2070 */
478
-	{ 0,	TM,	printargs,		"bsd43_mmap"	}, /* 2071 */
478
+	{ 0,	TD|TM,	printargs,		"bsd43_mmap"	}, /* 2071 */
479 479
 	{ 0,	0,	printargs,		"bsd43_vadvise"	}, /* 2072 */
480 480
 	{ 0,	TM,	printargs,		"bsd43_munmap"	}, /* 2073 */
481 481
 	{ 0,	TM,	printargs,		"bsd43_mprotect"	}, /* 2074 */
@@ -733,7 +733,7 @@
733 733
 	{ 0,	0,	printargs,		"posix_SGI_blkproc"	}, /* 3131 */
734 734
 	{ 0,	0,	NULL,			NULL		}, /* 3132 */
735 735
 	{ 0,	0,	printargs,		"posix_SGI_sgigsc"	}, /* 3133 */
736
-	{ 0,	TM,	printargs,		"posix_SGI_mmap"	}, /* 3134 */
736
+	{ 0,	TD|TM,	printargs,		"posix_SGI_mmap"	}, /* 3134 */
737 737
 	{ 0,	TM,	printargs,		"posix_SGI_munmap"	}, /* 3135 */
738 738
 	{ 0,	TM,	printargs,		"posix_SGI_mprotect"	}, /* 3136 */
739 739
 	{ 0,	TM,	printargs,		"posix_SGI_msync"	}, /* 3137 */
@@ -754,7 +754,7 @@
754 754
 	{ 0,	0,	printargs,		"posix_fchown"	}, /* 3152 */
755 755
 	{ 0,	0,	printargs,		"posix_fchmod"	}, /* 3153 */
756 756
 	{ 0,	0,	printargs,		"posix_wait3"	}, /* 3154 */
757
-	{ 0,	TM,	printargs,		"posix_mmap"	}, /* 3155 */
757
+	{ 0,	TD|TM,	printargs,		"posix_mmap"	}, /* 3155 */
758 758
 	{ 0,	TM,	printargs,		"posix_munmap"	}, /* 3156 */
759 759
 	{ 0,	TM,	printargs,		"posix_madvise"	}, /* 3157 */
760 760
 	{ 0,	0,	printargs,		"posix_BSD_getpagesize"	}, /* 3158 */
@@ -1083,7 +1083,7 @@
1083 1083
 	{ 4,	TD|TN,	sys_sendfile,		"sendfile"	}, /* 4207 */
1084 1084
 	{ 0,	0,	NULL,			NULL		}, /* 4208 */
1085 1085
 	{ 0,	0,	NULL,			NULL		}, /* 4209 */
1086
-	{ 6,	TD|TM,	sys_mmap,		"mmap"		}, /* 4210 */
1086
+	{ 6,	TD|TM,	sys_mmap_4koff,		"mmap"		}, /* 4210 */
1087 1087
 	{ 4,	TF,	sys_truncate64,		"truncate64"	}, /* 4211 */
1088 1088
 	{ 4,	TD,	sys_ftruncate64,	"ftruncate64"	}, /* 4212 */
1089 1089
 	{ 2,	TF,	sys_stat64,		"stat64"	}, /* 4213 */
@@ -1311,7 +1311,7 @@
1311 1311
 	{ 0,	0,	printargs,		"o32_swapon"	}, /* 4087 */
1312 1312
 	{ 0,	0,	printargs,		"o32_reboot"	}, /* 4088 */
1313 1313
 	{ 0,	0,	printargs,		"o32_readdir"	}, /* 4089 */
1314
-	{ 0,	TM,	printargs,		"o32_old_mmap"	}, /* 4090 */
1314
+	{ 0,	TD|TM,	printargs,		"o32_old_mmap"	}, /* 4090 */
1315 1315
 	{ 0,	TM,	printargs,		"o32_munmap"	}, /* 4091 */
1316 1316
 	{ 0,	0,	printargs,		"o32_truncate"	}, /* 4092 */
1317 1317
 	{ 0,	0,	printargs,		"o32_ftruncate"	}, /* 4093 */
@@ -1431,7 +1431,7 @@
1431 1431
 	{ 0,	0,	printargs,		"o32_sendfile"	}, /* 4207 */
1432 1432
 	{ 0,	0,	NULL,			NULL		}, /* 4208 */
1433 1433
 	{ 0,	0,	NULL,			NULL		}, /* 4209 */
1434
-	{ 0,	TM,	printargs,		"o32_mmap"		}, /* 4210 */
1434
+	{ 0,	TD|TM,	printargs,		"o32_mmap"		}, /* 4210 */
1435 1435
 	{ 0,	0,	printargs,		"o32_truncate64"	}, /* 4211 */
1436 1436
 	{ 0,	0,	printargs,		"o32_ftruncate64"	}, /* 4212 */
1437 1437
 	{ 0,	0,	printargs,		"o32_stat64"	}, /* 4213 */
@@ -1890,7 +1890,7 @@
1890 1890
 	{ 0,	0,	printargs,		"n64_lstat"		}, /* 5006 */
1891 1891
 	{ 0,	0,	printargs,		"n64_poll"		}, /* 5007 */
1892 1892
 	{ 0,	0,	printargs,		"n64_lseek"		}, /* 5008 */
1893
-	{ 0,	TM,	printargs,		"n64_mmap"		}, /* 5009 */
1893
+	{ 0,	TD|TM,	printargs,		"n64_mmap"		}, /* 5009 */
1894 1894
 	{ 0,	TM,	printargs,		"n64_mprotect"		}, /* 5010 */
1895 1895
 	{ 0,	TM,	printargs,		"n64_munmap"		}, /* 5011 */
1896 1896
 	{ 0,	TM,	printargs,		"n64_brk"		}, /* 5012 */
@@ -2514,7 +2514,7 @@
2514 2514
 	{ 0,	0,	printargs,		"n32_lstat"		}, /* 6006 */
2515 2515
 	{ 0,	0,	printargs,		"n32_poll"		}, /* 6007 */
2516 2516
 	{ 0,	0,	printargs,		"n32_lseek"		}, /* 6008 */
2517
-	{ 0,	TM,	printargs,		"n32_mmap"		}, /* 6009 */
2517
+	{ 0,	TD|TM,	printargs,		"n32_mmap"		}, /* 6009 */
2518 2518
 	{ 0,	TM,	printargs,		"n32_mprotect"		}, /* 6010 */
2519 2519
 	{ 0,	TM,	printargs,		"n32_munmap"		}, /* 6011 */
2520 2520
 	{ 0,	TM,	printargs,		"n32_brk"		}, /* 6012 */

+ 1
- 1
linux/or1k/syscallent.h View File

@@ -220,7 +220,7 @@
220 220
 	{  5,	0,	sys_keyctl,			"keyctl"		}, /* 219 */
221 221
 	{  5,	TP,	sys_clone,			"clone"			}, /* 220 */
222 222
 	{  3,	TF|TP,	sys_execve,			"execve"		}, /* 221 */
223
-	{  6,	TD,	sys_mmap,			"mmap2"			}, /* 222 */
223
+	{  6,	TD|TM,	sys_mmap_pgoff,			"mmap2"			}, /* 222 */
224 224
 	{  6,	TD,	sys_fadvise64_64,		"fadvise64_64"		}, /* 223 */
225 225
 	{  2,	TF,	sys_swapon,			"swapon"		}, /* 224 */
226 226
 	{  1,	TF,	sys_swapoff,			"swapoff"		}, /* 225 */

+ 1
- 1
linux/powerpc/syscallent.h View File

@@ -218,7 +218,7 @@
218 218
 	{ 0,	TP,	sys_vfork,		"vfork"			}, /* 189 */
219 219
 	{ 2,	0,	sys_getrlimit,		"getrlimit"		}, /* 190 */
220 220
 	{ 5,	TD,	sys_readahead,		"readahead"		}, /* 190 */
221
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"			}, /* 192 */
221
+	{ 6,	TD|TM,	sys_mmap_4koff,		"mmap2"			}, /* 192 */
222 222
 	{ 4,	TF,	sys_truncate64,		"truncate64"		}, /* 193 */
223 223
 	{ 4,	TD,	sys_ftruncate64,	"ftruncate64"		}, /* 194 */
224 224
 	{ 2,	TF,	sys_stat64,		"stat64"		}, /* 195 */

+ 1
- 1
linux/s390/syscallent.h View File

@@ -220,7 +220,7 @@
220 220
 	{ 5,	0,	sys_putpmsg,		"putpmsg"	}, /* 189 */
221 221
 	{ 0,	TP,	sys_vfork,		"vfork"		}, /* 190 */
222 222
 	{ 2,	0,	sys_getrlimit,		"getrlimit"	}, /* 191 */
223
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"		}, /* 192 */
223
+	{ 1,	TD|TM,	sys_old_mmap_pgoff,	"mmap2"		}, /* 192 */
224 224
 	{ 2,	TF,	sys_truncate64,		"truncate64"	}, /* 193 */
225 225
 	{ 2,	TD,	sys_ftruncate64,	"ftruncate64"	}, /* 194 */
226 226
 	{ 2,	TF,	sys_stat64,		"stat64"	}, /* 195 */

+ 1
- 1
linux/s390x/syscallent.h View File

@@ -117,7 +117,7 @@
117 117
 	{ 2,	TF,	sys_swapon,		"swapon"	}, /* 87 */
118 118
 	{ 4,	0,	sys_reboot,		"reboot"	}, /* 88 */
119 119
 	{ MA,	0,	NULL,			NULL		}, /* 89 */
120
-	{ 6,	TD|TM,	sys_old_mmap,		"mmap"		}, /* 90 */
120
+	{ 1,	TD|TM,	sys_old_mmap,		"mmap"		}, /* 90 */
121 121
 	{ 2,	TM,	sys_munmap,		"munmap"	}, /* 91 */
122 122
 	{ 2,	TF,	sys_truncate,		"truncate"	}, /* 92 */
123 123
 	{ 2,	TD,	sys_ftruncate,		"ftruncate"	}, /* 93 */

+ 2
- 2
linux/sh/syscallent.h View File

@@ -118,7 +118,7 @@
118 118
 	{ 2,	TF,	sys_swapon,		"swapon"	}, /* 87 */
119 119
 	{ 4,	0,	sys_reboot,		"reboot"	}, /* 88 */
120 120
 	{ 3,	TD,	sys_readdir,		"readdir"	}, /* 89 */
121
-	{ 6,	TD|TM,	sys_old_mmap,		"old_mmap"	}, /* 90 */
121
+	{ 6,	TD|TM,	sys_mmap,		"old_mmap"	}, /* 90 */
122 122
 	{ 2,	TM,	sys_munmap,		"munmap"	}, /* 91 */
123 123
 	{ 2,	TF,	sys_truncate,		"truncate"	}, /* 92 */
124 124
 	{ 2,	TD,	sys_ftruncate,		"ftruncate"	}, /* 93 */
@@ -221,7 +221,7 @@
221 221
 	{ 5,	0,	NULL,			NULL		}, /* 189 */
222 222
 	{ 0,	TP,	sys_vfork,		"vfork"		}, /* 190 */
223 223
 	{ 5,	0,	printargs,		"getrlimit"	}, /* 191 */
224
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"		}, /* 192 */
224
+	{ 6,	TD|TM,	sys_mmap_4koff,		"mmap2"		}, /* 192 */
225 225
 	{ 5,	0,	sys_truncate64,		"truncate64"	}, /* 193 */
226 226
 	{ 5,	TD,	sys_ftruncate64,	"ftruncate64"	}, /* 194 */
227 227
 	{ 2,	TF,	sys_stat64,		"stat64"	}, /* 195 */

+ 2
- 2
linux/sh64/syscallent.h View File

@@ -116,7 +116,7 @@
116 116
 	{ 2,	TF,	sys_swapon,		"swapon"	}, /* 87 */
117 117
 	{ 4,	0,	sys_reboot,		"reboot"	}, /* 88 */
118 118
 	{ 3,	TD,	sys_readdir,		"readdir"	}, /* 89 */
119
-	{ 6,	TD|TM,	sys_old_mmap,		"old_mmap"	}, /* 90 */
119
+	{ 6,	TD|TM,	sys_mmap,		"old_mmap"	}, /* 90 */
120 120
 	{ 2,	TM,	sys_munmap,		"munmap"	}, /* 91 */
121 121
 	{ 2,	TF,	sys_truncate,		"truncate"	}, /* 92 */
122 122
 	{ 2,	TD,	sys_ftruncate,		"ftruncate"	}, /* 93 */
@@ -218,7 +218,7 @@
218 218
 	{ 5,	0,	NULL,			NULL		}, /* 189 */
219 219
 	{ 0,	TP,	sys_vfork,		"vfork"		}, /* 190 */
220 220
 	{ 2,	0,	printargs,		"getrlimit"	}, /* 191 */
221
-	{ 6,	TD|TM,	sys_mmap,		"mmap2"		}, /* 192 */
221
+	{ 6,	TD|TM,	sys_mmap_4koff,		"mmap2"		}, /* 192 */
222 222
 	{ 2,	TF,	sys_truncate64,		"truncate64"	}, /* 193 */
223 223
 	{ 2,	TD,	sys_ftruncate64,	"ftruncate64"	}, /* 194 */
224 224
 	{ 2,	TF,	sys_stat64,		"stat64"	}, /* 195 */

+ 1
- 1
linux/sparc/syscallent1.h View File

@@ -140,7 +140,7 @@
140 140
 	{ 6,	0,	solaris_priocntlsys,	"priocntlsys"	}, /* 112 */
141 141
 	{ 6,	TF,	solaris_pathconf,	"pathconf"	}, /* 113 */
142 142
 	{ 6,	0,	solaris_mincore,	"mincore"	}, /* 114 */
143
-	{ 6,	TD,	solaris_mmap,		"mmap"		}, /* 115 */
143
+	{ 6,	TD|TM,	solaris_mmap,		"mmap"		}, /* 115 */
144 144
 	{ 6,	0,	solaris_mprotect,	"mprotect"	}, /* 116 */
145 145
 	{ 6,	0,	solaris_munmap,		"munmap"	}, /* 117 */
146 146
 	{ 6,	0,	solaris_fpathconf,	"fpathconf"	}, /* 118 */

+ 3
- 0
linux/syscall.h View File

@@ -138,6 +138,8 @@ int sys_mknod();
138 138
 int sys_mknodat();
139 139
 int sys_mlockall();
140 140
 int sys_mmap();
141
+int sys_mmap_pgoff();
142
+int sys_mmap_4koff();
141 143
 int sys_modify_ldt();
142 144
 int sys_mount();
143 145
 int sys_move_pages();
@@ -157,6 +159,7 @@ int sys_munmap();
157 159
 int sys_nanosleep();
158 160
 int sys_newfstatat();
159 161
 int sys_old_mmap();
162
+int sys_old_mmap_pgoff();
160 163
 int sys_oldfstat();
161 164
 int sys_oldlstat();
162 165
 int sys_oldselect();

+ 1
- 1
linux/tile/syscallent1.h View File

@@ -220,7 +220,7 @@
220 220
 	{ 5,	0,	sys_keyctl,			"keyctl"			}, /*  219 */
221 221
 	{ 5,	TP,	sys_clone,			"clone"				}, /*  220 */
222 222
 	{ 3,	TF|TP,	sys_execve,			"execve"			}, /*  221 */
223
-	{ 6,	TD|TM,	sys_mmap,			"mmap2"				}, /*  222 */
223
+	{ 6,	TD|TM,	sys_mmap_4koff,			"mmap2"				}, /*  222 */
224 224
 	{ 6,	TD,	sys_fadvise64,			"fadvise64"			}, /*  223 */
225 225
 	{ 1,	TF,	sys_swapon,			"swapon"			}, /*  224 */
226 226
 	{ 1,	TF,	sys_swapoff,			"swapoff"			}, /*  225 */

+ 76
- 38
mem.c View File

@@ -39,8 +39,14 @@
39 39
 #  define modify_ldt_ldt_s user_desc
40 40
 # endif
41 41
 #endif
42
+
43
+#include <sys/user.h>	/* for PAGE_SHIFT */
42 44
 #if defined(SH64)
43
-# include <asm/page.h>	    /* for PAGE_SHIFT */
45
+# include <asm/page.h>	/* for PAGE_SHIFT */
46
+#endif
47
+#if !defined(PAGE_SHIFT)
48
+# warning Failed to get PAGE_SHIFT, assuming 12
49
+# define PAGE_SHIFT 12
44 50
 #endif
45 51
 
46 52
 int
@@ -236,67 +242,99 @@ print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
236 242
 	return RVAL_HEX;
237 243
 }
238 244
 
239
-int sys_old_mmap(struct tcb *tcp)
245
+/* Syscall name<->function correspondence is messed up on many arches.
246
+ * For example:
247
+ * i386 has __NR_mmap == 90, and it is "old mmap", and
248
+ * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
249
+ * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
250
+ * Confused? Me too!
251
+ */
252
+
253
+/* Params are pointed to by u_arg[0], offset is in bytes */
254
+int
255
+sys_old_mmap(struct tcb *tcp)
240 256
 {
257
+	long u_arg[6];
241 258
 #if defined(IA64)
242 259
 	/*
243 260
 	 * IA64 processes never call this routine, they only use the
244
-	 * new `sys_mmap' interface.
245
-	 * For IA32 processes, this code converts the integer arguments
246
-	 * that they pushed onto the stack, into longs.
261
+	 * new 'sys_mmap' interface. Only IA32 processes come here.
247 262
 	 */
248 263
 	int i;
249
-	long u_arg[6];
250 264
 	unsigned narrow_arg[6];
251 265
 	if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
252 266
 		return 0;
253 267
 	for (i = 0; i < 6; i++)
254
-		u_arg[i] = narrow_arg[i];
255
-#elif defined(SH) || defined(SH64)
256
-	/* SH has always passed the args in registers */
257
-	long *u_arg = tcp->u_arg;
268
+		u_arg[i] = (unsigned long) narrow_arg[i];
258 269
 #elif defined(X86_64)
259
-	long u_arg[6];
260
-	if (current_personality == 1) {
261
-		int i;
262
-		unsigned narrow_arg[6];
263
-		if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
264
-			return 0;
265
-		for (i = 0; i < 6; ++i)
266
-			u_arg[i] = narrow_arg[i];
267
-	} else {
268
-		if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
269
-			return 0;
270
-	}
270
+	/* We are here only in personality 1 (i386) */
271
+	int i;
272
+	unsigned narrow_arg[6];
273
+	if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
274
+		return 0;
275
+	for (i = 0; i < 6; ++i)
276
+		u_arg[i] = (unsigned long) narrow_arg[i];
271 277
 #else
272
-	long u_arg[6];
273 278
 	if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
274 279
 		return 0;
275 280
 #endif
276
-	return print_mmap(tcp, u_arg, (unsigned long)u_arg[5]);
281
+	return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
282
+}
283
+
284
+#if defined(S390)
285
+/* Params are pointed to by u_arg[0], offset is in pages */
286
+int
287
+sys_old_mmap_pgoff(struct tcb *tcp)
288
+{
289
+	long u_arg[5];
290
+	int i;
291
+	unsigned narrow_arg[6];
292
+	unsigned long long offset;
293
+	if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
294
+		return 0;
295
+	for (i = 0; i < 5; i++)
296
+		u_arg[i] = (unsigned long) narrow_arg[i];
297
+	offset = narrow_arg[5];
298
+	offset <<= PAGE_SHIFT;
299
+	return print_mmap(tcp, u_arg, offset);
277 300
 }
301
+#endif
278 302
 
303
+/* Params are passed directly, offset is in bytes */
279 304
 int
280 305
 sys_mmap(struct tcb *tcp)
281 306
 {
282 307
 	unsigned long long offset = (unsigned long) tcp->u_arg[5];
283
-
284
-#if defined(SH64)
285
-	/*
286
-	 * Old mmap differs from new mmap in specifying the
287
-	 * offset in units of bytes rather than pages.  We
288
-	 * pretend it's in byte units so the user only ever
289
-	 * sees bytes in the printout.
290
-	 */
291
-	offset <<= PAGE_SHIFT;
292
-#elif defined(I386)
293
-	/* Try test/mmap_offset_decode.c */
294
-	offset <<= 12; /* 4096 byte pages */
295
-#elif defined(LINUX_MIPSN32) || defined(X32)
308
+#if defined(LINUX_MIPSN32) || defined(X32)
296 309
 	/* Try test/x32_mmap.c */
297
-	/* At least for X32 it definitely should not be page-shifted! */
298 310
 	offset = tcp->ext_arg[5];
299 311
 #endif
312
+	/* Example of kernel-side handling of this variety of mmap:
313
+	 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
314
+	 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
315
+	 * since the above code converts off to pages.
316
+	 */
317
+	return print_mmap(tcp, tcp->u_arg, offset);
318
+}
319
+
320
+/* Params are passed directly, offset is in pages */
321
+int
322
+sys_mmap_pgoff(struct tcb *tcp)
323
+{
324
+	/* Try test/mmap_offset_decode.c */
325
+	unsigned long long offset;
326
+	offset = (unsigned long) tcp->u_arg[5];
327
+	offset <<= PAGE_SHIFT;
328
+	return print_mmap(tcp, tcp->u_arg, offset);
329
+}
330
+
331
+/* Params are passed directly, offset is in 4k units */
332
+int
333
+sys_mmap_4koff(struct tcb *tcp)
334
+{
335
+	unsigned long long offset;
336
+	offset = (unsigned long) tcp->u_arg[5];
337
+	offset <<= 12;
300 338
 	return print_mmap(tcp, tcp->u_arg, offset);
301 339
 }
302 340
 

+ 7
- 1
pathtrace.c View File

@@ -231,7 +231,13 @@ pathtrace_match(struct tcb *tcp)
231 231
 
232 232
 	if (
233 233
 	    s->sys_func == sys_old_mmap ||
234
-	    s->sys_func == sys_mmap) {
234
+#if defined(S390)
235
+	    s->sys_func == sys_old_mmap_pgoff ||
236
+#endif
237
+	    s->sys_func == sys_mmap ||
238
+	    s->sys_func == sys_mmap_pgoff ||
239
+	    s->sys_func == sys_mmap_4koff
240
+	) {
235 241
 		/* x, x, x, x, fd */
236 242
 		return fdmatch(tcp, tcp->u_arg[4]);
237 243
 	}

+ 1
- 1
test/mmap_offset_decode.c View File

@@ -15,8 +15,8 @@
15 15
  * $ strace ./mmap_offset_decode
16 16
  *
17 17
  * As of today (2011-08), on i386 strace prints page offset.
18
+ * Fixed 2013-02-19. Now all mmaps on all arches should show byte offsets.
18 19
  */
19
-
20 20
 #define _LARGEFILE_SOURCE
21 21
 #define _LARGEFILE64_SOURCE
22 22
 #define _FILE_OFFSET_BITS 64

Loading…
Cancel
Save