Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libpthread _DIAGASSERT that RW_FLAGMASK bits are not set...
details: https://anonhg.NetBSD.org/src/rev/fbe759528013
branches: trunk
changeset: 1005663:fbe759528013
user: uwe <uwe%NetBSD.org@localhost>
date: Sun Dec 15 23:13:33 2019 +0000
description:
_DIAGASSERT that RW_FLAGMASK bits are not set in a thread pointer.
rwlock uses lower bits of a thread pointer for flags in the lock owner
field. Assert that the pointer is properly aligned and those bits are
actually free to use. This may not be the case when a program uses
its own allocator that can return less aligned pointers.
diffstat:
lib/libpthread/pthread_rwlock.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diffs (47 lines):
diff -r 87bc1b5e9fbb -r fbe759528013 lib/libpthread/pthread_rwlock.c
--- a/lib/libpthread/pthread_rwlock.c Sun Dec 15 22:57:26 2019 +0000
+++ b/lib/libpthread/pthread_rwlock.c Sun Dec 15 23:13:33 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_rwlock.c,v 1.34 2016/07/03 14:24:58 christos Exp $ */
+/* $NetBSD: pthread_rwlock.c,v 1.35 2019/12/15 23:13:33 uwe Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,11 +30,12 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_rwlock.c,v 1.34 2016/07/03 14:24:58 christos Exp $");
+__RCSID("$NetBSD: pthread_rwlock.c,v 1.35 2019/12/15 23:13:33 uwe Exp $");
#include <sys/types.h>
#include <sys/lwpctl.h>
+#include <assert.h>
#include <time.h>
#include <errno.h>
#include <stddef.h>
@@ -275,6 +276,7 @@
int error;
self = pthread__self();
+ _DIAGASSERT(((uintptr_t)self & RW_FLAGMASK) == 0);
#ifdef ERRORCHECK
if (ptr->ptr_magic != _PT_RWLOCK_MAGIC)
@@ -373,6 +375,7 @@
#endif
self = pthread__self();
+ _DIAGASSERT(((uintptr_t)self & RW_FLAGMASK) == 0);
for (owner = (uintptr_t)ptr->ptr_owner;; owner = next) {
if (owner != 0)
@@ -509,6 +512,7 @@
*/
self = pthread__self();
if ((thread = PTQ_FIRST(&ptr->ptr_wblocked)) != NULL) {
+ _DIAGASSERT(((uintptr_t)thread & RW_FLAGMASK) == 0);
new = (uintptr_t)thread | RW_WRITE_LOCKED;
if (PTQ_NEXT(thread, pt_sleep) != NULL)
Home |
Main Index |
Thread Index |
Old Index