Blame build/valgrind/memcheck.h

Packit b00eeb
Packit b00eeb
/*
Packit b00eeb
   ----------------------------------------------------------------
Packit b00eeb
Packit b00eeb
   Notice that the following BSD-style license applies to this one
Packit b00eeb
   file (memcheck.h) only.  The rest of Valgrind is licensed under the
Packit b00eeb
   terms of the GNU General Public License, version 2, unless
Packit b00eeb
   otherwise indicated.  See the COPYING file in the source
Packit b00eeb
   distribution for details.
Packit b00eeb
Packit b00eeb
   ----------------------------------------------------------------
Packit b00eeb
Packit b00eeb
   This file is part of MemCheck, a heavyweight Valgrind tool for
Packit b00eeb
   detecting memory errors.
Packit b00eeb
Packit b00eeb
   Copyright (C) 2000-2013 Julian Seward.  All rights reserved.
Packit b00eeb
Packit b00eeb
   Redistribution and use in source and binary forms, with or without
Packit b00eeb
   modification, are permitted provided that the following conditions
Packit b00eeb
   are met:
Packit b00eeb
Packit b00eeb
   1. Redistributions of source code must retain the above copyright
Packit b00eeb
      notice, this list of conditions and the following disclaimer.
Packit b00eeb
Packit b00eeb
   2. The origin of this software must not be misrepresented; you must 
Packit b00eeb
      not claim that you wrote the original software.  If you use this 
Packit b00eeb
      software in a product, an acknowledgment in the product 
Packit b00eeb
      documentation would be appreciated but is not required.
Packit b00eeb
Packit b00eeb
   3. Altered source versions must be plainly marked as such, and must
Packit b00eeb
      not be misrepresented as being the original software.
Packit b00eeb
Packit b00eeb
   4. The name of the author may not be used to endorse or promote 
Packit b00eeb
      products derived from this software without specific prior written 
Packit b00eeb
      permission.
Packit b00eeb
Packit b00eeb
   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
Packit b00eeb
   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Packit b00eeb
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit b00eeb
   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
Packit b00eeb
   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit b00eeb
   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
Packit b00eeb
   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit b00eeb
   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit b00eeb
   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit b00eeb
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit b00eeb
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit b00eeb
Packit b00eeb
   ----------------------------------------------------------------
Packit b00eeb
Packit b00eeb
   Notice that the above BSD-style license applies to this one file
Packit b00eeb
   (memcheck.h) only.  The entire rest of Valgrind is licensed under
Packit b00eeb
   the terms of the GNU General Public License, version 2.  See the
Packit b00eeb
   COPYING file in the source distribution for details.
Packit b00eeb
Packit b00eeb
   ---------------------------------------------------------------- 
Packit b00eeb
*/
Packit b00eeb
Packit b00eeb
Packit b00eeb
#ifndef __MEMCHECK_H
Packit b00eeb
#define __MEMCHECK_H
Packit b00eeb
Packit b00eeb
Packit b00eeb
/* This file is for inclusion into client (your!) code.
Packit b00eeb
Packit b00eeb
   You can use these macros to manipulate and query memory permissions
Packit b00eeb
   inside your own programs.
Packit b00eeb
Packit b00eeb
   See comment near the top of valgrind.h on how to use them.
Packit b00eeb
*/
Packit b00eeb
Packit b00eeb
#include "valgrind.h"
Packit b00eeb
Packit b00eeb
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! 
Packit b00eeb
   This enum comprises an ABI exported by Valgrind to programs
Packit b00eeb
   which use client requests.  DO NOT CHANGE THE ORDER OF THESE
Packit b00eeb
   ENTRIES, NOR DELETE ANY -- add new ones at the end. */
Packit b00eeb
typedef
Packit b00eeb
   enum { 
Packit b00eeb
      VG_USERREQ__MAKE_MEM_NOACCESS = VG_USERREQ_TOOL_BASE('M','C'),
Packit b00eeb
      VG_USERREQ__MAKE_MEM_UNDEFINED,
Packit b00eeb
      VG_USERREQ__MAKE_MEM_DEFINED,
Packit b00eeb
      VG_USERREQ__DISCARD,
Packit b00eeb
      VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE,
Packit b00eeb
      VG_USERREQ__CHECK_MEM_IS_DEFINED,
Packit b00eeb
      VG_USERREQ__DO_LEAK_CHECK,
Packit b00eeb
      VG_USERREQ__COUNT_LEAKS,
Packit b00eeb
Packit b00eeb
      VG_USERREQ__GET_VBITS,
Packit b00eeb
      VG_USERREQ__SET_VBITS,
Packit b00eeb
Packit b00eeb
      VG_USERREQ__CREATE_BLOCK,
Packit b00eeb
Packit b00eeb
      VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE,
Packit b00eeb
Packit b00eeb
      /* Not next to VG_USERREQ__COUNT_LEAKS because it was added later. */
Packit b00eeb
      VG_USERREQ__COUNT_LEAK_BLOCKS,
Packit b00eeb
Packit b00eeb
      /* This is just for memcheck's internal use - don't use it */
Packit b00eeb
      _VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR 
Packit b00eeb
         = VG_USERREQ_TOOL_BASE('M','C') + 256
Packit b00eeb
   } Vg_MemCheckClientRequest;
Packit b00eeb
Packit b00eeb
Packit b00eeb
Packit b00eeb
/* Client-code macros to manipulate the state of memory. */
Packit b00eeb
Packit b00eeb
/* Mark memory at _qzz_addr as unaddressable for _qzz_len bytes. */
Packit b00eeb
#define VALGRIND_MAKE_MEM_NOACCESS(_qzz_addr,_qzz_len)           \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
Packit b00eeb
                            VG_USERREQ__MAKE_MEM_NOACCESS,       \
Packit b00eeb
                            (_qzz_addr), (_qzz_len), 0, 0, 0)
Packit b00eeb
      
Packit b00eeb
/* Similarly, mark memory at _qzz_addr as addressable but undefined
Packit b00eeb
   for _qzz_len bytes. */
Packit b00eeb
#define VALGRIND_MAKE_MEM_UNDEFINED(_qzz_addr,_qzz_len)          \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
Packit b00eeb
                            VG_USERREQ__MAKE_MEM_UNDEFINED,      \
Packit b00eeb
                            (_qzz_addr), (_qzz_len), 0, 0, 0)
Packit b00eeb
Packit b00eeb
/* Similarly, mark memory at _qzz_addr as addressable and defined
Packit b00eeb
   for _qzz_len bytes. */
Packit b00eeb
#define VALGRIND_MAKE_MEM_DEFINED(_qzz_addr,_qzz_len)            \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
Packit b00eeb
                            VG_USERREQ__MAKE_MEM_DEFINED,        \
Packit b00eeb
                            (_qzz_addr), (_qzz_len), 0, 0, 0)
Packit b00eeb
Packit b00eeb
/* Similar to VALGRIND_MAKE_MEM_DEFINED except that addressability is
Packit b00eeb
   not altered: bytes which are addressable are marked as defined,
Packit b00eeb
   but those which are not addressable are left unchanged. */
Packit b00eeb
#define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(_qzz_addr,_qzz_len)     \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,              \
Packit b00eeb
                            VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE, \
Packit b00eeb
                            (_qzz_addr), (_qzz_len), 0, 0, 0)
Packit b00eeb
Packit b00eeb
/* Create a block-description handle.  The description is an ascii
Packit b00eeb
   string which is included in any messages pertaining to addresses
Packit b00eeb
   within the specified memory range.  Has no other effect on the
Packit b00eeb
   properties of the memory range. */
Packit b00eeb
#define VALGRIND_CREATE_BLOCK(_qzz_addr,_qzz_len, _qzz_desc)	   \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,        \
Packit b00eeb
                            VG_USERREQ__CREATE_BLOCK,              \
Packit b00eeb
                            (_qzz_addr), (_qzz_len), (_qzz_desc),  \
Packit b00eeb
                            0, 0)
Packit b00eeb
Packit b00eeb
/* Discard a block-description-handle. Returns 1 for an
Packit b00eeb
   invalid handle, 0 for a valid handle. */
Packit b00eeb
#define VALGRIND_DISCARD(_qzz_blkindex)                          \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
Packit b00eeb
                            VG_USERREQ__DISCARD,                 \
Packit b00eeb
                            0, (_qzz_blkindex), 0, 0, 0)
Packit b00eeb
Packit b00eeb
Packit b00eeb
/* Client-code macros to check the state of memory. */
Packit b00eeb
Packit b00eeb
/* Check that memory at _qzz_addr is addressable for _qzz_len bytes.
Packit b00eeb
   If suitable addressibility is not established, Valgrind prints an
Packit b00eeb
   error message and returns the address of the first offending byte.
Packit b00eeb
   Otherwise it returns zero. */
Packit b00eeb
#define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(_qzz_addr,_qzz_len)      \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0,                             \
Packit b00eeb
                            VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE,  \
Packit b00eeb
                            (_qzz_addr), (_qzz_len), 0, 0, 0)
Packit b00eeb
Packit b00eeb
/* Check that memory at _qzz_addr is addressable and defined for
Packit b00eeb
   _qzz_len bytes.  If suitable addressibility and definedness are not
Packit b00eeb
   established, Valgrind prints an error message and returns the
Packit b00eeb
   address of the first offending byte.  Otherwise it returns zero. */
Packit b00eeb
#define VALGRIND_CHECK_MEM_IS_DEFINED(_qzz_addr,_qzz_len)        \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0,                           \
Packit b00eeb
                            VG_USERREQ__CHECK_MEM_IS_DEFINED,    \
Packit b00eeb
                            (_qzz_addr), (_qzz_len), 0, 0, 0)
Packit b00eeb
Packit b00eeb
/* Use this macro to force the definedness and addressibility of an
Packit b00eeb
   lvalue to be checked.  If suitable addressibility and definedness
Packit b00eeb
   are not established, Valgrind prints an error message and returns
Packit b00eeb
   the address of the first offending byte.  Otherwise it returns
Packit b00eeb
   zero. */
Packit b00eeb
#define VALGRIND_CHECK_VALUE_IS_DEFINED(__lvalue)                \
Packit b00eeb
   VALGRIND_CHECK_MEM_IS_DEFINED(                                \
Packit b00eeb
      (volatile unsigned char *)&(__lvalue),                     \
Packit b00eeb
                      (unsigned long)(sizeof (__lvalue)))
Packit b00eeb
Packit b00eeb
Packit b00eeb
/* Do a full memory leak check (like --leak-check=full) mid-execution. */
Packit b00eeb
#define VALGRIND_DO_LEAK_CHECK                                   \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK,   \
Packit b00eeb
                                    0, 0, 0, 0, 0)
Packit b00eeb
Packit b00eeb
/* Same as VALGRIND_DO_LEAK_CHECK but only showing the entries for
Packit b00eeb
   which there was an increase in leaked bytes or leaked nr of blocks
Packit b00eeb
   since the previous leak search. */
Packit b00eeb
#define VALGRIND_DO_ADDED_LEAK_CHECK                            \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK,  \
Packit b00eeb
                                    0, 1, 0, 0, 0)
Packit b00eeb
Packit b00eeb
/* Same as VALGRIND_DO_ADDED_LEAK_CHECK but showing entries with
Packit b00eeb
   increased or decreased leaked bytes/blocks since previous leak
Packit b00eeb
   search. */
Packit b00eeb
#define VALGRIND_DO_CHANGED_LEAK_CHECK                          \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK,  \
Packit b00eeb
                                    0, 2, 0, 0, 0)
Packit b00eeb
Packit b00eeb
/* Do a summary memory leak check (like --leak-check=summary) mid-execution. */
Packit b00eeb
#define VALGRIND_DO_QUICK_LEAK_CHECK                             \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK,   \
Packit b00eeb
                                    1, 0, 0, 0, 0)
Packit b00eeb
Packit b00eeb
/* Return number of leaked, dubious, reachable and suppressed bytes found by
Packit b00eeb
   all previous leak checks.  They must be lvalues.  */
Packit b00eeb
#define VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed)     \
Packit b00eeb
   /* For safety on 64-bit platforms we assign the results to private
Packit b00eeb
      unsigned long variables, then assign these to the lvalues the user
Packit b00eeb
      specified, which works no matter what type 'leaked', 'dubious', etc
Packit b00eeb
      are.  We also initialise '_qzz_leaked', etc because
Packit b00eeb
      VG_USERREQ__COUNT_LEAKS doesn't mark the values returned as
Packit b00eeb
      defined. */                                                        \
Packit b00eeb
   {                                                                     \
Packit b00eeb
    unsigned long _qzz_leaked    = 0, _qzz_dubious    = 0;               \
Packit b00eeb
    unsigned long _qzz_reachable = 0, _qzz_suppressed = 0;               \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_STMT(                                     \
Packit b00eeb
                               VG_USERREQ__COUNT_LEAKS,                  \
Packit b00eeb
                               &_qzz_leaked, &_qzz_dubious,              \
Packit b00eeb
                               &_qzz_reachable, &_qzz_suppressed, 0);    \
Packit b00eeb
    leaked     = _qzz_leaked;                                            \
Packit b00eeb
    dubious    = _qzz_dubious;                                           \
Packit b00eeb
    reachable  = _qzz_reachable;                                         \
Packit b00eeb
    suppressed = _qzz_suppressed;                                        \
Packit b00eeb
   }
Packit b00eeb
Packit b00eeb
/* Return number of leaked, dubious, reachable and suppressed bytes found by
Packit b00eeb
   all previous leak checks.  They must be lvalues.  */
Packit b00eeb
#define VALGRIND_COUNT_LEAK_BLOCKS(leaked, dubious, reachable, suppressed) \
Packit b00eeb
   /* For safety on 64-bit platforms we assign the results to private
Packit b00eeb
      unsigned long variables, then assign these to the lvalues the user
Packit b00eeb
      specified, which works no matter what type 'leaked', 'dubious', etc
Packit b00eeb
      are.  We also initialise '_qzz_leaked', etc because
Packit b00eeb
      VG_USERREQ__COUNT_LEAKS doesn't mark the values returned as
Packit b00eeb
      defined. */                                                        \
Packit b00eeb
   {                                                                     \
Packit b00eeb
    unsigned long _qzz_leaked    = 0, _qzz_dubious    = 0;               \
Packit b00eeb
    unsigned long _qzz_reachable = 0, _qzz_suppressed = 0;               \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_STMT(                                     \
Packit b00eeb
                               VG_USERREQ__COUNT_LEAK_BLOCKS,            \
Packit b00eeb
                               &_qzz_leaked, &_qzz_dubious,              \
Packit b00eeb
                               &_qzz_reachable, &_qzz_suppressed, 0);    \
Packit b00eeb
    leaked     = _qzz_leaked;                                            \
Packit b00eeb
    dubious    = _qzz_dubious;                                           \
Packit b00eeb
    reachable  = _qzz_reachable;                                         \
Packit b00eeb
    suppressed = _qzz_suppressed;                                        \
Packit b00eeb
   }
Packit b00eeb
Packit b00eeb
Packit b00eeb
/* Get the validity data for addresses [zza..zza+zznbytes-1] and copy it
Packit b00eeb
   into the provided zzvbits array.  Return values:
Packit b00eeb
      0   if not running on valgrind
Packit b00eeb
      1   success
Packit b00eeb
      2   [previously indicated unaligned arrays;  these are now allowed]
Packit b00eeb
      3   if any parts of zzsrc/zzvbits are not addressable.
Packit b00eeb
   The metadata is not copied in cases 0, 2 or 3 so it should be
Packit b00eeb
   impossible to segfault your system by using this call.
Packit b00eeb
*/
Packit b00eeb
#define VALGRIND_GET_VBITS(zza,zzvbits,zznbytes)                \
Packit b00eeb
    (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0,                \
Packit b00eeb
                                    VG_USERREQ__GET_VBITS,      \
Packit b00eeb
                                    (const char*)(zza),         \
Packit b00eeb
                                    (char*)(zzvbits),           \
Packit b00eeb
                                    (zznbytes), 0, 0)
Packit b00eeb
Packit b00eeb
/* Set the validity data for addresses [zza..zza+zznbytes-1], copying it
Packit b00eeb
   from the provided zzvbits array.  Return values:
Packit b00eeb
      0   if not running on valgrind
Packit b00eeb
      1   success
Packit b00eeb
      2   [previously indicated unaligned arrays;  these are now allowed]
Packit b00eeb
      3   if any parts of zza/zzvbits are not addressable.
Packit b00eeb
   The metadata is not copied in cases 0, 2 or 3 so it should be
Packit b00eeb
   impossible to segfault your system by using this call.
Packit b00eeb
*/
Packit b00eeb
#define VALGRIND_SET_VBITS(zza,zzvbits,zznbytes)                \
Packit b00eeb
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0,                \
Packit b00eeb
                                    VG_USERREQ__SET_VBITS,      \
Packit b00eeb
                                    (const char*)(zza),         \
Packit b00eeb
                                    (const char*)(zzvbits),     \
Packit b00eeb
                                    (zznbytes), 0, 0 )
Packit b00eeb
Packit b00eeb
#endif
Packit b00eeb