Created
October 1, 2020 13:20
-
-
Save jlevon/18d9c50d36e6684937e1dc5337110af7 to your computer and use it in GitHub Desktop.
mincore test of memfd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#define _GNU_SOURCE /* See feature_test_macros(7) */ | |
#include <linux/mman.h> | |
#include <sys/mman.h> | |
#include <assert.h> | |
#include <stdio.h> | |
int main(int argc, char *argv[]) | |
{ | |
int fd = memfd_create("test", 0); | |
assert(fd != -1); | |
int rc = ftruncate(fd, 4096 * 256 * 1024); | |
assert(rc == 0); | |
void *addr = mmap(0, 4096 * 256 * 1024, PROT_READ | PROT_WRITE, | |
MAP_PRIVATE, fd, 0); | |
assert(addr != -1); | |
unsigned char in; | |
rc = mincore(addr, 4096, &in); | |
assert (rc == 0); | |
printf("in: %d\n", (int)in); | |
*((char *)addr) = 1; | |
rc = mincore(addr, 4096, &in); | |
assert (rc == 0); | |
printf("in: %d\n", (int)in); | |
} | |
$ ./mincore | |
in: 0 | |
in: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment