Title: [237922] trunk
- Revision
- 237922
- Author
- [email protected]
- Date
- 2018-11-07 06:24:09 -0800 (Wed, 07 Nov 2018)
Log Message
[Linux] Use memfd_create when available in SharedMemory implementation
https://bugs.webkit.org/show_bug.cgi?id=189741
Reviewed by Michael Catanzaro.
.:
Add include check for linux/memfd.h header.
* Source/cmake/OptionsCommon.cmake:
Source/WebKit:
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.
Modified Paths
Diff
Modified: trunk/ChangeLog (237921 => 237922)
--- trunk/ChangeLog 2018-11-07 11:50:30 UTC (rev 237921)
+++ trunk/ChangeLog 2018-11-07 14:24:09 UTC (rev 237922)
@@ -1,3 +1,14 @@
+2018-11-07 Carlos Garcia Campos <[email protected]>
+
+ [Linux] Use memfd_create when available in SharedMemory implementation
+ https://bugs.webkit.org/show_bug.cgi?id=189741
+
+ Reviewed by Michael Catanzaro.
+
+ Add include check for linux/memfd.h header.
+
+ * Source/cmake/OptionsCommon.cmake:
+
2018-11-05 Dominik Infuehr <[email protected]>
Enable LLInt on ARMv7/Linux
Modified: trunk/Source/WebKit/ChangeLog (237921 => 237922)
--- trunk/Source/WebKit/ChangeLog 2018-11-07 11:50:30 UTC (rev 237921)
+++ trunk/Source/WebKit/ChangeLog 2018-11-07 14:24:09 UTC (rev 237922)
@@ -1,3 +1,17 @@
+2018-11-07 Carlos Garcia Campos <[email protected]>
+
+ [Linux] Use memfd_create when available in SharedMemory implementation
+ https://bugs.webkit.org/show_bug.cgi?id=189741
+
+ Reviewed by Michael Catanzaro.
+
+ 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-11-06 Justin Fan <[email protected]>
[WebGPU] Experimental prototype for WebGPURenderPipeline and WebGPUSwapChain
Modified: trunk/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp (237921 => 237922)
--- trunk/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp 2018-11-07 11:50:30 UTC (rev 237921)
+++ trunk/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp 2018-11-07 14:24:09 UTC (rev 237922)
@@ -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 @@
return PROT_READ | PROT_WRITE;
}
-RefPtr<SharedMemory> SharedMemory::create(void* address, size_t size, Protection protection)
+static int createSharedMemory()
{
+#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;
-
- int fileDescriptor = -1;
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,8 +140,18 @@
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: %s", strerror(errno));
return nullptr;
}
@@ -127,7 +158,6 @@
while (ftruncate(fileDescriptor, size) == -1) {
if (errno != EINTR) {
closeWithRetry(fileDescriptor);
- shm_unlink(tempName.data());
return nullptr;
}
}
@@ -135,12 +165,9 @@
void* data = "" 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;
Modified: trunk/Source/cmake/OptionsCommon.cmake (237921 => 237922)
--- trunk/Source/cmake/OptionsCommon.cmake 2018-11-07 11:50:30 UTC (rev 237921)
+++ trunk/Source/cmake/OptionsCommon.cmake 2018-11-07 14:24:09 UTC (rev 237922)
@@ -122,6 +122,7 @@
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)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes