TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Herbert Rosenau
from: Jonathan de Boyne Pollard
date: 1998-09-28 09:46:28
subject: How do DLLs load and unload ?

JdBP>> How are DLLs loaded and unloaded ?  In particular, how does OS/2
 JdBP>> Warp keep track of which DLL_InitTerm functions it needs to call
 JdBP>> when executing DosFreeModule ?

 HR> It's no question!

Actually, it was quite a lot of questions.  But from the replies that you
gave me, I suspect that you didn't understand any of them.  I already know
that a module only has the one InitTerm function.  I already know what
parameters it takes.  I already know how dynamic linking resolves
inter-module fixups when a module is loaded (actually it defers doing this
until a page fault requires it).  I wasn't asking about any of that.  

I was asking Denis about, essentially, how the module table is managed
during a load and unload of a module, and how OS/2 solves the
chicken-and-egg problem in DosFreeModule of not knowing what InitTerm
functions to call until it has traversed the module graph and updated the
reference counts, but not being able to traverse the module graph, update
reference counts, and unmap modules from the process' address space until
it has called the InitTerm functions.

 JdBP>> It seems to me that there is a chicken-and-egg problem here.  It
 JdBP>> cannot know which InitTerm functions to call before it starts
 JdBP>> unloading modules from the address space, but it cannot unload the
 JdBP>> modules from the address space since they must remain mapped so
 JdBP>> that their InitTerm functions can be called.  How does OS/2 solve
 JdBP>> this ?

 HR> Each DLL can only have ONE InitTerm - the linker can't handle more
 HR> than one function with the same name.

That reply is a /non sequitur/.

 JdBP>> If you are about to tell me that OS/2 uses callbacks into ring 3
 JdBP>> from ring 0 in order to call the InitTerm functions, how does it
 JdBP>> *return* from those callbacks into ring 0 ?

 HR> What the problem?

If you don't know what the problem is here, then I suggest that you read a
bit about x86 programming.  A return instruction cannot transfer from a
lower privilege ring to a higher privilege ring.  Calling ring 3 from ring
0 necessitates that some magic be performed when the ring 3 code returns. 
Usually this involves some sort of trampoline.

 ¯ JdeBP ®

--- FleetStreet 1.19 NR
* Origin: JdeBP's point, using Squish (2:440/4.3)
SEEN-BY: 396/1 632/0 371 633/210 260 267 270 371 635/506 728 639/252 670/218
@PATH: 440/4 255/1 251/25 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.