File: fail40-frag.c

package info (click to toggle)
ghdl 0.26%2Bsvn98%2Bgcc4.1.2~dfsg-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 93,808 kB
  • ctags: 63,866
  • sloc: ansic: 645,601; ada: 91,832; makefile: 36,755; asm: 23,240; sh: 16,722; cpp: 3,121; perl: 685; yacc: 593; lex: 589; awk: 586; exp: 526; pascal: 86; lisp: 59
file content (56 lines) | stat: -rw-r--r-- 1,759 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Test proper lookup-uncaching of large objects */
#include "../config.h"

#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif

int main ()
{
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
#ifdef HAVE_MMAP
  volatile unsigned char *p;
  unsigned num = getpagesize ();
  unsigned i;
  int rc;

  /* Get a bit of usable address space.  We really want an 2**N+1-sized object,
     so the low/high addresses wrap when hashed into the lookup cache.  So we
     will manually unregister the entire mmap, then re-register a slice.  */
  p = mmap (NULL, num, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
  if (p == NULL)
    return 1;
  /* Now unregister it, as if munmap was called.  But don't actually munmap, so
     we can write into the memory.  */
  __mf_unregister ((void *) p, num, __MF_TYPE_HEAP_I);

  /* Now register it under a slightly inflated, 2**N+1 size.  */
  __mf_register ((void *) p, num+1, __MF_TYPE_HEAP_I, "fake mmap registration");

  /* Traverse array to ensure that entire lookup cache is made to point at it.  */
  for (i=0; i<num; i++)
    p[i] = 0;

  /* Unregister it.  This should clear the entire lookup cache, even though
     hash(low) == hash (high)  (and probably == 0) */
  __mf_unregister ((void *) p, num+1, __MF_TYPE_HEAP_I);

  /* Now touch the middle portion of the ex-array.  If the lookup cache was
     well and truly cleaned, then this access should trap.  */
  p[num/2] = 1;

  return 0;
#else
  return 1;
#endif
}
/* { dg-output "mudflap violation 1.*check/write.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap dead object.*fake mmap registration.*" } */
/* { dg-do run { xfail *-*-* } } */