Re: Detecting OS loader lock
- From: "Christian Kaiser" <bchk@xxxxxx>
- Date: Fri, 12 Oct 2007 09:21:46 +0200
While this is nice in theory, it might not be always applicable.
We just faced a problem with multiple threads and a loader lock. One thread
did end, releasing a DLL (not from us) as a side effect (which means getting
the loader lock). Inside this THREAD_DETACH, the DLL called
GetProcAddress(), which in turn did trigger a DLL of ours, which in turn
tried to aquired a CriticalSection internally (which protects a list of
modules). This is because we need own skinning and we need to catch
GetProcAddress() calls.
Not the other thread did aquire the CriticalSection and did try to get the
module's handle (GetModuleHandle(), innocent enough), which internally tries
to get the loader lock.
Duh. Deadlock.
Knowing the loader lock we'd know we max not call some system APIs.
We have a workaround for this special case, but this just works around this
special case.
And the morale of the story: while it's fine to say that the loader lock is
none of our business, and we should stay clear to any of these issues
internally, we cannot rely on other DLLs to behave the same way, so we (as
developers) should be able to check that lock to avoid the chances of
deadlocks due to interoperability! Especially not in multithreaded
environments.
If this were that easy, why was "TryEnterCriticalSection" ever programmed?
For the same reason it would be very nice (yet years too late!) to either
get the loader lock's state, or a "try" version of critical APIs like
GetModuleHandle().
Christian
""Jeffrey Tan[MSFT]"" <jetan@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:nZcZyrHDIHA.5712@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi Christoph,
Internally, OS loader lock is maintained in the PEB. But, we should not
look at the loader lock value in the PEB, not even for debugging purposes,
and especially not in libraries which might be reused.
In general, making any assumptions about undocumented system state is a
recipe for app compat problems down the line.
The recommended way is using AppVerifier. AppVerifier has checks that make
sure DLLs aren't doing anything wrong in DllMain. I think you can also run
with these checks on when running from Visual Studio with AppVerifier.
There's also a whitepaper on DLL best practices at
http://download.microsoft.com/download/a/f/7/af7777e5-7dcd-4800-8a0a-b183365
65f5b/DLL_bestprac.doc.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
.
- Follow-Ups:
- Re: Detecting OS loader lock
- From: Christoph Lindemann
- Re: Detecting OS loader lock
- References:
- Detecting OS loader lock
- From: Christoph Lindemann
- RE: Detecting OS loader lock
- From: "Jeffrey Tan[MSFT]"
- Detecting OS loader lock
- Prev by Date: Interacting with winlogon Desktop of Windows Vista
- Next by Date: RE: Windows 2003 Server throughput vs. Windows XP
- Previous by thread: RE: Detecting OS loader lock
- Next by thread: Re: Detecting OS loader lock
- Index(es):
Relevant Pages
|