@@ -0,0 +1,300 @@
From 4bfe04b667ac9f15961d55291e88e85282b0fe51 Mon Sep 17 00:00:00 2001
From: Calvin Hill <calvin@hakobaito.co.uk>
Date: Tue, 12 Feb 2019 12:51:52 +0000
Subject: Haiku platform support.


diff --git a/BUILD.gn b/BUILD.gn
index d52d806..92ec21c 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -603,7 +603,7 @@ config("toolchain") {
}
}

- if (is_clang) {
+ if (is_clang && !is_haiku) {
cflags += [
"-Wmissing-field-initializers",

@@ -3228,6 +3228,11 @@ v8_component("v8_libbase") {
"src/base/debug/stack_trace_fuchsia.cc",
"src/base/platform/platform-fuchsia.cc",
]
+ } else if (is_haiku) {
+ sources += [
+ "src/base/debug/stack_trace_posix.cc",
+ "src/base/platform/platform-haiku.cc",
+ ]
} else if (is_mac) {
sources += [
"src/base/debug/stack_trace_posix.cc",
@@ -3524,6 +3529,13 @@ if (is_fuchsia && !build_with_chromium) {

group("v8_fuzzers") {
testonly = true
+
+ if(host_os == "haiku"){
+ data_deps = []
+ }
+
+ if (host_os != "haiku") {
+
data_deps = [
":v8_simple_json_fuzzer",
":v8_simple_multi_return_fuzzer",
@@ -3535,6 +3547,8 @@ group("v8_fuzzers") {
":v8_simple_wasm_compile_fuzzer",
":v8_simple_wasm_fuzzer",
]
+ }
+
}

if (is_component_build) {
diff --git a/include/v8config.h b/include/v8config.h
index e30a582..9e65520 100644
--- a/include/v8config.h
+++ b/include/v8config.h
@@ -61,6 +61,7 @@
// V8_OS_CYGWIN - Cygwin
// V8_OS_DRAGONFLYBSD - DragonFlyBSD
// V8_OS_FREEBSD - FreeBSD
+// V8_OS_HAIKU - Haiku
// V8_OS_FUCHSIA - Fuchsia
// V8_OS_LINUX - Linux
// V8_OS_MACOSX - Mac OS X
@@ -96,6 +97,9 @@
# define V8_OS_BSD 1
# define V8_OS_FREEBSD 1
# define V8_OS_POSIX 1
+#elif defined(__HAIKU__)
+# define V8_OS_HAIKU 1
+# define V8_OS_POSIX 1
#elif defined(__Fuchsia__)
# define V8_OS_FUCHSIA 1
# define V8_OS_POSIX 1
diff --git a/src/base/debug/stack_trace_posix.cc b/src/base/debug/stack_trace_posix.cc
index ed602af..58b3b5d 100644
--- a/src/base/debug/stack_trace_posix.cc
+++ b/src/base/debug/stack_trace_posix.cc
@@ -25,14 +25,15 @@
#include <string>
#include <vector>

-#if V8_LIBC_GLIBC || V8_LIBC_BSD || V8_LIBC_UCLIBC || V8_OS_SOLARIS
+#if V8_LIBC_GLIBC || V8_LIBC_BSD || V8_LIBC_UCLIBC || V8_OS_SOLARIS || V8_OS_HAIKU
#define HAVE_EXECINFO_H 1
#endif

-#if HAVE_EXECINFO_H
+#if defined(HAVE_EXECINFO_H)
#include <cxxabi.h>
#include <execinfo.h>
#endif
+
#if V8_OS_MACOSX
#include <AvailabilityMacros.h>
#endif
diff --git a/src/base/platform/platform-haiku.cc b/src/base/platform/platform-haiku.cc
new file mode 100644
index 0000000..86bf945
--- /dev/null
+++ b/src/base/platform/platform-haiku.cc
@@ -0,0 +1,48 @@
+// Copyright 2012 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Platform-specific code for Haiku goes here. For the POSIX-compatible
+// parts, the implementation is in platform-posix.cc.
+
+#include <pthread.h>
+#include <semaphore.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+
+#include <errno.h>
+#include <fcntl.h> // open
+#include <stdarg.h>
+#include <strings.h> // index
+#include <sys/mman.h> // mmap & munmap
+#include <sys/stat.h> // open
+#include <sys/types.h> // mmap & munmap
+#include <unistd.h> // sysconf
+
+#include <cmath>
+
+#undef MAP_TYPE
+
+#include "src/base/macros.h"
+#include "src/base/platform/platform-posix-time.h"
+#include "src/base/platform/platform-posix.h"
+#include "src/base/platform/platform.h"
+
+namespace v8 {
+namespace base {
+
+TimezoneCache* OS::CreateTimezoneCache() {
+ return new PosixDefaultTimezoneCache();
+}
+
+std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
+ return std::vector<SharedLibraryAddress>();
+}
+
+void OS::SignalCodeMovingGC() {}
+
+} // namespace base
+} // namespace v8
diff --git a/src/base/platform/platform-posix.cc b/src/base/platform/platform-posix.cc
index e7edbf5..387290c 100644
--- a/src/base/platform/platform-posix.cc
+++ b/src/base/platform/platform-posix.cc
@@ -60,7 +60,7 @@
#include <sys/resource.h>
#endif

-#if !defined(_AIX) && !defined(V8_OS_FUCHSIA)
+#if !defined(_AIX) && !defined(V8_OS_FUCHSIA) && !defined(__HAIKU__)
#include <sys/syscall.h>
#endif

@@ -76,6 +76,14 @@ extern int madvise(caddr_t, size_t, int);
#endif
#endif

+#if defined(__HAIKU__)
+extern "C" int posix_madvise(void*, size_t, int);
+#endif
+
+#if defined(__HAIKU__)
+#define MADV_FREE POSIX_MADV_DONTNEED
+#endif
+
#ifndef MADV_FREE
#define MADV_FREE MADV_DONTNEED
#endif
@@ -127,7 +135,7 @@ int GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
int GetFlagsForMemoryPermission(OS::MemoryPermission access) {
int flags = MAP_PRIVATE | MAP_ANONYMOUS;
if (access == OS::MemoryPermission::kNoAccess) {
-#if !V8_OS_AIX && !V8_OS_FREEBSD && !V8_OS_QNX
+#if !V8_OS_AIX && !V8_OS_FREEBSD && !V8_OS_QNX && !V8_OS_HAIKU
flags |= MAP_NORESERVE;
#endif // !V8_OS_AIX && !V8_OS_FREEBSD && !V8_OS_QNX
#if V8_OS_QNX
@@ -356,6 +364,8 @@ bool OS::DiscardSystemPages(void* address, size_t size) {
int ret = madvise(address, size, MADV_FREE_REUSABLE);
#elif defined(_AIX) || defined(V8_OS_SOLARIS)
int ret = madvise(reinterpret_cast<caddr_t>(address), size, MADV_FREE);
+#elif defined(__HAIKU__)
+ int ret = posix_madvise(address, size, MADV_FREE);
#else
int ret = madvise(address, size, MADV_FREE);
#endif
@@ -367,6 +377,8 @@ bool OS::DiscardSystemPages(void* address, size_t size) {
// imply runtime support.
#if defined(_AIX) || defined(V8_OS_SOLARIS)
ret = madvise(reinterpret_cast<caddr_t>(address), size, MADV_DONTNEED);
+#elif defined(__HAIKU__)
+ ret = posix_madvise(address, size, MADV_FREE);
#else
ret = madvise(address, size, MADV_DONTNEED);
#endif
diff --git a/src/libsampler/sampler.cc b/src/libsampler/sampler.cc
index eb804a7..cd3c2bb 100644
--- a/src/libsampler/sampler.cc
+++ b/src/libsampler/sampler.cc
@@ -12,7 +12,7 @@
#include <sys/time.h>
#include <atomic>

-#if !V8_OS_QNX && !V8_OS_AIX
+#if !V8_OS_QNX && !V8_OS_AIX && !V8_OS_HAIKU
#include <sys/syscall.h> // NOLINT
#endif

@@ -20,7 +20,7 @@
#include <mach/mach.h>
// OpenBSD doesn't have <ucontext.h>. ucontext_t lives in <signal.h>
// and is a typedef for struct sigcontext. There is no uc_mcontext.
-#elif !V8_OS_OPENBSD
+#elif !V8_OS_OPENBSD && !V8_OS_HAIKU
#include <ucontext.h>
#endif

@@ -469,6 +469,16 @@ void SignalHandler::FillRegisterState(void* context, RegisterState* state) {
state->sp = reinterpret_cast<void*>(mcontext.mc_r13);
state->fp = reinterpret_cast<void*>(mcontext.mc_r11);
#endif // V8_HOST_ARCH_*
+#elif V8_OS_HAIKU
+#if V8_HOST_ARCH_IA32
+ state->pc = reinterpret_cast<void*>(mcontext.eip);
+ state->sp = reinterpret_cast<void*>(mcontext.esp);
+ state->fp = reinterpret_cast<void*>(mcontext.ebp);
+#elif V8_HOST_ARCH_X64
+ state->pc = reinterpret_cast<void*>(mcontext.rip);
+ state->sp = reinterpret_cast<void*>(mcontext.rsp);
+ state->fp = reinterpret_cast<void*>(mcontext.rbp);
+#endif // V8_HOST_ARCH_*
#elif V8_OS_NETBSD
#if V8_HOST_ARCH_IA32
state->pc = reinterpret_cast<void*>(mcontext.__gregs[_REG_EIP]);
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 70c8b51..073ff09 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -7,6 +7,16 @@ import("../gni/v8.gni")
group("gn_all") {
testonly = true

+ # Don't build tests for Haiku yet
+
+ if(host_os != "haiku"){
+ data_deps = []
+ }
+
+ deps = []
+
+ if (host_os != "haiku") {
+
data_deps = [
"benchmarks:v8_benchmarks",
"intl:v8_intl",
@@ -34,6 +44,8 @@ group("gn_all") {
"unittests:unittests",
]
}
+ }
+
}

###############################################################################
diff --git a/tools/mb/mb.py b/tools/mb/mb.py
index cbb5b5d..3238a7a 100755
--- a/tools/mb/mb.py
+++ b/tools/mb/mb.py
@@ -832,12 +832,15 @@ class MetaBuildWrapper(object):
subdir, exe = 'linux64', 'gn'
elif self.platform == 'darwin':
subdir, exe = 'mac', 'gn'
+ elif self.platform == 'haiku1':
+ subdir, exe = 'haiku','gn'
+ gn_path = "/bin/gn"
else:
subdir, exe = 'win', 'gn.exe'

arch = platform.machine()
if (arch.startswith('s390') or arch.startswith('ppc') or
- self.platform.startswith('aix')):
+ self.platform.startswith('aix') or self.platform.startswith('haiku')):
# use gn in PATH
gn_path = 'gn'
else:
--
2.19.1

@@ -0,0 +1,128 @@
SUMMARY="Google's open source JavaScript engine"
DESCRIPTION="V8 is Google's open source JavaScript engine. V8 is written in \
C++ and is used in Google Chrome, the open source browser from Google. V8 \
implements ECMAScript as specified in ECMA-262, 5th edition, and runs on \
Windows (XP or newer), Mac OS X (10.5 or newer), and Linux systems that use \
IA-32, x64, or ARM processors. V8 can run standalone, or can be embedded into \
any C++ application."
HOMEPAGE="https://v8.dev/"
COPYRIGHT="2006-2018 The V8 Project Authors"
LICENSE="BSD (3-clause)"
REVISION="1"
SOURCE_URI="https://github.com/v8/v8/archive/$portVersion.tar.gz"
SOURCE_DIR="v8-$portVersion"
CHECKSUM_SHA256="a9b1c74ff2fae728e1c94acf525321669679ef56da9cc4d781c427b26032bbf7"
srcChromeVersion="74.0.3729.157"
SOURCE_URI_2="https://gsdview.appspot.com/chromium-browser-official/chromium-$srcChromeVersion-lite.tar.xz"
CHECKSUM_SHA256_2="d7406d4efba9916000f8a0f087e7eaf443523f264a59a51d2089c4b2e4c66be0"
SOURCE_DIR_2="chromium-$srcChromeVersion"

PATCHES="v8-$portVersion.patchset"
PATCHES_2="build-$portVersion.patch"

ARCHITECTURES="!x86_gcc2 x86 x86_64"

if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
ARCH=x86
else
ARCH=x64
fi

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
commandBinDir=$prefix/bin
fi

PROVIDES="
v8$secondaryArchSuffix = $portVersion
cmd:d8$commandSuffix = $portVersion
lib:libv8$secondaryArchSuffix = $portVersion
lib:libv8_for_testing$secondaryArchSuffix = $portVersion
lib:libv8_libbase$secondaryArchSuffix = $portVersion
lib:libv8_libplatform$secondaryArchSuffix = $portVersion
"
REQUIRES="
haiku$secondaryArchSuffix
lib:libexecinfo$secondaryArchSuffix
lib:libssp$secondaryArchSuffix
"

PROVIDES_devel="
v8${secondaryArchSuffix}_devel = $portVersion
devel:libv8$secondaryArchSuffix
"
REQUIRES_devel="
v8$secondaryArchSuffix == $portVersion
"

BUILD_REQUIRES="
haiku${secondaryArchSuffix}_devel
gcc${secondaryArchSuffix}_syslibs
gcc${secondaryArchSuffix}_syslibs_devel
devel:libgcc$secondaryArchSuffix
devel:libexecinfo$secondaryArchSuffix
"
BUILD_PREREQUIRES="
cmd:gcc$secondaryArchSuffix
cmd:g++$secondaryArchSuffix
cmd:gn
cmd:ld$secondaryArchSuffix
cmd:ninja
cmd:python
cmd:which
"

BUILD()
{
cd $sourceDir

mkdir -p base/trace_event/common
mkdir -p build
mkdir -p buildtools
mkdir -p third_party/jinja2
mkdir -p third_party/markupsafe
mkdir -p tools/clang
mkdir -p third_party/googletest/src

cp -rf /$sourceDir2/base/trace_event/common/* $sourceDir/base/trace_event/common
cp -rf /$sourceDir2/build/* $sourceDir/build/
cp -rf /$sourceDir2/buildtools/* $sourceDir/buildtools
cp -rf /$sourceDir2/third_party/jinja2/* $sourceDir/third_party/jinja2
cp -rf /$sourceDir2/third_party/markupsafe/* $sourceDir/third_party/markupsafe
cp -rf /$sourceDir2/tools/clang/* $sourceDir/tools/clang
cp -rf /$sourceDir2/third_party/googletest/src/* $sourceDir/third_party/googletest/src

mkdir -p out.gn

gn gen out.gn/$ARCH.release --args="target_os=\"haiku\" target_cpu=\"$ARCH\"
v8_enable_embedded_builtins = false is_debug = false symbol_level=0
is_clang=false treat_warnings_as_errors=false use_sysroot=false
v8_enable_i18n_support=false is_component_build=true
v8_use_snapshot=false"

LIBRARY_PATH=$LIBRARY_PATH:. ninja -C out.gn/$ARCH.release $jobArgs
}

INSTALL()
{
mkdir $commandBinDir
cp -af out.gn/$ARCH.release/d8 ${commandBinDir}
mkdir -p ${includeDir}/v8
cp -af include/* ${includeDir}/v8
mkdir -p $libDir
cp -af out.gn/$ARCH.release/*.so ${libDir}

prepareInstalledDevelLibs libv8
packageEntries devel $developDir
}

TEST()
{
export LIBRARY_PATH=$LIBRARY_PATH::./out.gn/$ARCH.release

python tools/run-tests.py --gn $jobArgs --exit-after-n-failures=0 -p color \
--report -v -m release unittests message mkgrokdump fuzzer \
preparser wasm-spec-tests webkit cctest mjsunit
}