1 /* Test object-spanning accesses.  This is most conveniently done with
2    mmap, thus the config.h specificity here.  */
3 #include "../config.h"
4 
5 #include <unistd.h>
6 #include <string.h>
7 #ifdef HAVE_SYS_MMAN_H
8 #include <sys/mman.h>
9 #endif
10 
11 int main ()
12 {
13 #ifndef MAP_ANONYMOUS
14 #define MAP_ANONYMOUS MAP_ANON
15 #endif
16 #ifdef HAVE_MMAP
17   void *p;
18   unsigned pg = getpagesize ();
19   int rc;
20 
21   p = mmap (NULL, 4 * pg, PROT_READ|PROT_WRITE,
22             MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
23   if (p == NULL)
24     return 1;
25 
26   memset (p, 0, 4*pg);
27   rc = munmap (p, pg);
28   if (rc < 0) return 1;
29   memset (p+pg, 0, 3*pg);
30   rc = munmap (p+pg, pg);
31   if (rc < 0) return 1;
32   memset (p+2*pg, 0, 2*pg);
33   rc = munmap (p+2*pg, pg);
34   if (rc < 0) return 1;
35   memset (p+3*pg, 0, pg);
36   rc = munmap (p+3*pg, pg);
37   if (rc < 0) return 1;
38 #endif
39 
40   return 0;
41 }
42