Commit 4e81f258 authored by Samuel Groß's avatar Samuel Groß Committed by V8 LUCI CQ

[base] Only use memfd_create when available

The use of memfd_create causes V8 to require glibc 2.27 which wasn't
previously needed. This CL rewrites the affected code to check at
runtime whether memfd_create is available and otherwise use mkstemp.

Bug: v8:12682
Change-Id: I84dc3f5ab7504cec2b599bc92501ddecc2ae22cf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3516870Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Samuel Groß <saelo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79486}
parent f01a6098
......@@ -46,8 +46,11 @@
#include <atomic>
#endif
#if V8_OS_DARWIN || V8_OS_LINUX
#include <dlfcn.h> // for dlsym
#endif
#if V8_OS_DARWIN
#include <dlfcn.h>
#include <mach/mach.h>
#endif
......@@ -577,8 +580,18 @@ void OS::FreeAddressSpaceReservation(AddressSpaceReservation reservation) {
// static
PlatformSharedMemoryHandle OS::CreateSharedMemoryHandleForTesting(size_t size) {
#if V8_OS_LINUX && !V8_OS_ANDROID
const char* name = "V8MemFDForTesting";
int fd = memfd_create(name, MFD_CLOEXEC);
// Use memfd_create if available, otherwise mkstemp.
using memfd_create_t = int (*)(const char*, unsigned int);
memfd_create_t memfd_create =
reinterpret_cast<memfd_create_t>(dlsym(RTLD_DEFAULT, "memfd_create"));
int fd = -1;
if (memfd_create) {
fd = memfd_create("V8MemFDForTesting", MFD_CLOEXEC);
} else {
char filename[] = "/tmp/v8_tmp_file_for_testing_XXXXXX";
fd = mkstemp(filename);
if (fd != -1) CHECK_EQ(0, unlink(filename));
}
if (fd == -1) return kInvalidSharedMemoryHandle;
CHECK_EQ(0, ftruncate(fd, size));
return SharedMemoryHandleFromFileDescriptor(fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment