diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2021-05-11 20:49:01 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2021-05-11 20:49:01 +0300 |
commit | 54063bddfa9fb2353300f72950b149e8c4422f8f (patch) | |
tree | 100f791d90746c49617c3b3bf0bda21a6e2fa4b5 | |
parent | bfef269358716de18c7beab08b22c15e3654c5f7 (diff) |
Fix bug in POSIX map_handle::truncate() when used on non-backed maps whereby new map length was not set correctly.
map_handle::truncate()'s permit_relocation parameter is no longer defaulted to false, because the defaulting leads to me writing bad code.
-rw-r--r-- | include/llfio/v2.0/detail/impl/posix/map_handle.ipp | 7 | ||||
-rw-r--r-- | include/llfio/v2.0/map_handle.hpp | 2 |
2 files changed, 6 insertions, 3 deletions
diff --git a/include/llfio/v2.0/detail/impl/posix/map_handle.ipp b/include/llfio/v2.0/detail/impl/posix/map_handle.ipp index 4f3aeabf..bf676d4a 100644 --- a/include/llfio/v2.0/detail/impl/posix/map_handle.ipp +++ b/include/llfio/v2.0/detail/impl/posix/map_handle.ipp @@ -439,14 +439,17 @@ result<map_handle::size_type> map_handle::truncate(size_type newsize, bool permi extent_type length = _length; if(_section != nullptr) { - OUTCOME_TRY(auto &&length_, _section->length()); // length of the backing file - length = length_; + OUTCOME_TRY(length, _section->length()); // length of the backing file } auto _newsize = utils::round_up_to_page_size(newsize, _pagesize); if(_newsize == _reservation) { return success(); } + if(_section == nullptr) + { + length = _newsize; // newsize, but rounded up + } // If wiping the map ... if(newsize == 0) { diff --git a/include/llfio/v2.0/map_handle.hpp b/include/llfio/v2.0/map_handle.hpp index 299010de..69241720 100644 --- a/include/llfio/v2.0/map_handle.hpp +++ b/include/llfio/v2.0/map_handle.hpp @@ -659,7 +659,7 @@ public: \errors Any of the values POSIX `mremap()`, `mmap(addr)` or `VirtualAlloc(addr)` can return. */ LLFIO_MAKE_FREE_FUNCTION - LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<size_type> truncate(size_type newsize, bool permit_relocation = false) noexcept; + LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<size_type> truncate(size_type newsize, bool permit_relocation) noexcept; /*! Ask the system to commit the system resources to make the memory represented by the buffer available with the given permissions. addr and length should be page |