Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/sys verify that a LIST or TAILQ isn't already corrupted ...
details: https://anonhg.NetBSD.org/src/rev/44e9a7d634e3
branches: trunk
changeset: 499396:44e9a7d634e3
user: chs <chs%NetBSD.org@localhost>
date: Sun Nov 19 06:00:57 2000 +0000
description:
verify that a LIST or TAILQ isn't already corrupted before modifying it.
enable with "options QUEUEDEBUG".
diffstat:
sys/sys/queue.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 49 insertions(+), 2 deletions(-)
diffs (139 lines):
diff -r 3d350e312832 -r 44e9a7d634e3 sys/sys/queue.h
--- a/sys/sys/queue.h Sun Nov 19 05:53:21 2000 +0000
+++ b/sys/sys/queue.h Sun Nov 19 06:00:57 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: queue.h,v 1.25 2000/10/03 00:19:19 assar Exp $ */
+/* $NetBSD: queue.h,v 1.26 2000/11/19 06:00:57 chs Exp $ */
/*
* Copyright (c) 1991, 1993
@@ -104,11 +104,29 @@
/*
* List functions.
*/
+#if defined(_KERNEL) && defined(QUEUEDEBUG)
+#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field) \
+ if ((head)->lh_first && \
+ (head)->lh_first->field.le_prev != &(head)->lh_first) \
+ panic("LIST_INSERT_HEAD %p", (head));
+#define QUEUEDEBUG_LIST_OP(elm, field) \
+ if ((elm)->field.le_next && \
+ (elm)->field.le_next->field.le_prev != \
+ &(elm)->field.le_next) \
+ panic("LIST_* forw %p", elm); \
+ if (*(elm)->field.le_prev != (elm)) \
+ panic("LIST_* back %p", elm);
+#else
+#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field)
+#define QUEUEDEBUG_LIST_OP(elm, field)
+#endif
+
#define LIST_INIT(head) do { \
(head)->lh_first = NULL; \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
+ QUEUEDEBUG_LIST_OP(listelm, field) \
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
(listelm)->field.le_next->field.le_prev = \
&(elm)->field.le_next; \
@@ -117,6 +135,7 @@
} while (/*CONSTCOND*/0)
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
+ QUEUEDEBUG_LIST_OP(listelm, field) \
(elm)->field.le_prev = (listelm)->field.le_prev; \
(elm)->field.le_next = (listelm); \
*(listelm)->field.le_prev = (elm); \
@@ -124,6 +143,7 @@
} while (/*CONSTCOND*/0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
+ QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field) \
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
(head)->lh_first = (elm); \
@@ -131,6 +151,7 @@
} while (/*CONSTCOND*/0)
#define LIST_REMOVE(elm, field) do { \
+ QUEUEDEBUG_LIST_OP(elm, field) \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
@@ -201,7 +222,7 @@
} \
else { \
struct type *curelm = (head)->slh_first; \
- while( curelm->field.sle_next != (elm) ) \
+ while(curelm->field.sle_next != (elm)) \
curelm = curelm->field.sle_next; \
curelm->field.sle_next = \
curelm->field.sle_next->field.sle_next; \
@@ -289,12 +310,34 @@
/*
* Tail queue functions.
*/
+#if defined(_KERNEL) && defined(QUEUEDEBUG)
+#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field) \
+ if ((head)->tqh_first && \
+ (head)->tqh_first->field.tqe_prev != &(head)->tqh_first) \
+ panic("TAILQ_INSERT_HEAD %p", (head));
+#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field) \
+ if (*(head)->tqh_last != NULL) \
+ panic("TAILQ_INSERT_TAIL %p", (head));
+#define QUEUEDEBUG_TAILQ_OP(elm, field) \
+ if ((elm)->field.tqe_next && \
+ (elm)->field.tqe_next->field.tqe_prev != \
+ &(elm)->field.tqe_next) \
+ panic("TAILQ_* forw %p", elm); \
+ if (*(elm)->field.tqe_prev != (elm)) \
+ panic("TAILQ_* back %p", elm);
+#else
+#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field)
+#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field)
+#define QUEUEDEBUG_TAILQ_OP(elm, field)
+#endif
+
#define TAILQ_INIT(head) do { \
(head)->tqh_first = NULL; \
(head)->tqh_last = &(head)->tqh_first; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
+ QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field) \
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
(head)->tqh_first->field.tqe_prev = \
&(elm)->field.tqe_next; \
@@ -305,6 +348,7 @@
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
+ QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field) \
(elm)->field.tqe_next = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
@@ -312,6 +356,7 @@
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ QUEUEDEBUG_TAILQ_OP(listelm, field) \
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
(elm)->field.tqe_next->field.tqe_prev = \
&(elm)->field.tqe_next; \
@@ -322,6 +367,7 @@
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
+ QUEUEDEBUG_TAILQ_OP(listelm, field) \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
(elm)->field.tqe_next = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
@@ -329,6 +375,7 @@
} while (/*CONSTCOND*/0)
#define TAILQ_REMOVE(head, elm, field) do { \
+ QUEUEDEBUG_TAILQ_OP(elm, field) \
if (((elm)->field.tqe_next) != NULL) \
(elm)->field.tqe_next->field.tqe_prev = \
(elm)->field.tqe_prev; \
Home |
Main Index |
Thread Index |
Old Index