Diff
Modified: trunk/Source/WTF/ChangeLog (233400 => 233401)
--- trunk/Source/WTF/ChangeLog 2018-06-30 18:44:34 UTC (rev 233400)
+++ trunk/Source/WTF/ChangeLog 2018-06-30 20:53:56 UTC (rev 233401)
@@ -1,3 +1,20 @@
+2018-06-30 Adam Barth <aba...@webkit.org>
+
+ Port WTF to OS(FUCHSIA)
+ https://bugs.webkit.org/show_bug.cgi?id=187221
+
+ Reviewed by Yusuke Suzuki.
+
+ * wtf/FastMalloc.cpp: Fuchsia does not have resource.h
+ (WTF::fastMallocStatistics): Skip collecting stats without resource.h
+ * wtf/InlineASM.h: Fuchsia uses ELF
+ * wtf/Platform.h: Define OS(FUCHSIA) as an OS(UNIX) variant
+ * wtf/RandomDevice.cpp: Call zx_cprng_draw for crypographic randomness
+ (WTF::RandomDevice::cryptographicallyRandomValues):
+ * wtf/ThreadingPthreads.cpp: Fuchsia does not have pthread_setschedparam
+ (WTF::Thread::changePriority):
+ * wtf/unix/CPUTimeFuchsia.cpp: Added.
+
2018-06-30 Commit Queue <commit-qu...@webkit.org>
Unreviewed, rolling out r233391.
Modified: trunk/Source/WTF/wtf/CurrentTime.cpp (233400 => 233401)
--- trunk/Source/WTF/wtf/CurrentTime.cpp 2018-06-30 18:44:34 UTC (rev 233400)
+++ trunk/Source/WTF/wtf/CurrentTime.cpp 2018-06-30 20:53:56 UTC (rev 233401)
@@ -54,6 +54,10 @@
#include <sys/time.h>
#endif
+#if OS(FUCHSIA)
+#include <zircon/syscalls.h>
+#endif
+
#if USE(GLIB)
#include <glib.h>
#endif
@@ -261,6 +265,8 @@
});
return fromRawSeconds((mach_absolute_time() * timebaseInfo.numer) / (1.0e9 * timebaseInfo.denom));
+#elif OS(FUCHSIA)
+ return fromRawSeconds(zx_clock_get_monotonic() / static_cast<double>(ZX_SEC(1)));
#elif OS(LINUX) || OS(FREEBSD) || OS(OPENBSD) || OS(NETBSD)
struct timespec ts { };
clock_gettime(CLOCK_MONOTONIC, &ts);
Modified: trunk/Source/WTF/wtf/FastMalloc.cpp (233400 => 233401)
--- trunk/Source/WTF/wtf/FastMalloc.cpp 2018-06-30 18:44:34 UTC (rev 233400)
+++ trunk/Source/WTF/wtf/FastMalloc.cpp 2018-06-30 20:53:56 UTC (rev 233401)
@@ -35,7 +35,9 @@
#include <windows.h>
#else
#include <pthread.h>
+#if HAVE(RESOURCE_H)
#include <sys/resource.h>
+#endif // HAVE(RESOURCE_H)
#endif
#if OS(DARWIN)
@@ -361,7 +363,7 @@
PROCESS_MEMORY_COUNTERS resourceUsage;
GetProcessMemoryInfo(GetCurrentProcess(), &resourceUsage, sizeof(resourceUsage));
statistics.committedVMBytes = resourceUsage.PeakWorkingSetSize;
-#else
+#elif HAVE(RESOURCE_H)
struct rusage resourceUsage;
getrusage(RUSAGE_SELF, &resourceUsage);
Modified: trunk/Source/WTF/wtf/InlineASM.h (233400 => 233401)
--- trunk/Source/WTF/wtf/InlineASM.h 2018-06-30 18:44:34 UTC (rev 233400)
+++ trunk/Source/WTF/wtf/InlineASM.h 2018-06-30 20:53:56 UTC (rev 233401)
@@ -64,11 +64,12 @@
#elif OS(AIX)
// IBM's own file format
#define HIDE_SYMBOL(name) ".lglobl " #name
-#elif OS(LINUX) \
- || OS(FREEBSD) \
- || OS(OPENBSD) \
- || OS(HPUX) \
- || OS(NETBSD)
+#elif OS(LINUX) \
+ || OS(FREEBSD) \
+ || OS(FUCHSIA) \
+ || OS(OPENBSD) \
+ || OS(HPUX) \
+ || OS(NETBSD)
// ELF platform
#define HIDE_SYMBOL(name) ".hidden " #name
#else
@@ -80,8 +81,9 @@
// Don't know about any of the others.
#if OS(DARWIN)
#define LOCAL_LABEL_STRING(name) "L" #name
-#elif OS(LINUX) \
+#elif OS(LINUX) \
|| OS(FREEBSD) \
+ || OS(FUCHSIA) \
|| OS(OPENBSD) \
|| OS(HURD) \
|| OS(NETBSD) \
Modified: trunk/Source/WTF/wtf/Platform.h (233400 => 233401)
--- trunk/Source/WTF/wtf/Platform.h 2018-06-30 18:44:34 UTC (rev 233400)
+++ trunk/Source/WTF/wtf/Platform.h 2018-06-30 20:53:56 UTC (rev 233401)
@@ -359,6 +359,11 @@
#define WTF_OS_FREEBSD 1
#endif
+/* OS(FUCHSIA) - Fuchsia */
+#ifdef __Fuchsia__
+#define WTF_OS_FUCHSIA 1
+#endif
+
/* OS(HURD) - GNU/Hurd */
#ifdef __GNU__
#define WTF_OS_HURD 1
@@ -391,6 +396,7 @@
#if OS(AIX) \
|| OS(DARWIN) \
|| OS(FREEBSD) \
+ || OS(FUCHSIA) \
|| OS(HURD) \
|| OS(LINUX) \
|| OS(NETBSD) \
@@ -631,6 +637,11 @@
#define USE_PTHREADS 1
#endif /* OS(UNIX) */
+#if OS(UNIX) && !OS(FUCHSIA)
+#define HAVE_RESOURCE_H 1
+#define HAVE_PTHREAD_SETSCHEDPARAM 1
+#endif
+
#if OS(DARWIN)
#define HAVE_DISPATCH_H 1
#define HAVE_MADV_FREE 1
Modified: trunk/Source/WTF/wtf/PlatformJSCOnly.cmake (233400 => 233401)
--- trunk/Source/WTF/wtf/PlatformJSCOnly.cmake 2018-06-30 18:44:34 UTC (rev 233400)
+++ trunk/Source/WTF/wtf/PlatformJSCOnly.cmake 2018-06-30 20:53:56 UTC (rev 233401)
@@ -19,9 +19,18 @@
text/unix/TextBreakIteratorInternalICUUnix.cpp
- unix/CPUTimeUnix.cpp
unix/LanguageUnix.cpp
)
+ if (WTF_OS_FUCHSIA)
+ list(APPEND WTF_SOURCES
+ fuchsia/CPUTimeFuchsia.cpp
+ )
+ else ()
+ list(APPEND WTF_SOURCES
+ unix/CPUTimeUnix.cpp
+ )
+ endif ()
+
endif ()
if (WIN32)
Modified: trunk/Source/WTF/wtf/RandomDevice.cpp (233400 => 233401)
--- trunk/Source/WTF/wtf/RandomDevice.cpp 2018-06-30 18:44:34 UTC (rev 233400)
+++ trunk/Source/WTF/wtf/RandomDevice.cpp 2018-06-30 20:53:56 UTC (rev 233401)
@@ -30,7 +30,7 @@
#include <stdint.h>
#include <stdlib.h>
-#if !OS(DARWIN) && OS(UNIX)
+#if !OS(DARWIN) && !OS(FUCHSIA) && OS(UNIX)
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
@@ -45,9 +45,13 @@
#include "CommonCryptoSPI.h"
#endif
+#if OS(FUCHSIA)
+#include <zircon/syscalls.h>
+#endif
+
namespace WTF {
-#if !OS(DARWIN) && OS(UNIX)
+#if !OS(DARWIN) && !OS(FUCHSIA) && OS(UNIX)
NEVER_INLINE NO_RETURN_DUE_TO_CRASH static void crashUnableToOpenURandom()
{
CRASH();
@@ -59,7 +63,7 @@
}
#endif
-#if !OS(DARWIN) && !OS(WINDOWS)
+#if !OS(DARWIN) && !OS(FUCHSIA) && !OS(WINDOWS)
RandomDevice::RandomDevice()
{
int ret = 0;
@@ -72,7 +76,7 @@
}
#endif
-#if !OS(DARWIN) && !OS(WINDOWS)
+#if !OS(DARWIN) && !OS(FUCHSIA) && !OS(WINDOWS)
RandomDevice::~RandomDevice()
{
close(m_fd);
@@ -85,6 +89,8 @@
{
#if OS(DARWIN)
RELEASE_ASSERT(!CCRandomCopyBytes(kCCRandomDefault, buffer, length));
+#elif OS(FUCHSIA)
+ zx_cprng_draw(buffer, length);
#elif OS(UNIX)
ssize_t amountRead = 0;
while (static_cast<size_t>(amountRead) < length) {
Modified: trunk/Source/WTF/wtf/RandomDevice.h (233400 => 233401)
--- trunk/Source/WTF/wtf/RandomDevice.h 2018-06-30 18:44:34 UTC (rev 233400)
+++ trunk/Source/WTF/wtf/RandomDevice.h 2018-06-30 20:53:56 UTC (rev 233401)
@@ -47,7 +47,7 @@
void cryptographicallyRandomValues(unsigned char* buffer, size_t length);
private:
-#if OS(DARWIN) || OS(WINDOWS)
+#if OS(DARWIN) || OS(FUCHSIA) || OS(WINDOWS)
#elif OS(UNIX)
int m_fd { -1 };
#else
Modified: trunk/Source/WTF/wtf/ThreadingPthreads.cpp (233400 => 233401)
--- trunk/Source/WTF/wtf/ThreadingPthreads.cpp 2018-06-30 18:44:34 UTC (rev 233400)
+++ trunk/Source/WTF/wtf/ThreadingPthreads.cpp 2018-06-30 20:53:56 UTC (rev 233401)
@@ -256,6 +256,7 @@
void Thread::changePriority(int delta)
{
+#if HAVE(PTHREAD_SETSCHEDPARAM)
auto locker = holdLock(m_mutex);
int policy;
@@ -267,6 +268,7 @@
param.sched_priority += delta;
pthread_setschedparam(m_handle, policy, ¶m);
+#endif
}
int Thread::waitForCompletion()
Added: trunk/Source/WTF/wtf/fuchsia/CPUTimeFuchsia.cpp (0 => 233401)
--- trunk/Source/WTF/wtf/fuchsia/CPUTimeFuchsia.cpp (rev 0)
+++ trunk/Source/WTF/wtf/fuchsia/CPUTimeFuchsia.cpp 2018-06-30 20:53:56 UTC (rev 233401)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2018 Google, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CPUTime.h"
+
+#include <zircon/syscalls.h>
+
+namespace WTF {
+
+static Seconds timeToSeconds(zx_time_t t)
+{
+ return Seconds(t / static_cast<double>(ZX_SEC(1)));
+}
+
+std::optional<CPUTime> CPUTime::get()
+{
+ // Fuchsia issue ZX-2318 tracks being able to get the monotonic and thread
+ // times atomically and being able to separate ZX_CLOCK_THREAD into user and
+ // kernel time.
+ zx_time_t thread = zx_clock_get(ZX_CLOCK_THREAD);
+
+ return CPUTime { MonotonicTime::now(), timeToSeconds(thread), Seconds() };
+}
+
+Seconds CPUTime::forCurrentThread()
+{
+ return timeToSeconds(zx_clock_get(ZX_CLOCK_THREAD));
+}
+
+}