Revert r135493 & r135463
[official-gcc.git] / libmudflap / testsuite / libmudflap.c / fail40-frag.c
blob610be20554dc8a77ddf0f0f68f4cf1dffeea2238
1 /* Test proper lookup-uncaching of large objects */
2 #include "../config.h"
4 #include <unistd.h>
5 #include <string.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #ifdef HAVE_SYS_MMAN_H
9 #include <sys/mman.h>
10 #endif
12 int main ()
14 #ifndef MAP_ANONYMOUS
15 #define MAP_ANONYMOUS MAP_ANON
16 #endif
17 #ifdef HAVE_MMAP
18 volatile unsigned char *p;
19 unsigned num = getpagesize ();
20 unsigned i;
21 int rc;
23 /* Get a bit of usable address space. We really want an 2**N+1-sized object,
24 so the low/high addresses wrap when hashed into the lookup cache. So we
25 will manually unregister the entire mmap, then re-register a slice. */
26 p = mmap (NULL, num, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
27 if (p == NULL)
28 return 1;
29 /* Now unregister it, as if munmap was called. But don't actually munmap, so
30 we can write into the memory. */
31 __mf_unregister ((void *) p, num, __MF_TYPE_HEAP_I);
33 /* Now register it under a slightly inflated, 2**N+1 size. */
34 __mf_register ((void *) p, num+1, __MF_TYPE_HEAP_I, "fake mmap registration");
36 /* Traverse array to ensure that entire lookup cache is made to point at it. */
37 for (i=0; i<num; i++)
38 p[i] = 0;
40 /* Unregister it. This should clear the entire lookup cache, even though
41 hash(low) == hash (high) (and probably == 0) */
42 __mf_unregister ((void *) p, num+1, __MF_TYPE_HEAP_I);
44 /* Now touch the middle portion of the ex-array. If the lookup cache was
45 well and truly cleaned, then this access should trap. */
46 p[num/2] = 1;
48 return 0;
49 #else
50 return 1;
51 #endif
53 /* { dg-output "mudflap violation 1.*check/write.*" } */
54 /* { dg-output "Nearby object 1.*" } */
55 /* { dg-output "mudflap dead object.*fake mmap registration.*" } */
56 /* { dg-do run { xfail *-*-* } } */