mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibCore: Convert AnonymousBuffer to use System::anon_create
This commit is contained in:
parent
cf1f58d51c
commit
6409618413
Notes:
sideshowbarker
2024-07-17 19:02:27 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/6409618413 Pull-request: https://github.com/SerenityOS/serenity/pull/12352 Reviewed-by: https://github.com/Jorropo Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/mjz19910
1 changed files with 2 additions and 30 deletions
|
@ -6,44 +6,16 @@
|
|||
|
||||
#include <AK/Try.h>
|
||||
#include <LibCore/AnonymousBuffer.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibIPC/File.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#if defined(__serenity__)
|
||||
# include <serenity.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) && !defined(MFD_CLOEXEC)
|
||||
# include <linux/memfd.h>
|
||||
# include <sys/syscall.h>
|
||||
|
||||
static int memfd_create(const char* name, unsigned int flags)
|
||||
{
|
||||
return syscall(SYS_memfd_create, name, flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace Core {
|
||||
|
||||
ErrorOr<AnonymousBuffer> AnonymousBuffer::create_with_size(size_t size)
|
||||
{
|
||||
int fd = -1;
|
||||
#if defined(__serenity__)
|
||||
fd = anon_create(round_up_to_power_of_two(size, PAGE_SIZE), O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
return Error::from_errno(errno);
|
||||
#elif defined(__linux__)
|
||||
fd = memfd_create("", MFD_CLOEXEC);
|
||||
if (fd < 0)
|
||||
return Error::from_errno(errno);
|
||||
if (ftruncate(fd, size) < 0) {
|
||||
close(fd);
|
||||
return Error::from_errno(errno);
|
||||
}
|
||||
#endif
|
||||
if (fd < 0)
|
||||
return Error::from_errno(errno);
|
||||
auto fd = TRY(Core::System::anon_create(size, O_CLOEXEC));
|
||||
return create_from_anon_fd(fd, size);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue