This commit is contained in:
stasoid 2024-11-21 14:11:31 +01:00 committed by GitHub
commit 1a3a14964d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 33 additions and 5 deletions

View file

@ -22,6 +22,10 @@ serenity_lib(LibCoreMinimal coreminimal)
if (WIN32) if (WIN32)
find_path(DIRENT_INCLUDE_DIR dirent.h REQUIRED) find_path(DIRENT_INCLUDE_DIR dirent.h REQUIRED)
target_include_directories(LibCoreMinimal PRIVATE ${DIRENT_INCLUDE_DIR}) 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() endif()
if (LAGOM_TOOLS_ONLY) if (LAGOM_TOOLS_ONLY)
@ -110,3 +114,7 @@ endif()
if (ANDROID) if (ANDROID)
target_link_libraries(LibCore PRIVATE log) target_link_libraries(LibCore PRIVATE log)
endif() endif()
if (WIN32)
target_include_directories(LibCore PRIVATE ${MMAN_INCLUDE_DIR})
endif()

View file

@ -9,9 +9,7 @@
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibCore/MappedFile.h> #include <LibCore/MappedFile.h>
#include <LibCore/System.h> #include <LibCore/System.h>
#include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h>
namespace Core { namespace Core {
@ -29,10 +27,8 @@ ErrorOr<NonnullOwnPtr<MappedFile>> MappedFile::map_from_file(NonnullOwnPtr<Core:
ErrorOr<NonnullOwnPtr<MappedFile>> MappedFile::map_from_fd_and_close(int fd, [[maybe_unused]] StringView path, Mode mode) ErrorOr<NonnullOwnPtr<MappedFile>> MappedFile::map_from_fd_and_close(int fd, [[maybe_unused]] StringView path, Mode mode)
{ {
TRY(Core::System::fcntl(fd, F_SETFD, FD_CLOEXEC));
ScopeGuard fd_close_guard = [fd] { ScopeGuard fd_close_guard = [fd] {
::close(fd); (void)System::close(fd);
}; };
auto stat = TRY(Core::System::fstat(fd)); auto stat = TRY(Core::System::fstat(fd));

View file

@ -15,6 +15,7 @@
#include <Windows.h> #include <Windows.h>
#include <direct.h> #include <direct.h>
#include <io.h> #include <io.h>
#include <sys/mman.h>
namespace Core::System { namespace Core::System {
@ -166,4 +167,21 @@ ErrorOr<struct stat> fstatat(int, StringView, int)
VERIFY_NOT_REACHED(); 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 {};
}
} }

View file

@ -0,0 +1,2 @@
find_path(MMAN_INCLUDE_DIR sys/mman.h PATH_SUFFIXES mman)
find_library(MMAN_LIBRARY mman)

View file

@ -71,6 +71,10 @@
"simd" "simd"
] ]
}, },
{
"name": "mman",
"platform": "windows"
},
"simdutf", "simdutf",
{ {
"name": "skia", "name": "skia",