Skip to content

Commit

Permalink
LibCore/System: Add mmap, munmap for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stasoid authored and gmta committed Nov 26, 2024
1 parent 4ae3a0d commit 3f7affa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Libraries/LibCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions Libraries/LibCore/SystemWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <Windows.h>
#include <direct.h>
#include <io.h>
#include <sys/mman.h>

namespace Core::System {

Expand Down Expand Up @@ -166,4 +167,21 @@ ErrorOr<struct stat> fstatat(int, StringView, int)
VERIFY_NOT_REACHED();
}

ErrorOr<void*> 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<void> munmap(void* address, size_t size)
{
if (::munmap(address, size) < 0)
return Error::from_syscall("munmap"sv, -errno);
return {};
}

}
2 changes: 2 additions & 0 deletions Meta/CMake/Findmman.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
find_path(MMAN_INCLUDE_DIR sys/mman.h PATH_SUFFIXES mman)
find_library(MMAN_LIBRARY mman)
4 changes: 4 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
"simd"
]
},
{
"name": "mman",
"platform": "windows"
},
"simdutf",
{
"name": "skia",
Expand Down

0 comments on commit 3f7affa

Please sign in to comment.