blob: d79dabc910204181726a44b98bf32259384c443e [file] [log] [blame]
njn717cde52005-05-10 02:47:21 +00001
2/*--------------------------------------------------------------------*/
3/*--- High-level memory management. pub_core_mallocfree.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
10 Copyright (C) 2000-2005 Julian Seward
11 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_CORE_MALLOCFREE_H
32#define __PUB_CORE_MALLOCFREE_H
33
34#include "pub_tool_mallocfree.h"
35
36//--------------------------------------------------------------------
37// PURPOSE: high-level memory allocation (malloc/free), for the core and
38// tools.
39//--------------------------------------------------------------------
40
41/* Allocation arenas.
42
43 CORE for the core's general use.
44 TOOL for the tool to use (and the only one it uses).
45 SYMTAB for Valgrind's symbol table storage.
46 CLIENT for the client's mallocs/frees, if the tool replaces glibc's
47 malloc() et al -- redzone size is chosen by the tool.
48 DEMANGLE for the C++ demangler.
49 EXECTXT for storing ExeContexts.
50 ERRORS for storing CoreErrors.
51
52 When adding a new arena, remember also to add it to ensure_mm_init().
53*/
54typedef Int ArenaId;
55
56#define VG_N_ARENAS 7
57
58#define VG_AR_CORE 0
59#define VG_AR_TOOL 1
60#define VG_AR_SYMTAB 2
61#define VG_AR_CLIENT 3
62#define VG_AR_DEMANGLE 4
63#define VG_AR_EXECTXT 5
64#define VG_AR_ERRORS 6
65
66// This is both the minimum payload size of a malloc'd block, and its
67// minimum alignment. Must be a power of 2 greater than 4, and should be
68// greater than 8.
69#define VG_MIN_MALLOC_SZB 8
70
njn088bfb42005-08-17 05:01:37 +000071/* This struct definition MUST match the system one. */
72/* SVID2/XPG mallinfo structure */
73struct vg_mallinfo {
74 int arena; /* total space allocated from system */
75 int ordblks; /* number of non-inuse chunks */
76 int smblks; /* unused -- always zero */
77 int hblks; /* number of mmapped regions */
78 int hblkhd; /* total space in mmapped regions */
79 int usmblks; /* unused -- always zero */
80 int fsmblks; /* unused -- always zero */
81 int uordblks; /* total allocated space */
82 int fordblks; /* total non-inuse space */
83 int keepcost; /* top-most, releasable (via malloc_trim) space */
84};
85
njn717cde52005-05-10 02:47:21 +000086extern void* VG_(arena_malloc) ( ArenaId arena, SizeT nbytes );
87extern void VG_(arena_free) ( ArenaId arena, void* ptr );
88extern void* VG_(arena_calloc) ( ArenaId arena,
89 SizeT nmemb, SizeT bytes_per_memb );
90extern void* VG_(arena_realloc) ( ArenaId arena, void* ptr, SizeT size );
91extern void* VG_(arena_memalign)( ArenaId aid, SizeT req_alignB,
92 SizeT req_pszB );
njn6ba622c2005-06-11 01:12:08 +000093extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s);
njn717cde52005-05-10 02:47:21 +000094
sewardj45f4e7c2005-09-27 19:20:21 +000095extern SizeT VG_(arena_payload_szB) ( ThreadId tid, ArenaId aid, void* payload );
njn717cde52005-05-10 02:47:21 +000096
njn088bfb42005-08-17 05:01:37 +000097extern void VG_(mallinfo) ( ThreadId tid, struct vg_mallinfo* mi );
98
njn717cde52005-05-10 02:47:21 +000099extern void VG_(sanity_check_malloc_all) ( void );
100
101extern void VG_(print_all_arena_stats) ( void );
102
103#endif // __PUB_CORE_MALLOCFREE_H
104
105/*--------------------------------------------------------------------*/
106/*--- end ---*/
107/*--------------------------------------------------------------------*/