|
@@ -76,6 +76,7 @@ static void init_heap ( void ) {
|
76
|
76
|
}
|
77
|
77
|
|
78
|
78
|
ASSERT ( size != 0 );
|
|
79
|
+ DBG ( "HEAP using region [%x,%x)\n", heap_start, heap_end );
|
79
|
80
|
heap_ptr = heap_end;
|
80
|
81
|
}
|
81
|
82
|
|
|
@@ -92,11 +93,15 @@ void * emalloc ( size_t size, unsigned int align ) {
|
92
|
93
|
addr = ( ( ( heap_ptr - size ) & ~( align - 1 ) )
|
93
|
94
|
- sizeof ( struct heap_block ) );
|
94
|
95
|
if ( addr < heap_start ) {
|
|
96
|
+ DBG ( "HEAP no space for %x bytes (alignment %d) in [%x,%x)\n",
|
|
97
|
+ size, align, heap_start, heap_ptr );
|
95
|
98
|
return NULL;
|
96
|
99
|
}
|
97
|
100
|
|
98
|
101
|
block = phys_to_virt ( addr );
|
99
|
102
|
block->size = ( heap_ptr - addr );
|
|
103
|
+ DBG ( "HEAP allocated %x bytes (alignment %d) at %x [%x,%x)\n",
|
|
104
|
+ size, align, virt_to_phys ( block->data ), addr, heap_ptr );
|
100
|
105
|
heap_ptr = addr;
|
101
|
106
|
return block->data;
|
102
|
107
|
}
|
|
@@ -123,6 +128,9 @@ void efree ( void *ptr ) {
|
123
|
128
|
( ptr - offsetof ( struct heap_block, data ) );
|
124
|
129
|
heap_ptr += block->size;
|
125
|
130
|
|
|
131
|
+ DBG ( "HEAP freed %x [%x,%x)\n", virt_to_phys ( ptr ),
|
|
132
|
+ virt_to_phys ( block ), heap_ptr );
|
|
133
|
+
|
126
|
134
|
ASSERT ( heap_ptr <= heap_end );
|
127
|
135
|
}
|
128
|
136
|
|
|
@@ -131,6 +139,9 @@ void efree ( void *ptr ) {
|
131
|
139
|
*
|
132
|
140
|
*/
|
133
|
141
|
void efree_all ( void ) {
|
|
142
|
+ DBG ( "HEAP discarding allocated blocks in [%x,%x)\n",
|
|
143
|
+ heap_ptr, heap_end );
|
|
144
|
+
|
134
|
145
|
heap_ptr = heap_end;
|
135
|
146
|
}
|
136
|
147
|
|