From 10ed124895de3cf4d7253e4a63e3632c95dec71a Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Fri, 15 Feb 2019 15:58:34 +0300
Subject: Add Haiku support


diff --git a/src/kjs/collector.cpp b/src/kjs/collector.cpp
index 8c58458..08a4474 100644
--- a/src/kjs/collector.cpp
+++ b/src/kjs/collector.cpp
@@ -64,6 +64,15 @@ using std::memset;
 #include <pthread_np.h>
 #endif
 
+#if PLATFORM(HAIKU_OS)
+#include <OS.h>
+static const ptrdiff_t estimateStackSize = 128 * sizeof(void*) *1024;
+static void* estimateStackBound(void *origin)
+{
+    return static_cast<char*>(origin) - estimateStackSize;
+}
+#endif
+
 #endif
 
 #define DEBUG_COLLECTOR 0
@@ -508,6 +517,10 @@ static inline void *currentThreadStackBase()
     return s.ss_sp;
     // NOTREACHED
     void *stackBase = nullptr;
+#elif PLATFORM(HAIKU_OS)
+    thread_info threadInfo;
+    get_thread_info(find_thread(NULL), &threadInfo);    
+    void *stackBase = estimateStackBound(threadInfo.stack_end);
 #elif PLATFORM(UNIX)
     static void *stackBase = nullptr;
     static pthread_t stackThread;
diff --git a/src/wtf/Platform.h b/src/wtf/Platform.h
index aaf0673..3070490 100644
--- a/src/wtf/Platform.h
+++ b/src/wtf/Platform.h
@@ -72,6 +72,7 @@
    || defined(unix)        \
    || defined(__unix)      \
    || defined(__unix__)    \
+   || defined(__HAIKU__)    \
    || defined (__NetBSD__) \
    || defined(_AIX)
 #define WTF_PLATFORM_UNIX 1
@@ -85,6 +86,11 @@
 #define WTF_PLATFORM_SOLARIS_OS 1
 #endif
 
+/* PLATFORM(HAIKU_OS) */
+#if defined(__HAIKU__)
+#define WTF_PLATFORM_HAIKU_OS 1
+#endif
+
 /* Operating environments */
 
 /* I made the BUILDING_KDE__ macro up for the KDE build system to define */
-- 
2.19.1

