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_mutexattr_t and pthread_mutex_t m...
details: https://anonhg.NetBSD.org/src/rev/fd9ca9db5540
branches: trunk
changeset: 744329:fd9ca9db5540
user: kamil <kamil%NetBSD.org@localhost>
date: Wed Jan 29 21:11:24 2020 +0000
description:
Use pthread_mutexattr_t and pthread_mutex_t magic fields
Validate _PT_MUTEX_MAGIC in pthread_mutex_t and _PT_MUTEXATTR_MAGIC
in pthread_mutexattr_t accordingly.
diffstat:
lib/libpthread/pthread_mutex.c | 35 +++++++++++++++++++++++++++--------
1 files changed, 27 insertions(+), 8 deletions(-)
diffs (119 lines):
diff -r 1a446aa018ca -r fd9ca9db5540 lib/libpthread/pthread_mutex.c
--- a/lib/libpthread/pthread_mutex.c Wed Jan 29 19:29:23 2020 +0000
+++ b/lib/libpthread/pthread_mutex.c Wed Jan 29 21:11:24 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_mutex.c,v 1.69 2020/01/29 10:55:23 kamil Exp $ */
+/* $NetBSD: pthread_mutex.c,v 1.70 2020/01/29 21:11:24 kamil Exp $ */
/*-
* Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_mutex.c,v 1.69 2020/01/29 10:55:23 kamil Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.70 2020/01/29 21:11:24 kamil Exp $");
#include <sys/types.h>
#include <sys/lwpctl.h>
@@ -197,6 +197,9 @@
if (__predict_false(__uselibcstub))
return __libc_mutex_lock_stub(ptm);
+ pthread__error(EINVAL, "Invalid mutex",
+ ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
self = pthread__self();
val = atomic_cas_ptr(&ptm->ptm_owner, NULL, self);
if (__predict_true(val == NULL)) {
@@ -214,6 +217,9 @@
pthread_t self;
void *val;
+ pthread__error(EINVAL, "Invalid mutex",
+ ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
self = pthread__self();
val = atomic_cas_ptr(&ptm->ptm_owner, NULL, self);
if (__predict_true(val == NULL)) {
@@ -298,9 +304,6 @@
int serrno;
int error;
- pthread__error(EINVAL, "Invalid mutex",
- ptm->ptm_magic == _PT_MUTEX_MAGIC);
-
owner = ptm->ptm_owner;
self = pthread__self();
@@ -410,6 +413,9 @@
if (__predict_false(__uselibcstub))
return __libc_mutex_trylock_stub(ptm);
+ pthread__error(EINVAL, "Invalid mutex",
+ ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
self = pthread__self();
val = atomic_cas_ptr(&ptm->ptm_owner, NULL, self);
if (__predict_true(val == NULL)) {
@@ -450,6 +456,9 @@
if (__predict_false(__uselibcstub))
return __libc_mutex_unlock_stub(ptm);
+ pthread__error(EINVAL, "Invalid mutex",
+ ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
#ifndef PTHREAD__ATOMIC_IS_MEMBAR
membar_exit();
#endif
@@ -468,9 +477,6 @@
pthread_t self, owner, new;
int weown, error;
- pthread__error(EINVAL, "Invalid mutex",
- ptm->ptm_magic == _PT_MUTEX_MAGIC);
-
self = pthread__self();
owner = ptm->ptm_owner;
weown = (MUTEX_OWNER(owner) == (uintptr_t)self);
@@ -725,6 +731,9 @@
int * __restrict pshared)
{
+ pthread__error(EINVAL, "Invalid mutex attribute",
+ attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
+
*pshared = PTHREAD_PROCESS_PRIVATE;
return 0;
}
@@ -733,6 +742,9 @@
pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
{
+ pthread__error(EINVAL, "Invalid mutex attribute",
+ attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
+
switch(pshared) {
case PTHREAD_PROCESS_PRIVATE:
return 0;
@@ -772,6 +784,10 @@
int
pthread_mutex_getprioceiling(const pthread_mutex_t *ptm, int *ceil)
{
+
+ pthread__error(EINVAL, "Invalid mutex",
+ ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
*ceil = ptm->ptm_ceiling;
return 0;
}
@@ -781,6 +797,9 @@
{
int error;
+ pthread__error(EINVAL, "Invalid mutex",
+ ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
error = pthread_mutex_lock(ptm);
if (error == 0) {
*old_ceil = ptm->ptm_ceiling;
Home |
Main Index |
Thread Index |
Old Index