2009-12-09 14:42:33 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2010-07-10 02:24:43 +02:00
|
|
|
#include <errno.h>
|
2009-12-09 14:42:33 +01:00
|
|
|
#include <sys/mman.h>
|
2010-07-10 02:24:43 +02:00
|
|
|
#include <sys/wait.h>
|
2009-12-09 14:42:33 +01:00
|
|
|
|
2013-04-16 18:04:46 +02:00
|
|
|
int max_error = 2;
|
|
|
|
#include "common.h"
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
|
|
|
|
int subtest = 0;
|
|
|
|
|
2009-12-09 14:42:33 +01:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
#define CHUNKSIZE 8192
|
|
|
|
#define CHUNKS1 3
|
|
|
|
#define CHUNKS2 2
|
|
|
|
#define CHUNKS (CHUNKS1+CHUNKS2)
|
2010-09-14 23:31:56 +02:00
|
|
|
#define LARGESIZE 262144
|
2009-12-09 14:42:33 +01:00
|
|
|
int i, fd;
|
|
|
|
char *v[CHUNKS];
|
|
|
|
#define STARTV 0x90000000
|
|
|
|
char *vaddr = (char *) STARTV;
|
|
|
|
ssize_t l;
|
2010-07-10 02:24:43 +02:00
|
|
|
pid_t f;
|
2009-12-09 14:42:33 +01:00
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
start(44);
|
2009-12-09 14:42:33 +01:00
|
|
|
|
|
|
|
for(i = 0; i < CHUNKS; i++) {
|
2011-07-22 12:15:42 +02:00
|
|
|
v[i] = minix_mmap(vaddr, CHUNKSIZE, PROT_READ|PROT_WRITE, 0,
|
|
|
|
-1, 0);
|
2009-12-09 14:42:33 +01:00
|
|
|
if(v[i] == MAP_FAILED) {
|
2011-07-22 12:15:42 +02:00
|
|
|
perror("minix_mmap");
|
|
|
|
fprintf(stderr, "minix_mmap failed\n");
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2009-12-09 14:42:33 +01:00
|
|
|
}
|
|
|
|
if(v[i] != vaddr) {
|
2011-07-22 12:15:42 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"minix_mmap said 0x%p but i wanted 0x%p\n",
|
2009-12-09 14:42:33 +01:00
|
|
|
v[i], vaddr);
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2009-12-09 14:42:33 +01:00
|
|
|
}
|
|
|
|
vaddr += CHUNKSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEV_ZERO "/dev/zero"
|
|
|
|
if((fd=open(DEV_ZERO, O_RDONLY)) < 0) {
|
|
|
|
perror("open");
|
|
|
|
fprintf(stderr, "open failed for %s\n", DEV_ZERO);
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2009-12-09 14:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define TOTAL1 (CHUNKS1*CHUNKSIZE)
|
|
|
|
/* Make single read cross region boundary. */
|
|
|
|
if((l=read(fd, v[0], TOTAL1)) != TOTAL1) {
|
|
|
|
fprintf(stderr, "read %d but expected %d\n", l, TOTAL1);
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2009-12-09 14:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Force single copy to cross region boundary. */
|
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
t = v[CHUNKS1]+CHUNKSIZE-2;
|
|
|
|
if((l=read(fd, t, CHUNKSIZE)) != CHUNKSIZE) {
|
|
|
|
fprintf(stderr, "read %d but expected %d\n", l, CHUNKSIZE);
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2009-12-09 14:42:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-10 02:24:43 +02:00
|
|
|
/* Now start a child to test bogus memory access */
|
|
|
|
if((f = fork()) == -1) {
|
|
|
|
perror("fork");
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2010-07-10 02:24:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(f > 0) {
|
|
|
|
int st;
|
|
|
|
/* Parent waits. */
|
|
|
|
if(waitpid(f, &st, 0) < 0) {
|
|
|
|
perror("waitpid");
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2010-07-10 02:24:43 +02:00
|
|
|
}
|
|
|
|
if(!WIFEXITED(st)) {
|
|
|
|
fprintf(stderr, "child not signaled\n");
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2010-07-10 02:24:43 +02:00
|
|
|
}
|
|
|
|
if(WEXITSTATUS(st) != 0) {
|
|
|
|
fprintf(stderr, "child exited with nonzero status\n");
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2010-07-10 02:24:43 +02:00
|
|
|
}
|
|
|
|
} else {
|
2010-09-14 23:31:56 +02:00
|
|
|
/* Child performs bogus read */
|
2010-07-10 02:24:43 +02:00
|
|
|
int res;
|
|
|
|
char *buf = v[CHUNKS-1];
|
|
|
|
errno = 0;
|
2010-09-14 23:31:56 +02:00
|
|
|
res = read(fd, buf, LARGESIZE);
|
2010-07-10 02:24:43 +02:00
|
|
|
if(res >= 0) {
|
|
|
|
fprintf(stderr, "res %d\n", res);
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2010-07-10 02:24:43 +02:00
|
|
|
}
|
|
|
|
if(errno != EFAULT) {
|
|
|
|
fprintf(stderr, "errno %d\n", errno);
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2010-07-10 02:24:43 +02:00
|
|
|
}
|
2011-12-16 15:45:53 +01:00
|
|
|
return(0);
|
2010-07-10 02:24:43 +02:00
|
|
|
}
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
|
|
|
return(-1);
|
2009-12-09 14:42:33 +01:00
|
|
|
}
|