Skip to content

Commit b8e070a

Browse files
authored
Refactor memory unmapping functions to improve error handling (#1195)
- Renamed `sys_munmap` to `sys_munmap_nothrow` to indicate it does not throw errors. - Updated calls to `sys_munmap` in `posix_file_loader.h` to use the new `sys_munmap_nothrow` function for safer memory management.
1 parent 9a15b9a commit b8e070a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

include/fast_io_hosted/file_loaders/posix_file_loader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ inline void posix_unload_address(void *address, [[maybe_unused]] ::std::size_t f
3434
{
3535
if (address != (void *)-1) [[likely]]
3636
{
37-
sys_munmap(address, file_size);
37+
sys_munmap_nothrow(address, file_size);
3838
}
3939
}
4040

include/fast_io_hosted/platforms/posix_mapping.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ inline int sys_mprotect(void *start, ::std::size_t len, int prot)
6969
return result;
7070
}
7171

72-
inline int sys_munmap(void *addr, ::std::size_t len)
72+
inline int sys_munmap_nothrow(void *addr, ::std::size_t len)
7373
{
7474
return
7575
#if defined(__linux__) && defined(__NR_munmap)
@@ -79,9 +79,9 @@ inline int sys_munmap(void *addr, ::std::size_t len)
7979
#endif
8080
}
8181

82-
inline void sys_munmap_throw_error(void *addr, ::std::size_t len)
82+
inline void sys_munmap(void *addr, ::std::size_t len)
8383
{
84-
system_call_throw_error(sys_munmap(addr, len));
84+
system_call_throw_error(sys_munmap_nothrow(addr, len));
8585
}
8686
} // namespace details
8787

@@ -195,7 +195,7 @@ class posix_memory_map_file
195195
}
196196
if (this->address_begin != reinterpret_cast<::std::byte *>(MAP_FAILED)) [[likely]]
197197
{
198-
details::sys_munmap(this->address_begin, static_cast<::std::size_t>(address_end - address_begin));
198+
details::sys_munmap_nothrow(this->address_begin, static_cast<::std::size_t>(address_end - address_begin));
199199
}
200200
this->address_begin = other.address_begin;
201201
this->address_end = other.address_end;
@@ -295,7 +295,7 @@ class posix_memory_map_file
295295
{
296296
if (this->address_begin != MAP_FAILED) [[likely]]
297297
{
298-
auto ret{details::sys_munmap(this->address_begin, static_cast<::std::size_t>(address_end - address_begin))};
298+
auto ret{details::sys_munmap_nothrow(this->address_begin, static_cast<::std::size_t>(address_end - address_begin))};
299299
this->address_end = this->address_begin = reinterpret_cast<::std::byte *>(MAP_FAILED);
300300
system_call_throw_error(ret);
301301
}
@@ -304,7 +304,7 @@ class posix_memory_map_file
304304
{
305305
if (this->address_begin != MAP_FAILED) [[likely]]
306306
{
307-
details::sys_munmap(this->address_begin, static_cast<::std::size_t>(address_end - address_begin));
307+
details::sys_munmap_nothrow(this->address_begin, static_cast<::std::size_t>(address_end - address_begin));
308308
}
309309
}
310310
};

0 commit comments

Comments
 (0)