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) { ...@@ -319,15 +319,11 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
// This causes VirtualMemory::Commit to not always commit the memory region // This causes VirtualMemory::Commit to not always commit the memory region
// specified. // specified.
bool VirtualMemory::IsReserved() { VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
return address_ != NULL;
}
VirtualMemory::VirtualMemory(size_t size) { VirtualMemory::VirtualMemory(size_t size)
address_ = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS); : address_(ReserveRegion(size)), size_(size) { }
size_ = size;
}
VirtualMemory::~VirtualMemory() { VirtualMemory::~VirtualMemory() {
...@@ -337,6 +333,17 @@ 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) { bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
if (NULL == VirtualAlloc(address, size, MEM_COMMIT, prot)) { if (NULL == VirtualAlloc(address, size, MEM_COMMIT, prot)) {
...@@ -365,6 +372,29 @@ bool VirtualMemory::Guard(void* address) { ...@@ -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() { bool VirtualMemory::HasLazyCommits() {
// TODO(alph): implement for the platform. // TODO(alph): implement for the platform.
return false; return false;
......
...@@ -358,12 +358,12 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) { ...@@ -358,12 +358,12 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
static const int kMmapFd = -1; static const int kMmapFd = -1;
static const int kMmapFdOffset = 0; 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); VirtualMemory::VirtualMemory(size_t size)
size_ = size; : address_(ReserveRegion(size)), size_(size) { }
}
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
......
...@@ -643,12 +643,12 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) { ...@@ -643,12 +643,12 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
static const int kMmapFd = -1; static const int kMmapFd = -1;
static const int kMmapFdOffset = 0; 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); VirtualMemory::VirtualMemory(size_t size)
size_ = size; : address_(ReserveRegion(size)), size_(size) { }
}
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
......
...@@ -408,12 +408,33 @@ VirtualMemory::~VirtualMemory() { ...@@ -408,12 +408,33 @@ VirtualMemory::~VirtualMemory() {
} }
bool VirtualMemory::IsReserved() {
return address_ != NULL;
}
void VirtualMemory::Reset() { void VirtualMemory::Reset() {
address_ = NULL; address_ = NULL;
size_ = 0; 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* VirtualMemory::ReserveRegion(size_t size) {
void* result = mmap(OS::GetRandomMmapAddr(), void* result = mmap(OS::GetRandomMmapAddr(),
size, size,
...@@ -428,22 +449,6 @@ void* VirtualMemory::ReserveRegion(size_t 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, bool VirtualMemory::CommitRegion(void* address,
size_t size, size_t size,
bool is_executable) { bool is_executable) {
...@@ -462,11 +467,6 @@ bool VirtualMemory::CommitRegion(void* address, ...@@ -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) { bool VirtualMemory::UncommitRegion(void* address, size_t size) {
return mmap(address, return mmap(address,
size, size,
......
...@@ -317,6 +317,16 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) { ...@@ -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) { VirtualMemory::VirtualMemory(size_t size, void* address_hint) {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
...@@ -333,6 +343,11 @@ bool VirtualMemory::IsReserved() { ...@@ -333,6 +343,11 @@ bool VirtualMemory::IsReserved() {
} }
void VirtualMemory::Reset() {
UNIMPLEMENTED();
}
bool VirtualMemory::Commit(void* address, size_t size, bool executable) { bool VirtualMemory::Commit(void* address, size_t size, bool executable) {
UNIMPLEMENTED(); UNIMPLEMENTED();
return false; return false;
...@@ -351,6 +366,30 @@ bool VirtualMemory::Guard(void* address) { ...@@ -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() { bool VirtualMemory::HasLazyCommits() {
// TODO(alph): implement for the platform. // TODO(alph): implement for the platform.
return false; return false;
......
...@@ -386,12 +386,12 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) { ...@@ -386,12 +386,12 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
static const int kMmapFd = -1; static const int kMmapFd = -1;
static const int kMmapFdOffset = 0; 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); VirtualMemory::VirtualMemory(size_t size)
size_ = size; : address_(ReserveRegion(size)), size_(size) { }
}
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
......
...@@ -328,10 +328,9 @@ static const int kMmapFdOffset = 0; ...@@ -328,10 +328,9 @@ 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); VirtualMemory::VirtualMemory(size_t size)
size_ = size; : address_(ReserveRegion(size)), size_(size) { }
}
VirtualMemory::VirtualMemory(size_t size, size_t alignment) VirtualMemory::VirtualMemory(size_t size, size_t alignment)
......
...@@ -1518,7 +1518,7 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment) ...@@ -1518,7 +1518,7 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment)
VirtualMemory::~VirtualMemory() { VirtualMemory::~VirtualMemory() {
if (IsReserved()) { if (IsReserved()) {
bool result = ReleaseRegion(address_, size_); bool result = ReleaseRegion(address(), size());
ASSERT(result); ASSERT(result);
USE(result); USE(result);
} }
...@@ -1551,6 +1551,17 @@ bool VirtualMemory::Uncommit(void* address, size_t size) { ...@@ -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) { void* VirtualMemory::ReserveRegion(size_t size) {
return RandomizedVirtualAlloc(size, MEM_RESERVE, PAGE_NOACCESS); return RandomizedVirtualAlloc(size, MEM_RESERVE, PAGE_NOACCESS);
} }
...@@ -1567,17 +1578,6 @@ bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { ...@@ -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) { bool VirtualMemory::UncommitRegion(void* base, size_t size) {
return VirtualFree(base, size, MEM_DECOMMIT) != 0; 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