#include <stdio.h>
#include <string.h>
#define __USE_GNU
#include <unistd.h>
#include <sys/mman.h>
int main() {
int PAGE_SIZE = getpagesize();
char* m = NULL;
void* temp;
printf("page size = %d\n", PAGE_SIZE);
m = (char*)mmap(0, PAGE_SIZE*3, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
temp = m+PAGE_SIZE*2;
memset(m, '0', PAGE_SIZE);
memset(m+PAGE_SIZE, '1', PAGE_SIZE);
printf("before %c %c\n", m[0], m[PAGE_SIZE]);
mremap(m + PAGE_SIZE, PAGE_SIZE, PAGE_SIZE, MREMAP_FIXED | MREMAP_MAYMOVE, temp);
mremap(m, PAGE_SIZE, PAGE_SIZE, MREMAP_FIXED | MREMAP_MAYMOVE, m+PAGE_SIZE);
mremap(temp, PAGE_SIZE, PAGE_SIZE, MREMAP_FIXED | MREMAP_MAYMOVE, m);
printf("after %c %c\n", m[0], m[PAGE_SIZE]);
return 0;
}