DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 4BHGd2iq044717 Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 4BHGd2iq044717 Authentication-Results: delorie.com; dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=yG1NjRne X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1BB8F3858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1734453540; bh=aK0KJRd26YQEYF+AAoMD0ccsLZoVPvJe1KVyARvagA8=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=yG1NjRneWblxU+Hw6K4Dg8ciIxkisG7qlSQoDANUsnj4vSC1XX7xbXEJpHFd87dQe OwYg7D+KlB25L4yk5suE7VRpJBO/KK5xzFr/T8jWFXKuwJ/IP29a1ttNxr2N116zj3 QzYKd58xCOHtCNgUHTTtfC8YVh4Djkm+DQDwVN8A= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13D5E3858D1E Date: Tue, 17 Dec 2024 17:38:35 +0100 To: cygwin AT cygwin DOT com Subject: Re: Atomic mmap replacement Message-ID: Mail-Followup-To: cygwin AT cygwin DOT com References: <66bf4f86-4618-b9a3-3e33-2c240b9204d0 AT cornell DOT edu> <20180219090042 DOT GC3417 AT calimero DOT vinschen DOT de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Corinna Vinschen via Cygwin Reply-To: cygwin AT cygwin DOT com Cc: Corinna Vinschen Content-Type: text/plain; charset="utf-8" Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 4BHGd2iq044717 Hi Ken, On Dec 17 10:34, Ken Brown via Cygwin wrote: > On 12/16/2024 2:58 PM, Ken Brown via Cygwin wrote: > > On 12/16/2024 8:32 AM, Corinna Vinschen via Cygwin wrote: > > > Right now, mmaping with PROT_NONE and then re-mmaping with PROT_WRITE > > > doesn't work.  Cygwin implements PROT_NONE not as MAP_RESERVE, but as > > > MEM_COMMIT with PAGE_NOACCESS.  mmap() doesn't check if the requested > > > pages are already allocated with PAGE_NOACCESS and then succeeds while > > > in fact just changing the page protection.  This is basically what > > > you want.  Right now, you'd have to call mprotect() instead. > > > > > > With anonymous mappings only, this is all just adding a bit of code to > > > mmap() to do what mprotect() does in this case. > > > > [...] > > > > > So only anonymous mappings would be possible, assuming we tweak mmap() > > > to check if the old mapping was anonymous either and then allow to > > > just change the page protection, as if mprotect has been called. > > > > > > And, funny enough, something pretty similar already exists in mmap(). > > > See mmap.cc, line 1051 and the mmap_list::try_map() method.  Right > > > now it only checks if an anonymous mapping has been partially unmapped > > > and can be recycled.  But it could be improved by allowing to recycle > > > the anonymous mapping either way, as long as the new mapping is also > > > anonymous and the SHARED/PRIVATE flags match. > > Thanks!  This looks doable.  I hope to get back to you with a patch in > > the not-too-distant future. > While looking at this, I came across a bug in the use of > mmap_list::try_map(): On success, the recycled pages are given the same > protection they had as part of the original mmap_record instead of the > protection requested in the mmap call. This is done in > mmap_record::map_pages. Thanks for catching! > Would you like a separate patch to fix this, or should I just fix it as part > of the bigger project? Ideally a separate patch. If you see a chance to send it to cygwin-patches this week, we can even merge it into 3.5.5, which I'm planning to release end of this week (after that --> vacation :))) Thanks, Corinna -- 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