Turn off unused result warnings
[valgrind.git] / coregrind / pub_core_mallocfree.h
blob6f0cd293bf0a881672f08cbc120e9460465d3435
2 /*--------------------------------------------------------------------*/
3 /*--- High-level memory management. pub_core_mallocfree.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_CORE_MALLOCFREE_H
30 #define __PUB_CORE_MALLOCFREE_H
32 #include "pub_tool_mallocfree.h"
34 //--------------------------------------------------------------------
35 // PURPOSE: high-level memory allocation (malloc/free), for the core and
36 // tools.
37 //--------------------------------------------------------------------
39 /* Allocation arenas.
41 CORE for the core's and tools' general use.
42 DINFO for debug info (symbols, line #s, CFI, etc) storage.
43 CLIENT for the client's mallocs/frees, if the tool replaces glibc's
44 malloc() et al -- redzone size is chosen by the tool.
45 DEMANGLE for the C++ demangler.
46 TTAUX for storing TT/TC auxiliary structures (address range
47 equivalence classes).
49 When adding a new arena, remember also to add it to ensure_mm_init().
51 typedef Int ArenaId;
53 #define VG_N_ARENAS 5
55 #define VG_AR_CORE 0
56 #define VG_AR_DINFO 1
57 #define VG_AR_CLIENT 2
58 #define VG_AR_DEMANGLE 3
59 #define VG_AR_TTAUX 4
61 // This is both the minimum payload size of a malloc'd block, and its
62 // minimum alignment. Must be a power of 2 greater than 4, and should be
63 // greater than 8.
64 #if defined(VGP_arm_linux) || \
65 defined(VGP_mips32_linux) || \
66 (defined(VGP_mips64_linux) && defined(VGABI_N32)) || \
67 defined(VGP_nanomips_linux) || \
68 defined(VGP_x86_solaris)
69 # define VG_MIN_MALLOC_SZB 8
70 // Nb: We always use 16 bytes for Darwin, even on 32-bits, so it can be used
71 // for any AltiVec- or SSE-related type. This matches the Darwin libc.
72 // Also, use 16 bytes for any PPC variant, since 16 is required to make
73 // Altiveccery work right.
74 #elif defined(VGP_x86_linux) || \
75 defined(VGP_amd64_linux) || \
76 defined(VGP_ppc32_linux) || \
77 defined(VGP_ppc64be_linux) || \
78 defined(VGP_ppc64le_linux) || \
79 defined(VGP_s390x_linux) || \
80 (defined(VGP_mips64_linux) && !defined(VGABI_N32)) || \
81 defined(VGP_x86_freebsd) || \
82 defined(VGP_amd64_freebsd) || \
83 defined(VGP_arm64_freebsd) || \
84 defined(VGP_x86_darwin) || \
85 defined(VGP_amd64_darwin) || \
86 defined(VGP_arm64_linux) || \
87 defined(VGP_amd64_solaris)
88 # define VG_MIN_MALLOC_SZB 16
89 #else
90 # error Unknown platform
91 #endif
93 /* This struct definition MUST match the system one. */
94 /* SVID2/XPG mallinfo structure */
95 struct vg_mallinfo {
96 int arena; /* total space allocated from system */
97 int ordblks; /* number of non-inuse chunks */
98 int smblks; /* unused -- always zero */
99 int hblks; /* number of mmapped regions */
100 int hblkhd; /* total space in mmapped regions */
101 int usmblks; /* unused -- always zero */
102 int fsmblks; /* unused -- always zero */
103 int uordblks; /* total allocated space */
104 int fordblks; /* total non-inuse space */
105 int keepcost; /* top-most, releasable (via malloc_trim) space */
108 extern void* VG_(arena_malloc) ( ArenaId arena, const HChar* cc, SizeT nbytes );
109 extern void VG_(arena_free) ( ArenaId arena, void* ptr );
110 extern void* VG_(arena_calloc) ( ArenaId arena, const HChar* cc,
111 SizeT nmemb, SizeT bytes_per_memb );
112 extern void* VG_(arena_realloc) ( ArenaId arena, const HChar* cc,
113 void* ptr, SizeT size );
114 extern void* VG_(arena_memalign)( ArenaId aid, const HChar* cc,
115 SizeT req_alignB, SizeT req_pszB );
116 extern HChar* VG_(arena_strdup) ( ArenaId aid, const HChar* cc,
117 const HChar* s);
119 /* Specialised version of realloc, that shrinks the size of the block ptr from
120 its current size to req_pszB.
121 req_pszB must be <= to the current size of ptr (otherwise it will assert).
122 Compared to VG_(arena_realloc):
123 * VG_(arena_realloc_shrink) cannot increase the size of ptr.
124 * If large enough, the unused memory is made usable for other allocation.
125 * ptr is shrunk in place, so as to avoid temporary allocation and memcpy. */
126 extern void VG_(arena_realloc_shrink) ( ArenaId aid,
127 void* ptr, SizeT req_pszB);
129 extern SizeT VG_(arena_malloc_usable_size) ( ArenaId aid, void* payload );
131 extern SizeT VG_(arena_redzone_size) ( ArenaId aid );
133 extern void VG_(mallinfo) ( ThreadId tid, struct vg_mallinfo* mi );
135 // VG_(arena_perm_malloc) is for permanent allocation of small blocks.
136 // See VG_(perm_malloc) in pub_tool_mallocfree.h for more details.
137 // Do not call any VG_(arena_*) functions with these permanent blocks.
138 extern void* VG_(arena_perm_malloc) ( ArenaId aid, SizeT nbytes, Int align );
140 extern void VG_(sanity_check_malloc_all) ( void );
142 extern void VG_(print_all_arena_stats) ( void );
144 extern void VG_(print_arena_cc_analysis) ( void );
146 typedef
147 struct _AddrArenaInfo
148 AddrArenaInfo;
150 struct _AddrArenaInfo {
151 ArenaId aid;
152 const HChar* name; // arena name, !NULL if Addr a points in an arena.
153 SizeT block_szB;
154 PtrdiffT rwoffset;
155 Bool free; // True if this is in the arena free zone.
157 /* If Addr a points in one of the allocation arenas, describes Addr a in *aai
158 otherwise sets *aai to 0/NULL/...
159 Note that no information is produced for addresses allocated with
160 VG_(arena_perm_malloc). */
161 extern void VG_(describe_arena_addr) ( Addr a, /*OUT*/AddrArenaInfo* aai );
163 #endif // __PUB_CORE_MALLOCFREE_H
165 /*--------------------------------------------------------------------*/
166 /*--- end ---*/
167 /*--------------------------------------------------------------------*/