# HG changeset patch # User Paul Boddie # Date 1653000027 -7200 # Node ID 911d151bbbfcc70bb93c91f1999dccd38512549f # Parent 12b7393c13dcb1147e85eb6dac4b6936c3dbc550 Introduced dataspace-based allocation of memory, to be improved. diff -r 12b7393c13dc -r 911d151bbbfc libfsserver/lib/generic/pager.cc --- a/libfsserver/lib/generic/pager.cc Thu May 19 14:08:28 2022 +0200 +++ b/libfsserver/lib/generic/pager.cc Fri May 20 00:40:27 2022 +0200 @@ -89,7 +89,7 @@ /* Prevent access beyond that defined by the pager. */ - if (flags & ~_flags) + if (flags & (~(_flags | L4RE_DS_F_X))) return -L4_EACCESS; Flexpage *flexpage = _mapper->get(file_offset, flags); diff -r 12b7393c13dc -r 911d151bbbfc libmem/Control --- a/libmem/Control Thu May 19 14:08:28 2022 +0200 +++ b/libmem/Control Fri May 20 00:40:27 2022 +0200 @@ -1,3 +1,3 @@ -requires: libstdc++ libc libsystypes +requires: libstdc++ libc libsystypes libipc provides: libmem maintainer: paul@boddie.org.uk diff -r 12b7393c13dc -r 911d151bbbfc libmem/include/mem/memory_incremental.h --- a/libmem/include/mem/memory_incremental.h Thu May 19 14:08:28 2022 +0200 +++ b/libmem/include/mem/memory_incremental.h Fri May 20 00:40:27 2022 +0200 @@ -1,7 +1,7 @@ /* * A memory pool allocating a region at a time from the system. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -43,6 +43,8 @@ Region *allocate(offset_t size); + void deallocate(Region *region); + public: explicit MemoryIncremental(unsigned int limit, offset_t region_size=PAGE_SIZE); diff -r 12b7393c13dc -r 911d151bbbfc libmem/include/mem/region.h --- a/libmem/include/mem/region.h Thu May 19 14:08:28 2022 +0200 +++ b/libmem/include/mem/region.h Fri May 20 00:40:27 2022 +0200 @@ -1,7 +1,7 @@ /* * Memory region abstractions. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -59,8 +59,6 @@ explicit Region(offset_t start, offset_t end); - virtual ~Region(); - offset_t size(); int compare(Region *other); diff -r 12b7393c13dc -r 911d151bbbfc libmem/lib/src/Makefile --- a/libmem/lib/src/Makefile Thu May 19 14:08:28 2022 +0200 +++ b/libmem/lib/src/Makefile Fri May 20 00:40:27 2022 +0200 @@ -8,7 +8,7 @@ flexpage.cc memory_incremental.cc memory_preallocated.cc \ memory_utils.cc region.cc -REQUIRES_LIBS = l4re_c-util libstdc++ libsystypes +REQUIRES_LIBS = l4re_c-util libstdc++ libsystypes libipc PRIVATE_INCDIR = $(PKGDIR)/include $(PKGDIR)/include/mem CONTRIB_INCDIR = libmem diff -r 12b7393c13dc -r 911d151bbbfc libmem/lib/src/memory_incremental.cc --- a/libmem/lib/src/memory_incremental.cc Thu May 19 14:08:28 2022 +0200 +++ b/libmem/lib/src/memory_incremental.cc Fri May 20 00:40:27 2022 +0200 @@ -1,7 +1,7 @@ /* * A memory pool allocating a region at a time from the system. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -21,6 +21,8 @@ #include "memory_incremental.h" +#include + #include @@ -45,18 +47,31 @@ { /* Attempt to allocate aligned memory. */ - void *current; + void *current = NULL; + l4re_ds_t ds; /* Make the size appropriate for the invocation. */ size = round_multiple(size, PAGE_SIZE); - if (posix_memalign(¤t, size, size)) + /* Use allocation permitting executable mapping of the memory. + NOTE: A collection of blocks needs to be allocated, and a collection of + dataspaces might also be employed. */ + + if (ipc_allocate_align(size, L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_RWX, page_order(size), ¤t, &ds)) return NULL; return new Region((offset_t) current, (offset_t) current + size); } +/* Deallocate the given region. */ + +void MemoryIncremental::deallocate(Region *region) +{ + ipc_detach_dataspace((void *) region->start); + delete region; +} + /* Allocate a new region of the given 'size' rounded to the nearest page. */ Region *MemoryIncremental::region(offset_t size) @@ -109,7 +124,7 @@ if (_limited) _limit += pages; - delete region; + deallocate(region); } // vim: tabstop=4 expandtab shiftwidth=4 diff -r 12b7393c13dc -r 911d151bbbfc libmem/lib/src/region.cc --- a/libmem/lib/src/region.cc Thu May 19 14:08:28 2022 +0200 +++ b/libmem/lib/src/region.cc Fri May 20 00:40:27 2022 +0200 @@ -58,13 +58,6 @@ memset((void *) start, 0, end - start); } -/* Deallocate the region, freeing its memory. */ - -Region::~Region() -{ - free((void *) start); -} - /* Return the size of the region. */ offset_t Region::size()