Print this page
9959 pthread_mutex_init should initialize mutex appropriately for robust mutex_init

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/threads/pthr_mutex.c
          +++ new/usr/src/lib/libc/port/threads/pthr_mutex.c
↓ open down ↓ 218 lines elided ↑ open up ↑
 219  219                  if ((ap = attr->__pthread_mutexattrp) == NULL)
 220  220                          return (EINVAL);
 221  221                  type = ap->pshared | ap->type | ap->protocol | ap->robustness;
 222  222                  if (ap->protocol == PTHREAD_PRIO_PROTECT)
 223  223                          prioceiling = ap->prioceiling;
 224  224          } else {
 225  225                  type = PTHREAD_PROCESS_PRIVATE | PTHREAD_MUTEX_DEFAULT |
 226  226                      PTHREAD_PRIO_NONE | PTHREAD_MUTEX_STALLED;
 227  227          }
 228  228  
      229 +        /*
      230 +         * POSIX mutexes (this interface) make no guarantee about the state of
      231 +         * the mutex before pthread_mutex_init(3C) is called.  Sun mutexes, upon
      232 +         * which these are built and which mutex_init(3C) below represents
      233 +         * require that a robust mutex be initialized to all 0s _prior_ to
      234 +         * mutex_init() being called, and that mutex_init() of an initialized
      235 +         * mutex return EBUSY.
      236 +         *
      237 +         * We respect both these behaviors by zeroing the mutex here in the
      238 +         * POSIX implementation if and only if the mutex magic is incorrect,
      239 +         * and the mutex is robust.
      240 +         */
      241 +        if (((type & PTHREAD_MUTEX_ROBUST) != 0) &&
      242 +            (((mutex_t *)mutex)->mutex_magic != MUTEX_MAGIC)) {
      243 +                (void) memset(mutex, 0, sizeof (*mutex));
      244 +        }
      245 +
 229  246          return (mutex_init((mutex_t *)mutex, type, &prioceiling));
 230  247  }
 231  248  
 232  249  /*
 233  250   * pthread_mutex_setprioceiling: sets the prioceiling.
 234  251   * From the SUSv3 (POSIX) specification for pthread_mutex_setprioceiling():
 235  252   *      The process of locking the mutex need not
 236  253   *      adhere to the priority protect protocol.
 237  254   * We pass the MUTEX_NOCEIL flag to mutex_lock_internal() so that
 238  255   * a non-realtime thread can successfully execute this operation.
↓ open down ↓ 89 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX