1.1 --- a/memory.cc Wed Feb 03 22:22:30 2021 +0100
1.2 +++ b/memory.cc Wed Feb 03 23:33:48 2021 +0100
1.3 @@ -1,12 +1,6 @@
1.4 #include "memory.h"
1.5 -#include "memory_map.h"
1.6 -
1.7 -
1.8
1.9 -/* Global memory allocator. */
1.10 -
1.11 -extern Allocator allocator;
1.12 -
1.13 +#include <stdlib.h>
1.14
1.15
1.16 /* Initialise the memory pool with an optional 'limit' in pages. */
1.17 @@ -23,6 +17,24 @@
1.18 _limited = false;
1.19 }
1.20
1.21 +/* Allocate a block of the given 'size'. */
1.22 +
1.23 +Region *Memory::allocate(offset_t size)
1.24 +{
1.25 + /* Attempt to allocate aligned memory. */
1.26 +
1.27 + void *current;
1.28 +
1.29 + /* Make the size appropriate for the invocation. */
1.30 +
1.31 + size = round_multiple(size, PAGE_SIZE);
1.32 +
1.33 + if (posix_memalign(¤t, size, size))
1.34 + return NULL;
1.35 +
1.36 + return new Region((offset_t) current, (offset_t) current + size);
1.37 +}
1.38 +
1.39 /* Allocate a new region of the given 'size' rounded to the nearest page. */
1.40
1.41 Region *Memory::region(offset_t size)
1.42 @@ -38,7 +50,7 @@
1.43 {
1.44 /* Attempt to allocate aligned memory. */
1.45
1.46 - Region *region = allocator.region(rounded);
1.47 + Region *region = allocate(rounded);
1.48
1.49 if (region == NULL)
1.50 return NULL;
1.51 @@ -72,8 +84,6 @@
1.52 if (_limited)
1.53 _limit += pages;
1.54
1.55 - allocator.remove(region);
1.56 -
1.57 delete region;
1.58 }
1.59