X-Spam-Check-By: sourceware.org Date: Wed, 22 Mar 2006 13:55:41 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: pthread_create leaves valid mutex pointers on the stack Message-ID: <20060322125541.GB9091@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <17433 DOT 39495 DOT 950903 DOT 287320 AT metro-north DOT cs DOT columbia DOT edu> <20060316171139 DOT GM4280 AT implementation DOT labri DOT fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20060316171139.GM4280@implementation.labri.fr> User-Agent: Mutt/1.4.2i Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk 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 Mar 16 18:11, Samuel Thibault wrote: > Hi, > > Jonathan Lennox, le Thu 16 Mar 2006 12:03:03 -0500, a écrit : > Content-Description: message body text > > In general, the idea of verifying objects on their init functions seems > > dubious to me -- how can you tell initialized objects from random stack or > > heap garbage? > > Posix says: > Attempting to initialize an already initialized mutex results in undefined > behavior. According to SUSv3 pthread_mutex_init is allowed to check the incoming mutex and return EBUSY if the mutex is already in use: The pthread_mutex_init() function may fail if: [EBUSY] The implementation has detected an attempt to reinitialize the object referenced by mutex, a previously initialized, but not yet destroyed, mutex. But the problem is obvious. On initializing an object you can't trust the value on the stack to be meant as a pointer to an existing object, or to be just random bytes or, in your nice example, being a value left on the stack by an earlier function call. That's probably the reason why SUSv3 says "may" and not "must", and that's probably also the reason that such a test isn't made on Linux. I disabled the validity checks now in the methods corresponding to the functions pthread_mutex_init, pthread_rwlock_init and pthread_cond_init. Thanks for the testcase, Jonathan. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/