delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1999/10/24/22:22:54

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-developers-unsubscribe-archive-cygwin-developers=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
From: Chris Faylor <cgf AT cygnus DOT com>
Date: Sun, 24 Oct 1999 22:25:16 -0400
To: cygwin-developers AT sourceware DOT cygnus DOT com
Subject: Loading a DLL after a fork is "fixed"
Message-ID: <19991024222516.A10213@cygnus.com>
Mail-Followup-To: cygwin-developers AT sourceware DOT cygnus DOT com
Mime-Version: 1.0
X-Mailer: Mutt 0.95.6i

I've just posted a message to the cygwin mailing list indicating that
I've worked around the long-standing problem with loading DLLs in a
forked process.

Formerly, cygwin was able to load DLLs in a forked process only if the
DLLs were loaded into the DLL's specified base address.  That means if
two DLLs attempted to load to the same base address cygwin would blow up
on a fork.

I'm not exactly happy about the way that I had to fix this.  Here's
what I did:

1) Fork, starts a new process

2) "Forked" process does its usual magic, waits for DLL data segment to
    be filled in.  Then it determines if DLLs need to be loaded.

3) If DLLs need to be loaded, call
   LoadLibraryEx (name, NULL, DONT_RESOLVE_DLL_REFERENCES) for each
   name.  If the load address for the library == the parent's load address,
   everything is fine.  Load the library again and unload the previous handle.
   goto 5

4) If the address is different, mark as "reserved" all memory up to the parent DLL's
   load address.  Then attempt the load again.  The DLL should then load at the correct
   address.

5) Loop until no more DLLs

6) Go on about the fork().

As I said, this seems to work but gawd it's kludgy.

I couldn't find any better way to do this in any of my creative DejaNews or Altavista
searches.

If somebody has a better idea on how to do this, let me know.

-chris

- Raw text -


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