10 /* first find free segment of 40K, then unmap it */
11 void *initial_area
= mmap((void *)0x10000000, 40960, PROT_READ
|PROT_WRITE
,
12 MAP_ANONYMOUS
|MAP_PRIVATE
,0,0);
14 if (initial_area
== MAP_FAILED
)
15 perror ("initial area");
16 printf("initial_area= %p\n", initial_area
);
17 if (munmap(initial_area
, 40960) != 0)
18 perror ("munmap initial_area");
20 /* remap the same segment, but with 4K size */
21 void *area
= mmap(initial_area
, 4096, PROT_READ
|PROT_WRITE
,
22 MAP_ANONYMOUS
|MAP_PRIVATE
,0,0);
23 if (area
== MAP_FAILED
)
25 if (area
!= initial_area
)
26 printf("FAILED : was expecting to get back the initial_area\n");
27 printf("area= %p\n", area
);
28 strcpy(area
, "Hello World");
30 /* extend it to 40K */
31 void *a2
= mremap(area
, 4096, 40960, 0);
32 if (a2
== MAP_FAILED
) {
35 if (a2
!= initial_area
)
36 printf("FAILED : was expecting to get back the same area increased\n");
37 printf("increased area= %p\n", a2
);
38 printf("%s\n", (char *)a2
);