1.1 --- a/libexec/lib/src/pager.cc Tue Mar 14 23:51:57 2023 +0100
1.2 +++ b/libexec/lib/src/pager.cc Wed Mar 15 00:33:40 2023 +0100
1.3 @@ -20,7 +20,6 @@
1.4 */
1.5
1.6 #include <l4/re/env.h>
1.7 -#include <l4/re/c/rm.h>
1.8
1.9 #include <mem/memory_utils.h>
1.10
1.11 @@ -31,7 +30,7 @@
1.12 /* Initialise common functionality. */
1.13
1.14 ExecPager::ExecPager(address_t start, address_t end)
1.15 -: _start(start), _end(end)
1.16 +: _area(start, end)
1.17 {
1.18 }
1.19
1.20 @@ -43,118 +42,34 @@
1.21
1.22
1.23
1.24 -/* Add a region to the pager. */
1.25 +/* Add an area to the pager. */
1.26
1.27 -void ExecPager::add(MappedRegion ®ion)
1.28 +void ExecPager::add(MemoryArea &area)
1.29 {
1.30 - _regions[region.start] = region;
1.31 + _area.add(area);
1.32 }
1.33
1.34 -/* Remove a region from the pager. */
1.35 +/* Remove an area from the pager. */
1.36
1.37 -void ExecPager::remove(MappedRegion ®ion)
1.38 +void ExecPager::remove(MemoryArea &area)
1.39 {
1.40 - _regions.erase(region.start);
1.41 + _area.remove(area);
1.42 }
1.43
1.44
1.45
1.46 -/* Attach a region for provision when page faults occur. */
1.47 +/* Find an area suitable for attaching a memory region. */
1.48
1.49 long ExecPager::find(address_t *start, address_t *size, map_flags_t flags,
1.50 - address_t offset, unsigned char align)
1.51 + unsigned char align, MemoryArea **area)
1.52 {
1.53 if (align < L4_PAGESHIFT)
1.54 align = L4_PAGESHIFT;
1.55
1.56 - /* Obtain the alignment increment and a properly aligned size. */
1.57 -
1.58 - address_t increment = 1UL << align;
1.59 - address_t region_size = round(*size, increment);
1.60 -
1.61 - /* Either attempt to find an address for the specified region, starting from
1.62 + /* Attempt to find an address for the specified region, starting from
1.63 any indicated address. */
1.64
1.65 - if (flags & L4RE_RM_F_SEARCH_ADDR)
1.66 - {
1.67 - /* Align any desired location. */
1.68 -
1.69 - address_t region_start = trunc(*start, increment);
1.70 -
1.71 - /* Enforce a minimum address. */
1.72 -
1.73 - if (region_start < _start)
1.74 - region_start = round(_start, increment);
1.75 -
1.76 - /* Search for existing regions after the desired, conformant address. */
1.77 -
1.78 - MappedRegions::iterator it = _regions.upper_bound(region_start);
1.79 -
1.80 - /* Consider any region preceding or encompassing the desired address. */
1.81 -
1.82 - if (it != _regions.begin())
1.83 - {
1.84 - MappedRegions::iterator next = it;
1.85 -
1.86 - /* Step back to the preceding region to get its details. */
1.87 -
1.88 - it--;
1.89 - MappedRegion &pr = it->second;
1.90 - address_t previous_end = pr.start + pr.size;
1.91 - it = next;
1.92 -
1.93 - /* The preceding region may displace the desired region location if it
1.94 - is encompassed by the region. */
1.95 -
1.96 - if (region_start < previous_end)
1.97 - region_start = round(previous_end, increment);
1.98 - }
1.99 -
1.100 - /* Consider the regions following the current region start candidate. */
1.101 -
1.102 - while ((it != _regions.end()) && !(_end && ((region_start + region_size) > _end)))
1.103 - {
1.104 - MappedRegion &r = it->second;
1.105 -
1.106 - /* Obtain the limit of available space being considered. */
1.107 -
1.108 - address_t end_limit = r.start;
1.109 -
1.110 - /* Investigate subsequent regions if not enough space exists between the
1.111 - preceding region (or start of memory) and the current region. */
1.112 -
1.113 - if ((region_start + region_size) > end_limit)
1.114 - {
1.115 - region_start = round(r.start + r.size, increment);
1.116 - it++;
1.117 - }
1.118 -
1.119 - /* Otherwise, the region can be positioned. */
1.120 -
1.121 - else
1.122 - break;
1.123 - }
1.124 -
1.125 - /* Test for enough memory constrained by any predefined limit. */
1.126 -
1.127 - if (_end && ((region_start + region_size) > _end))
1.128 - return -L4_ENOMEM;
1.129 -
1.130 - /* Return the configured start and size. */
1.131 -
1.132 - *start = region_start;
1.133 - *size = region_size;
1.134 - return L4_EOK;
1.135 - }
1.136 -
1.137 - /* Or attempt to add the specified region at a specific address. */
1.138 -
1.139 - else
1.140 - {
1.141 - // NOTE: To be implemented.
1.142 -
1.143 - return -L4_ENOMEM;
1.144 - }
1.145 + return _area.find(start, size, flags, align, area);
1.146 }
1.147
1.148 /* vim: tabstop=2 expandtab shiftwidth=2