1 // Test program which explores whether mmap's ofs parameter
2 // is 64-bit, and whether it needs to be shifted << PAGE_SHIFT.
3 // Apparently it is 64-bit and isn't shifted.
5 // Build: x86_64-gcc -static -Wall -ox32_mmap x32_mmap.c
7 // 7f9390696000-7f93906a6000 r--s 12345670000 08:06 2224545 /etc/passwd
10 #include <sys/types.h>
18 #include <asm/unistd.h>
19 // Ensure we are compiling to 64 bits
20 struct bug { int t[sizeof(long) > 4 ? 1 : -1]; };
21 int main(int argc, char **argv)
23 long ofs = 0x12345670000; // fails if not page-aligned
26 if (open("/etc/passwd", O_RDONLY))
29 (long) (__NR_mmap | 0x40000000), // make x32 call
31 (long) (0x10000), // len
32 (long) (PROT_READ), // prot
33 (long) (MAP_SHARED), // flags
37 printf("ret:0x%lx errno:%m\n", r);
40 sprintf(buf, "/proc/%d/maps", getpid());
41 int fd = open(buf, O_RDONLY);
43 int sz = read(fd, buf, sizeof(buf));