1.1 --- a/libmem/lib/src/memory_incremental.cc Thu May 19 14:08:28 2022 +0200
1.2 +++ b/libmem/lib/src/memory_incremental.cc Fri May 20 00:40:27 2022 +0200
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * A memory pool allocating a region at a time from the system.
1.6 *
1.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -21,6 +21,8 @@
1.13
1.14 #include "memory_incremental.h"
1.15
1.16 +#include <ipc/mem_ipc.h>
1.17 +
1.18 #include <stdlib.h>
1.19
1.20
1.21 @@ -45,18 +47,31 @@
1.22 {
1.23 /* Attempt to allocate aligned memory. */
1.24
1.25 - void *current;
1.26 + void *current = NULL;
1.27 + l4re_ds_t ds;
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 + /* Use allocation permitting executable mapping of the memory.
1.35 + NOTE: A collection of blocks needs to be allocated, and a collection of
1.36 + dataspaces might also be employed. */
1.37 +
1.38 + if (ipc_allocate_align(size, L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_RWX, page_order(size), ¤t, &ds))
1.39 return NULL;
1.40
1.41 return new Region((offset_t) current, (offset_t) current + size);
1.42 }
1.43
1.44 +/* Deallocate the given region. */
1.45 +
1.46 +void MemoryIncremental::deallocate(Region *region)
1.47 +{
1.48 + ipc_detach_dataspace((void *) region->start);
1.49 + delete region;
1.50 +}
1.51 +
1.52 /* Allocate a new region of the given 'size' rounded to the nearest page. */
1.53
1.54 Region *MemoryIncremental::region(offset_t size)
1.55 @@ -109,7 +124,7 @@
1.56 if (_limited)
1.57 _limit += pages;
1.58
1.59 - delete region;
1.60 + deallocate(region);
1.61 }
1.62
1.63 // vim: tabstop=4 expandtab shiftwidth=4