From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2201) id 7DFE9384B0C0; Tue, 21 Jul 2020 14:20:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7DFE9384B0C0 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jon TURNEY To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: Don't dump non-writable image regions X-Act-Checkin: newlib-cygwin X-Git-Author: Jon Turney X-Git-Refname: refs/heads/master X-Git-Oldrev: 44103c062166dc66c54ac0640cd4b2ab80d5561e X-Git-Newrev: 35227fec9781dd85ef30257f12b857d58dec1840 Message-Id: <20200721142032.7DFE9384B0C0@sourceware.org> Date: Tue, 21 Jul 2020 14:20:32 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jul 2020 14:20:32 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=35227fec9781dd85ef30257f12b857d58dec1840 commit 35227fec9781dd85ef30257f12b857d58dec1840 Author: Jon Turney Date: Sun Jul 5 14:42:59 2020 +0100 Cygwin: Don't dump non-writable image regions After this, we will end up dumping memory regions where: - state is MEM_COMMIT (i.e. is not MEM_RESERVE or MEM_FREE), and -- type is MEM_PRIVATE and protection allows reads (i.e. not a guardpage), or -- type is MEM_IMAGE and protection allows writes Making this decision based on the current protection isn't 100% correct, because it may have been changed using VirtualProtect(). But we don't know how to determine if a region is shareable. (As a practical matter, anything which gets us the stack (MEM_PRIVATE) and .data/.bss (RW MEM_IMAGE) is going to be enough for 99% of cases) Diff: --- winsup/utils/dumper.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/winsup/utils/dumper.cc b/winsup/utils/dumper.cc index 2a0c66002..b96ee54cc 100644 --- a/winsup/utils/dumper.cc +++ b/winsup/utils/dumper.cc @@ -292,6 +292,12 @@ dumper::collect_memory_sections () int skip_region_p = 0; const char *disposition = "dumped"; + if ((mbi.Type & MEM_IMAGE) && !(mbi.Protect & (PAGE_EXECUTE_READWRITE | PAGE_READWRITE))) + { + skip_region_p = 1; + disposition = "skipped due to non-writeable MEM_IMAGE"; + } + if (mbi.Protect & PAGE_NOACCESS) { skip_region_p = 1;