1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 11:37:35 +00:00

LibCore: Make MappedFile OwnPtr-based

Since it will become a stream in a little bit, it should behave like all
non-trivial stream classes, who are not primarily intended to have
shared ownership to make closing behavior more predictable. Across all
uses of MappedFile, there is only one use case of shared mapped files in
LibVideo, which now uses the thin SharedMappedFile wrapper.
This commit is contained in:
kleines Filmröllchen 2023-09-26 00:54:34 +02:00 committed by Tim Schumacher
parent 5b2496e522
commit 062e0db46c
32 changed files with 80 additions and 64 deletions

View file

@ -14,18 +14,18 @@
namespace Core {
ErrorOr<NonnullRefPtr<MappedFile>> MappedFile::map(StringView path)
ErrorOr<NonnullOwnPtr<MappedFile>> MappedFile::map(StringView path)
{
auto fd = TRY(Core::System::open(path, O_RDONLY | O_CLOEXEC, 0));
return map_from_fd_and_close(fd, path);
}
ErrorOr<NonnullRefPtr<MappedFile>> MappedFile::map_from_file(NonnullOwnPtr<Core::File> stream, StringView path)
ErrorOr<NonnullOwnPtr<MappedFile>> MappedFile::map_from_file(NonnullOwnPtr<Core::File> stream, StringView path)
{
return map_from_fd_and_close(stream->leak_fd(Badge<MappedFile> {}), path);
}
ErrorOr<NonnullRefPtr<MappedFile>> MappedFile::map_from_fd_and_close(int fd, [[maybe_unused]] StringView path)
ErrorOr<NonnullOwnPtr<MappedFile>> MappedFile::map_from_fd_and_close(int fd, [[maybe_unused]] StringView path)
{
TRY(Core::System::fcntl(fd, F_SETFD, FD_CLOEXEC));
@ -38,7 +38,7 @@ ErrorOr<NonnullRefPtr<MappedFile>> MappedFile::map_from_fd_and_close(int fd, [[m
auto* ptr = TRY(Core::System::mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0, 0, path));
return adopt_ref(*new MappedFile(ptr, size));
return adopt_own(*new MappedFile(ptr, size));
}
MappedFile::MappedFile(void* ptr, size_t size)