blob: 95561365a53d0c1509c4a2ef7591a3addf6cb22e (
plain) (
blame)
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
57
58
59
60
61
62
63
|
#!/bin/sh
# Test scenario by Michiel Boland <michiel@boland.org>
# panic: pmap_remove_all: page 0xc491f000 is fictitious
[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
. ../default.cfg
odir=`pwd`
cd /tmp
sed '1,/^EOF/d' < $odir/$0 > mmap.c
mycc -o mmap -Wall mmap.c
rm -f mmap.c
./mmap
rm -f ./mmap
exit
EOF
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
static const off_t map_address = 0xa0000;
static const size_t map_size = 0x1000;
static int testit(int fd)
{
void *p;
int rv;
p = mmap(NULL, 2 * map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
map_address);
if (p == MAP_FAILED) {
perror("mmap");
return -1;
}
rv = *(char *) p;
if (munmap(p, map_size) == -1) {
perror("munmap");
return -1;
}
return rv;
}
int main(void)
{
int fd, rv;
fd = open("/dev/mem", O_RDWR);
if (fd == -1) {
perror("open");
return 1;
}
rv = testit(fd);
close(fd);
return rv;
}
|