public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* mmap failing with MAP_FIXED
@ 2022-07-01 16:33 David Allsopp
  2022-07-01 16:45 ` gs-cygwin.com
  2022-07-04  8:19 ` Corinna Vinschen
  0 siblings, 2 replies; 3+ messages in thread
From: David Allsopp @ 2022-07-01 16:33 UTC (permalink / raw)
  To: cygwin

This program fails at the second mmap call with EINVAL:

  #include <stdio.h>
  #include <sys/mman.h>
  #include <error.h>

  int main (void) {
    void * mem;
    /* Reserve 256MB address space for the minor heaps */
    mem = mmap(0, 268439552, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    if (mem == MAP_FAILED)
      error(1, 0, "Reservation failed");
    /* Commit the first 2MB heap */
    if (mmap(mem, 2097152, PROT_READ | PROT_WRITE, MAP_PRIVATE |
MAP_ANONYMOUS | MAP_FIXED, -1, 0) == MAP_FAILED)
      error(1, 0, "Commit failed");
  }

Is this something that's expected to fail for Cygwin, or a bug? The example
is extracted from OCaml 5.0's runtime, which reserves an area of address
space and then commits chunks of it as required. The above snippet comes
from the Linux side, on Windows we're using VirtualAlloc with PAGE_NOACCESS
to reserve the address space and then VirtualAlloc with MEM_COMMIT and
PAGE_READWRITE to commit smaller portions of it.

Is there a way to do that with Cygwin's mmap?

Thanks,


David


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-04  8:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01 16:33 mmap failing with MAP_FIXED David Allsopp
2022-07-01 16:45 ` gs-cygwin.com
2022-07-04  8:19 ` 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).