Index: src/base/platform/platform.h |
diff --git a/src/base/platform/platform.h b/src/base/platform/platform.h |
index 9464fb11231dbcd59efed2846ff4d4894681f83f..d3b6c9c1cf3d758276ccc39c50a20b51fc9f9f98 100644 |
--- a/src/base/platform/platform.h |
+++ b/src/base/platform/platform.h |
@@ -337,6 +337,23 @@ class VirtualMemory { |
// Creates a single guard page at the given address. |
bool Guard(void* address); |
+ // Releases the memory after |free_start|. |
+ void ReleasePartial(void* free_start) { |
+ DCHECK(IsReserved()); |
+ // Notice: Order is important here. The VirtualMemory object might live |
+ // inside the allocated region. |
+ size_t size = size_ - (reinterpret_cast<size_t>(free_start) - |
+ reinterpret_cast<size_t>(address_)); |
+ CHECK(InVM(free_start, size)); |
+ DCHECK_LT(address_, free_start); |
+ DCHECK_LT(free_start, reinterpret_cast<void*>( |
+ reinterpret_cast<size_t>(address_) + size_)); |
+ bool result = ReleasePartialRegion(address_, size_, free_start, size); |
+ USE(result); |
+ DCHECK(result); |
+ size_ -= size; |
+ } |
+ |
void Release() { |
DCHECK(IsReserved()); |
// Notice: Order is important here. The VirtualMemory object might live |
@@ -369,6 +386,12 @@ class VirtualMemory { |
// and the same size it was reserved with. |
static bool ReleaseRegion(void* base, size_t size); |
+ // Must be called with a base pointer that has been returned by ReserveRegion |
+ // and the same size it was reserved with. |
+ // [free_start, free_start + free_size] is the memory that will be released. |
+ static bool ReleasePartialRegion(void* base, size_t size, void* free_start, |
+ size_t free_size); |
+ |
// Returns true if OS performs lazy commits, i.e. the memory allocation call |
// defers actual physical memory allocation till the first memory access. |
// Otherwise returns false. |