]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a new kind of memory-painting primitive, which is: 'make_defined'.
authorJulian Seward <jseward@acm.org>
Fri, 10 Mar 2006 13:41:58 +0000 (13:41 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 10 Mar 2006 13:41:58 +0000 (13:41 +0000)
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
memcheck/memcheck.h

index f63986b53ebeeedb50203dff21849f735c2f2453..20192ef8ed6dd02069d61d44621f7e3dd77227a4 100644 (file)
@@ -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();
index 735a34a6d24153fd4f7693e8ae6b25319c67e128..0c529f3280194e5026267c471350b8c4dc92ae5f 100644 (file)
 
 #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