12 #define MiB(a) ((a)*1024*1024)
14 void err_exit(char *op)
16 fprintf(stderr, "%s: %s\n", op, strerror(errno));
20 int main(int argc, char *argv[])
22 volatile int a __attribute__((__unused__));
23 char *buffer = "HELLO WORLD!";
28 printf("Usage: %s <pmem file>\n", basename(argv[0]));
32 fd = open(argv[1], O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
37 * This allows us to map a huge zero page, and we do it at a non-zero
38 * offset for a little additional testing.
41 ftruncate(fd, MiB(4));
43 data = mmap(NULL, MiB(2), PROT_READ, MAP_SHARED, fd, MiB(2));
46 * This faults in a 2MiB zero page to satisfy the read.
47 * 'a' is volatile so this read doesn't get optimized out.
51 pwrite(fd, buffer, strlen(buffer), MiB(2));
54 * Try and use the mmap to read back the data we just wrote with
55 * pwrite(). If the kernel bug is present the mapping from the 2MiB
56 * zero page will still be intact, and we'll read back zeros instead.
58 if (strncmp(buffer, data, strlen(buffer))) {
59 fprintf(stderr, "strncmp mismatch: '%s' vs '%s'\n", buffer,
64 err = munmap(data, MiB(2));