L4Re/departure

Changeset

521:0a8544715240
2023-03-18 Paul Boddie raw files shortlog changelog graph Fixed unwanted mapped region growth due to adjustment of region boundaries. As the region size would be effectively rounded up from the current size every time a region was remapped, repeated remapping would cause steadily larger regions to be mapped. This appeared to cause a failure to map regions in testing, although it might not be the actual cause of such failures.
libfsclient/Control (file) libfsclient/lib/src/Makefile (file) libfsclient/lib/src/client.cc (file)
     1.1 --- a/libfsclient/Control	Sat Mar 18 00:52:53 2023 +0100
     1.2 +++ b/libfsclient/Control	Sat Mar 18 23:57:46 2023 +0100
     1.3 @@ -1,3 +1,3 @@
     1.4 -requires: libstdc++ libc libipc
     1.5 +requires: libstdc++ libc libipc libmem
     1.6  provides: libfsclient
     1.7  maintainer: paul@boddie.org.uk
     2.1 --- a/libfsclient/lib/src/Makefile	Sat Mar 18 00:52:53 2023 +0100
     2.2 +++ b/libfsclient/lib/src/Makefile	Sat Mar 18 23:57:46 2023 +0100
     2.3 @@ -31,7 +31,7 @@
     2.4  				$(CLIENT_INTERFACES_SRC_CC) \
     2.5  				$(PLAIN_SRC_CC)
     2.6  
     2.7 -REQUIRES_LIBS	= l4re_c-util libipc libstdc++ libsystypes
     2.8 +REQUIRES_LIBS	= l4re_c-util libipc libstdc++ libsystypes libmem
     2.9  
    2.10  PRIVATE_INCDIR	= $(PKGDIR)/include/fsclient $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
    2.11  CONTRIB_INCDIR	= libfsclient
     3.1 --- a/libfsclient/lib/src/client.cc	Sat Mar 18 00:52:53 2023 +0100
     3.2 +++ b/libfsclient/lib/src/client.cc	Sat Mar 18 23:57:46 2023 +0100
     3.3 @@ -26,6 +26,7 @@
     3.4  #include <stdlib.h>
     3.5  #include <string.h>
     3.6  
     3.7 +#include <mem/memory_utils.h>
     3.8  #include <systypes/env.h>
     3.9  #include <systypes/fcntl.h>
    3.10  
    3.11 @@ -79,11 +80,24 @@
    3.12  
    3.13    if (file->object_flags & OBJECT_SUPPORTS_MMAP)
    3.14    {
    3.15 +    offset_t adjusted_position = position;
    3.16 +
    3.17      /* Where the position is outside the current region, re-map. */
    3.18  
    3.19      if ((position < file->start_pos) || (position >= file->end_pos))
    3.20      {
    3.21 -      if (file_mmap(file, position, file_span(file), 0, 0,
    3.22 +      offset_t length = file_span(file);
    3.23 +
    3.24 +      if (!length)
    3.25 +        length = PAGE_SIZE;
    3.26 +
    3.27 +      /* Avoid growth of the mapped region when the end of the region is
    3.28 +         calculated to be position + span, which is then rounded up, whereas the
    3.29 +         start of the region is rounded down. */
    3.30 +
    3.31 +      adjusted_position = trunc(position, PAGE_SIZE);
    3.32 +
    3.33 +      if (file_mmap(file, adjusted_position, length, 0, 0,
    3.34                      file_region_flags(file->flags)))
    3.35          return -L4_EIO;
    3.36      }