John_Page
Posts: 1
Joined: Jun. 13, '03,
Status: offline
|
Just found out why our database server crashes on Interix 3 but not on 2.2. Seems MMAP is badly broken. It will happily assign you a pointer it has already assigned or one that overwrites data you already have mapped, see the following.
Anyone else seen this :-(.
memory mappings.
The attached C program demonstrates this as follows.
$ ./testing
MMAPING File #3 size 0x20000 at address 0x7FF80000 - 0x7FFA0000
MMAPING File #4 size 0x10000 at address 0x7FF70000- 0x7FF80000
MMAPING File #5 size 0x1FC00 at address 0x7FF50000 - 0x7FF6FC00
Unmapping 0x10000 bytes at 0x7FF70000
MMAPING File #6 size 0x30000 at address 0x7FF50000 - 0x7FF80000
THis is mapping in 3 files then unmapping the second one and mapping
a fourth. The address assigned to the fourth file is the one already
in use for the third file.
To run this program create 4 files one 128k, one 64k, one 127k and one
192k. The easiest way is with dd
dd if=/dev/zero of=file1 bs=1k count=128
dd if=/dev/zero of=file2 bs=1k count=64
dd if=/dev/zero of=file3 bs=1k count=127
dd if=/dev/zero of=file4 bs=1k count=192
Compile with
gcc testprog.c -o testprog
----------- testprog.c ------
#include <sys/mman.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
struct stat sb;
int size1,size2,size3,size4;
int fno;
unsigned char *ptr1,*ptr3,*ptr2,*ptr4;
// Map the first file
stat(" file1" ,&sb);
fno = open( " file1" , O_RDONLY);
size1 = sb.st_size;
printf(" MMAPING File #%d size 0x%X " ,fno,size1);
ptr1 = mmap( NULL,
size1,
PROT_READ,
MAP_SHARED|MAP_NORESERVE,
fno,
0);
printf (" at address 0x%X - 0x%X \n" ,ptr1,ptr1+size1);
//close(fno);
// Map the Second file
stat(" file2" ,&sb);
fno = open( " file2" , O_RDONLY);
size2 = sb.st_size;
printf(" MMAPING File #%d size 0x%X" ,fno,size2);
ptr2 = mmap( NULL,
size2,
PROT_READ,
MAP_SHARED|MAP_NORESERVE,
fno,
0);
printf (" at address 0x%X- 0x%X \n" ,ptr2,ptr2+size2);
//Map the Third file
stat(" file3" ,&sb);
fno = open( " file3" , O_RDONLY);
size3 = sb.st_size;
printf(" MMAPING File #%d size 0x%X" ,fno,size3);
ptr3 = mmap( NULL,
size3,
PROT_READ,
MAP_SHARED|MAP_NORESERVE,
fno,
0);
printf (" at address 0x%X - 0x%X \n" ,ptr3,ptr3+size3);
//Unmap
printf(" Unmapping 0x%X bytes at 0x%X\n" ,size2,ptr2);
munmap(ptr2,size2);
// Map the first file
stat(" file4" ,&sb);
fno = open( " file4" , O_RDONLY);
size4 = sb.st_size;
printf(" MMAPING File #%d size 0x%X" ,fno,size4);
ptr4 = mmap( NULL,
size4,
PROT_READ,
MAP_SHARED|MAP_NORESERVE,
fno,
0);
printf (" at address 0x%X - 0x%X \n" ,ptr4,ptr4+size4);
}
|