qt5_qtwebkit.patch

From: Christian Prochaska <christian.prochaska@genode-labs.com>


---
 .../Source/JavaScriptCore/dfg/DFGOperations.cpp    |    1 +
 qtwebkit/Source/WTF/wtf/Assertions.h               |   11 ++++++++++
 qtwebkit/Source/WTF/wtf/FastMalloc.cpp             |    2 +-
 qtwebkit/Source/WTF/wtf/InlineASM.h                |    4 ++--
 qtwebkit/Source/WTF/wtf/OSAllocatorPosix.cpp       |   13 ++++++++++++
 qtwebkit/Source/WTF/wtf/OSRandomSource.cpp         |    8 ++++++++
 qtwebkit/Source/WTF/wtf/Platform.h                 |   19 +++++++++++++++---
 qtwebkit/Source/WTF/wtf/StackBounds.cpp            |   12 +++++++++++
 qtwebkit/Source/WTF/wtf/TCSystemAlloc.cpp          |   21 ++++++++++++++++++++
 .../platform/graphics/qt/MediaPlayerPrivateQt.cpp  |    3 +++
 10 files changed, 88 insertions(+), 6 deletions(-)

diff --git a/qtwebkit/Source/JavaScriptCore/dfg/DFGOperations.cpp b/qtwebkit/Source/JavaScriptCore/dfg/DFGOperations.cpp
index bb9ccc3..077cbed 100644
--- a/qtwebkit/Source/JavaScriptCore/dfg/DFGOperations.cpp
+++ b/qtwebkit/Source/JavaScriptCore/dfg/DFGOperations.cpp
@@ -1624,6 +1624,7 @@ namespace JSC {
 
 #if COMPILER(GCC) && CPU(X86_64)
 asm (
+".text" "\n" \
 ".globl " SYMBOL_STRING(getHostCallReturnValue) "\n"
 HIDE_SYMBOL(getHostCallReturnValue) "\n"
 SYMBOL_STRING(getHostCallReturnValue) ":" "\n"
diff --git a/qtwebkit/Source/WTF/wtf/Assertions.h b/qtwebkit/Source/WTF/wtf/Assertions.h
index 7e079ab..cac10fc 100644
--- a/qtwebkit/Source/WTF/wtf/Assertions.h
+++ b/qtwebkit/Source/WTF/wtf/Assertions.h
@@ -50,6 +50,10 @@
 #include <inttypes.h>
 #endif
 
+#if OS(GENODE)
+#include <base/printf.h>
+#endif
+
 #ifdef NDEBUG
 /* Disable ASSERT* macros in release mode. */
 #define ASSERTIONS_DISABLED_DEFAULT 1
@@ -173,6 +177,13 @@ WTF_EXPORT_PRIVATE void WTFInstallReportBacktraceOnCrashHook();
      WTFInvokeCrashHook(), \
      (*(int *)(uintptr_t)0xbbadbeef = 0), \
      __builtin_trap())
+#elif OS(GENODE)
+#define CRASH() ( \
+	PERR("WebKit CRASH in '%s'", WTF_PRETTY_FUNCTION), \
+	PERR("  in %s:%d", __FILE__, __LINE__), \
+    *(int *)(uintptr_t)0xbbadbeef = 0, \
+    ((void(*)())0)() /* More reliable, but doesn't say BBADBEEF */ \
+)
 #else
 #define CRASH() \
     (WTFReportBacktrace(), \
diff --git a/qtwebkit/Source/WTF/wtf/FastMalloc.cpp b/qtwebkit/Source/WTF/wtf/FastMalloc.cpp
index f2e34c7..f91c2fc 100644
--- a/qtwebkit/Source/WTF/wtf/FastMalloc.cpp
+++ b/qtwebkit/Source/WTF/wtf/FastMalloc.cpp
@@ -101,7 +101,7 @@
 #endif
 
 // Use a background thread to periodically scavenge memory to release back to the system
-#if PLATFORM(IOS)
+#if PLATFORM(IOS) || OS(GENODE)
 #define USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 0
 #else
 #define USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY 1
diff --git a/qtwebkit/Source/WTF/wtf/InlineASM.h b/qtwebkit/Source/WTF/wtf/InlineASM.h
index 0a2fe78..d1fdd01 100644
--- a/qtwebkit/Source/WTF/wtf/InlineASM.h
+++ b/qtwebkit/Source/WTF/wtf/InlineASM.h
@@ -62,12 +62,12 @@
 #elif OS(AIX)
     // IBM's own file format
 #define HIDE_SYMBOL(name) ".lglobl " #name
-#elif   OS(LINUX)               \
+#elif   (OS(LINUX)               \
      || OS(FREEBSD)             \
      || OS(OPENBSD)             \
      || OS(SOLARIS)             \
      || (OS(HPUX) && CPU(IA64)) \
-     || OS(NETBSD)
+     || OS(NETBSD))             \
     // ELF platform
 #define HIDE_SYMBOL(name) ".hidden " #name
 #else
diff --git a/qtwebkit/Source/WTF/wtf/OSAllocatorPosix.cpp b/qtwebkit/Source/WTF/wtf/OSAllocatorPosix.cpp
index a2f6a79..be8fff9 100644
--- a/qtwebkit/Source/WTF/wtf/OSAllocatorPosix.cpp
+++ b/qtwebkit/Source/WTF/wtf/OSAllocatorPosix.cpp
@@ -120,6 +120,7 @@ void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bo
 #endif
             CRASH();
     }
+#if !OS(GENODE)
     if (result && includesGuardPages) {
         // We use mmap to remap the guardpages rather than using mprotect as
         // mprotect results in multiple references to the code region.  This
@@ -128,6 +129,7 @@ void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bo
         mmap(result, pageSize(), PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, fd, 0);
         mmap(static_cast<char*>(result) + bytes - pageSize(), pageSize(), PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, fd, 0);
     }
+#endif /* OS(GENODE) */
     return result;
 }
 
@@ -179,9 +181,20 @@ void OSAllocator::decommit(void* address, size_t bytes)
 
 void OSAllocator::releaseDecommitted(void* address, size_t bytes)
 {
+#if OS(GENODE)
+    /*
+     * 'releaseDecommitted()' sometimes gets called with a start address
+     * different than the one returned by 'mmap()' to release only a part of the
+     * allocated memory. This feature is currently not supported by Genode's
+     * 'munmap()' implementation, so we don't crash on purpose if the result of
+     * 'munmap()' is -1.
+     */
+    munmap(address, bytes);
+#else
     int result = munmap(address, bytes);
     if (result == -1)
         CRASH();
+#endif /* OS(GENODE) */
 }
 
 } // namespace WTF
diff --git a/qtwebkit/Source/WTF/wtf/OSRandomSource.cpp b/qtwebkit/Source/WTF/wtf/OSRandomSource.cpp
index 0c1416a..5a10b3d 100644
--- a/qtwebkit/Source/WTF/wtf/OSRandomSource.cpp
+++ b/qtwebkit/Source/WTF/wtf/OSRandomSource.cpp
@@ -29,6 +29,10 @@
 #include <stdint.h>
 #include <stdlib.h>
 
+#if OS(GENODE)
+#include <base/printf.h>
+#endif /* OS(GENODE) */
+
 #if OS(UNIX)
 #include <fcntl.h>
 #include <unistd.h>
@@ -44,6 +48,10 @@ namespace WTF {
 #if USE(OS_RANDOMNESS)
 void cryptographicallyRandomValuesFromOS(unsigned char* buffer, size_t length)
 {
+#if OS(GENODE)
+	PWRN("cryptographicallyRandomValuesFromOS(): no strong source of randomness available");
+	return;
+#endif /* OS(GENODE) */
 #if OS(UNIX)
     int fd = open("/dev/urandom", O_RDONLY, 0);
     if (fd < 0)
diff --git a/qtwebkit/Source/WTF/wtf/Platform.h b/qtwebkit/Source/WTF/wtf/Platform.h
index 35fa7e3..89e6205 100644
--- a/qtwebkit/Source/WTF/wtf/Platform.h
+++ b/qtwebkit/Source/WTF/wtf/Platform.h
@@ -426,6 +426,12 @@
 #define WTF_OS_UNIX 1
 #endif
 
+/* OS(GENODE) */
+#ifdef __GENODE__
+/* Note: WTF_OS_FREEBSD is defined, too */
+#define WTF_OS_GENODE 1
+#endif
+
 /* Operating environments */
 
 /* FIXME: these are all mixes of OS, operating environment and policy choices. */
@@ -699,7 +705,8 @@
 
 #if !OS(WINDOWS) && !OS(SOLARIS) \
     && !OS(RVCT) \
-    && !OS(ANDROID)
+    && !OS(ANDROID) \
+    && !OS(GENODE)
 #define HAVE_TM_GMTOFF 1
 #define HAVE_TM_ZONE 1
 #define HAVE_TIMEGM 1
@@ -764,6 +771,11 @@
 #define HAVE_SYS_PARAM_H 1
 #define HAVE_SYS_TIME_H 1
 
+#elif OS(GENODE)
+
+#define HAVE_ERRNO_H 1
+#define HAVE_SYS_TIME_H 1
+
 #else
 
 /* FIXME: is this actually used or do other platforms generate their own config.h? */
@@ -782,7 +794,7 @@
 #if PLATFORM(QT)
 /* We must not customize the global operator new and delete for the Qt port. */
 #define ENABLE_GLOBAL_FASTMALLOC_NEW 0
-#if !OS(UNIX)
+#if !OS(UNIX) || OS(GENODE)
 #define USE_SYSTEM_MALLOC 1
 #endif
 #endif
@@ -1005,7 +1017,8 @@
 #define ENABLE_REGEXP_TRACING 0
 
 /* Yet Another Regex Runtime - turned on by default for JIT enabled ports. */
-#if !defined(ENABLE_YARR_JIT) && (ENABLE(JIT) || ENABLE(LLINT_C_LOOP)) && !PLATFORM(CHROMIUM)
+/* When enabled for Genode, the 'exec()' function returns invalid string objects */
+#if !defined(ENABLE_YARR_JIT) && (ENABLE(JIT) || ENABLE(LLINT_C_LOOP)) && !PLATFORM(CHROMIUM) && !OS(GENODE)
 #define ENABLE_YARR_JIT 1
 
 /* Setting this flag compares JIT results with interpreter results. */
diff --git a/qtwebkit/Source/WTF/wtf/StackBounds.cpp b/qtwebkit/Source/WTF/wtf/StackBounds.cpp
index a272ce3..a2e7484 100644
--- a/qtwebkit/Source/WTF/wtf/StackBounds.cpp
+++ b/qtwebkit/Source/WTF/wtf/StackBounds.cpp
@@ -44,6 +44,10 @@
 #include <string.h>
 #include <sys/procfs.h>
 
+#elif OS(GENODE)
+
+#include <base/thread.h>
+
 #elif OS(UNIX)
 
 #include <pthread.h>
@@ -128,6 +132,14 @@ void StackBounds::initialize()
     m_bound = estimateStackBound(m_origin);
 }
 
+#elif OS(GENODE)
+
+void StackBounds::initialize()
+{
+    m_bound = Genode::Thread_base::myself()->stack_base();
+    m_origin = Genode::Thread_base::myself()->stack_top();
+}
+
 #elif OS(UNIX)
 
 void StackBounds::initialize()
diff --git a/qtwebkit/Source/WTF/wtf/TCSystemAlloc.cpp b/qtwebkit/Source/WTF/wtf/TCSystemAlloc.cpp
index f547085..07fc9b0 100644
--- a/qtwebkit/Source/WTF/wtf/TCSystemAlloc.cpp
+++ b/qtwebkit/Source/WTF/wtf/TCSystemAlloc.cpp
@@ -49,6 +49,12 @@
 #include <sys/mman.h>
 #endif
 
+#if OS(GENODE)
+#include <base/printf.h>
+#include <base/stdint.h>
+#include <util/misc_math.h>
+#endif
+
 #ifndef MAP_ANONYMOUS
 #define MAP_ANONYMOUS MAP_ANON
 #endif
@@ -367,6 +373,21 @@ void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size, size_t alignment) {
     }
 #endif
 
+#if OS(GENODE)
+    if (actual_size)
+      *actual_size = size;
+
+    void* real_address = malloc(sizeof(Genode::addr_t) + size + alignment);
+    Genode::addr_t address = reinterpret_cast<Genode::addr_t>(real_address);
+    address += sizeof(Genode::addr_t);
+    address = Genode::align_addr(address, Genode::log2(alignment));
+    address -= sizeof(Genode::addr_t);
+    *(Genode::addr_t*)address = (Genode::addr_t)real_address;
+    address += sizeof(Genode::addr_t);
+
+    return (void*)address;;
+#endif
+
     // nothing worked - reset failure flags and try again
     devmem_failure = false;
     sbrk_failure = false;
diff --git a/qtwebkit/Source/WebCore/platform/graphics/qt/MediaPlayerPrivateQt.cpp b/qtwebkit/Source/WebCore/platform/graphics/qt/MediaPlayerPrivateQt.cpp
index e083e29..dc73aac 100644
--- a/qtwebkit/Source/WebCore/platform/graphics/qt/MediaPlayerPrivateQt.cpp
+++ b/qtwebkit/Source/WebCore/platform/graphics/qt/MediaPlayerPrivateQt.cpp
@@ -18,6 +18,8 @@
 */
 
 #include "config.h"
+
+#if ENABLE(VIDEO)
 #include "MediaPlayerPrivateQt.h"
 
 #include "Frame.h"
@@ -661,3 +663,4 @@ PlatformMedia MediaPlayerPrivateQt::platformMedia() const
 } // namespace WebCore
 
 #include "moc_MediaPlayerPrivateQt.cpp"
+#endif /* ENABLE(VIDEO) */
