dwarf_alloc.h
4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
dwarf_alloc.h
$Revision: 1.1.1.1 $ $Date: 2002/05/02 03:29:20 $
*/
Dwarf_Ptr _dwarf_get_alloc (Dwarf_Debug, Dwarf_Small, Dwarf_Unsigned);
Dwarf_Debug _dwarf_get_debug (void);
Dwarf_Debug _dwarf_setup_debug (Dwarf_Debug);
int _dwarf_free_all_of_one_debug (Dwarf_Debug);
/*
This macro adds the size of a pointer to the size of a
struct that is given to it. It rounds up the size to
be a multiple of the size of a pointer. This is done
so that every struct returned by _dwarf_get_alloc()
can be preceded by a pointer to the chunk it came from.
Before, it checks if the size of struct is less than
the size of a pointer. If yes, it returns the size
of 2 pointers. The returned size should be at least
the size of 2 pointers, since the first points to the
chunk the struct was allocated from, and the second
is used to link the free list.
If this is n32, we want the sizes to be 64-bit aligned
so that longlong in the structure we return to user
is aligned properly. Thus the _dw_fac of 2
Only long longs need to be properly aligned: we don't
have long double and don't align for that.
*/
#if _MIPS_SIM == _MIPS_SIM_NABI32
#define _DW_FAC 2
#define _DW_PS sizeof(void *)
#else
#define _DW_FAC 1
#define _DW_PS sizeof(void *)
#endif
#define _DW_RESERVE (_DW_FAC * _DW_PS)
#define ROUND_SIZE(inputsize) \
((inputsize) < (_DW_RESERVE) ? \
( _DW_RESERVE) : \
((inputsize) % (_DW_RESERVE) == 0 ? \
((inputsize) ): \
((inputsize) + \
(_DW_RESERVE) - ((inputsize) % (_DW_RESERVE)) )))
#define ROUND_SIZE_WITH_POINTER(i_size) (ROUND_SIZE(i_size) + _DW_RESERVE)
typedef struct Dwarf_Alloc_Area_s *Dwarf_Alloc_Area;
typedef struct Dwarf_Free_List_s *Dwarf_Free_List;
/*
This struct is used to chain all the deallocated
structs on the free list of each chain. The structs
are chained internally, by using the memory they
contain.
*/
struct Dwarf_Free_List_s {
Dwarf_Free_List fl_next;
};
/*
This struct is used to manage all the chunks malloc'ed
for a particular alloc_type. Many of the fields are
initialized by dwarf_init().
*/
struct Dwarf_Alloc_Hdr_s {
/* Count of actual number of structs allocated. */
Dwarf_Sword ah_struct_alloc_count;
/*
Size of each struct that will be allocated for
this alloc_type. Initialized by dwarf_init().
*/
Dwarf_Half ah_alloc_size;
/*
Number of structs of this alloc_type that will
be contained in each chunk that is malloc'ed.
Initialized by dwarf_init().
*/
Dwarf_Word ah_alloc_num;
/*
Number of bytes malloc'ed per chunk, that is
ah_alloc_size * ah_alloc_num.
*/
Dwarf_Word ah_malloc_length;
/* Count of chunks currently allocated for type. */
Dwarf_Sword ah_curr_alloc;
/* Max number of chunks ever allocated for type. */
Dwarf_Sword ah_max_alloc;
/*
Points to a chain of Dwarf_Alloc_Area_s structs
that represent all the chunks currently allocated
for the alloc_type.
*/
Dwarf_Alloc_Area ah_alloc_area_head;
/* Last Alloc Area that was allocated from. */
Dwarf_Alloc_Area ah_last_alloc_area;
};
/*
This struct is used to manage each chunk that is
malloc'ed for a particular alloc_type. For each
allocation type, the allocation header points to
a list of all the chunks malloc'ed for that type.
*/
struct Dwarf_Alloc_Area_s {
/* Points to the free list of structs in the chunk. */
Dwarf_Ptr aa_free_list;
/*
Count of the number of free structs in the chunk.
This includes both those on the free list, and in
the blob.
*/
Dwarf_Sword aa_free_count;
/*
Points to the first byte of the blob from which
struct will be allocated. A struct is put on the
free_list only when it dwrf_deallocated. Initial
allocations are from the blob.
*/
Dwarf_Small *aa_blob_start;
/* Points just past the last byte of the blob. */
Dwarf_Small *aa_blob_end;
/* Points to alloc_hdr this alloc_area is linked to. */
Dwarf_Alloc_Hdr aa_alloc_hdr;
/*
Used for chaining Dwarf_Alloc_Area_s atructs.
Alloc areas are doubly linked to enable deletion
from the list in constant time.
*/
Dwarf_Alloc_Area aa_next;
Dwarf_Alloc_Area aa_prev;
};