From owner-freebsd-arch Tue Feb 4 11:13:36 2003 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6163A37B6F9; Tue, 4 Feb 2003 11:13:34 -0800 (PST) Received: from bluejay.mail.pas.earthlink.net (bluejay.mail.pas.earthlink.net [207.217.120.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6301843F85; Tue, 4 Feb 2003 11:13:33 -0800 (PST) (envelope-from tlambert2@mindspring.com) Received: from pool0327.cvx21-bradley.dialup.earthlink.net ([209.179.193.72] helo=mindspring.com) by bluejay.mail.pas.earthlink.net with asmtp (SSLv3:RC4-MD5:128) (Exim 3.33 #1) id 18g8Vd-0000Gk-00; Tue, 04 Feb 2003 11:13:30 -0800 Message-ID: <3E401082.6C6512F8@mindspring.com> Date: Tue, 04 Feb 2003 11:12:02 -0800 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Mikhail Teterin Cc: arch@FreeBSD.org, Alfred Perlstein , Wes Peters , Mario Sergio Fujikawa Ferreira Subject: Re: dlclose() vs. atexit() References: <200302030506.h1356Nha011918@repoman.freebsd.org> <1044319099.358.57.camel@zaphod.softweyr.com> <20030204082625.GB85104@elvis.mu.org> <200302041046.13767.mi+mx@aldan.algebra.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-ELNK-Trace: b1a02af9316fbb217a47c185c03b154d40683398e744b8a4a9111c3053963c55c9b0d9bca052c179350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Mikhail Teterin wrote: > Last time I brought this up, it was not clear, what The Right Thing to > do is. Are these details mandatated by some standard out there, or is > everyone on their own, and we should, indeed, do what Linux does, to not > increase the enthropy? > > Should, for example, exit handlers, which will still be valid after the > dlclose() still be called at dlclose() or at the actual exit()? How > about atexit() calls made between dlopen() and dlclose(), and not by the > library but by the application, or by another library? Have each library > get its own list of exit-handlers? > > Or should it still be a global list, but examined by both dlclose() > and exit() -- if an item on the list is about to become invalid after > dlclose() (how can we know, BTW?), have dlclose() call it -- otherwise, > leave it alone? FWIW, the way Windows handles this is to have various entry point to manage this: ProcessAttach Called after a process attaches to a shared object ProcessDetach Called before a process detaches a shared object ThreadAttach Called after a thread attaches to a shared object ThreadDetach Called before a thread detaches a shared object The key here is that all processes have at least one thread. These are really the entry points, not the atexit(), that should be used. Right now, FreeBSD can at least do the Process[Attach|Detach] for dlopen'ed objects, by abusing the .init and .fini sections, and/or abusing the .ctor and .dtor sections. Probably, this is the correct approach, overall, but requires some small mod to crt*.c to make it entirely happy (declaring multiple .init/.fini sections displaces, rather than aggregating them, as only the first entry in the linker set is invoked, not the whole list, and using the .ctor/.dtor approach requires using the C++ crt*.c in the C case). I've actually posted code to abuse .init/.fini to this list in the past, a part of creating a static libdlopen. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message