summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc/port/threads
diff options
context:
space:
mode:
authorRichard Lowe <richlowe@richlowe.net>2018-11-06 00:57:32 +0000
committerDan McDonald <danmcd@joyent.com>2018-11-25 21:13:30 -0500
commit6da2547363ddbd247ee9513db83b05a31bca31af (patch)
treeacc75c57856c121dc747ad4ca5a985dcbc1947b2 /usr/src/lib/libc/port/threads
parent2258ad0b755b24a55c6173b1e6bb6188389f72dd (diff)
downloadillumos-joyent-6da2547363ddbd247ee9513db83b05a31bca31af.tar.gz
9959 pthread_mutex_init should initialize mutex appropriately for robust mutex_init
Reviewed by: Jason King <jason.king@joyent.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/libc/port/threads')
-rw-r--r--usr/src/lib/libc/port/threads/pthr_mutex.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/usr/src/lib/libc/port/threads/pthr_mutex.c b/usr/src/lib/libc/port/threads/pthr_mutex.c
index 1f70725677..c8943671aa 100644
--- a/usr/src/lib/libc/port/threads/pthr_mutex.c
+++ b/usr/src/lib/libc/port/threads/pthr_mutex.c
@@ -226,6 +226,23 @@ pthread_mutex_init(pthread_mutex_t *_RESTRICT_KYWD mutex,
PTHREAD_PRIO_NONE | PTHREAD_MUTEX_STALLED;
}
+ /*
+ * POSIX mutexes (this interface) make no guarantee about the state of
+ * the mutex before pthread_mutex_init(3C) is called. Sun mutexes, upon
+ * which these are built and which mutex_init(3C) below represents
+ * require that a robust mutex be initialized to all 0s _prior_ to
+ * mutex_init() being called, and that mutex_init() of an initialized
+ * mutex return EBUSY.
+ *
+ * We respect both these behaviors by zeroing the mutex here in the
+ * POSIX implementation if and only if the mutex magic is incorrect,
+ * and the mutex is robust.
+ */
+ if (((type & PTHREAD_MUTEX_ROBUST) != 0) &&
+ (((mutex_t *)mutex)->mutex_magic != MUTEX_MAGIC)) {
+ (void) memset(mutex, 0, sizeof (*mutex));
+ }
+
return (mutex_init((mutex_t *)mutex, type, &prioceiling));
}