njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 1 | |
| 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 | |
sewardj | 03f8d3f | 2012-08-05 15:46:46 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2012 Julian Seward |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 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). |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 45 | DINFO for debug info (symbols, line #s, CFI, etc) storage. |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 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. |
sewardj | cd0309b | 2005-10-18 02:20:18 +0000 | [diff] [blame] | 51 | TTAUX for storing TT/TC auxiliary structures (address range |
| 52 | equivalence classes). |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 53 | |
| 54 | When adding a new arena, remember also to add it to ensure_mm_init(). |
| 55 | */ |
| 56 | typedef Int ArenaId; |
| 57 | |
sewardj | cd0309b | 2005-10-18 02:20:18 +0000 | [diff] [blame] | 58 | #define VG_N_ARENAS 8 |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 59 | |
| 60 | #define VG_AR_CORE 0 |
| 61 | #define VG_AR_TOOL 1 |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 62 | #define VG_AR_DINFO 2 |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 63 | #define VG_AR_CLIENT 3 |
| 64 | #define VG_AR_DEMANGLE 4 |
| 65 | #define VG_AR_EXECTXT 5 |
| 66 | #define VG_AR_ERRORS 6 |
sewardj | cd0309b | 2005-10-18 02:20:18 +0000 | [diff] [blame] | 67 | #define VG_AR_TTAUX 7 |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 68 | |
| 69 | // This is both the minimum payload size of a malloc'd block, and its |
| 70 | // minimum alignment. Must be a power of 2 greater than 4, and should be |
| 71 | // greater than 8. |
njn | 88d560f | 2009-05-21 03:36:21 +0000 | [diff] [blame] | 72 | #if defined(VGP_x86_linux) || \ |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 73 | defined(VGP_arm_linux) |
njn | 88d560f | 2009-05-21 03:36:21 +0000 | [diff] [blame] | 74 | # define VG_MIN_MALLOC_SZB 8 |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 75 | // Nb: We always use 16 bytes for Darwin, even on 32-bits, so it can be used |
| 76 | // for any AltiVec- or SSE-related type. This matches the Darwin libc. |
sewardj | 11684aa | 2011-04-27 23:25:15 +0000 | [diff] [blame] | 77 | // Also, use 16 bytes for any PPC variant, since 16 is required to make |
| 78 | // Altiveccery work right. |
njn | 88d560f | 2009-05-21 03:36:21 +0000 | [diff] [blame] | 79 | #elif defined(VGP_amd64_linux) || \ |
sewardj | 11684aa | 2011-04-27 23:25:15 +0000 | [diff] [blame] | 80 | defined(VGP_ppc32_linux) || \ |
njn | 88d560f | 2009-05-21 03:36:21 +0000 | [diff] [blame] | 81 | defined(VGP_ppc64_linux) || \ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 82 | defined(VGP_s390x_linux) || \ |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 83 | defined(VGP_mips32_linux) || \ |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 84 | defined(VGP_x86_darwin) || \ |
| 85 | defined(VGP_amd64_darwin) |
njn | 88d560f | 2009-05-21 03:36:21 +0000 | [diff] [blame] | 86 | # define VG_MIN_MALLOC_SZB 16 |
| 87 | #else |
| 88 | # error Unknown platform |
| 89 | #endif |
| 90 | |
njn | 088bfb4 | 2005-08-17 05:01:37 +0000 | [diff] [blame] | 91 | /* This struct definition MUST match the system one. */ |
| 92 | /* SVID2/XPG mallinfo structure */ |
| 93 | struct vg_mallinfo { |
| 94 | int arena; /* total space allocated from system */ |
| 95 | int ordblks; /* number of non-inuse chunks */ |
| 96 | int smblks; /* unused -- always zero */ |
| 97 | int hblks; /* number of mmapped regions */ |
| 98 | int hblkhd; /* total space in mmapped regions */ |
| 99 | int usmblks; /* unused -- always zero */ |
| 100 | int fsmblks; /* unused -- always zero */ |
| 101 | int uordblks; /* total allocated space */ |
| 102 | int fordblks; /* total non-inuse space */ |
| 103 | int keepcost; /* top-most, releasable (via malloc_trim) space */ |
| 104 | }; |
| 105 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 106 | extern void* VG_(arena_malloc) ( ArenaId arena, HChar* cc, SizeT nbytes ); |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 107 | extern void VG_(arena_free) ( ArenaId arena, void* ptr ); |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 108 | extern void* VG_(arena_calloc) ( ArenaId arena, HChar* cc, |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 109 | SizeT nmemb, SizeT bytes_per_memb ); |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 110 | extern void* VG_(arena_realloc) ( ArenaId arena, HChar* cc, |
| 111 | void* ptr, SizeT size ); |
| 112 | extern void* VG_(arena_memalign)( ArenaId aid, HChar* cc, |
| 113 | SizeT req_alignB, SizeT req_pszB ); |
| 114 | extern Char* VG_(arena_strdup) ( ArenaId aid, HChar* cc, |
| 115 | const Char* s); |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 116 | |
njn | 8b140de | 2009-02-17 04:31:18 +0000 | [diff] [blame] | 117 | extern SizeT VG_(arena_malloc_usable_size) ( ArenaId aid, void* payload ); |
| 118 | |
njn | 088bfb4 | 2005-08-17 05:01:37 +0000 | [diff] [blame] | 119 | extern void VG_(mallinfo) ( ThreadId tid, struct vg_mallinfo* mi ); |
| 120 | |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 121 | extern void VG_(sanity_check_malloc_all) ( void ); |
| 122 | |
| 123 | extern void VG_(print_all_arena_stats) ( void ); |
| 124 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 125 | extern void VG_(print_arena_cc_analysis) ( void ); |
| 126 | |
njn | 717cde5 | 2005-05-10 02:47:21 +0000 | [diff] [blame] | 127 | #endif // __PUB_CORE_MALLOCFREE_H |
| 128 | |
| 129 | /*--------------------------------------------------------------------*/ |
| 130 | /*--- end ---*/ |
| 131 | /*--------------------------------------------------------------------*/ |