paul@1 | 1 | #include "memory.h" |
paul@1 | 2 | |
paul@14 | 3 | #include <stdlib.h> |
paul@1 | 4 | |
paul@1 | 5 | |
paul@1 | 6 | /* Initialise the memory pool with an optional 'limit' in pages. */ |
paul@1 | 7 | |
paul@58 | 8 | Memory::Memory(offset_t region_size) |
paul@58 | 9 | : _region_size(region_size) |
paul@1 | 10 | { |
paul@1 | 11 | } |
paul@1 | 12 | |
paul@14 | 13 | /* Allocate a block of the given 'size'. */ |
paul@14 | 14 | |
paul@14 | 15 | Region *Memory::allocate(offset_t size) |
paul@14 | 16 | { |
paul@14 | 17 | /* Attempt to allocate aligned memory. */ |
paul@14 | 18 | |
paul@14 | 19 | void *current; |
paul@14 | 20 | |
paul@14 | 21 | /* Make the size appropriate for the invocation. */ |
paul@14 | 22 | |
paul@14 | 23 | size = round_multiple(size, PAGE_SIZE); |
paul@14 | 24 | |
paul@14 | 25 | if (posix_memalign(¤t, size, size)) |
paul@14 | 26 | return NULL; |
paul@14 | 27 | |
paul@14 | 28 | return new Region((offset_t) current, (offset_t) current + size); |
paul@14 | 29 | } |
paul@14 | 30 | |
paul@1 | 31 | // vim: tabstop=4 expandtab shiftwidth=4 |