# HG changeset patch # User Paul Boddie # Date 1679180266 -3600 # Node ID 0a8544715240165b367325f6f1504b7ec30d4c9c # Parent 79622a75409c887a03413de9d74c9dd79d785f0f 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. diff -r 79622a75409c -r 0a8544715240 libfsclient/Control --- a/libfsclient/Control Sat Mar 18 00:52:53 2023 +0100 +++ b/libfsclient/Control Sat Mar 18 23:57:46 2023 +0100 @@ -1,3 +1,3 @@ -requires: libstdc++ libc libipc +requires: libstdc++ libc libipc libmem provides: libfsclient maintainer: paul@boddie.org.uk diff -r 79622a75409c -r 0a8544715240 libfsclient/lib/src/Makefile --- a/libfsclient/lib/src/Makefile Sat Mar 18 00:52:53 2023 +0100 +++ b/libfsclient/lib/src/Makefile Sat Mar 18 23:57:46 2023 +0100 @@ -31,7 +31,7 @@ $(CLIENT_INTERFACES_SRC_CC) \ $(PLAIN_SRC_CC) -REQUIRES_LIBS = l4re_c-util libipc libstdc++ libsystypes +REQUIRES_LIBS = l4re_c-util libipc libstdc++ libsystypes libmem PRIVATE_INCDIR = $(PKGDIR)/include/fsclient $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) CONTRIB_INCDIR = libfsclient diff -r 79622a75409c -r 0a8544715240 libfsclient/lib/src/client.cc --- a/libfsclient/lib/src/client.cc Sat Mar 18 00:52:53 2023 +0100 +++ b/libfsclient/lib/src/client.cc Sat Mar 18 23:57:46 2023 +0100 @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -79,11 +80,24 @@ if (file->object_flags & OBJECT_SUPPORTS_MMAP) { + offset_t adjusted_position = position; + /* Where the position is outside the current region, re-map. */ if ((position < file->start_pos) || (position >= file->end_pos)) { - if (file_mmap(file, position, file_span(file), 0, 0, + offset_t length = file_span(file); + + if (!length) + length = PAGE_SIZE; + + /* Avoid growth of the mapped region when the end of the region is + calculated to be position + span, which is then rounded up, whereas the + start of the region is rounded down. */ + + adjusted_position = trunc(position, PAGE_SIZE); + + if (file_mmap(file, adjusted_position, length, 0, 0, file_region_flags(file->flags))) return -L4_EIO; }