]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/test/stress2/misc/mmap.sh
contrib/bc: update to version 5.1.1
[FreeBSD/FreeBSD.git] / tools / test / stress2 / misc / mmap.sh
1 #!/bin/sh
2
3 # Test scenario by Michiel Boland <michiel@boland.org>
4
5 # panic: pmap_remove_all: page 0xc491f000 is fictitious
6
7 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
8
9 . ../default.cfg
10
11 odir=`pwd`
12 cd /tmp
13 sed '1,/^EOF/d' < $odir/$0 > mmap.c
14 mycc -o mmap -Wall mmap.c
15 rm -f mmap.c
16
17 ./mmap
18 rm -f ./mmap
19 exit
20
21 EOF
22 #include <sys/types.h>
23 #include <sys/mman.h>
24 #include <fcntl.h>
25 #include <stdio.h>
26 #include <unistd.h>
27
28 static const off_t map_address = 0xa0000;
29 static const size_t map_size = 0x1000;
30
31 static int testit(int fd)
32 {
33         void *p;
34         int rv;
35
36         p = mmap(NULL, 2 * map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
37                   map_address);
38         if (p == MAP_FAILED) {
39                 perror("mmap");
40                 return -1;
41         }
42         rv = *(char *) p;
43         if (munmap(p, map_size) == -1) {
44                 perror("munmap");
45                 return -1;
46         }
47         return rv;
48 }
49
50 int main(void)
51 {
52         int fd, rv;
53
54         fd = open("/dev/mem", O_RDWR);
55         if (fd == -1) {
56                 perror("open");
57                 return 1;
58         }
59         rv = testit(fd);
60         close(fd);
61         return rv;
62 }
63