blob: e237fff16f65f8db98ec67dd4d2ca132f5582832 [file] [log] [blame]
njn717cde52005-05-10 02:47:21 +00001
2/*--------------------------------------------------------------------*/
3/*--- Malloc replacement. pub_tool_replacemalloc.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
Elliott Hughesed398002017-06-21 14:41:24 -070010 Copyright (C) 2000-2017 Julian Seward
njn717cde52005-05-10 02:47:21 +000011 jseward@acm.org
12
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.
17
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.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 02111-1307, USA.
27
28 The GNU General Public License is contained in the file COPYING.
29*/
30
31#ifndef __PUB_TOOL_REPLACEMALLOC_H
32#define __PUB_TOOL_REPLACEMALLOC_H
33
florian535fb1b2013-09-15 13:54:34 +000034#include "pub_tool_basics.h" // Addr
35
njn717cde52005-05-10 02:47:21 +000036/* If a tool replaces malloc() et al, the easiest way to do so is to
37 link libreplacemalloc_toolpreload.o into its vgpreload_*.so file, and
38 use the functions declared below. You can do it from scratch,
39 though, if you enjoy that sort of thing. */
40
41/* Can be called from VG_(tdict).malloc_malloc et al to do the actual
42 * alloc/freeing. */
43extern void* VG_(cli_malloc) ( SizeT align, SizeT nbytes );
44extern void VG_(cli_free) ( void* p );
floriane464e802014-09-11 20:15:23 +000045// Returns the usable size of a heap-block. It's the asked-for size plus
46// possibly some more due to rounding up.
47extern SizeT VG_(cli_malloc_usable_size)( void* p );
48
njn717cde52005-05-10 02:47:21 +000049
bart545380e2008-04-21 17:28:50 +000050/* If a tool uses deferred freeing (e.g. memcheck to catch accesses to
51 freed memory) it can maintain number and total size of queued blocks
52 in these variable to provide more accurate statistics about client
53 memory usage. Currently used by mallinfo(). */
54extern Long VG_(free_queue_volume);
55extern Long VG_(free_queue_length);
56
njn717cde52005-05-10 02:47:21 +000057/* Check if an address is within a range, allowing for redzones at edges */
58extern Bool VG_(addr_is_in_block)( Addr a, Addr start,
59 SizeT size, SizeT rz_szB );
60
61/* ------------------------------------------------------------------ */
62/* Some options that can be used by a tool if malloc() et al are replaced.
63 The tool should call the functions in the appropriate places to give
64 control over these aspects of Valgrind's version of malloc(). */
65
66/* DEBUG: print malloc details? default: NO */
67extern Bool VG_(clo_trace_malloc);
68/* Minimum alignment in functions that don't specify alignment explicitly.
69 default: VG_MIN_MALLOC_SZB */
70extern UInt VG_(clo_alignment);
71
florian19f91bb2012-11-10 22:29:54 +000072extern Bool VG_(replacement_malloc_process_cmd_line_option) ( const HChar* arg );
njn717cde52005-05-10 02:47:21 +000073
florianac3a1d82013-09-15 09:18:03 +000074// If tool is replacing malloc for the client, the below returns
75// the effective client redzone as derived from the default
76// provided by the tool, VG_(clo_redzone_size) and the minimum
77// redzone required by m_mallocfree.c.
78// It is an error to call this before VG_(needs_malloc_replacement) has
79// been called.
80extern SizeT VG_(malloc_effective_client_redzone_size)(void);
81
njn717cde52005-05-10 02:47:21 +000082#endif // __PUB_TOOL_REPLACEMALLOC_H
83
84/*--------------------------------------------------------------------*/
85/*--- end ---*/
86/*--------------------------------------------------------------------*/