public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Ken Brown <kbrown@cornell.edu>
To: cygwin <cygwin@cygwin.com>
Subject: Atomic mmap replacement
Date: Sun, 18 Feb 2018 03:37:00 -0000	[thread overview]
Message-ID: <66bf4f86-4618-b9a3-3e33-2c240b9204d0@cornell.edu> (raw)

Some code in emacs wants to reserve a chunk of address space with a big 
PROT_NONE anonymous mapping, and then carve it up into separate mappings 
associated to segments of a file.  This fails on Cygwin.  Here's a test 
case that illustrates the problem:

$ truncate -s 64k foo

$ cat mmap_test.c
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>

const size_t page_size = 64 * 1024;

int
main ()
{
   void *mem = mmap (NULL, 2 * page_size,
                     PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   if (mem == MAP_FAILED)
     {
       perror ("mmap");
       exit (1);
     }
   int fd = open ("foo", O_RDONLY);
   void *res = mmap (mem, page_size, PROT_READ | PROT_WRITE,
                     MAP_PRIVATE | MAP_FIXED, fd, 0);
   if (res == MAP_FAILED)
     {
       perror ("mmap");
       exit (2);
     }
}

$ gcc mmap_test.c

$ ./a
mmap: Invalid argument

$ echo $?
2

Is this a bug, or is it simply a limitation of Cygwin's mmap?  If the 
latter, is there a simple workaround?

Ken

P.S. For context, you can start reading here, but it might not make a 
lot of sense:

   https://lists.gnu.org/archive/html/emacs-devel/2018-02/msg00440.html

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

             reply	other threads:[~2018-02-18  3:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-18  3:37 Ken Brown [this message]
2018-02-19  9:01 ` Corinna Vinschen
2018-02-19 13:22   ` Ken Brown
2018-02-19 17:19     ` Corinna Vinschen
2018-02-19 22:33       ` Ken Brown
2018-02-20 10:31         ` Corinna Vinschen
2018-02-20  1:04       ` John Hood
2018-02-20 10:47         ` 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=66bf4f86-4618-b9a3-3e33-2c240b9204d0@cornell.edu \
    --to=kbrown@cornell.edu \
    --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).