Title: [233415] trunk/Source/WTF
Revision
233415
Author
[email protected]
Date
2018-07-01 21:24:33 -0700 (Sun, 01 Jul 2018)

Log Message

[WTF] RandomDevice should be initialized inside std::call_once
https://bugs.webkit.org/show_bug.cgi?id=186017

Reviewed by Darin Adler.

While Linux ports uses mutex-guarded static variables, Mac ports do not.
So we should guard static variables' initialization by using std::call_once.
This patch does it for RandomDevice.

* wtf/OSRandomSource.cpp:
(WTF::cryptographicallyRandomValuesFromOS):
* wtf/RandomDevice.h: Small fix for OS(FUCHSIA).

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (233414 => 233415)


--- trunk/Source/WTF/ChangeLog	2018-07-02 01:52:14 UTC (rev 233414)
+++ trunk/Source/WTF/ChangeLog	2018-07-02 04:24:33 UTC (rev 233415)
@@ -1,3 +1,18 @@
+2018-07-01  Yusuke Suzuki  <[email protected]>
+
+        [WTF] RandomDevice should be initialized inside std::call_once
+        https://bugs.webkit.org/show_bug.cgi?id=186017
+
+        Reviewed by Darin Adler.
+
+        While Linux ports uses mutex-guarded static variables, Mac ports do not.
+        So we should guard static variables' initialization by using std::call_once.
+        This patch does it for RandomDevice.
+
+        * wtf/OSRandomSource.cpp:
+        (WTF::cryptographicallyRandomValuesFromOS):
+        * wtf/RandomDevice.h: Small fix for OS(FUCHSIA).
+
 2018-07-01  Myles C. Maxfield  <[email protected]>
 
         [Cocoa] LastResort in the font family list causes emoji with joiners to be rendered as multiple .notdef characters

Modified: trunk/Source/WTF/wtf/OSRandomSource.cpp (233414 => 233415)


--- trunk/Source/WTF/wtf/OSRandomSource.cpp	2018-07-02 01:52:14 UTC (rev 233414)
+++ trunk/Source/WTF/wtf/OSRandomSource.cpp	2018-07-02 04:24:33 UTC (rev 233415)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "OSRandomSource.h"
 
+#include <mutex>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/RandomDevice.h>
 
@@ -33,7 +34,13 @@
 
 void cryptographicallyRandomValuesFromOS(unsigned char* buffer, size_t length)
 {
-    static NeverDestroyed<RandomDevice> device;
+    static LazyNeverDestroyed<RandomDevice> device;
+    static std::once_flag onceFlag;
+    std::call_once(
+        onceFlag,
+        [] {
+            device.construct();
+        });
     device.get().cryptographicallyRandomValues(buffer, length);
 }
 

Modified: trunk/Source/WTF/wtf/RandomDevice.h (233414 => 233415)


--- trunk/Source/WTF/wtf/RandomDevice.h	2018-07-02 01:52:14 UTC (rev 233414)
+++ trunk/Source/WTF/wtf/RandomDevice.h	2018-07-02 04:24:33 UTC (rev 233415)
@@ -34,7 +34,7 @@
 class RandomDevice {
     WTF_MAKE_NONCOPYABLE(RandomDevice);
 public:
-#if OS(DARWIN) || OS(WINDOWS)
+#if OS(DARWIN) || OS(FUCHSIA) || OS(WINDOWS)
     RandomDevice() = default;
 #else
     RandomDevice();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to