summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-02-08 10:42:15 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-10 21:35:17 +0100
commit64096184131a7746a2c963a588c7a5162f11f8d7 (patch)
treeab7e4e7e57dbee65650399b6601e8beb8e55e015 /Userland
parentcf1f58d51ca0028fe6f48950dd0f66dcc82f142b (diff)
downloadserenity-64096184131a7746a2c963a588c7a5162f11f8d7.zip
LibCore: Convert AnonymousBuffer to use System::anon_create
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibCore/AnonymousBuffer.cpp32
1 files changed, 2 insertions, 30 deletions
diff --git a/Userland/Libraries/LibCore/AnonymousBuffer.cpp b/Userland/Libraries/LibCore/AnonymousBuffer.cpp
index dd09846b12..2385b83a13 100644
--- a/Userland/Libraries/LibCore/AnonymousBuffer.cpp
+++ b/Userland/Libraries/LibCore/AnonymousBuffer.cpp
@@ -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);
}