Statistics
| Branch: | Revision:

root / tests / cris / check_mmap1.c @ 7b239bec

History | View | Annotate | Download (834 Bytes)

1 dd43edf4 ths
/*
2 dd43edf4 ths
#notarget: cris*-*-elf
3 dd43edf4 ths
*/
4 dd43edf4 ths
5 dd43edf4 ths
#define _GNU_SOURCE
6 dd43edf4 ths
#include <string.h>
7 dd43edf4 ths
#include <stdlib.h>
8 dd43edf4 ths
#include <stdio.h>
9 dd43edf4 ths
#include <sys/types.h>
10 dd43edf4 ths
#include <sys/stat.h>
11 dd43edf4 ths
#include <fcntl.h>
12 dd43edf4 ths
#include <unistd.h>
13 dd43edf4 ths
#include <sys/mman.h>
14 dd43edf4 ths
15 dd43edf4 ths
int main (int argc, char *argv[])
16 dd43edf4 ths
{
17 dd43edf4 ths
  int fd = open (argv[0], O_RDONLY);
18 dd43edf4 ths
  struct stat sb;
19 dd43edf4 ths
  int size;
20 dd43edf4 ths
  void *a;
21 dd43edf4 ths
  const char *str = "a string you'll only find in the program";
22 dd43edf4 ths
23 dd43edf4 ths
  if (fd == -1)
24 dd43edf4 ths
    {
25 dd43edf4 ths
      perror ("open");
26 dd43edf4 ths
      abort ();
27 dd43edf4 ths
    }
28 dd43edf4 ths
29 dd43edf4 ths
  if (fstat (fd, &sb) < 0)
30 dd43edf4 ths
    {
31 dd43edf4 ths
      perror ("fstat");
32 dd43edf4 ths
      abort ();
33 dd43edf4 ths
    }
34 dd43edf4 ths
35 dd43edf4 ths
  size = sb.st_size;
36 dd43edf4 ths
37 dd43edf4 ths
  /* We want to test mmapping a size that isn't exactly a page.  */
38 dd43edf4 ths
  if ((size & 8191) == 0)
39 dd43edf4 ths
    size--;
40 dd43edf4 ths
41 dd43edf4 ths
  a = mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
42 dd43edf4 ths
43 dd43edf4 ths
  if (memmem (a, size, str, strlen (str) + 1) == NULL)
44 dd43edf4 ths
    abort ();
45 dd43edf4 ths
46 dd43edf4 ths
  printf ("pass\n");
47 dd43edf4 ths
  exit (0);
48 dd43edf4 ths
}