Title: [102493] trunk/Source/WebKit2
Revision
102493
Author
commit-qu...@webkit.org
Date
2011-12-09 17:01:12 -0800 (Fri, 09 Dec 2011)

Log Message

[Qt] Open shared memory files with shm_open.
https://bugs.webkit.org/show_bug.cgi?id=74078

Original patch by Kimmo Kinnunen

Patch by Allan Sandfeld Jensen <allan.jen...@nokia.com> on 2011-12-09
Reviewed by Kenneth Rohde Christiansen.

Open shared memory files with shm_open. This uses mount point that is
intended to host shared memory files. Typically this is /dev/shm.

This fixes crashes when filesystem that hosts QDir::temp() is full.

This is also more well-defined with respect to question whether SHM
writes to temp dir would cause unintended wear if hosted on flash drives.

This also fixes performance problems regarding QDir::temp() and
mkostemp(), both of which appear to be long operations.

* Platform/unix/SharedMemoryUnix.cpp:
(WebKit::SharedMemory::create):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (102492 => 102493)


--- trunk/Source/WebKit2/ChangeLog	2011-12-10 01:01:02 UTC (rev 102492)
+++ trunk/Source/WebKit2/ChangeLog	2011-12-10 01:01:12 UTC (rev 102493)
@@ -1,3 +1,26 @@
+2011-12-09  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
+
+        [Qt] Open shared memory files with shm_open.
+        https://bugs.webkit.org/show_bug.cgi?id=74078
+
+        Original patch by Kimmo Kinnunen
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Open shared memory files with shm_open. This uses mount point that is
+        intended to host shared memory files. Typically this is /dev/shm.
+
+        This fixes crashes when filesystem that hosts QDir::temp() is full.
+
+        This is also more well-defined with respect to question whether SHM
+        writes to temp dir would cause unintended wear if hosted on flash drives.
+
+        This also fixes performance problems regarding QDir::temp() and
+        mkostemp(), both of which appear to be long operations.
+
+        * Platform/unix/SharedMemoryUnix.cpp:
+        (WebKit::SharedMemory::create):
+
 2011-12-09  Hugo Parente Lima  <hugo.l...@openbossa.org>
 
         [Qt] Click's count is limited to three continuous clicks.

Modified: trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp (102492 => 102493)


--- trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp	2011-12-10 01:01:02 UTC (rev 102492)
+++ trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp	2011-12-10 01:01:12 UTC (rev 102493)
@@ -105,8 +105,8 @@
 PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
 {
 #if PLATFORM(QT)
-    QString tempName = QDir::temp().filePath(QLatin1String("qwkshm.XXXXXX"));
-    QByteArray tempNameCSTR = tempName.toLocal8Bit();
+    QByteArray tempNameCSTR("/qwkshm.");
+    tempNameCSTR += QByteArray::number(qrand(), 36);
     char* tempNameC = tempNameCSTR.data();
 #elif PLATFORM(GTK)
     GOwnPtr<gchar> tempName(g_build_filename(g_get_tmp_dir(), "WK2SharedMemoryXXXXXX", NULL));
@@ -114,6 +114,12 @@
 #endif
 
     int fileDescriptor;
+#if PLATFORM(QT)
+    while ((fileDescriptor = shm_open(tempNameC, O_CREAT | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR)) == -1) {
+        if (errno != EINTR)
+            return 0;
+    }
+#else
     while ((fileDescriptor = mkstemp(tempNameC)) == -1) {
         if (errno != EINTR)
             return 0;
@@ -125,11 +131,15 @@
             return 0;
         }
     }
-
+#endif
     while (ftruncate(fileDescriptor, size) == -1) {
         if (errno != EINTR) {
             while (close(fileDescriptor) == -1 && errno == EINTR) { }
+#if PLATFORM(QT)
+            shm_unlink(tempNameC);
+#else
             unlink(tempNameC);
+#endif
             return 0;
         }
     }
@@ -137,11 +147,19 @@
     void* data = "" size, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0);
     if (data == MAP_FAILED) {
         while (close(fileDescriptor) == -1 && errno == EINTR) { }
+#if PLATFORM(QT)
+        shm_unlink(tempNameC);
+#else
         unlink(tempNameC);
+#endif
         return 0;
     }
 
+#if PLATFORM(QT)
+    shm_unlink(tempNameC);
+#else
     unlink(tempNameC);
+#endif
 
     RefPtr<SharedMemory> instance = adoptRef(new SharedMemory());
     instance->m_data = data;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to