* Re: 1.3.2-1: mmap and MAP_PRIVATE|MAP_FIXED|MAP_ANON
@ 2001-09-18 23:29 Kandziora Jan
0 siblings, 0 replies; 3+ messages in thread
From: Kandziora Jan @ 2001-09-18 23:29 UTC (permalink / raw)
To: 'Corinna Vinschen'
>
> > You are right. But it does *not* return MAP_FAILED, it returns
0x60001000,
> > which is a valid address.
>
> Ok, I figured out what's going wrong. A fix will be in the next
> developers snapshot.
>
For all you who are interested: I was able to walk around this problem by
using a disk file for each area and mmap that file with
MAP_PRIVATE|MAP_FIXED, avoiding MAP_ANON. The disk file must be at least as
long as requested in the following mmap call, though; But that can be done
easily by creating, lseeking, writing and immediately unlinking it from
within the program.
Jan
--
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: 1.3.2-1: mmap and MAP_PRIVATE|MAP_FIXED|MAP_ANON
2001-09-18 2:03 Kandziora Jan
@ 2001-09-18 2:27 ` Corinna Vinschen
0 siblings, 0 replies; 3+ messages in thread
From: Corinna Vinschen @ 2001-09-18 2:27 UTC (permalink / raw)
To: 'cygwin@cygwin.com'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1553 bytes --]
On Tue, Sep 18, 2001 at 11:02:22AM +0200, Kandziora Jan wrote:
> if ((buf2=mmap((void*)0x70000000,1,
>
> PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,0,0))==NULL)
^^^^
Hmm!
$ man mmap
[...]
RETURN VALUE
On success, mmap returns a pointer to the mapped area. On
error, MAP_FAILED (-1) is returned, and errno is set
appropriately...
> Is it impossible with windows to mmap a couple of anonymous areas anywhere I
> want and no memory is already mapped?
More or less. Windows is somewhat bulky in giving you the area
you want. However:
$ man mmap
[...]
MAP_FIXED Do not select a different address than the one
specified. If the specified address cannot be
used, mmap will fail. If MAP_FIXED is speciÂ
fied, start must be a multiple of the pagesize.
Use of this option is discouraged.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note that. A normal application should have no
need ever to desire a specific address.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Developer mailto:cygwin@cygwin.com
Red Hat, Inc.
--
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
* 1.3.2-1: mmap and MAP_PRIVATE|MAP_FIXED|MAP_ANON
@ 2001-09-18 2:03 Kandziora Jan
2001-09-18 2:27 ` Corinna Vinschen
0 siblings, 1 reply; 3+ messages in thread
From: Kandziora Jan @ 2001-09-18 2:03 UTC (permalink / raw)
To: 'cygwin@cygwin.com'
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-09-18 23:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-18 23:29 1.3.2-1: mmap and MAP_PRIVATE|MAP_FIXED|MAP_ANON Kandziora Jan
-- strict thread matches above, loose matches on Subject: below --
2001-09-18 2:03 Kandziora Jan
2001-09-18 2:27 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).