Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:35:54

0001 
0002 /*--------------------------------------------------------------------*/
0003 /*--- Malloc replacement.                 pub_tool_replacemalloc.h ---*/
0004 /*--------------------------------------------------------------------*/
0005 
0006 /*
0007    This file is part of Valgrind, a dynamic binary instrumentation
0008    framework.
0009 
0010    Copyright (C) 2000-2017 Julian Seward
0011       jseward@acm.org
0012 
0013    This program is free software; you can redistribute it and/or
0014    modify it under the terms of the GNU General Public License as
0015    published by the Free Software Foundation; either version 2 of the
0016    License, or (at your option) any later version.
0017 
0018    This program is distributed in the hope that it will be useful, but
0019    WITHOUT ANY WARRANTY; without even the implied warranty of
0020    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0021    General Public License for more details.
0022 
0023    You should have received a copy of the GNU General Public License
0024    along with this program; if not, see <http://www.gnu.org/licenses/>.
0025 
0026    The GNU General Public License is contained in the file COPYING.
0027 */
0028 
0029 #ifndef __PUB_TOOL_REPLACEMALLOC_H
0030 #define __PUB_TOOL_REPLACEMALLOC_H
0031 
0032 #include "pub_tool_basics.h"   // Addr
0033 
0034 /* If a tool replaces malloc() et al, the easiest way to do so is to
0035    link libreplacemalloc_toolpreload.o into its vgpreload_*.so file, and
0036    use the functions declared below.  You can do it from scratch,
0037    though, if you enjoy that sort of thing. */
0038 
0039 /* Can be called from VG_(tdict).malloc_malloc et al to do the actual
0040  * alloc/freeing. */
0041 extern void* VG_(cli_malloc) ( SizeT align, SizeT nbytes );
0042 extern void* VG_(cli_realloc)( void* ptr, SizeT nbytes );
0043 extern void  VG_(cli_free)   ( void* p );
0044 // Returns the usable size of a heap-block.  It's the asked-for size plus
0045 // possibly some more due to rounding up.
0046 extern SizeT VG_(cli_malloc_usable_size)( void* p );
0047 
0048 
0049 /* If a tool uses deferred freeing (e.g. memcheck to catch accesses to
0050    freed memory) it can maintain number and total size of queued blocks
0051    in these variable to provide more accurate statistics about client
0052    memory usage. Currently used by mallinfo(). */
0053 extern Long VG_(free_queue_volume);
0054 extern Long VG_(free_queue_length);
0055 
0056 /* Check if an address is within a range, allowing for redzones at edges */
0057 extern Bool VG_(addr_is_in_block)( Addr a, Addr start,
0058                                    SizeT size, SizeT rz_szB );
0059 
0060 /* ------------------------------------------------------------------ */
0061 /* Some options that can be used by a tool if malloc() et al are replaced.
0062    The tool should call the functions in the appropriate places to give
0063    control over these aspects of Valgrind's version of malloc(). */
0064 
0065 /* DEBUG: print malloc details?  default: NO */
0066 extern Bool VG_(clo_trace_malloc);
0067 /* Minimum alignment in functions that don't specify alignment explicitly.
0068    default: VG_MIN_MALLOC_SZB */
0069 extern UInt VG_(clo_alignment);
0070 /* Controls the behaviour of realloc(ptr, 0) */
0071 extern Bool VG_(clo_realloc_zero_bytes_frees);
0072 
0073 extern Bool VG_(replacement_malloc_process_cmd_line_option) ( const HChar* arg );
0074 
0075 // If tool is replacing malloc for the client, the below returns
0076 // the effective client redzone as derived from the default
0077 // provided by the tool, VG_(clo_redzone_size) and the minimum
0078 // redzone required by m_mallocfree.c.
0079 // It is an error to call this before VG_(needs_malloc_replacement) has
0080 // been called.
0081 extern SizeT VG_(malloc_effective_client_redzone_size)(void);
0082 
0083 /* We have 4 different C functions that perform aligned allocation
0084  * They all have slightly different error conditions. But we only have
0085  * one wrapper - tl_memalign. Rather than split that into four
0086  * nearly identical functions (or resort to a lot of client
0087  * requests), the following enum and struct add context so that
0088  * memcheck can figure out whether to emit an error.
0089  * This isn't a problem for the C++ allocators. Even though
0090  * there are many of them they all have the same alignment
0091  * behaviour. */
0092 
0093 typedef enum {
0094    AllocKindMemalign,
0095    AllocKindPosixMemalign,
0096    AllocKindAlignedAlloc,
0097    AllocKindDeleteDefault,
0098    AllocKindVecDeleteDefault,
0099    AllocKindDeleteSized,
0100    AllocKindVecDeleteSized,
0101    AllocKindNewAligned,
0102    AllocKindVecNewAligned,
0103    AllocKindDeleteAligned,
0104    AllocKindVecDeleteAligned,
0105    AllocKindDeleteSizedAligned,
0106    AllocKindVecDeleteSizedAligned,
0107    AllocKindFreeSized,
0108    AllocKindFreeAlignedSized
0109 } AlignedAllocKind;
0110 
0111 struct AlignedAllocInfo {
0112    SizeT orig_alignment;
0113    SizeT size;
0114    void *mem;
0115    AlignedAllocKind alloc_kind;
0116 };
0117 
0118 #endif   // __PUB_TOOL_REPLACEMALLOC_H
0119 
0120 /*--------------------------------------------------------------------*/
0121 /*--- end                                                          ---*/
0122 /*--------------------------------------------------------------------*/