mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
LibCore: Use mmap() and munmap() wrappers in Core::MappedFile
This commit is contained in:
parent
45842a5208
commit
094fa900a3
1 changed files with 2 additions and 12 deletions
|
@ -36,16 +36,7 @@ ErrorOr<NonnullRefPtr<MappedFile>> MappedFile::map_from_fd_and_close(int fd, [[m
|
||||||
auto stat = TRY(Core::System::fstat(fd));
|
auto stat = TRY(Core::System::fstat(fd));
|
||||||
auto size = stat.st_size;
|
auto size = stat.st_size;
|
||||||
|
|
||||||
auto* ptr = mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0);
|
auto* ptr = TRY(Core::System::mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0, 0, path));
|
||||||
|
|
||||||
if (ptr == MAP_FAILED)
|
|
||||||
return Error::from_errno(errno);
|
|
||||||
|
|
||||||
#ifdef __serenity__
|
|
||||||
if (set_mmap_name(ptr, size, path.characters()) < 0) {
|
|
||||||
perror("set_mmap_name");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return adopt_ref(*new MappedFile(ptr, size));
|
return adopt_ref(*new MappedFile(ptr, size));
|
||||||
}
|
}
|
||||||
|
@ -58,8 +49,7 @@ MappedFile::MappedFile(void* ptr, size_t size)
|
||||||
|
|
||||||
MappedFile::~MappedFile()
|
MappedFile::~MappedFile()
|
||||||
{
|
{
|
||||||
auto rc = munmap(m_data, m_size);
|
MUST(Core::System::munmap(m_data, m_size));
|
||||||
VERIFY(rc == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue