1
2/*--------------------------------------------------------------------*/
3/*--- MallocFree: high-level memory management.                    ---*/
4/*---                                        pub_tool_mallocfree.h ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8   This file is part of Valgrind, a dynamic binary instrumentation
9   framework.
10
11   Copyright (C) 2000-2013 Julian Seward
12      jseward@acm.org
13
14   This program is free software; you can redistribute it and/or
15   modify it under the terms of the GNU General Public License as
16   published by the Free Software Foundation; either version 2 of the
17   License, or (at your option) any later version.
18
19   This program is distributed in the hope that it will be useful, but
20   WITHOUT ANY WARRANTY; without even the implied warranty of
21   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22   General Public License for more details.
23
24   You should have received a copy of the GNU General Public License
25   along with this program; if not, write to the Free Software
26   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27   02111-1307, USA.
28
29   The GNU General Public License is contained in the file COPYING.
30*/
31
32#ifndef __PUB_TOOL_MALLOCFREE_H
33#define __PUB_TOOL_MALLOCFREE_H
34
35#include "pub_tool_basics.h"   // SizeT
36
37// These can be for allocating memory used by tools.
38// Nb: the allocators *always succeed* -- they never return NULL (Valgrind
39// will abort if they can't allocate the memory).
40// The 'cc' is a string that identifies the allocation point.  It's used when
41// --profile-heap=yes is specified.
42extern void* VG_(malloc)         ( const HChar* cc, SizeT nbytes );
43extern void  VG_(free)           ( void* p );
44extern void* VG_(calloc)         ( const HChar* cc, SizeT n, SizeT bytes_per_elem );
45extern void*  VG_(realloc)       ( const HChar* cc, void* p, SizeT size );
46extern HChar* VG_(strdup)        ( const HChar* cc, const HChar* s );
47
48// Returns the usable size of a heap-block.  It's the asked-for size plus
49// possibly some more due to rounding up.
50extern SizeT VG_(malloc_usable_size)( void* p );
51
52// TODO: move somewhere else
53// Call here to bomb the system when out of memory (mmap anon fails)
54__attribute__((noreturn))
55extern void VG_(out_of_memory_NORETURN) ( const HChar* who, SizeT szB );
56
57// VG_(perm_malloc) is for allocating small blocks which are
58// never released. The overhead for such blocks is minimal.
59// VG_(perm_malloc) returns memory which is (at least) aligned
60// on a multiple of align.
61// Use the macro vg_alignof (type) to get a safe alignment for a type.
62// No other function can be used on these permanently allocated blocks.
63// In particular, do *not* call VG_(free) or VG_(malloc_usable_size)
64// or VG_(realloc).
65// Technically, these blocks will be returned from big superblocks
66// only containing such permanently allocated blocks.
67// Note that there is no cc cost centre : all such blocks will be
68// regrouped under the "perm_alloc" cost centre.
69extern void* VG_(perm_malloc)    ( SizeT nbytes, Int align );
70
71#endif   // __PUB_TOOL_MALLOCFREE_H
72
73/*--------------------------------------------------------------------*/
74/*--- end                                                          ---*/
75/*--------------------------------------------------------------------*/
76
77