<--- cut here ---->
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
char filename[] = "/tmp/crashLinux";
#define MYMAPSIZE 360448
#define MYPROT PROT_READ | PROT_WRITE
#define MYFLAGS MAP_SHARED
#define MYLEN 40
#define MYLOOP 1000 /* set to -1 to loop forever */
int do_open(char * filename);
void * do_map(int fd);
main()
{
int fd;
void * vp1;
void * vp2;
unsigned char * cp1;
unsigned char * cp2;
unsigned char * p;
mode_t mask;
char buffer[4096];
unsigned int i, j;
mask = umask(0);
fd = do_open(filename);
vp1 = do_map(fd);
write(fd, buffer, MYLEN);
close(fd);
printf("vp1 %p\n", vp1);
fd = do_open(filename);
vp2 = do_map(fd);
printf("vp2 %p\n", vp2);
close(fd);
cp1 = (unsigned char *)vp1;
cp2 = (unsigned char *)vp2;
#ifdef LONG_TEST
p = cp2;
for(j = 0;j< 40; j++)
*p++ = 2;
#endif
for(i = 0; i< MYLOOP; i++) {
#ifdef LONG_TEST
p = cp1;
for(j = 0;j< MYLEN; j++){
if(*p != 2)
printf("bad cp1 %x\n",*cp1);
*p++ = 1;
}
p = cp2;
for(j = 0; j < MYLEN; j++) {
if(*p != 1)
printf("bad cp2 %x\n",*cp2);
*p++ = 2;
}
#else
*cp1 = 1;
if(*cp2 != 1)
printf("bad cp2 %x\n",*cp1);
*cp2 = 2;
if(*cp1 != 2)
printf("bad cp1 %x\n",*cp1);
#endif
}
unlink(filename);
umask(mask);
}
int do_open(char * filename)
{
int fd;
fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
| S_IROTH | S_IWOTH);
if(fd < 0) {
perror("open");
exit(-2);
}
return fd;
}
void * do_map(int fd)
{
void * vp;
vp = mmap(NULL, MYMAPSIZE, MYPROT, MYFLAGS, fd, 0);
if(vp == MAP_FAILED) {
perror("mmap");
exit(-3);
}
return vp;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/