Set version to 3.22.0-RC2
[valgrind.git] / include / pub_tool_replacemalloc.h
blob4bddaa89433c97d669707f3f8a05850091fb507d
2 /*--------------------------------------------------------------------*/
3 /*--- Malloc replacement. pub_tool_replacemalloc.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2000-2017 Julian Seward
11 jseward@acm.org
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #ifndef __PUB_TOOL_REPLACEMALLOC_H
30 #define __PUB_TOOL_REPLACEMALLOC_H
32 #include "pub_tool_basics.h" // Addr
34 /* If a tool replaces malloc() et al, the easiest way to do so is to
35 link libreplacemalloc_toolpreload.o into its vgpreload_*.so file, and
36 use the functions declared below. You can do it from scratch,
37 though, if you enjoy that sort of thing. */
39 /* Can be called from VG_(tdict).malloc_malloc et al to do the actual
40 * alloc/freeing. */
41 extern void* VG_(cli_malloc) ( SizeT align, SizeT nbytes );
42 extern void* VG_(cli_realloc)( void* ptr, SizeT nbytes );
43 extern void VG_(cli_free) ( void* p );
44 // Returns the usable size of a heap-block. It's the asked-for size plus
45 // possibly some more due to rounding up.
46 extern SizeT VG_(cli_malloc_usable_size)( void* p );
49 /* If a tool uses deferred freeing (e.g. memcheck to catch accesses to
50 freed memory) it can maintain number and total size of queued blocks
51 in these variable to provide more accurate statistics about client
52 memory usage. Currently used by mallinfo(). */
53 extern Long VG_(free_queue_volume);
54 extern Long VG_(free_queue_length);
56 /* Check if an address is within a range, allowing for redzones at edges */
57 extern Bool VG_(addr_is_in_block)( Addr a, Addr start,
58 SizeT size, SizeT rz_szB );
60 /* ------------------------------------------------------------------ */
61 /* Some options that can be used by a tool if malloc() et al are replaced.
62 The tool should call the functions in the appropriate places to give
63 control over these aspects of Valgrind's version of malloc(). */
65 /* DEBUG: print malloc details? default: NO */
66 extern Bool VG_(clo_trace_malloc);
67 /* Minimum alignment in functions that don't specify alignment explicitly.
68 default: VG_MIN_MALLOC_SZB */
69 extern UInt VG_(clo_alignment);
70 /* Controls the behaviour of realloc(ptr, 0) */
71 extern Bool VG_(clo_realloc_zero_bytes_frees);
73 extern Bool VG_(replacement_malloc_process_cmd_line_option) ( const HChar* arg );
75 // If tool is replacing malloc for the client, the below returns
76 // the effective client redzone as derived from the default
77 // provided by the tool, VG_(clo_redzone_size) and the minimum
78 // redzone required by m_mallocfree.c.
79 // It is an error to call this before VG_(needs_malloc_replacement) has
80 // been called.
81 extern SizeT VG_(malloc_effective_client_redzone_size)(void);
83 /* We have 4 different C functions that perform aligned allocation
84 * They all have slightly different error conditions. But we only have
85 * one wrapper - tl_memalign. Rather than split that into four
86 * nearly identical functions (or resort to a lot of client
87 * requests), the following enum and struct add context so that
88 * memcheck can figure out whether to emit an error.
89 * This isn't a problem for the C++ allocators. Even though
90 * there are many of them they all have the same alignment
91 * behaviour. */
93 typedef enum {
94 AllocKindMemalign,
95 AllocKindPosixMemalign,
96 AllocKindAlignedAlloc,
97 AllocKindDeleteDefault,
98 AllocKindVecDeleteDefault,
99 AllocKindDeleteSized,
100 AllocKindVecDeleteSized,
101 AllocKindNewAligned,
102 AllocKindVecNewAligned,
103 AllocKindDeleteAligned,
104 AllocKindVecDeleteAligned,
105 AllocKindDeleteSizedAligned,
106 AllocKindVecDeleteSizedAligned
107 } AlignedAllocKind;
109 struct AlignedAllocInfo {
110 SizeT orig_alignment;
111 SizeT size;
112 void *mem;
113 AlignedAllocKind alloc_kind;
116 #endif // __PUB_TOOL_REPLACEMALLOC_H
118 /*--------------------------------------------------------------------*/
119 /*--- end ---*/
120 /*--------------------------------------------------------------------*/