|
From: Jeremy F. <je...@go...> - 2005-03-01 06:22:40
|
CVS commit by fitzhardinge:
Don't create general blocks when using VALGRIND_MAKE_* macros. Instead, add
a new VALGRIND_CREATE_BLOCK call which creates a description for a region
of memory. The VALGRIND_MAKE_* macros always return -1 under Valgrind, which
should be OK to VALGRIND_DISCARD.
M +2 -2 coregrind/vg_malloc2.c 1.36
M +27 -28 memcheck/mc_main.c 1.65
M +17 -8 memcheck/memcheck.h 1.21
--- valgrind/memcheck/memcheck.h #1.20:1.21
@@ -92,4 +92,6 @@ typedef
VG_USERREQ__SET_VBITS,
+ VG_USERREQ__CREATE_BLOCK,
+
/* This is just for memcheck's internal use - don't use it */
_VG_USERREQ__MEMCHECK_GET_RECORD_OVERLAP = VG_USERREQ_SKIN_BASE('M','C')+256
@@ -101,6 +103,5 @@ typedef
/* Mark memory at _qzz_addr as unaddressible and undefined for
- _qzz_len bytes. Returns an int handle pertaining to the block
- descriptions Valgrind will use in subsequent error messages. */
+ _qzz_len bytes. */
#define VALGRIND_MAKE_NOACCESS(_qzz_addr,_qzz_len) \
(__extension__({unsigned int _qzz_res; \
@@ -131,10 +132,18 @@ typedef
}))
-/* Discard a block-description-handle obtained from the above three
- macros. After this, Valgrind will no longer be able to relate
- addressing errors to the user-defined block associated with the
- handle. The permissions settings associated with the handle remain
- in place. Returns 1 for an invalid handle, 0 for a valid
- handle. */
+/* Create a block-description handle. The description is an ascii
+ string which is included in any messages pertaining to addresses
+ within the specified memory range. Has no other effect on the
+ properties of the memory range. */
+#define VALGRIND_CREATE_BLOCK(_qzz_addr,_qzz_len, _qzz_desc) \
+ (__extension__({unsigned int _qzz_res; \
+ VALGRIND_MAGIC_SEQUENCE(_qzz_res, 0 /* default return */, \
+ VG_USERREQ__CREATE_BLOCK, \
+ _qzz_addr, _qzz_len, _qzz_desc, 0); \
+ _qzz_res; \
+ }))
+
+/* Discard a block-description-handle. Returns 1 for an
+ invalid handle, 0 for a valid handle. */
#define VALGRIND_DISCARD(_qzz_blkindex) \
(__extension__ ({unsigned int _qzz_res; \
--- valgrind/memcheck/mc_main.c #1.64:1.65
@@ -1684,9 +1684,7 @@ void SK_(print_debug_usage)(void)
an empty slot at allocation time. This in turn means allocation is
relatively expensive, so we hope this does not happen too often.
-*/
-typedef
- enum { CG_NotInUse, CG_NoAccess, CG_Writable, CG_Readable }
- CGenBlockKind;
+ An unused block has start == size == 0
+*/
typedef
@@ -1695,5 +1693,5 @@ typedef
SizeT size;
ExeContext* where;
- CGenBlockKind kind;
+ Char* desc;
}
CGenBlock;
@@ -1721,5 +1719,5 @@ Int vg_alloc_client_block ( void )
for (i = 0; i < vg_cgb_used; i++) {
vg_cgb_search++;
- if (vg_cgbs[i].kind == CG_NotInUse)
+ if (vg_cgbs[i].start == 0 && vg_cgbs[i].size == 0)
return i;
}
@@ -1774,5 +1772,5 @@ static Bool client_perm_maybe_describe(
/* Perhaps it's a general block ? */
for (i = 0; i < vg_cgb_used; i++) {
- if (vg_cgbs[i].kind == CG_NotInUse)
+ if (vg_cgbs[i].start == 0 && vg_cgbs[i].size == 0)
continue;
if (VG_(addr_is_in_block)(a, vg_cgbs[i].start, vg_cgbs[i].size)) {
@@ -1806,4 +1804,5 @@ static Bool client_perm_maybe_describe(
ai->rwoffset = (Int)(a) - (Int)(vg_cgbs[i].start);
ai->lastchange = vg_cgbs[i].where;
+ ai->desc = vg_cgbs[i].desc;
return True;
}
@@ -1855,40 +1854,40 @@ Bool SK_(handle_client_request) ( Thread
case VG_USERREQ__MAKE_NOACCESS: /* make no access */
- i = vg_alloc_client_block();
- /* VG_(printf)("allocated %d %p\n", i, vg_cgbs); */
- vg_cgbs[i].kind = CG_NoAccess;
- vg_cgbs[i].start = arg[1];
- vg_cgbs[i].size = arg[2];
- vg_cgbs[i].where = VG_(get_ExeContext) ( tid );
mc_make_noaccess ( arg[1], arg[2] );
- *ret = i;
+ *ret = -1;
break;
case VG_USERREQ__MAKE_WRITABLE: /* make writable */
- i = vg_alloc_client_block();
- vg_cgbs[i].kind = CG_Writable;
- vg_cgbs[i].start = arg[1];
- vg_cgbs[i].size = arg[2];
- vg_cgbs[i].where = VG_(get_ExeContext) ( tid );
mc_make_writable ( arg[1], arg[2] );
- *ret = i;
+ *ret = -1;
break;
case VG_USERREQ__MAKE_READABLE: /* make readable */
+ mc_make_readable ( arg[1], arg[2] );
+ *ret = -1;
+ break;
+
+ case VG_USERREQ__CREATE_BLOCK: /* describe a block */
+ if (arg[1] != 0 && arg[2] != 0) {
i = vg_alloc_client_block();
- vg_cgbs[i].kind = CG_Readable;
+ /* VG_(printf)("allocated %d %p\n", i, vg_cgbs); */
vg_cgbs[i].start = arg[1];
vg_cgbs[i].size = arg[2];
+ vg_cgbs[i].desc = VG_(strdup)((Char *)arg[3]);
vg_cgbs[i].where = VG_(get_ExeContext) ( tid );
- mc_make_readable ( arg[1], arg[2] );
+
*ret = i;
+ } else
+ *ret = -1;
break;
case VG_USERREQ__DISCARD: /* discard */
if (vg_cgbs == NULL
- || arg[2] >= vg_cgb_used || vg_cgbs[arg[2]].kind == CG_NotInUse)
+ || arg[2] >= vg_cgb_used ||
+ (vg_cgbs[arg[2]].start == 0 && vg_cgbs[arg[2]].size == 0))
return 1;
sk_assert(arg[2] >= 0 && arg[2] < vg_cgb_used);
- vg_cgbs[arg[2]].kind = CG_NotInUse;
+ vg_cgbs[arg[2]].start = vg_cgbs[arg[2]].size = 0;
+ VG_(free)(vg_cgbs[arg[2]].desc);
vg_cgb_discards++;
*ret = 0;
--- valgrind/coregrind/vg_malloc2.c #1.35:1.36
@@ -480,5 +480,5 @@ Superblock* newSuperblock ( Arena* a, Si
}
vg_assert(NULL != sb);
- VALGRIND_DISCARD(VALGRIND_MAKE_WRITABLE(sb, cszB));
+ VALGRIND_MAKE_WRITABLE(sb, cszB);
vg_assert(0 == (Addr)sb % VG_MIN_MALLOC_SZB);
sb->n_payload_bytes = cszB - sizeof(Superblock);
@@ -869,5 +869,5 @@ void mkFreeBlock ( Arena* a, Block* b, S
SizeT pszB = bszB_to_pszB(a, bszB);
vg_assert(b_lno == pszB_to_listNo(pszB));
- VALGRIND_DISCARD(VALGRIND_MAKE_WRITABLE(b, bszB));
+ VALGRIND_MAKE_WRITABLE(b, bszB);
// Set the size fields and indicate not-in-use.
set_bszB_lo(b, mk_free_bszB(bszB));
|