| Index: src/base/platform/platform-aix.cc
|
| diff --git a/src/base/platform/platform-freebsd.cc b/src/base/platform/platform-aix.cc
|
| similarity index 64%
|
| copy from src/base/platform/platform-freebsd.cc
|
| copy to src/base/platform/platform-aix.cc
|
| index 58316f8bc1a9abf0ce86549cc0976fce1120ea2d..3083f752dad4e9ca68eb5a4b14d62ee8c711e516 100644
|
| --- a/src/base/platform/platform-freebsd.cc
|
| +++ b/src/base/platform/platform-aix.cc
|
| @@ -1,29 +1,28 @@
|
| -// Copyright 2012 the V8 project authors. All rights reserved.
|
| +// Copyright 2014 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 FreeBSD goes here. For the POSIX-compatible
|
| -// parts, the implementation is in platform-posix.cc.
|
| +// Platform specific code for AIX goes here. For the POSIX comaptible 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 <sys/types.h>
|
| #include <sys/ucontext.h>
|
|
|
| -#include <sys/fcntl.h> // open
|
| -#include <sys/mman.h> // mmap & munmap
|
| -#include <sys/stat.h> // open
|
| -#include <sys/types.h> // mmap & munmap
|
| -#include <unistd.h> // getpagesize
|
| -// If you don't have execinfo.h then you need devel/libexecinfo from ports.
|
| #include <errno.h>
|
| +#include <fcntl.h> // open
|
| #include <limits.h>
|
| #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> // getpagesize
|
|
|
| #include <cmath>
|
|
|
| @@ -37,30 +36,36 @@ namespace v8 {
|
| namespace base {
|
|
|
|
|
| +static inline void* mmapHelper(size_t len, int prot, int flags, int fildes,
|
| + off_t off) {
|
| + void* addr = OS::GetRandomMmapAddr();
|
| + return mmap(addr, len, prot, flags, fildes, off);
|
| +}
|
| +
|
| +
|
| const char* OS::LocalTimezone(double time, TimezoneCache* cache) {
|
| if (std::isnan(time)) return "";
|
| - time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
|
| + time_t tv = static_cast<time_t>(floor(time / msPerSecond));
|
| struct tm* t = localtime(&tv);
|
| if (NULL == t) return "";
|
| - return t->tm_zone;
|
| + return tzname[0]; // The location of the timezone string on AIX.
|
| }
|
|
|
|
|
| double OS::LocalTimeOffset(TimezoneCache* cache) {
|
| - time_t tv = time(NULL);
|
| - struct tm* t = localtime(&tv);
|
| - // tm_gmtoff includes any daylight savings offset, so subtract it.
|
| - return static_cast<double>(t->tm_gmtoff * msPerSecond -
|
| - (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
|
| + // On AIX, struct tm does not contain a tm_gmtoff field.
|
| + time_t utc = time(NULL);
|
| + DCHECK(utc != -1);
|
| + struct tm* loc = localtime(&utc);
|
| + DCHECK(loc != NULL);
|
| + return static_cast<double>((mktime(loc) - utc) * msPerSecond);
|
| }
|
|
|
|
|
| -void* OS::Allocate(const size_t requested,
|
| - size_t* allocated,
|
| - bool executable) {
|
| +void* OS::Allocate(const size_t requested, size_t* allocated, bool executable) {
|
| const size_t msize = RoundUp(requested, getpagesize());
|
| int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0);
|
| - void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0);
|
| + void* mbase = mmapHelper(msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
|
|
| if (mbase == MAP_FAILED) return NULL;
|
| *allocated = msize;
|
| @@ -71,10 +76,11 @@ void* OS::Allocate(const size_t requested,
|
| class PosixMemoryMappedFile : public OS::MemoryMappedFile {
|
| public:
|
| PosixMemoryMappedFile(FILE* file, void* memory, int size)
|
| - : file_(file), memory_(memory), size_(size) { }
|
| + : file_(file), memory_(memory), size_(size) {}
|
| virtual ~PosixMemoryMappedFile();
|
| virtual void* memory() { return memory_; }
|
| virtual int size() { return size_; }
|
| +
|
| private:
|
| FILE* file_;
|
| void* memory_;
|
| @@ -90,13 +96,13 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
|
| int size = ftell(file);
|
|
|
| void* memory =
|
| - mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
|
| + mmapHelper(size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
|
| return new PosixMemoryMappedFile(file, memory, size);
|
| }
|
|
|
|
|
| OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
|
| - void* initial) {
|
| + void* initial) {
|
| FILE* file = fopen(name, "w+");
|
| if (file == NULL) return NULL;
|
| int result = fwrite(initial, size, 1, file);
|
| @@ -105,7 +111,7 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
|
| return NULL;
|
| }
|
| void* memory =
|
| - mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
|
| + mmapHelper(size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
|
| return new PosixMemoryMappedFile(file, memory, size);
|
| }
|
|
|
| @@ -131,23 +137,22 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
|
| addr_buffer[0] = '0';
|
| addr_buffer[1] = 'x';
|
| addr_buffer[10] = 0;
|
| - ssize_t bytes_read = read(fd, addr_buffer + 2, 8);
|
| - if (bytes_read < 8) break;
|
| + ssize_t rc = read(fd, addr_buffer + 2, 8);
|
| + if (rc < 8) break;
|
| unsigned start = StringToLong(addr_buffer);
|
| - bytes_read = read(fd, addr_buffer + 2, 1);
|
| - if (bytes_read < 1) break;
|
| + rc = read(fd, addr_buffer + 2, 1);
|
| + if (rc < 1) break;
|
| if (addr_buffer[2] != '-') break;
|
| - bytes_read = read(fd, addr_buffer + 2, 8);
|
| - if (bytes_read < 8) break;
|
| + rc = read(fd, addr_buffer + 2, 8);
|
| + if (rc < 8) break;
|
| unsigned end = StringToLong(addr_buffer);
|
| char buffer[MAP_LENGTH];
|
| - bytes_read = -1;
|
| + int bytes_read = -1;
|
| do {
|
| bytes_read++;
|
| - if (bytes_read >= MAP_LENGTH - 1)
|
| - break;
|
| - bytes_read = read(fd, buffer + bytes_read, 1);
|
| - if (bytes_read < 1) break;
|
| + if (bytes_read >= MAP_LENGTH - 1) break;
|
| + rc = read(fd, buffer + bytes_read, 1);
|
| + if (rc < 1) break;
|
| } while (buffer[bytes_read] != '\n');
|
| buffer[bytes_read] = 0;
|
| // Ignore mappings that are not executable.
|
| @@ -163,34 +168,28 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
|
| }
|
|
|
|
|
| -void OS::SignalCodeMovingGC() {
|
| -}
|
| -
|
| +void OS::SignalCodeMovingGC() {}
|
|
|
|
|
| // Constants used for mmap.
|
| static const int kMmapFd = -1;
|
| static const int kMmapFdOffset = 0;
|
|
|
| -
|
| -VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
|
| +VirtualMemory::VirtualMemory() : address_(NULL), size_(0) {}
|
|
|
|
|
| VirtualMemory::VirtualMemory(size_t size)
|
| - : address_(ReserveRegion(size)), size_(size) { }
|
| + : address_(ReserveRegion(size)), size_(size) {}
|
|
|
|
|
| VirtualMemory::VirtualMemory(size_t size, size_t alignment)
|
| : address_(NULL), size_(0) {
|
| DCHECK((alignment % OS::AllocateAlignment()) == 0);
|
| - size_t request_size = RoundUp(size + alignment,
|
| - static_cast<intptr_t>(OS::AllocateAlignment()));
|
| - void* reservation = mmap(OS::GetRandomMmapAddr(),
|
| - request_size,
|
| - PROT_NONE,
|
| - MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
|
| - kMmapFd,
|
| - kMmapFdOffset);
|
| + size_t request_size =
|
| + RoundUp(size + alignment, static_cast<intptr_t>(OS::AllocateAlignment()));
|
| + void* reservation =
|
| + mmapHelper(request_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, kMmapFd,
|
| + kMmapFdOffset);
|
| if (reservation == MAP_FAILED) return;
|
|
|
| uint8_t* base = static_cast<uint8_t*>(reservation);
|
| @@ -229,9 +228,7 @@ VirtualMemory::~VirtualMemory() {
|
| }
|
|
|
|
|
| -bool VirtualMemory::IsReserved() {
|
| - return address_ != NULL;
|
| -}
|
| +bool VirtualMemory::IsReserved() { return address_ != NULL; }
|
|
|
|
|
| void VirtualMemory::Reset() {
|
| @@ -257,12 +254,8 @@ bool VirtualMemory::Guard(void* address) {
|
|
|
|
|
| void* VirtualMemory::ReserveRegion(size_t size) {
|
| - void* result = mmap(OS::GetRandomMmapAddr(),
|
| - size,
|
| - PROT_NONE,
|
| - MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
|
| - kMmapFd,
|
| - kMmapFdOffset);
|
| + void* result = mmapHelper(size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS,
|
| + kMmapFd, kMmapFdOffset);
|
|
|
| if (result == MAP_FAILED) return NULL;
|
|
|
| @@ -271,26 +264,21 @@ void* VirtualMemory::ReserveRegion(size_t size) {
|
|
|
|
|
| bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
|
| +#if defined(__native_client__)
|
| + // The Native Client port of V8 uses an interpreter,
|
| + // so code pages don't need PROT_EXEC.
|
| + int prot = PROT_READ | PROT_WRITE;
|
| +#else
|
| int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
|
| - if (MAP_FAILED == mmap(base,
|
| - size,
|
| - prot,
|
| - MAP_PRIVATE | MAP_ANON | MAP_FIXED,
|
| - kMmapFd,
|
| - kMmapFdOffset)) {
|
| - return false;
|
| - }
|
| +#endif
|
| + if (mprotect(base, size, prot) == -1) return false;
|
| +
|
| return true;
|
| }
|
|
|
|
|
| bool VirtualMemory::UncommitRegion(void* base, size_t size) {
|
| - return mmap(base,
|
| - size,
|
| - PROT_NONE,
|
| - MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED,
|
| - kMmapFd,
|
| - kMmapFdOffset) != MAP_FAILED;
|
| + return mprotect(base, size, PROT_NONE) != -1;
|
| }
|
|
|
|
|
| @@ -299,9 +287,6 @@ bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
|
| }
|
|
|
|
|
| -bool VirtualMemory::HasLazyCommits() {
|
| - // TODO(alph): implement for the platform.
|
| - return false;
|
| +bool VirtualMemory::HasLazyCommits() { return true; }
|
| }
|
| -
|
| -} } // namespace v8::base
|
| +} // namespace v8::base
|
|
|