WebKit Bugzilla
Attachment 350101 Details for
Bug 189741
: [Linux] Use memfd_create when available in SharedMemory implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
wk2-memfd.diff (text/plain), 5.00 KB, created by
Carlos Garcia Campos
on 2018-09-19 03:08:22 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Carlos Garcia Campos
Created:
2018-09-19 03:08:22 PDT
Size:
5.00 KB
patch
obsolete
>diff --git a/ChangeLog b/ChangeLog >index a35724bb016..f466d0cca1f 100644 >--- a/ChangeLog >+++ b/ChangeLog >@@ -1,3 +1,14 @@ >+2018-09-19 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [Linux] Use memfd_create when available in SharedMemory implementation >+ https://bugs.webkit.org/show_bug.cgi?id=189741 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add include check for linux/memfd.h header. >+ >+ * Source/cmake/OptionsCommon.cmake: >+ > 2018-09-06 Adrian Perez de Castro <aperez@igalia.com> > > Unreviewed. Update OptionsWPE.cmake and NEWS for 2.21.92 release. >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 4b70fda1531..f88b0578a01 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,17 @@ >+2018-09-19 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [Linux] Use memfd_create when available in SharedMemory implementation >+ https://bugs.webkit.org/show_bug.cgi?id=189741 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ If memfd is available, use it instead of shm_open. >+ >+ * Platform/unix/SharedMemoryUnix.cpp: >+ (WebKit::createSharedMemory): Helper to create the shared memory, trying first with memfd and falling back to >+ shm if it's not available. >+ (WebKit::SharedMemory::create): Use createSharedMemory() helper. >+ > 2018-08-31 John Wilander <wilander@apple.com> > > Storage Access API: Maintain access through same-site navigations >diff --git a/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp b/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp >index 713dc35270b..1d17768be50 100644 >--- a/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp >+++ b/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp >@@ -44,6 +44,11 @@ > #include <wtf/text/CString.h> > #include <wtf/text/WTFString.h> > >+#if HAVE(LINUX_MEMFD_H) >+#include <linux/memfd.h> >+#include <sys/syscall.h> >+#endif >+ > namespace WebKit { > > SharedMemory::Handle::Handle() >@@ -106,11 +111,27 @@ static inline int accessModeMMap(SharedMemory::Protection protection) > return PROT_READ | PROT_WRITE; > } > >-RefPtr<SharedMemory> SharedMemory::create(void* address, size_t size, Protection protection) >+static int createSharedMemory() > { >- CString tempName; >- >+#if HAVE(LINUX_MEMFD_H) >+ static bool isMemFdAvailable = true; > int fileDescriptor = -1; >+ if (isMemFdAvailable) { >+ do { >+ fileDescriptor = syscall(__NR_memfd_create, "WebKitSharedMemory", MFD_CLOEXEC); >+ } while (fileDescriptor == -1 && errno == EINTR); >+ >+ if (fileDescriptor != -1) >+ return fileDescriptor; >+ >+ if (errno == ENOSYS) >+ return fileDescriptor; >+ >+ isMemFdAvailable = false; >+ } >+#endif >+ >+ CString tempName; > for (int tries = 0; fileDescriptor == -1 && tries < 10; ++tries) { > String name = String("/WK2SharedMemory.") + String::number(static_cast<unsigned>(WTF::randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0))); > tempName = name.utf8(); >@@ -119,15 +140,24 @@ RefPtr<SharedMemory> SharedMemory::create(void* address, size_t size, Protection > fileDescriptor = shm_open(tempName.data(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); > } while (fileDescriptor == -1 && errno == EINTR); > } >+ >+ if (fileDescriptor != -1) >+ shm_unlink(tempName.data()); >+ >+ return fileDescriptor; >+} >+ >+RefPtr<SharedMemory> SharedMemory::create(void* address, size_t size, Protection protection) >+{ >+ int fileDescriptor = createSharedMemory(); > if (fileDescriptor == -1) { >- WTFLogAlways("Failed to create shared memory file %s: %s", tempName.data(), strerror(errno)); >+ WTFLogAlways("Failed to create shared memory file: %s", strerror(errno)); > return nullptr; > } > > while (ftruncate(fileDescriptor, size) == -1) { > if (errno != EINTR) { > closeWithRetry(fileDescriptor); >- shm_unlink(tempName.data()); > return nullptr; > } > } >@@ -135,12 +165,9 @@ RefPtr<SharedMemory> SharedMemory::create(void* address, size_t size, Protection > void* data = mmap(address, size, accessModeMMap(protection), MAP_SHARED, fileDescriptor, 0); > if (data == MAP_FAILED) { > closeWithRetry(fileDescriptor); >- shm_unlink(tempName.data()); > return nullptr; > } > >- shm_unlink(tempName.data()); >- > RefPtr<SharedMemory> instance = adoptRef(new SharedMemory()); > instance->m_data = data; > instance->m_fileDescriptor = fileDescriptor; >diff --git a/Source/cmake/OptionsCommon.cmake b/Source/cmake/OptionsCommon.cmake >index cd893d333c9..dc1b8fb030b 100644 >--- a/Source/cmake/OptionsCommon.cmake >+++ b/Source/cmake/OptionsCommon.cmake >@@ -122,6 +122,7 @@ WEBKIT_CHECK_HAVE_INCLUDE(HAVE_STRINGS_H strings.h) > WEBKIT_CHECK_HAVE_INCLUDE(HAVE_SYS_PARAM_H sys/param.h) > WEBKIT_CHECK_HAVE_INCLUDE(HAVE_SYS_TIME_H sys/time.h) > WEBKIT_CHECK_HAVE_INCLUDE(HAVE_SYS_TIMEB_H sys/timeb.h) >+WEBKIT_CHECK_HAVE_INCLUDE(HAVE_LINUX_MEMFD_H linux/memfd.h) > > # Check for functions > WEBKIT_CHECK_HAVE_FUNCTION(HAVE_ALIGNED_MALLOC _aligned_malloc)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
mcatanzaro
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189741
: 350101