3 Copyright (C) 2000,2005 Silicon Graphics, Inc. All Rights Reserved.
4 Portions Copyright (C) 2008-2010 David Anderson. All Rights Reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of version 2.1 of the GNU Lesser General Public License
8 as published by the Free Software Foundation.
10 This program is distributed in the hope that it would be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 Further, this software is distributed without any warranty that it is
15 free of the rightful claim of any third person regarding infringement
16 or the like. Any license provided herein, whether implied or
17 otherwise, applies only to this software file. Patent licenses, if
18 any, provided herein do not apply to combinations of this program with
19 other software, or any other product whatsoever.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this program; if not, write the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
26 Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
27 Mountain View, CA 94043, or:
31 For further information regarding this notice, see:
33 http://oss.sgi.com/projects/GenInfo/NoticeExplan
37 /* #define DWARF_SIMPLE_MALLOC 1 */
39 Dwarf_Ptr
_dwarf_get_alloc(Dwarf_Debug
, Dwarf_Small
, Dwarf_Unsigned
);
40 Dwarf_Debug
_dwarf_get_debug(void);
41 Dwarf_Debug
_dwarf_setup_debug(Dwarf_Debug
);
42 int _dwarf_free_all_of_one_debug(Dwarf_Debug
);
44 typedef struct Dwarf_Alloc_Area_s
*Dwarf_Alloc_Area
;
45 typedef struct Dwarf_Free_List_s
*Dwarf_Free_List
;
47 /* ALLOC_AREA_INDEX_TABLE_MAX is the size of the
48 struct ial_s index_into_allocated array in dwarf_alloc.c
50 #define ALLOC_AREA_INDEX_TABLE_MAX 45
51 /* ALLOC_AREA_REAL_TABLE_MAX is the size of the array needed
52 to hold pointers to dwarf alloc chunk areas.
53 It's smaller as some of the index_into_allocated
54 entries (they look like {0,1,1,0,0} )
55 are treated specially and don't use 'chunks'.
57 #define ALLOC_AREA_REAL_TABLE_MAX 32
60 This struct is used to chain all the deallocated
61 structs on the free list of each chain. The structs
62 are chained internally, by using the memory they
65 struct Dwarf_Free_List_s
{
66 Dwarf_Free_List fl_next
;
71 This struct is used to manage all the chunks malloc'ed
72 for a particular alloc_type. Many of the fields are
73 initialized by dwarf_init().
75 struct Dwarf_Alloc_Hdr_s
{
77 /* Count of actual number of structs user app holds pointers to
79 Dwarf_Sword ah_struct_user_holds
;
82 Size of each struct that will be allocated for this alloc_type.
83 Initialized by dwarf_init(). */
84 Dwarf_Half ah_bytes_one_struct
;
87 Number of structs of this alloc_type that will be contained in
88 each chunk that is malloc'ed. Initialized by dwarf_init(). */
89 Dwarf_Word ah_structs_per_chunk
;
92 Number of bytes malloc'ed per chunk which is basically
93 (ah_bytes_one_struct+_DWARF_RESERVE) * ah_alloc_num. */
94 Dwarf_Word ah_bytes_malloc_per_chunk
;
96 /* Count of chunks currently allocated for type. */
97 Dwarf_Sword ah_chunks_allocated
;
100 Points to a chain of Dwarf_Alloc_Area_s structs that represent
101 all the chunks currently allocated for the alloc_type. */
102 Dwarf_Alloc_Area ah_alloc_area_head
;
104 /* Last Alloc Area that was allocated by malloc. The
105 free-space-search area looks here first and only if it is full
106 goes thru the list pointed to by ah_alloc_area_head. */
107 Dwarf_Alloc_Area ah_last_alloc_area
;
112 This struct is used to manage each chunk that is
113 malloc'ed for a particular alloc_type. For each
114 allocation type, the allocation header points to
115 a list of all the chunks malloc'ed for that type.
117 struct Dwarf_Alloc_Area_s
{
119 /* Points to the free list of structs in the chunk. */
120 Dwarf_Ptr aa_free_list
;
123 Count of the number of free structs in the chunk. This includes
124 both those on the free list, and in the blob. */
125 Dwarf_Sword aa_free_structs_in_chunk
;
128 Points to the first byte of the blob from which struct will be
129 allocated. A struct is put on the free_list only when it
130 dwarf_deallocated. Initial allocations are from the blob. */
131 Dwarf_Small
*aa_blob_start
;
133 /* Points just past the last byte of the blob. */
134 Dwarf_Small
*aa_blob_end
;
136 /* Points to alloc_hdr this alloc_area is linked to: The owner, in
138 Dwarf_Alloc_Hdr aa_alloc_hdr
;
141 Used for chaining Dwarf_Alloc_Area_s atructs. Alloc areas are
142 doubly linked to enable deletion from the list in constant time. */
143 Dwarf_Alloc_Area aa_next
;
144 Dwarf_Alloc_Area aa_prev
;
147 struct Dwarf_Error_s
*_dwarf_special_no_dbg_error_malloc(void);
149 #ifdef DWARF_SIMPLE_MALLOC
151 DWARF_SIMPLE_MALLOC is for testing the hypothesis that the existing
152 complex malloc scheme in libdwarf is pointless complexity.
154 DWARF_SIMPLE_MALLOC also makes it easy for a malloc-tracing
155 tool to verify libdwarf malloc has no botches (though of course
156 such does not test the complicated standard-libdwarf-alloc code).
160 struct simple_malloc_entry_s
{
161 Dwarf_Small
*se_addr
;
162 unsigned long se_size
;
165 #define DSM_BLOCK_COUNT (1000)
166 #define DSM_BLOCK_SIZE (sizeof(struct simple_malloc_entry_s)*DSM_BLOCK_COUNT)
168 /* we do this so dwarf_dealloc can really free everything */
169 struct simple_malloc_record_s
{
170 struct simple_malloc_record_s
*sr_next
;
172 struct simple_malloc_entry_s sr_entry
[DSM_BLOCK_COUNT
];
177 #endif /* DWARF_SIMPLE_MALLOC */