X-Recipient: archive-cygwin@delorie.com
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 375E63858D28
Authentication-Results: sourceware.org;
 dmarc=none (p=none dis=none) header.from=gluelogic.com
Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gluelogic.com
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-Spam-Language: en
X-Spam-Relay-Country: 
X-Spam-DCC: B=; R=smtp1.atof.net 1202; Body=1 Fuz1=1 Fuz2=1
X-Spam-RBL: 
X-Spam-PYZOR: Reported 0 times.
Date: Fri, 1 Jul 2022 12:45:31 -0400
From: gs-cygwin.com@gluelogic.com
To: David Allsopp <David.Allsopp@cl.cam.ac.uk>
Subject: Re: mmap failing with MAP_FIXED
Message-ID: <Yr8kqyUZXlFToSn8@xps13>
References: <000001d88d68$4d5a7a40$e80f6ec0$@cl.cam.ac.uk>
Mime-Version: 1.0
Content-Disposition: inline
In-Reply-To: <000001d88d68$4d5a7a40$e80f6ec0$@cl.cam.ac.uk>
X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS,
 SPF_HELO_NONE, SPF_PASS, TXREP,
 T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Cc: cygwin@cygwin.com
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

On Fri, Jul 01, 2022 at 05:33:31PM +0100, David Allsopp wrote:
> 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?

Have you tried 'msync()' with MS_ASYNC flag as an alternative approach?

Cheers, Glenn

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