Unified the structure of VirtualMemory implementations across platforms a bit.

This is just shuffling some code around to make comparing the platform files easier.

Made cygwin/nullos support a bit more complete on the way.

Review URL: https://codereview.chromium.org/14162004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14250 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5de8e81c
......@@ -319,15 +319,11 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
// This causes VirtualMemory::Commit to not always commit the memory region
// specified.
bool VirtualMemory::IsReserved() {
return address_ != NULL;
}
VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
VirtualMemory::VirtualMemory(size_t size) {
address_ = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
size_ = size;
}
VirtualMemory::VirtualMemory(size_t size)
: address_(ReserveRegion(size)), size_(size) { }
VirtualMemory::~VirtualMemory() {
......@@ -337,6 +333,17 @@ VirtualMemory::~VirtualMemory() {
}
bool VirtualMemory::IsReserved() {
return address_ != NULL;
}
void VirtualMemory::Reset() {
address_ = NULL;
size_ = 0;
}
bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
if (NULL == VirtualAlloc(address, size, MEM_COMMIT, prot)) {
......@@ -365,6 +372,29 @@ bool VirtualMemory::Guard(void* address) {
}
void* VirtualMemory::ReserveRegion(size_t size) {
return VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
}
bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
UNIMPLEMENTED();
return false;
}
bool VirtualMemory::UncommitRegion(void* base, size_t size) {
UNIMPLEMENTED();
return false;
}
bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
UNIMPLEMENTED();
return false;
}
bool VirtualMemory::HasLazyCommits() {
// TODO(alph): implement for the platform.
return false;
......
......@@ -358,12 +358,12 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
static const int kMmapFd = -1;
static const int kMmapFdOffset = 0;
VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
VirtualMemory::VirtualMemory(size_t size) {
address_ = ReserveRegion(size);
size_ = size;
}
VirtualMemory::VirtualMemory(size_t size)
: address_(ReserveRegion(size)), size_(size) { }
VirtualMemory::VirtualMemory(size_t size, size_t alignment)
......
......@@ -643,12 +643,12 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
static const int kMmapFd = -1;
static const int kMmapFdOffset = 0;
VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
VirtualMemory::VirtualMemory(size_t size) {
address_ = ReserveRegion(size);
size_ = size;
}
VirtualMemory::VirtualMemory(size_t size)
: address_(ReserveRegion(size)), size_(size) { }
VirtualMemory::VirtualMemory(size_t size, size_t alignment)
......
......@@ -408,12 +408,33 @@ VirtualMemory::~VirtualMemory() {
}
bool VirtualMemory::IsReserved() {
return address_ != NULL;
}
void VirtualMemory::Reset() {
address_ = NULL;
size_ = 0;
}
bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
return CommitRegion(address, size, is_executable);
}
bool VirtualMemory::Uncommit(void* address, size_t size) {
return UncommitRegion(address, size);
}
bool VirtualMemory::Guard(void* address) {
OS::Guard(address, OS::CommitPageSize());
return true;
}
void* VirtualMemory::ReserveRegion(size_t size) {
void* result = mmap(OS::GetRandomMmapAddr(),
size,
......@@ -428,22 +449,6 @@ void* VirtualMemory::ReserveRegion(size_t size) {
}
bool VirtualMemory::IsReserved() {
return address_ != NULL;
}
bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
return CommitRegion(address, size, is_executable);
}
bool VirtualMemory::Guard(void* address) {
OS::Guard(address, OS::CommitPageSize());
return true;
}
bool VirtualMemory::CommitRegion(void* address,
size_t size,
bool is_executable) {
......@@ -462,11 +467,6 @@ bool VirtualMemory::CommitRegion(void* address,
}
bool VirtualMemory::Uncommit(void* address, size_t size) {
return UncommitRegion(address, size);
}
bool VirtualMemory::UncommitRegion(void* address, size_t size) {
return mmap(address,
size,
......
......@@ -317,6 +317,16 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
}
VirtualMemory::VirtualMemory() {
UNIMPLEMENTED();
}
VirtualMemory::VirtualMemory(size_t size) {
UNIMPLEMENTED();
}
VirtualMemory::VirtualMemory(size_t size, void* address_hint) {
UNIMPLEMENTED();
}
......@@ -333,6 +343,11 @@ bool VirtualMemory::IsReserved() {
}
void VirtualMemory::Reset() {
UNIMPLEMENTED();
}
bool VirtualMemory::Commit(void* address, size_t size, bool executable) {
UNIMPLEMENTED();
return false;
......@@ -351,6 +366,30 @@ bool VirtualMemory::Guard(void* address) {
}
void* VirtualMemory::ReserveRegion(size_t size) {
UNIMPLEMENTED();
return NULL;
}
bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
UNIMPLEMENTED();
return false;
}
bool VirtualMemory::UncommitRegion(void* base, size_t size) {
UNIMPLEMENTED();
return false;
}
bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
UNIMPLEMENTED();
return false;
}
bool VirtualMemory::HasLazyCommits() {
// TODO(alph): implement for the platform.
return false;
......
......@@ -386,12 +386,12 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
static const int kMmapFd = -1;
static const int kMmapFdOffset = 0;
VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
VirtualMemory::VirtualMemory(size_t size) {
address_ = ReserveRegion(size);
size_ = size;
}
VirtualMemory::VirtualMemory(size_t size)
: address_(ReserveRegion(size)), size_(size) { }
VirtualMemory::VirtualMemory(size_t size, size_t alignment)
......
......@@ -328,10 +328,9 @@ static const int kMmapFdOffset = 0;
VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
VirtualMemory::VirtualMemory(size_t size) {
address_ = ReserveRegion(size);
size_ = size;
}
VirtualMemory::VirtualMemory(size_t size)
: address_(ReserveRegion(size)), size_(size) { }
VirtualMemory::VirtualMemory(size_t size, size_t alignment)
......
......@@ -1518,7 +1518,7 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment)
VirtualMemory::~VirtualMemory() {
if (IsReserved()) {
bool result = ReleaseRegion(address_, size_);
bool result = ReleaseRegion(address(), size());
ASSERT(result);
USE(result);
}
......@@ -1551,6 +1551,17 @@ bool VirtualMemory::Uncommit(void* address, size_t size) {
}
bool VirtualMemory::Guard(void* address) {
if (NULL == VirtualAlloc(address,
OS::CommitPageSize(),
MEM_COMMIT,
PAGE_READONLY | PAGE_GUARD)) {
return false;
}
return true;
}
void* VirtualMemory::ReserveRegion(size_t size) {
return RandomizedVirtualAlloc(size, MEM_RESERVE, PAGE_NOACCESS);
}
......@@ -1567,17 +1578,6 @@ bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
}
bool VirtualMemory::Guard(void* address) {
if (NULL == VirtualAlloc(address,
OS::CommitPageSize(),
MEM_COMMIT,
PAGE_READONLY | PAGE_GUARD)) {
return false;
}
return true;
}
bool VirtualMemory::UncommitRegion(void* base, size_t size) {
return VirtualFree(base, size, MEM_DECOMMIT) != 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment