1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 // Platform specific code for NULLOS goes here
30 // Minimal include to get access to abort, fprintf and friends for bootstrapping
38 #include "vm-state-inl.h"
44 // Give V8 the opportunity to override the default ceil behaviour.
45 double ceiling(double x) {
51 // Give V8 the opportunity to override the default fmod behavior.
52 double modulo(double x, double y) {
58 double fast_sin(double x) {
64 double fast_cos(double x) {
70 double fast_tan(double x) {
76 double fast_log(double x) {
82 // Initialize OS class early in the V8 startup.
84 // Seed the random number generator.
89 void OS::PostSetUp() {
99 // Returns the accumulated user time for thread.
100 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
108 // Returns current time as the number of milliseconds since
109 // 00:00:00 UTC, January 1, 1970.
110 double OS::TimeCurrentMillis() {
116 // Returns ticks in microsecond resolution.
117 int64_t OS::Ticks() {
123 // Returns a string identifying the current timezone taking into
124 // account daylight saving.
125 const char* OS::LocalTimezone(double time) {
131 // Returns the daylight savings offset in milliseconds for the given time.
132 double OS::DaylightSavingsOffset(double time) {
138 int OS::GetLastError() {
144 // Returns the local time offset in milliseconds east of UTC without
145 // taking daylight savings time into account.
146 double OS::LocalTimeOffset() {
152 // Print (debug) message to console.
153 void OS::Print(const char* format, ...) {
158 // Print (debug) message to console.
159 void OS::VPrint(const char* format, va_list args) {
160 // Minimalistic implementation for bootstrapping.
161 vfprintf(stdout, format, args);
165 void OS::FPrint(FILE* out, const char* format, ...) {
167 va_start(args, format);
168 VFPrint(out, format, args);
173 void OS::VFPrint(FILE* out, const char* format, va_list args) {
174 vfprintf(out, format, args);
178 // Print error message to console.
179 void OS::PrintError(const char* format, ...) {
180 // Minimalistic implementation for bootstrapping.
182 va_start(args, format);
183 VPrintError(format, args);
188 // Print error message to console.
189 void OS::VPrintError(const char* format, va_list args) {
190 // Minimalistic implementation for bootstrapping.
191 vfprintf(stderr, format, args);
195 int OS::SNPrintF(char* str, size_t size, const char* format, ...) {
201 int OS::VSNPrintF(char* str, size_t size, const char* format, va_list args) {
207 uint64_t OS::CpuFeaturesImpliedByPlatform() {
212 double OS::nan_value() {
218 bool OS::ArmCpuHasFeature(CpuFeature feature) {
223 bool OS::ArmUsingHardFloat() {
228 bool OS::IsOutsideAllocatedSpace(void* address) {
234 size_t OS::AllocateAlignment() {
240 void* OS::Allocate(const size_t requested,
248 void OS::Free(void* buf, const size_t length) {
249 // TODO(1240712): potential system call return value which is ignored here.
254 void OS::Guard(void* address, const size_t size) {
259 void OS::Sleep(int milliseconds) {
265 // Minimalistic implementation for bootstrapping.
270 void OS::DebugBreak() {
275 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
281 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
288 void OS::LogSharedLibraryAddresses() {
293 void OS::SignalCodeMovingGC() {
298 int OS::StackWalk(Vector<OS::StackFrame> frames) {
304 VirtualMemory::VirtualMemory(size_t size, void* address_hint) {
309 VirtualMemory::~VirtualMemory() {
314 bool VirtualMemory::IsReserved() {
320 bool VirtualMemory::Commit(void* address, size_t size, bool executable) {
326 bool VirtualMemory::Uncommit(void* address, size_t size) {
332 bool VirtualMemory::Guard(void* address) {
338 class Thread::PlatformData : public Malloced {
348 Thread::Thread(const Options& options)
349 : data_(new PlatformData()),
350 stack_size_(options.stack_size) {
351 set_name(options.name);
356 Thread::Thread(const char* name)
357 : data_(new PlatformData()),
370 void Thread::set_name(const char* name) {
371 strncpy(name_, name, sizeof(name_));
372 name_[sizeof(name_) - 1] = '\0';
376 void Thread::Start() {
381 void Thread::Join() {
386 Thread::LocalStorageKey Thread::CreateThreadLocalKey() {
388 return static_cast<LocalStorageKey>(0);
392 void Thread::DeleteThreadLocalKey(LocalStorageKey key) {
397 void* Thread::GetThreadLocal(LocalStorageKey key) {
403 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
408 void Thread::YieldCPU() {
413 class NullMutex : public Mutex {
415 NullMutex() : data_(NULL) {
419 virtual ~NullMutex() {
428 virtual int Unlock() {
438 Mutex* OS::CreateMutex() {
440 return new NullMutex();
444 class NullSemaphore : public Semaphore {
446 explicit NullSemaphore(int count) : data_(NULL) {
450 virtual ~NullSemaphore() {
454 virtual void Wait() {
458 virtual void Signal() {
466 Semaphore* OS::CreateSemaphore(int count) {
468 return new NullSemaphore(count);
472 class ProfileSampler::PlatformData : public Malloced {
480 ProfileSampler::ProfileSampler(int interval) {
482 // Shared setup follows.
483 data_ = new PlatformData();
484 interval_ = interval;
489 ProfileSampler::~ProfileSampler() {
491 // Shared tear down follows.
496 void ProfileSampler::Start() {
501 void ProfileSampler::Stop() {
506 } } // namespace v8::internal