<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The NT DLL Loader: DLL_PROCESS_ATTACH reentrancy - step 1 - LoadLibrary()</title><link>http://blogs.msdn.com/mgrier/archive/2005/06/22/431674.aspx</link><description>So what happens if you call back into the loader when you're inside a loader callout (DllMain) for DLL_PROCESS_ATTACH? I'll be addressing teardown (DLL_PROCESS_DETACH) after completing the DLL_PROCESS_ATTACH series. The first issue is: what about LoadLibrary()?</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: The NT DLL Loader: DLL_PROCESS_ATTACH reentrancy - step 1 - LoadLibrary()</title><link>http://blogs.msdn.com/mgrier/archive/2005/06/22/431674.aspx#431878</link><pubDate>Thu, 23 Jun 2005 16:09:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:431878</guid><dc:creator>Wound</dc:creator><description>The question then is: what does LoadLibrary return if the library hasn't actually been loaded, and what are you calling GetProcAddress on? In your example I would expect GetProcAddress to fail, but DllMain to return TRUE, even though &amp;quot;SomeFunction&amp;quot; was not called.</description></item><item><title>re: The NT DLL Loader: DLL_PROCESS_ATTACH reentrancy - step 1 - LoadLibrary()</title><link>http://blogs.msdn.com/mgrier/archive/2005/06/22/431674.aspx#431889</link><pubDate>Thu, 23 Jun 2005 16:49:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:431889</guid><dc:creator>Graham Harper</dc:creator><description>I would expect the library has been mapped into the virtual address space of the process and you do get a valid base address back as indicated by the HMODULE. That doesn't mean the module has been initialized however.&lt;br&gt;&lt;br&gt;It’s funny because GetProcAddress's contract with the caller is only that of providing an address into the module from a symbolic name. It can't (and won't) guarantee the module is in a suitable state to run the method pointed to.&lt;br&gt;&lt;br&gt;But i could be wrong.........</description></item><item><title>re: The NT DLL Loader: DLL_PROCESS_ATTACH reentrancy - step 1 - LoadLibrary()</title><link>http://blogs.msdn.com/mgrier/archive/2005/06/22/431674.aspx#432051</link><pubDate>Fri, 24 Jun 2005 01:58:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:432051</guid><dc:creator>mgrier</dc:creator><description>Sorry, Graham, you were in fact wrong.  I do say &amp;quot;implied&amp;quot; because that's what it happens to do and also because if it didn't run the initializers in the &amp;quot;simple&amp;quot; cases, using the pointer you got back from GetProcAddress() wouldn't be useful anyways.&lt;br&gt;&lt;br&gt;Eventually I'm going to get to recommendations of what to do in your DLL_PROCESS_ATTACH (basically nothing!) and how to live with the consequences.</description></item><item><title>re: The NT DLL Loader: DLL_PROCESS_ATTACH reentrancy - step 1 - LoadLibrary()</title><link>http://blogs.msdn.com/mgrier/archive/2005/06/22/431674.aspx#432163</link><pubDate>Fri, 24 Jun 2005 10:13:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:432163</guid><dc:creator>Graham Harper</dc:creator><description>Sorry I was being really thick!&lt;br&gt;&lt;br&gt;What your saying makes an awful lot of sense now. &lt;br&gt;&lt;br&gt;It effectivley becomes Just-In-Time initialization of the module as LoadLibrary cannot always guarentee intialization of the target and it's dependencies?&lt;br&gt;&lt;br&gt;If A.DLL calls the LoadLibrary\GetProcAddress pair on B.DLL, which in turn has a static dependency on A.DLL (unbeknown to it) the loader isn't going reinitialize A.DLL again because it's already in the tables and is currently being initialized. B.DLL will be initialized (because that’s what GetProcAddress implicitly guarantees?) and any subsequent call on the returned pointer into B.DLL could &amp;quot;end in tears&amp;quot; as we're still sitting in the initialization section of one of the modules on which B.DLL depends. Is this correct?</description></item><item><title>re: The NT DLL Loader: DLL_PROCESS_ATTACH reentrancy - step 1 - LoadLibrary()</title><link>http://blogs.msdn.com/mgrier/archive/2005/06/22/431674.aspx#432277</link><pubDate>Fri, 24 Jun 2005 18:16:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:432277</guid><dc:creator>mgrier</dc:creator><description>Graham, the loader is smart enough to not try to run A's initializer again but as you point out that doesn't mean that B's initializer will actually work.  Now you might think B was smart enough about this, but also all of B's static imports have to be smart about how they call into A.&lt;br&gt;&lt;br&gt;Now you need dynamic global analysis in order to predict whether you have any bugs.  Sounds like a recipe for failure to me...</description></item><item><title>re: The NT DLL Loader: DLL_PROCESS_ATTACH reentrancy - step 1 - LoadLibrary()</title><link>http://blogs.msdn.com/mgrier/archive/2005/06/22/431674.aspx#433304</link><pubDate>Tue, 28 Jun 2005 14:54:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:433304</guid><dc:creator>Richard</dc:creator><description>I note that the DllMain documentation on MSDN (July 05 edition) explicitly says that DllMain must not call LoadLibrary or LoadLibraryEx.</description></item><item><title>Laden einer DLL innerhalb einer anderen DLL | hilpers</title><link>http://blogs.msdn.com/mgrier/archive/2005/06/22/431674.aspx#9347295</link><pubDate>Tue, 20 Jan 2009 17:21:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9347295</guid><dc:creator>Laden einer DLL innerhalb einer anderen DLL | hilpers</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.hilpers.com/954660-laden-einer-dll-innerhalb-einer"&gt;http://www.hilpers.com/954660-laden-einer-dll-innerhalb-einer&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>