regions: add region_heap_init() helper function
This will allow to create a region allocator without requiring a
working heap.
The existing region_allocator() function has been refactored to use
this helper function.
@@ -61,15 +61,20 @@ static inline u64 allocate_region(heap h, bytes size)
return result;
}
-static inline heap region_allocator(heap h, u64 pagesize, int type)
+static inline void region_heap_init(region_heap rh, u64 pagesize, int type)
{
- region_heap rh = allocate(h, sizeof(struct region_heap));
- if (rh == INVALID_ADDRESS)
- return INVALID_ADDRESS;
rh->h.dealloc = leak;
rh->h.alloc = allocate_region;
rh->h.pagesize = pagesize;
rh->type = type;
+}
+
+static inline heap region_allocator(heap h, u64 pagesize, int type)
+{
+ region_heap rh = allocate(h, sizeof(struct region_heap));
+ if (rh == INVALID_ADDRESS)
+ return INVALID_ADDRESS;
+ region_heap_init(rh, pagesize, type);
return (heap)rh;
}
