X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY X-Spam-Check-By: sourceware.org X-Yahoo-SMTP: jenXL62swBAWhMTL3wnej93oaS0ClBQOAKs8jbEbx_o- Date: Tue, 15 Mar 2011 16:28:17 -0400 From: Christopher Faylor To: cygwin AT cygwin DOT com Subject: Re: Calling sem_wait() in DllMain( DLL_THREAD_DETACH) crashes Message-ID: <20110315202816.GA8747@ednor.casa.cgf.cx> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <4D7FB133 DOT 7030301 AT dronecode DOT org DOT uk> <20110315190733 DOT GA23825 AT ednor DOT casa DOT cgf DOT cx> <4D7FC59F DOT 6030901 AT cwilson DOT fastmail DOT fm> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4D7FC59F.6030901@cwilson.fastmail.fm> User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On Tue, Mar 15, 2011 at 04:01:35PM -0400, Charles Wilson wrote: >On 3/15/2011 3:07 PM, Christopher Faylor wrote: >> On Tue, Mar 15, 2011 at 06:34:27PM +0000, Jon TURNEY wrote: >>> >>> I've come across a problem whilst trying to run the twisted test suite, where >>> some tests just cause python to segfault. It seems to be the same issue with >>> libcrypto as reported in [2],[3] > >>Actually you aren't supposed to be able to call anything you like here >>and it isn't clear why a POSIX/UNIX/Linux program would be relying on >>DllMain. > >There are cases where cygwin-ish code does win32-ish things, like >login.exe, or the PyWin32 extensions for Python-on-Windows(and cygwin). >Maybe twisty uses PyWin32? The python Twisted stuff works on UNIX systems so there should be no reason to use Windows-isms in Cygwin code - especially when the Windows-ism *calls* UNIX code. The ability to get into trouble when you mix Windows stuff like DllMain with Cygwin stuff is very high. >However, it does seem that python (or one of its extensions) is doing >something it shouldn't. > >From http://msdn.microsoft.com/en-us/library/ms682583%28v=vs.85%29.aspx >> The entry-point function should perform only simple initialization >> or termination tasks. It must not call the LoadLibrary or LoadLibraryEx >> function (or a function that calls these functions), because this may >> create dependency loops in the DLL load order. This can result in a DLL >> being used before the system has executed its initialization code. >> Similarly, the entry-point function must not call the FreeLibrary >> function (or a function that calls FreeLibrary) during process >> termination, because this can result in a DLL being used after the >> system has executed its termination code. >> >> Because Kernel32.dll is guaranteed to be loaded in the process >> space when the entry-point function is called, calling functions in >> Kernel32.dll does not result in the DLL being used before its >> initialization code has been executed. Therefore, the entry-point >> function can call functions in Kernel32.dll that do not load other DLLs. >> For example, DllMain can create synchronization objects such as critical >> sections and mutexes, and use TLS. Unfortunately, there is not a >> comprehensive list of safe functions in Kernel32.dll. >> >> Windows 2000: Do not create a named synchronization object in >> DllMain because the system will then load an additional DLL. >> >> Calling functions that require DLLs other than Kernel32.dll may >> result in problems that are difficult to diagnose. For example, >> calling User, Shell, and COM functions can cause access violation >> errors, because some functions load other system components. >> Conversely, calling functions such as these during termination can >> cause access violation errors because the corresponding component may >> already have been unloaded or uninitialized. >> >> Because DLL notifications are serialized, entry-point functions >> should not attempt to communicate with other threads or processes. >> Deadlocks may occur as a result. i.e., "you aren't supposed to be able to call anything you like here" i.e., "you can't do that" cgf -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple