public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "David Allsopp" <David.Allsopp@cl.cam.ac.uk>
To: <cygwin@cygwin.com>
Subject: mmap failing with MAP_FIXED
Date: Fri, 1 Jul 2022 17:33:31 +0100	[thread overview]
Message-ID: <000001d88d68$4d5a7a40$e80f6ec0$@cl.cam.ac.uk> (raw)

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


             reply	other threads:[~2022-07-01 16:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01 16:33 David Allsopp [this message]
2022-07-01 16:45 ` gs-cygwin.com
2022-07-04  8:19 ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000001d88d68$4d5a7a40$e80f6ec0$@cl.cam.ac.uk' \
    --to=david.allsopp@cl.cam.ac.uk \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).