summaryrefslogtreecommitdiff
path: root/deps/v8/src/base/platform/platform-starboard.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/base/platform/platform-starboard.cc')
-rw-r--r--deps/v8/src/base/platform/platform-starboard.cc67
1 files changed, 31 insertions, 36 deletions
diff --git a/deps/v8/src/base/platform/platform-starboard.cc b/deps/v8/src/base/platform/platform-starboard.cc
index 16bb2d494b..f631d800de 100644
--- a/deps/v8/src/base/platform/platform-starboard.cc
+++ b/deps/v8/src/base/platform/platform-starboard.cc
@@ -4,7 +4,7 @@
// Platform-specific code for Starboard goes here. Starboard is the platform
// abstraction layer for Cobalt, an HTML5 container used mainly by YouTube
-// apps in the livingroom.
+// apps in the living room.
#include "src/base/lazy-instance.h"
#include "src/base/macros.h"
@@ -12,6 +12,7 @@
#include "src/base/platform/time.h"
#include "src/base/timezone-cache.h"
#include "src/base/utils/random-number-generator.h"
+#include "starboard/client_porting/eztime/eztime.h"
#include "starboard/common/condition_variable.h"
#include "starboard/common/log.h"
#include "starboard/common/string.h"
@@ -71,6 +72,8 @@ static LazyInstance<RandomNumberGenerator>::type
static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
bool g_hard_abort = false;
+// We only use this stack size to get the topmost stack frame.
+const int kStackSize = 1;
} // namespace
@@ -149,37 +152,6 @@ void* Allocate(void* address, size_t size, OS::MemoryPermission access) {
return result;
}
-// The following code was taken from old v8 to deal with rounding up pointers.
-namespace {
-// Compute the 0-relative offset of some absolute value x of type T.
-// This allows conversion of Addresses and integral types into
-// 0-relative int offsets.
-template <typename T>
-constexpr inline intptr_t OffsetFrom(T x) {
- return x - static_cast<T>(0);
-}
-
-// Compute the absolute value of type T for some 0-relative offset x.
-// This allows conversion of 0-relative int offsets into Addresses and
-// integral types.
-template <typename T>
-constexpr inline T AddressFrom(intptr_t x) {
- return static_cast<T>(static_cast<T>(0) + x);
-}
-
-template <typename T>
-inline T RoundDown(T x, intptr_t m) {
- // m must be a power of two.
- DCHECK(m != 0 && ((m & (m - 1)) == 0));
- return AddressFrom<T>(OffsetFrom(x) & -m);
-}
-
-template <typename T>
-inline T RoundUpOld(T x, intptr_t m) {
- return RoundDown<T>(static_cast<T>(x + m - 1), m);
-}
-} // namespace
-
// static
void* OS::Allocate(void* address, size_t size, size_t alignment,
MemoryPermission access) {
@@ -195,7 +167,8 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
// Unmap memory allocated before the aligned base address.
uint8_t* base = static_cast<uint8_t*>(result);
- uint8_t* aligned_base = RoundUpOld(base, alignment);
+ uint8_t* aligned_base = reinterpret_cast<uint8_t*>(
+ RoundUp(reinterpret_cast<uintptr_t>(base), alignment));
if (aligned_base != base) {
DCHECK_LT(base, aligned_base);
size_t prefix_size = static_cast<size_t>(aligned_base - base);
@@ -430,10 +403,11 @@ void Thread::set_name(const char* name) {
name_[sizeof(name_) - 1] = '\0';
}
-void Thread::Start() {
+bool Thread::Start() {
data_->thread_ =
SbThreadCreate(stack_size_, kSbThreadNoPriority, kSbThreadNoAffinity,
true, name_, ThreadEntry, this);
+ return SbThreadIsValid(data_->thread_);
}
void Thread::Join() { SbThreadJoin(data_->thread_, nullptr); }
@@ -457,7 +431,6 @@ void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
class StarboardTimezoneCache : public TimezoneCache {
public:
- double DaylightSavingsOffset(double time_ms) override { return 0.0; }
void Clear(TimeZoneDetection time_zone_detection) override {}
~StarboardTimezoneCache() override {}
@@ -471,7 +444,18 @@ class StarboardDefaultTimezoneCache : public StarboardTimezoneCache {
return SbTimeZoneGetName();
}
double LocalTimeOffset(double time_ms, bool is_utc) override {
- return SbTimeZoneGetCurrent() * 60000.0;
+ // SbTimeZOneGetCurrent returns an offset west of Greenwich, which has the
+ // opposite sign V8 expects.
+ // The starboard function returns offset in minutes. We convert to return
+ // value in milliseconds.
+ return SbTimeZoneGetCurrent() * 60.0 * msPerSecond * (-1);
+ }
+ double DaylightSavingsOffset(double time_ms) override {
+ EzTimeValue value = EzTimeValueFromSbTime(SbTimeGetNow());
+ EzTimeExploded ez_exploded;
+ bool result =
+ EzTimeValueExplode(&value, kEzTimeZoneLocal, &ez_exploded, NULL);
+ return ez_exploded.tm_isdst > 0 ? 3600 * msPerSecond : 0;
}
~StarboardDefaultTimezoneCache() override {}
@@ -495,5 +479,16 @@ bool OS::DiscardSystemPages(void* address, size_t size) {
return true;
}
+// static
+Stack::StackSlot Stack::GetCurrentStackPosition() {
+ void* addresses[kStackSize];
+ const size_t count = SbSystemGetStack(addresses, kStackSize);
+ if (count > 0) {
+ return addresses[0];
+ } else {
+ return nullptr;
+ }
+}
+
} // namespace base
} // namespace v8