|
From: <sv...@va...> - 2008-08-24 08:28:33
|
Author: sewardj
Date: 2008-08-24 09:28:42 +0100 (Sun, 24 Aug 2008)
New Revision: 8544
Log:
Add a magic number to 'struct _SO' to catch cases where the library's
client screws up its management thereof.
Modified:
branches/YARD/helgrind/libhb_core.c
Modified: branches/YARD/helgrind/libhb_core.c
===================================================================
--- branches/YARD/helgrind/libhb_core.c 2008-08-24 08:27:46 UTC (rev 8543)
+++ branches/YARD/helgrind/libhb_core.c 2008-08-24 08:28:42 UTC (rev 8544)
@@ -5391,18 +5391,25 @@
// //
/////////////////////////////////////////////////////////
+// (UInt) `echo "Synchronisation object" | md5sum`
+#define SO_MAGIC 0x56b3c5b0
+
struct _SO {
VtsID viR; /* r-clock of sender */
VtsID viW; /* w-clock of sender */
+ UInt magic;
};
static SO* SO__Alloc ( void ) {
SO* so = main_zalloc( sizeof(SO) );
- so->viR = VtsID_INVALID;
- so->viW = VtsID_INVALID;
+ so->viR = VtsID_INVALID;
+ so->viW = VtsID_INVALID;
+ so->magic = SO_MAGIC;
return so;
}
static void SO__Dealloc ( SO* so ) {
+ tl_assert(so);
+ tl_assert(so->magic == SO_MAGIC);
if (so->viR == VtsID_INVALID) {
tl_assert(so->viW == VtsID_INVALID);
} else {
@@ -5410,6 +5417,7 @@
VtsID__rcdec(so->viR);
VtsID__rcdec(so->viW);
}
+ so->magic = 0;
main_dealloc( so );
}
@@ -5643,6 +5651,8 @@
void libhb_so_dealloc ( SO* so )
{
+ tl_assert(so);
+ tl_assert(so->magic == SO_MAGIC);
SO__Dealloc(so);
}
@@ -5653,6 +5663,9 @@
/* Copy the VTSs from 'thr' into the sync object, and then move
the thread along one step. */
+ tl_assert(so);
+ tl_assert(so->magic == SO_MAGIC);
+
/* stay sane .. a thread's read-clock must always lead or be the
same as its write-clock */
{ POrd ord = VtsID__getOrdering(thr->viW, thr->viR);
@@ -5695,6 +5708,9 @@
void libhb_so_recv ( Thr* thr, SO* so, Bool strong_recv )
{
+ tl_assert(so);
+ tl_assert(so->magic == SO_MAGIC);
+
if (so->viR != VtsID_INVALID) {
tl_assert(so->viW != VtsID_INVALID);
|