This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pthread_create leaves valid mutex pointers on the stack


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]