From 91fbb26c0386b8aaa2aedc95bae5f30f1df93893 Mon Sep 17 00:00:00 2001 From: stasoid Date: Wed, 20 Nov 2024 18:39:13 +0500 Subject: [PATCH] LibCore/System: Add mmap, munmap for Windows --- Libraries/LibCore/CMakeLists.txt | 4 ++++ Libraries/LibCore/SystemWindows.cpp | 18 ++++++++++++++++++ Meta/CMake/Findmman.cmake | 2 ++ vcpkg.json | 4 ++++ 4 files changed, 28 insertions(+) create mode 100644 Meta/CMake/Findmman.cmake diff --git a/Libraries/LibCore/CMakeLists.txt b/Libraries/LibCore/CMakeLists.txt index 7465c41290d..5ed2c0bc62a 100644 --- a/Libraries/LibCore/CMakeLists.txt +++ b/Libraries/LibCore/CMakeLists.txt @@ -22,6 +22,10 @@ serenity_lib(LibCoreMinimal coreminimal) if (WIN32) find_path(DIRENT_INCLUDE_DIR dirent.h REQUIRED) target_include_directories(LibCoreMinimal PRIVATE ${DIRENT_INCLUDE_DIR}) + + find_package(mman REQUIRED) + target_include_directories(LibCoreMinimal PRIVATE ${MMAN_INCLUDE_DIR}) + target_link_libraries(LibCoreMinimal PRIVATE ${MMAN_LIBRARY}) endif() if (LAGOM_TOOLS_ONLY) diff --git a/Libraries/LibCore/SystemWindows.cpp b/Libraries/LibCore/SystemWindows.cpp index 9587ec9d10f..c4fe2ed1444 100644 --- a/Libraries/LibCore/SystemWindows.cpp +++ b/Libraries/LibCore/SystemWindows.cpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace Core::System { @@ -166,4 +167,21 @@ ErrorOr fstatat(int, StringView, int) VERIFY_NOT_REACHED(); } +ErrorOr mmap(void* address, size_t size, int protection, int flags, int fd, off_t offset, size_t alignment, StringView) +{ + // custom alignment is not supported + VERIFY(!alignment); + void* ptr = ::mmap(address, size, protection, flags, fd, offset); + if (ptr == MAP_FAILED) + return Error::from_syscall("mmap"sv, -errno); + return ptr; +} + +ErrorOr munmap(void* address, size_t size) +{ + if (::munmap(address, size) < 0) + return Error::from_syscall("munmap"sv, -errno); + return {}; +} + } diff --git a/Meta/CMake/Findmman.cmake b/Meta/CMake/Findmman.cmake new file mode 100644 index 00000000000..ea6ab5aa2c0 --- /dev/null +++ b/Meta/CMake/Findmman.cmake @@ -0,0 +1,2 @@ +find_path(MMAN_INCLUDE_DIR sys/mman.h PATH_SUFFIXES mman) +find_library(MMAN_LIBRARY mman) diff --git a/vcpkg.json b/vcpkg.json index cab66098657..86d8ab31136 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -71,6 +71,10 @@ "simd" ] }, + { + "name": "mman", + "platform": "windows" + }, "simdutf", { "name": "skia",