Source-Changes-HG archive

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

[src/nathanw_sa]: src/lib/libpthread Improve error checking.



details:   https://anonhg.NetBSD.org/src/rev/fa880a35b3d0
branches:  nathanw_sa
changeset: 506731:fa880a35b3d0
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sat Jan 11 09:14:34 2003 +0000

description:
Improve error checking.

OK'd by Nathan.

diffstat:

 lib/libpthread/pthread_alarms.c |   3 +--
 lib/libpthread/pthread_cond.c   |  21 ++++++++++++++++++---
 lib/libpthread/pthread_rwlock.c |   4 +++-
 3 files changed, 22 insertions(+), 6 deletions(-)

diffs (91 lines):

diff -r fdd930a1fd10 -r fa880a35b3d0 lib/libpthread/pthread_alarms.c
--- a/lib/libpthread/pthread_alarms.c   Sat Jan 11 01:21:33 2003 +0000
+++ b/lib/libpthread/pthread_alarms.c   Sat Jan 11 09:14:34 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_alarms.c,v 1.1.2.7 2002/12/16 18:19:10 nathanw Exp $   */
+/*     $NetBSD: pthread_alarms.c,v 1.1.2.8 2003/01/11 09:14:35 skrll Exp $     */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -104,7 +104,6 @@
                    self, it.it_value.tv_sec, it.it_value.tv_nsec/1000));
                retval = timer_settime(pthread_alarmtimer, TIMER_ABSTIME, 
                    &it, NULL);
-               assert(retval == 0);
                if (retval)
                        err(1, "timer_settime");
                        
diff -r fdd930a1fd10 -r fa880a35b3d0 lib/libpthread/pthread_cond.c
--- a/lib/libpthread/pthread_cond.c     Sat Jan 11 01:21:33 2003 +0000
+++ b/lib/libpthread/pthread_cond.c     Sat Jan 11 09:14:34 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_cond.c,v 1.1.2.17 2003/01/09 19:27:51 thorpej Exp $    */
+/*     $NetBSD: pthread_cond.c,v 1.1.2.18 2003/01/11 09:14:34 skrll Exp $      */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -110,11 +110,17 @@
 #ifdef ERRORCHECK
        if (cond->ptc_mutex == NULL)
                cond->ptc_mutex = mutex;
-       else
+       else {
                if (cond->ptc_mutex != mutex) {
                        pthread_spinunlock(self, &cond->ptc_lock);
                        return EINVAL;
                }
+               /* Check the mutex is actually locked */
+               if (mutex->ptm_lock != __SIMPLELOCK_LOCKED) {
+                       pthread_spinunlock(self, &cond->ptc_lock);
+                       return EPERM;
+               }
+       }
 #endif
        SDPRINTF(("(cond wait %p) Waiting on %p, mutex %p\n",
            self, cond, mutex));
@@ -162,17 +168,26 @@
        if ((cond == NULL) || (cond->ptc_magic != _PT_COND_MAGIC) ||
            (mutex == NULL) || (mutex->ptm_magic != _PT_MUTEX_MAGIC))
                return EINVAL;
+       if ((abstime == NULL) || (abstime->tv_sec < 0 ||
+           abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+               return EINVAL;
 #endif
        self = pthread__self();
        pthread_spinlock(self, &cond->ptc_lock);
 #ifdef ERRORCHECK
        if (cond->ptc_mutex == NULL)
                cond->ptc_mutex = mutex;
-       else
+       else {
                if (cond->ptc_mutex != mutex) {
                        pthread_spinunlock(self, &cond->ptc_lock);
                        return EINVAL;
                }
+               /* Check the mutex is actually locked */
+               if (mutex->ptm_lock != __SIMPLELOCK_LOCKED) {
+                       pthread_spinunlock(self, &cond->ptc_lock);
+                       return EPERM;
+               }
+       }
 #endif
        wait.ptw_thread = self;
        wait.ptw_cond = cond;
diff -r fdd930a1fd10 -r fa880a35b3d0 lib/libpthread/pthread_rwlock.c
--- a/lib/libpthread/pthread_rwlock.c   Sat Jan 11 01:21:33 2003 +0000
+++ b/lib/libpthread/pthread_rwlock.c   Sat Jan 11 09:14:34 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_rwlock.c,v 1.1.2.4 2003/01/09 19:27:52 thorpej Exp $ */
+/*     $NetBSD: pthread_rwlock.c,v 1.1.2.5 2003/01/11 09:14:35 skrll Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -250,6 +250,8 @@
 #ifdef ERRORCHECK
        if ((rwlock == NULL) || (rwlock->ptr_magic != _PT_RWLOCK_MAGIC))
                return EINVAL;
+       if ((abs_timeout == NULL) || (abs_timeout->tv_nsec >= 1000000000))
+               return EINVAL;
 #endif
        self = pthread__self();
        



Home | Main Index | Thread Index | Old Index