2011-08-19 19:07:38 +04:00
/* Should strace show byte or page offsets in mmap syscalls
* which take page offset parameters ?
*
* At the time of writing , sys_mmap ( ) converts page to byte offsets ,
* but only for SH64 ! But this routine is used on i386 too - by mmap2 syscall ,
* which uses page offsets too . As it stands now , SH64 and i386 are inconsistent .
*
* sys_old_mmap ( ) is used for old mmap syscall , which uses byte offset -
* should be ok .
* sys_mmap64 ( ) is currently buggy ( should print bogus offset , but I can ' t
* test it right now . What arch / bitness invokes sys_mmap64 ? )
*
* This program is intended for testing what strace actually shows . Usage :
* $ gcc test / mmap_offset_decode . c - o mmap_offset_decode - static
* $ strace . / mmap_offset_decode
*
* As of today ( 2011 - 08 ) , on i386 strace prints page offset .
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>
2013-02-19 14:28:20 +04:00
* Fixed 2013 - 02 - 19. Now all mmaps on all arches should show byte offsets .
2011-08-19 19:07:38 +04:00
*/
# define _LARGEFILE_SOURCE
# define _LARGEFILE64_SOURCE
# define _FILE_OFFSET_BITS 64
# include <sys/mman.h>
# include <errno.h>
2017-06-17 22:08:36 +03:00
int
main ( void )
2011-08-19 19:07:38 +04:00
{
/* 0x1000 is meant to be page size multiplier */
mmap ( 0 , 4096 , PROT_READ | PROT_WRITE , MAP_PRIVATE | MAP_ANONYMOUS , - 1 ,
0x7fff0000LL * 0x1000 ) ;
return errno ! = 0 ;
}