Commit 7b2b3afa authored by Samuel Groß's avatar Samuel Groß Committed by V8 LUCI CQ

[base] Use memfd_create instead of shm_open when creating shared memory

Using shm_open with a constant name can lead to race conditions with
other V8 instances using (and unlinking) the same shared memory object.

Bug: v8:12636
Change-Id: Ic2d2317f99c1df7aedec2dc52b187c64eea11d2c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3468899Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Samuel Groß <saelo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79146}
parent f146851d
......@@ -577,11 +577,10 @@ bool OS::FreeAddressSpaceReservation(AddressSpaceReservation reservation) {
// static
PlatformSharedMemoryHandle OS::CreateSharedMemoryHandleForTesting(size_t size) {
#if V8_OS_LINUX && !V8_OS_ANDROID
const char* shm_name = "/V8_SharedMemoryForTesting";
int fd = shm_open(shm_name, O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
const char* name = "V8MemFDForTesting";
int fd = memfd_create(name, MFD_CLOEXEC);
if (fd == -1) return kInvalidSharedMemoryHandle;
CHECK_EQ(0, ftruncate(fd, size));
CHECK_EQ(0, shm_unlink(shm_name));
return SharedMemoryHandleFromFileDescriptor(fd);
#else
return kInvalidSharedMemoryHandle;
......
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