From owner-freebsd-hackers Thu Nov 23 14:38:37 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (Postfix) with ESMTP id C0C7437B4CF for ; Thu, 23 Nov 2000 14:38:34 -0800 (PST) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.9.3/8.9.3) with ESMTP id OAA09619; Thu, 23 Nov 2000 14:38:25 -0800 (PST) (envelope-from jdp@wall.polstra.com) Received: (from jdp@localhost) by vashon.polstra.com (8.11.0/8.11.0) id eANMcOf81020; Thu, 23 Nov 2000 14:38:24 -0800 (PST) (envelope-from jdp) Date: Thu, 23 Nov 2000 14:38:24 -0800 (PST) Message-Id: <200011232238.eANMcOf81020@vashon.polstra.com> To: hackers@freebsd.org From: John Polstra Reply-To: hackers@freebsd.org Cc: Konstantin.Chuguev@dante.org.uk Subject: Re: dlopen() In-Reply-To: <3A1D2BC7.65AB61AA@dante.org.uk> References: <001001c05552$45913f80$0e61bec3@dima> <3A1D1E52.95A9E626@dante.org.uk> <20001123154748.C7746@ringworld.oblivion.bg> <3A1D2BC7.65AB61AA@dante.org.uk> Organization: Polstra & Co., Seattle, WA Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article <3A1D2BC7.65AB61AA@dante.org.uk>, Konstantin Chuguev wrote: > Peter Pentchev wrote: > > > So the original poster's question is better translated as 'does the dynamic > > loader ever close and reopen a file after the initial loading, so it could > > accidentally open the new version of the library and use the old addresses'? > > > > I'd guess the answer is 'no' - the dynamic loader most probably opens > > the file once, and mmap()'s the needed functions; I might very well be wrong > > though. > > > > This is how I think it works (don't have any FreeBSD box nearby): > For all dynamically loaded modules: > dlopen() opens the file (gets a file descriptor) and mmaps it (possibly > excluding the debug and some other sections). dlclose() unmaps and closes it. Not quite. The dynamic linker opens the file, mmaps it, and closes it immediately. A mapping created by mmap endures even after you close the underlying file. I assume (but have not tested) that it is OK to remove the file after the dlopen call. The file is still mmapped, so I don't think the underlying storage will go away. John -- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Disappointment is a good sign of basic intelligence." -- Chögyam Trungpa To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message