Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread Use pthread_condattr_t and pthread_cond_t mag...



details:   https://anonhg.NetBSD.org/src/rev/592711cd36c7
branches:  trunk
changeset: 968829:592711cd36c7
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jan 29 15:07:46 2020 +0000

description:
Use pthread_condattr_t and pthread_cond_t magic fields

Validate _PT_CONDATTR_MAGIC and _PT_COND_MAGIC respectively.

diffstat:

 lib/libpthread/pthread_cond.c |  34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)

diffs (111 lines):

diff -r d68e52af5939 -r 592711cd36c7 lib/libpthread/pthread_cond.c
--- a/lib/libpthread/pthread_cond.c     Wed Jan 29 15:00:39 2020 +0000
+++ b/lib/libpthread/pthread_cond.c     Wed Jan 29 15:07:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_cond.c,v 1.66 2020/01/13 18:22:56 ad Exp $     */
+/*     $NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $  */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_cond.c,v 1.66 2020/01/13 18:22:56 ad Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $");
 
 #include <stdlib.h>
 #include <errno.h>
@@ -78,6 +78,10 @@
 static clockid_t
 pthread_cond_getclock(const pthread_cond_t *cond)
 {
+
+       pthread__error(EINVAL, "Invalid condition variable",
+           cond->ptc_magic == _PT_COND_MAGIC);
+
        return cond->ptc_private ? 
            *(clockid_t *)cond->ptc_private : CLOCK_REALTIME;
 }
@@ -222,9 +226,6 @@
        pthread_mutex_t *mutex;
        lwpid_t lid;
 
-       pthread__error(EINVAL, "Invalid condition variable",
-           cond->ptc_magic == _PT_COND_MAGIC);
-
        /*
         * Pull the first thread off the queue.  If the current thread
         * is associated with the condition variable, remove it without
@@ -278,6 +279,9 @@
        if (__predict_false(__uselibcstub))
                return __libc_cond_signal_stub(cond);
 
+       pthread__error(EINVAL, "Invalid condition variable",
+           cond->ptc_magic == _PT_COND_MAGIC);
+
        if (__predict_true(PTQ_EMPTY(&cond->ptc_waiters)))
                return 0;
        return pthread__cond_wake_one(cond);
@@ -291,9 +295,6 @@
        u_int max;
        size_t nwaiters;
 
-       pthread__error(EINVAL, "Invalid condition variable",
-           cond->ptc_magic == _PT_COND_MAGIC);
-
        /*
         * Try to defer waking threads (see pthread_cond_signal()).
         * Only transfer waiters for which there is no pending wakeup.
@@ -328,6 +329,9 @@
        if (__predict_false(__uselibcstub))
                return __libc_cond_broadcast_stub(cond);
 
+       pthread__error(EINVAL, "Invalid condition variable",
+           cond->ptc_magic == _PT_COND_MAGIC);
+
        if (__predict_true(PTQ_EMPTY(&cond->ptc_waiters)))
                return 0;
        return pthread__cond_wake_all(cond);
@@ -353,6 +357,10 @@
 int
 pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clck)
 {
+
+       pthread__error(EINVAL, "Invalid condition variable attribute",
+           attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
        switch (clck) {
        case CLOCK_MONOTONIC:
        case CLOCK_REALTIME:
@@ -371,6 +379,10 @@
 pthread_condattr_getclock(const pthread_condattr_t *__restrict attr,
     clockid_t *__restrict clock_id)
 {
+
+       pthread__error(EINVAL, "Invalid condition variable attribute",
+           attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
        if (attr == NULL || attr->ptca_private == NULL)
                return EINVAL;
        *clock_id = *(clockid_t *)attr->ptca_private;
@@ -396,6 +408,9 @@
     int * __restrict pshared)
 {
 
+       pthread__error(EINVAL, "Invalid condition variable attribute",
+           attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
        *pshared = PTHREAD_PROCESS_PRIVATE;
        return 0;
 }
@@ -404,6 +419,9 @@
 pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
 {
 
+       pthread__error(EINVAL, "Invalid condition variable attribute",
+           attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
        switch(pshared) {
        case PTHREAD_PROCESS_PRIVATE:
                return 0;



Home | Main Index | Thread Index | Old Index