delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/03/26/13:11:03

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:from:subject:to:message-id:date:mime-version
:content-type; q=dns; s=default; b=I/PP8jrIG0uAZgKmxfDsOy+C94R0I
w+NMtOyKQJGEjc9VO55UPg0/xvkZxO4ECccR3l2RBrbdgO3n05vqS+QA5hZumeZB
ybn63xqfrp7foOnfrlGvGh3rUVjt1wbu/R3ktPDHF0GOo82cnhYccEF4S56HF72o
aJ0ujIwfcDg8zQ=
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:from:subject:to:message-id:date:mime-version
:content-type; s=default; bh=D4ryGRYHeEZRe8JbQdUCDDXIq74=; b=dFT
P6OqaYvmgFJV/RokboXI2R2pXcG8GYr6gfDtziUogBoxCIbn3G9iBCK5LsimzlOo
Ey/2i8z/T+adugJrv7lA5KiF0Q9gvhCYGLhli5niczP92znAIbg9ZdZOJfbW2YZG
+KOERYtGjRJZYVftg8R4GUGwbOIFfZa5WrEnBBBw=
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-Spam-SWARE-Status: No, score=-14.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=sk:michael, HX-Envelope-From:sk:michael, chances, exploit
X-HELO: atfriesa01.ssi-schaefer.com
From: Michael Haubenwallner <michael DOT haubenwallner AT ssi-schaefer DOT com>
Subject: [PATCH RFC] fork: reduce chances for "address space is already occupied" errors
To: cygwin AT cygwin DOT com
Message-ID: <8c77b589-fcae-fd0d-f5c5-c2520cfebbfa@ssi-schaefer.com>
Date: Tue, 26 Mar 2019 18:10:45 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1
MIME-Version: 1.0

--------------33DD318DDF3AB8748DE0C42F
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

Hi Corinna,

as I do still encounter fork errors (address space needed by <dll> is already occupied)
with dynamically loaded dlls (but unrelated to replaced dlls), one of them repeating
even upon multiple retries, I'm coming up with attached patch.

What do you think about it?

Thanks!
/haubi/

--------------33DD318DDF3AB8748DE0C42F
Content-Type: text/x-patch;
 name="0001-Cygwin-fork-reserve-dynloaded-dll-areas-earlier.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0001-Cygwin-fork-reserve-dynloaded-dll-areas-earlier.patch"

From dfc28bcbb7ed55fe33ddb8d15e761b4d5b4815f8 Mon Sep 17 00:00:00 2001
From: Michael Haubenwallner <michael DOT haubenwallner AT ssi-schaefer DOT com>
Date: Tue, 26 Mar 2019 17:38:36 +0100
Subject: [PATCH] Cygwin: fork: reserve dynloaded dll areas earlier

In dll_crt0_0, both threadinterface->Init and sigproc_init allocate
windows object handles using unpredictable memory regions, which may
collide with dynamically loaded dlls when they were relocated.
---
 winsup/cygwin/dcrt0.cc | 6 ++++++
 winsup/cygwin/fork.cc  | 6 ------
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 11edcdf0d..fb726a739 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -632,6 +632,12 @@ child_info_fork::handle_fork ()
 
   if (fixup_mmaps_after_fork (parent))
     api_fatal ("recreate_mmaps_after_fork_failed");
+
+  /* We need to occupy the address space for dynamically loaded dlls
+     before we allocate any dynamic object, or we may end up with
+     error "address space needed by <dll> is already occupied"
+     for no good reason (seen with some relocated dll). */
+  dlls.reserve_space ();
 }
 
 bool
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 74ee9acf4..7e1c08990 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -136,12 +136,6 @@ frok::child (volatile char * volatile here)
 {
   HANDLE& hParent = ch.parent;
 
-  /* NOTE: Logically this belongs in dll_list::load_after_fork, but by
-     doing it here, before the first sync_with_parent, we can exploit
-     the existing retry mechanism in hopes of getting a more favorable
-     address space layout next time. */
-  dlls.reserve_space ();
-
   sync_with_parent ("after longjmp", true);
   debug_printf ("child is running.  pid %d, ppid %d, stack here %p",
 		myself->pid, myself->ppid, __builtin_frame_address (0));
-- 
2.17.0



--------------33DD318DDF3AB8748DE0C42F
Content-Type: text/plain; charset=us-ascii


--
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
--------------33DD318DDF3AB8748DE0C42F--

- Raw text -


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