delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/09/18/05:04:45

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <F536EC3453B2D411AD6100508BAF5F9901FAB3FA@bwga521a.ts.siemens.de>
From: Kandziora Jan <Jan DOT Kandziora AT ts DOT siemens DOT de>
To: "'cygwin AT cygwin DOT com'" <cygwin AT cygwin DOT com>
Subject: 1.3.2-1: mmap and MAP_PRIVATE|MAP_FIXED|MAP_ANON
Date: Tue, 18 Sep 2001 11:02:22 +0200
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019