@@ -134,9 +134,7 @@ supervisor_allocation* allocation_from_ptr(void *ptr) {
134
134
}
135
135
136
136
supervisor_allocation * allocate_remaining_memory (void ) {
137
- uint32_t * low_address = low_head ? low_head -> data + low_head -> length / 4 : port_heap_get_bottom ();
138
- uint32_t * high_address = high_head ? (uint32_t * )high_head : port_heap_get_top ();
139
- return allocate_memory ((high_address - low_address ) * 4 - sizeof (supervisor_allocation_node ), false, false);
137
+ return allocate_memory ((uint32_t )-1 , false, false);
140
138
}
141
139
142
140
static supervisor_allocation_node * find_hole (supervisor_allocation_node * node , size_t length ) {
@@ -152,15 +150,19 @@ static supervisor_allocation_node* allocate_memory_node(uint32_t length, bool hi
152
150
// supervisor_move_memory() currently does not support movable allocations on the high side, it
153
151
// must be extended first if this is ever needed.
154
152
assert (!(high && movable ));
153
+ uint32_t * low_address = low_head ? low_head -> data + low_head -> length / 4 : port_heap_get_bottom ();
154
+ uint32_t * high_address = high_head ? (uint32_t * )high_head : port_heap_get_top ();
155
+ // Special case for allocate_remaining_memory(), avoids computing low/high_address twice.
156
+ if (length == (uint32_t )-1 ) {
157
+ length = (high_address - low_address ) * 4 - sizeof (supervisor_allocation_node );
158
+ }
155
159
if (length == 0 || length % 4 != 0 ) {
156
160
return NULL ;
157
161
}
158
162
// 1. Matching hole on the requested side?
159
163
supervisor_allocation_node * node = find_hole (high ? high_head : low_head , length );
160
164
if (!node ) {
161
165
// 2. Enough free space in the middle?
162
- uint32_t * low_address = low_head ? low_head -> data + low_head -> length / 4 : port_heap_get_bottom ();
163
- uint32_t * high_address = high_head ? (uint32_t * )high_head : port_heap_get_top ();
164
166
if ((high_address - low_address ) * 4 >= (int32_t )(sizeof (supervisor_allocation_node ) + length )) {
165
167
if (high ) {
166
168
high_address -= (sizeof (supervisor_allocation_node ) + length ) / 4 ;
0 commit comments