diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-02-28 02:41:57 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-02-28 02:41:57 +0000 |
commit | 4890b5c1594c7c7b253e144c69171365a885158a (patch) | |
tree | 649ff87972aa7662a1ca76ee7724b7ea5af60d6d /lib/librthread | |
parent | 0078f3261d35531643989ca51d263fb4aeb61dda (diff) |
Our default mutex type is PTHREAD_MUTEX_ERRORCHECK, for which trying
to unlock an uninitialized mutex is required to return EPERM, so add
the necessary checks.
For recursive mutexes, return an error from pthread_mutex_lock()
if the count would overflow.
problem observed in glib testing by aja@
Diffstat (limited to 'lib/librthread')
-rw-r--r-- | lib/librthread/rthread_sync.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c index 2d5b5afe587..c5d74f131c6 100644 --- a/lib/librthread/rthread_sync.c +++ b/lib/librthread/rthread_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sync.c,v 1.32 2012/02/23 07:58:25 guenther Exp $ */ +/* $OpenBSD: rthread_sync.c,v 1.33 2012/02/28 02:41:56 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> @@ -128,6 +128,10 @@ _rthread_mutex_lock(pthread_mutex_t *mutexp, int trywait, _spinlock(&mutex->lock); return (ETIMEDOUT); } + if (mutex->count == INT_MAX) { + _spinunlock(&mutex->lock); + return (EAGAIN); + } } else if (trywait) { /* try failed */ _spinunlock(&mutex->lock); @@ -183,6 +187,11 @@ pthread_mutex_unlock(pthread_mutex_t *mutexp) _rthread_debug(5, "%p: mutex_unlock %p\n", (void *)self, (void *)mutex); +#if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_ERRORCHECK + if (mutex == NULL) + return (EPERM); +#endif + if (mutex->owner != self) return (EPERM); @@ -264,6 +273,11 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp, _rthread_debug(5, "%p: cond_timed %p,%p\n", (void *)self, (void *)cond, (void *)mutex); +#if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_ERRORCHECK + if (mutex == NULL) + return (EPERM); +#endif + if (mutex->owner != self) return (EPERM); if (abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 || @@ -403,6 +417,11 @@ pthread_cond_wait(pthread_cond_t *condp, pthread_mutex_t *mutexp) _rthread_debug(5, "%p: cond_timed %p,%p\n", (void *)self, (void *)cond, (void *)mutex); +#if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_ERRORCHECK + if (mutex == NULL) + return (EPERM); +#endif + if (mutex->owner != self) return (EPERM); |