2 #include "tests/sys_mman.h"
6 static char *mkmap(unsigned sz
)
15 p
= (char *)mmap(0, sz
, PROT_READ
|PROT_WRITE
, MAP_PRIVATE
|MAP_ANONYMOUS
, -1, 0);
17 if (p
== (char *)-1) {
35 np
= mremap(p
, 1024*1024, 256*1024, 0); /* shrink, fixed */
37 perror("mremap(shrink, fixed)");
39 fprintf(stderr
, "shrink, nomove: p=%p np=%p: shrink moved?!\n",
45 np
= mremap(p
, 1024*1024, 256*1024, MREMAP_MAYMOVE
); /* shrink, maymove */
47 perror("mremap(shrink, maymove)");
49 fprintf(stderr
, "shrink, maymove: p=%p np=%p: shrink moved?!\n",
55 np
= mremap(p
, 1024*1024, 2048*1024, 0); /* grow, fixed */
57 perror("mremap(grow, fixed)");
59 fprintf(stderr
, "grow, nomove: p=%p np=%p: shrink moved?!\n",
62 munmap(np
, 2048*1024);
65 np
= mremap(p
, 1024*1024, 2048*1024, MREMAP_MAYMOVE
); /* grow, maymove */
67 perror("mremap(grow, maymove)");
69 fprintf(stderr
, "grow, maymove: p=%p np=%p: shrink moved?!\n",
72 munmap(np
, 2048*1024);
75 munmap(p
+512*1024, 4096);
76 np
= mremap(p
, 512*1024, 1024*1024, 0); /* grow, nomove, constrained */
78 perror("mremap(grow, nomove, constrained)");
80 fprintf(stderr
, "grow, maymove, constrained: p=%p np=%p (managed to grow without moving?!)\n",
83 munmap(np
, 1024*1024);
86 munmap(p
+512*1024, 4096);
88 np
= mremap(p
, 512*1024, 1024*1024, MREMAP_MAYMOVE
); /* grow, maymove, constrained */
90 perror("mremap(grow, maymove, constrained)");
92 fprintf(stderr
, "grow, maymove, constrained: p=%p np=%p (managed to grow without moving?!)\n",
95 munmap(np
, 1024*1024);