Rev 68697 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
/*----------------------------------------------------------------Notice that the following BSD-style license applies to this onefile (memcheck.h) only. The rest of Valgrind is licensed under theterms of the GNU General Public License, version 2, unlessotherwise indicated. See the COPYING file in the sourcedistribution for details.----------------------------------------------------------------This file is part of MemCheck, a heavyweight Valgrind tool fordetecting memory errors.Copyright (C) 2000-2013 Julian Seward. All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditionsare met:1. Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer.2. The origin of this software must not be misrepresented; you mustnot claim that you wrote the original software. If you use thissoftware in a product, an acknowledgment in the productdocumentation would be appreciated but is not required.3. Altered source versions must be plainly marked as such, and mustnot be misrepresented as being the original software.4. The name of the author may not be used to endorse or promoteproducts derived from this software without specific prior writtenpermission.THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSOR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSEARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTEGOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESSINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDINGNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.----------------------------------------------------------------Notice that the above BSD-style license applies to this one file(memcheck.h) only. The entire rest of Valgrind is licensed underthe terms of the GNU General Public License, version 2. See theCOPYING file in the source distribution for details.----------------------------------------------------------------*/#ifndef __MEMCHECK_H#define __MEMCHECK_H/* This file is for inclusion into client (your!) code.You can use these macros to manipulate and query memory permissionsinside your own programs.See comment near the top of valgrind.h on how to use them.*//* R change to ensure that our copy of the header is used */#include "vg/valgrind.h"/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!This enum comprises an ABI exported by Valgrind to programswhich use client requests. DO NOT CHANGE THE ORDER OF THESEENTRIES, NOR DELETE ANY -- add new ones at the end. */typedefenum {VG_USERREQ__MAKE_MEM_NOACCESS = VG_USERREQ_TOOL_BASE('M','C'),VG_USERREQ__MAKE_MEM_UNDEFINED,VG_USERREQ__MAKE_MEM_DEFINED,VG_USERREQ__DISCARD,VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE,VG_USERREQ__CHECK_MEM_IS_DEFINED,VG_USERREQ__DO_LEAK_CHECK,VG_USERREQ__COUNT_LEAKS,VG_USERREQ__GET_VBITS,VG_USERREQ__SET_VBITS,VG_USERREQ__CREATE_BLOCK,VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE,/* Not next to VG_USERREQ__COUNT_LEAKS because it was added later. */VG_USERREQ__COUNT_LEAK_BLOCKS,VG_USERREQ__ENABLE_ADDR_ERROR_REPORTING_IN_RANGE,VG_USERREQ__DISABLE_ADDR_ERROR_REPORTING_IN_RANGE,/* 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} Vg_MemCheckClientRequest;/* Client-code macros to manipulate the state of memory. *//* Mark memory at _qzz_addr as unaddressable for _qzz_len bytes. */#define VALGRIND_MAKE_MEM_NOACCESS(_qzz_addr,_qzz_len) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \VG_USERREQ__MAKE_MEM_NOACCESS, \(_qzz_addr), (_qzz_len), 0, 0, 0)/* Similarly, mark memory at _qzz_addr as addressable but undefinedfor _qzz_len bytes. */#define VALGRIND_MAKE_MEM_UNDEFINED(_qzz_addr,_qzz_len) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \VG_USERREQ__MAKE_MEM_UNDEFINED, \(_qzz_addr), (_qzz_len), 0, 0, 0)/* Similarly, mark memory at _qzz_addr as addressable and definedfor _qzz_len bytes. */#define VALGRIND_MAKE_MEM_DEFINED(_qzz_addr,_qzz_len) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \VG_USERREQ__MAKE_MEM_DEFINED, \(_qzz_addr), (_qzz_len), 0, 0, 0)/* Similar to VALGRIND_MAKE_MEM_DEFINED except that addressability isnot altered: bytes which are addressable are marked as defined,but those which are not addressable are left unchanged. */#define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(_qzz_addr,_qzz_len) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE, \(_qzz_addr), (_qzz_len), 0, 0, 0)/* Create a block-description handle. The description is an asciistring which is included in any messages pertaining to addresseswithin the specified memory range. Has no other effect on theproperties of the memory range. */#define VALGRIND_CREATE_BLOCK(_qzz_addr,_qzz_len, _qzz_desc) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \VG_USERREQ__CREATE_BLOCK, \(_qzz_addr), (_qzz_len), (_qzz_desc), \0, 0)/* Discard a block-description-handle. Returns 1 for aninvalid handle, 0 for a valid handle. */#define VALGRIND_DISCARD(_qzz_blkindex) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \VG_USERREQ__DISCARD, \0, (_qzz_blkindex), 0, 0, 0)/* Client-code macros to check the state of memory. *//* Check that memory at _qzz_addr is addressable for _qzz_len bytes.If suitable addressibility is not established, Valgrind prints anerror message and returns the address of the first offending byte.Otherwise it returns zero. */#define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(_qzz_addr,_qzz_len) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE, \(_qzz_addr), (_qzz_len), 0, 0, 0)/* Check that memory at _qzz_addr is addressable and defined for_qzz_len bytes. If suitable addressibility and definedness are notestablished, Valgrind prints an error message and returns theaddress of the first offending byte. Otherwise it returns zero. */#define VALGRIND_CHECK_MEM_IS_DEFINED(_qzz_addr,_qzz_len) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \VG_USERREQ__CHECK_MEM_IS_DEFINED, \(_qzz_addr), (_qzz_len), 0, 0, 0)/* Use this macro to force the definedness and addressibility of anlvalue to be checked. If suitable addressibility and definednessare not established, Valgrind prints an error message and returnsthe address of the first offending byte. Otherwise it returnszero. */#define VALGRIND_CHECK_VALUE_IS_DEFINED(__lvalue) \VALGRIND_CHECK_MEM_IS_DEFINED( \(volatile unsigned char *)&(__lvalue), \(unsigned long)(sizeof (__lvalue)))/* Do a full memory leak check (like --leak-check=full) mid-execution. */#define VALGRIND_DO_LEAK_CHECK \VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \0, 0, 0, 0, 0)/* Same as VALGRIND_DO_LEAK_CHECK but only showing the entries forwhich there was an increase in leaked bytes or leaked nr of blockssince the previous leak search. */#define VALGRIND_DO_ADDED_LEAK_CHECK \VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \0, 1, 0, 0, 0)/* Same as VALGRIND_DO_ADDED_LEAK_CHECK but showing entries withincreased or decreased leaked bytes/blocks since previous leaksearch. */#define VALGRIND_DO_CHANGED_LEAK_CHECK \VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \0, 2, 0, 0, 0)/* Do a summary memory leak check (like --leak-check=summary) mid-execution. */#define VALGRIND_DO_QUICK_LEAK_CHECK \VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \1, 0, 0, 0, 0)/* Return number of leaked, dubious, reachable and suppressed bytes found byall previous leak checks. They must be lvalues. */#define VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed) \/* For safety on 64-bit platforms we assign the results to privateunsigned long variables, then assign these to the lvalues the userspecified, which works no matter what type 'leaked', 'dubious', etcare. We also initialise '_qzz_leaked', etc becauseVG_USERREQ__COUNT_LEAKS doesn't mark the values returned asdefined. */ \{ \unsigned long _qzz_leaked = 0, _qzz_dubious = 0; \unsigned long _qzz_reachable = 0, _qzz_suppressed = 0; \VALGRIND_DO_CLIENT_REQUEST_STMT( \VG_USERREQ__COUNT_LEAKS, \&_qzz_leaked, &_qzz_dubious, \&_qzz_reachable, &_qzz_suppressed, 0); \leaked = _qzz_leaked; \dubious = _qzz_dubious; \reachable = _qzz_reachable; \suppressed = _qzz_suppressed; \}/* Return number of leaked, dubious, reachable and suppressed bytes found byall previous leak checks. They must be lvalues. */#define VALGRIND_COUNT_LEAK_BLOCKS(leaked, dubious, reachable, suppressed) \/* For safety on 64-bit platforms we assign the results to privateunsigned long variables, then assign these to the lvalues the userspecified, which works no matter what type 'leaked', 'dubious', etcare. We also initialise '_qzz_leaked', etc becauseVG_USERREQ__COUNT_LEAKS doesn't mark the values returned asdefined. */ \{ \unsigned long _qzz_leaked = 0, _qzz_dubious = 0; \unsigned long _qzz_reachable = 0, _qzz_suppressed = 0; \VALGRIND_DO_CLIENT_REQUEST_STMT( \VG_USERREQ__COUNT_LEAK_BLOCKS, \&_qzz_leaked, &_qzz_dubious, \&_qzz_reachable, &_qzz_suppressed, 0); \leaked = _qzz_leaked; \dubious = _qzz_dubious; \reachable = _qzz_reachable; \suppressed = _qzz_suppressed; \}/* Get the validity data for addresses [zza..zza+zznbytes-1] and copy itinto the provided zzvbits array. Return values:0 if not running on valgrind1 success2 [previously indicated unaligned arrays; these are now allowed]3 if any parts of zzsrc/zzvbits are not addressable.The metadata is not copied in cases 0, 2 or 3 so it should beimpossible to segfault your system by using this call.*/#define VALGRIND_GET_VBITS(zza,zzvbits,zznbytes) \(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \VG_USERREQ__GET_VBITS, \(const char*)(zza), \(char*)(zzvbits), \(zznbytes), 0, 0)/* Set the validity data for addresses [zza..zza+zznbytes-1], copying itfrom the provided zzvbits array. Return values:0 if not running on valgrind1 success2 [previously indicated unaligned arrays; these are now allowed]3 if any parts of zza/zzvbits are not addressable.The metadata is not copied in cases 0, 2 or 3 so it should beimpossible to segfault your system by using this call.*/#define VALGRIND_SET_VBITS(zza,zzvbits,zznbytes) \(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \VG_USERREQ__SET_VBITS, \(const char*)(zza), \(const char*)(zzvbits), \(zznbytes), 0, 0 )/* Disable and re-enable reporting of addressing errors in thespecified address range. */#define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(_qzz_addr,_qzz_len) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \VG_USERREQ__DISABLE_ADDR_ERROR_REPORTING_IN_RANGE, \(_qzz_addr), (_qzz_len), 0, 0, 0)#define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(_qzz_addr,_qzz_len) \VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \VG_USERREQ__ENABLE_ADDR_ERROR_REPORTING_IN_RANGE, \(_qzz_addr), (_qzz_len), 0, 0, 0)#endif