delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/02/17/22:37:21

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:message-id:date:mime-version
:content-type:content-transfer-encoding; q=dns; s=default; b=svi
dFEfe3nqCNKGaIaSURzZn1IggC5E/zgwYtmjEUU3KKIIOEJ5QWH6BJltBwYxN95E
IYf1st3Y/6wYkd9aonuwKl3YBuo2ti3/pFavltnBVUP8agDDKee0/p/eBvteVJTC
Z6/TeOP0DeMfIJdSdUKgGYcAnFmgp5hc9MdEUgTE=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:message-id:date:mime-version
:content-type:content-transfer-encoding; s=default; bh=Qch5AqoiU
8tN0xQ01kx2dIM+34U=; b=qHmCxGZhWr1D3ceG20aaamOEIxVxbooVJeNJz7mnG
r5PFCiXrXXMaGmLZJQq46pEA6eSBnHDvCBJqsxWEUD3mG7Y7mNCXiMDvAqdb69KV
2h/Phsl0tTIZH0YyB2QPkoS17darLg72fzahJY5XGDvbDyaCFR3oYinGfedczVCt
50=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*MI:4618, H*M:4618
X-HELO: limerock02.mail.cornell.edu
X-CornellRouted: This message has been Routed already.
To: cygwin <cygwin AT cygwin DOT com>
From: Ken Brown <kbrown AT cornell DOT edu>
Subject: Atomic mmap replacement
Message-ID: <66bf4f86-4618-b9a3-3e33-2c240b9204d0@cornell.edu>
Date: Sat, 17 Feb 2018 22:37:03 -0500
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0
MIME-Version: 1.0
X-PMX-Cornell-Gauge: Gauge=XXXXX
X-PMX-CORNELL-AUTH-RESULTS: dkim-out=none;
X-IsSubscribed: yes

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

- Raw text -


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