Hello,

I got a problem using mmap with MAP_PRIVATE|MAP_FIXED|MAP_ANON several times
in a program. It does not reserve the desired address range the second time
I call it, neither it returns an error. The test case is:

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char* argv[])
{
        int   fd1;
        void *buf1;
        void *buf2;

/*
        if ((fd1=open("file1",O_RDWR))<0)
        {
                perror("f1");
                exit(EXIT_FAILURE);
        }
*/

        if ((buf1=mmap((void*)0x60000000,1,
        
PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,0,0))==NULL)
//              PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,fd1,0))==NULL)
        {
                perror("m1");
                exit(EXIT_FAILURE);
        }

        if ((buf2=mmap((void*)0x70000000,1,
        
PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,0,0))==NULL)
        {
                perror("m2");
                exit(EXIT_FAILURE);
        }


        printf("buf1: %p\n",buf1);
        printf("buf2: %p\n",buf2);

        return 0;
}

The program prints
        buf1: 0x60000000
        buf2: 0x60001000
and not as desired 
        buf1: 0x60000000
        buf2: 0x70000000

Moreover, I get the desired output and can use the mapped memory if I do not
use MAP_ANON with the first mmap.

Is it impossible with windows to mmap a couple of anonymous areas anywhere I
want and no memory is already mapped?
At least cygwin should return an error if the desired address and the
address returned by the windows system call do not match and MAP_FIXED is
returned. That problem was not easy to find.

My system:

WinNT Ver 4.0 build 1381 Service Pack 6
   Cygwin DLL version info:
        dll major: 1003
        dll minor: 2
        dll epoch: 19
        dll bad signal mask: 19005
        dll old termios: 5
        dll malloc env: 28
        api major: 0
        api minor: 39
        shared data: 3
        dll identifier: cygwin1
       build date: Sun May 20 23:28:17 EDT 2001

Thanks in advance

        Jan Kandziora


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply via email to