#include #include #include #include #include #include int main(int argc, char **argv) { struct stat stbuf; char *anon, *foo; int fd, i; fd = open(argv[1], O_RDWR); if (fd == -1) return 1; if (fstat(fd, &stbuf) == -1) return 1; anon = mmap(NULL, 10 * 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (anon == MAP_FAILED) return 1; foo = mmap(anon + 4096, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, fd, 0); if (foo == MAP_FAILED) { printf("could not map\n"); return 1; } for (i = 0; i < 10; i++) printf("first byte of page[%d] = 0x%02x\n", i, anon[i * 4096]); munmap(foo, 4096); for (i = 0; i < 10; i++) printf("first byte of page[%d] = 0x%02x\n", i, anon[i * 4096]); munmap(anon, 10 * 4096); close(fd); return 0; }