From 522cf5944fd284f5e3d7af10ff271ab7f8b46e6b Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Fri, 10 Mar 2006 13:41:58 +0000 Subject: [PATCH] Add a new kind of memory-painting primitive, which is: 'make_defined'. For each byte in the range, if the byte is addressible, make it be initialised, but if it isn't addressible, leave it alone. So it's like a version of make_readable which doesn't alter addressibility. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5736 --- memcheck/mc_main.c | 21 +++++++++++++++++++++ memcheck/memcheck.h | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/memcheck/mc_main.c b/memcheck/mc_main.c index f63986b53e..20192ef8ed 100644 --- a/memcheck/mc_main.c +++ b/memcheck/mc_main.c @@ -741,6 +741,22 @@ static void mc_make_readable ( Addr a, SizeT len ) set_address_range_perms ( a, len, VGM_BIT_VALID, VGM_BIT_VALID ); } +/* For each byte in [a,a+len), if the byte is addressable, make it be + defined, but if it isn't addressible, leave it alone. In other + words a version of mc_make_readable that doesn't mess with + addressibility. Low-performance implementation. */ +static void mc_make_defined ( Addr a, SizeT len ) +{ + SizeT i; + UWord abit, vbyte; + DEBUG("mc_make_defined(%p, %llu)\n", a, (ULong)len); + for (i = 0; i < len; i++) { + get_abit_and_vbyte( &abit, &vbyte, a+i ); + if (EXPECTED_TAKEN(abit == VGM_BIT_VALID)) + set_vbyte(a+i, VGM_BYTE_VALID); + } +} + /* --- Block-copy permissions (needed for implementing realloc() and sys_mremap). --- */ @@ -2519,6 +2535,11 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret ) *ret = -1; break; + case VG_USERREQ__MAKE_DEFINED: /* make defined */ + mc_make_defined ( arg[1], arg[2] ); + *ret = -1; + break; + case VG_USERREQ__CREATE_BLOCK: /* describe a block */ if (arg[1] != 0 && arg[2] != 0) { i = alloc_client_block(); diff --git a/memcheck/memcheck.h b/memcheck/memcheck.h index 735a34a6d2..0c529f3280 100644 --- a/memcheck/memcheck.h +++ b/memcheck/memcheck.h @@ -70,6 +70,10 @@ #include "valgrind.h" +/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! + This enum comprises an ABI exported by Valgrind to programs + which use client requests. DO NOT CHANGE THE ORDER OF THESE + ENTRIES, NOT DELETE ANY -- add new ones at the end. */ typedef enum { VG_USERREQ__MAKE_NOACCESS = VG_USERREQ_TOOL_BASE('M','C'), @@ -86,6 +90,8 @@ typedef VG_USERREQ__CREATE_BLOCK, + VG_USERREQ__MAKE_DEFINED, + /* This is just for memcheck's internal use - don't use it */ _VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR = VG_USERREQ_TOOL_BASE('M','C') + 256 @@ -125,6 +131,18 @@ typedef _qzz_res; \ })) +/* Similar to mark memory at VALGRIND_MAKE_READABLE except that + addressibility is not altered: bytes which are addressible are + marked as defined, but those which are not addressible are + left unchanged. */ +#define VALGRIND_MAKE_DEFINED(_qzz_addr,_qzz_len) \ + (__extension__({unsigned int _qzz_res; \ + VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0 /* default return */, \ + VG_USERREQ__MAKE_DEFINED, \ + _qzz_addr, _qzz_len, 0, 0, 0); \ + _qzz_res; \ + })) + /* 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 -- 2.47.2