17 main(int argc
, char *argv
[])
19 #define CHUNKSIZE 8192
22 #define CHUNKS (CHUNKS1+CHUNKS2)
23 #define LARGESIZE 262144
26 #define STARTV 0x90000000
27 char *vaddr
= (char *) STARTV
;
33 for(i
= 0; i
< CHUNKS
; i
++) {
34 v
[i
] = mmap(vaddr
, CHUNKSIZE
, PROT_READ
|PROT_WRITE
, 0,
36 if(v
[i
] == MAP_FAILED
) {
38 fprintf(stderr
, "mmap failed\n");
43 "mmap said 0x%p but i wanted 0x%p\n",
50 #define DEV_ZERO "/dev/zero"
51 if((fd
=open(DEV_ZERO
, O_RDONLY
)) < 0) {
53 fprintf(stderr
, "open failed for %s\n", DEV_ZERO
);
57 #define TOTAL1 (CHUNKS1*CHUNKSIZE)
58 /* Make single read cross region boundary. */
59 if((l
=read(fd
, v
[0], TOTAL1
)) != TOTAL1
) {
60 fprintf(stderr
, "read %d but expected %d\n", l
, TOTAL1
);
64 /* Force single copy to cross region boundary. */
67 t
= v
[CHUNKS1
]+CHUNKSIZE
-2;
68 if((l
=read(fd
, t
, CHUNKSIZE
)) != CHUNKSIZE
) {
69 fprintf(stderr
, "read %d but expected %d\n", l
, CHUNKSIZE
);
74 /* Now start a child to test bogus memory access */
75 if((f
= fork()) == -1) {
83 if(waitpid(f
, &st
, 0) < 0) {
88 fprintf(stderr
, "child not signaled\n");
91 if(WEXITSTATUS(st
) != 0) {
92 fprintf(stderr
, "child exited with nonzero status\n");
96 /* Child performs bogus read */
98 char *buf
= v
[CHUNKS
-1];
100 res
= read(fd
, buf
, LARGESIZE
);
102 fprintf(stderr
, "res %d\n", res
);
105 if(errno
!= EFAULT
) {
106 fprintf(stderr
, "errno %d\n", errno
);