Chromium Code Reviews| Index: src/platform-win32.cc |
| diff --git a/src/platform-win32.cc b/src/platform-win32.cc |
| index c441b96ce48fedfab29d49a4f0c8d0d157e4bf57..0a26f5e93a8a3c02ae31a55f78bd8912e82b5e59 100644 |
| --- a/src/platform-win32.cc |
| +++ b/src/platform-win32.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright 2006-2008 the V8 project authors. All rights reserved. |
| +// Copyright 2011 the V8 project authors. All rights reserved. |
| // Redistribution and use in source and binary forms, with or without |
| // modification, are permitted provided that the following conditions are |
| // met: |
| @@ -1503,6 +1503,35 @@ void* VirtualMemory::ReserveRegion(size_t size) { |
| } |
| +void* VirtualMemory::ReserveAlignedRegion(size_t size, size_t alignment) { |
| + ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); |
| + size_t request_size = RoundUp(size + alignment, |
| + static_cast<intptr_t>(OS::AllocateAlignment())); |
| + Address result; |
| + do { |
| + void* reservation = |
| + VirtualAlloc(NULL, request_size, MEM_RESERVE, PAGE_NOACCESS); |
| + // If we can't allocate at all, give up. |
| + if (reservation == NULL) return NULL; |
| + Address base = static_cast<Address>(reservation); |
| + Address aligned_base = RoundUp(base, alignment); |
| + ASSERT(base <= aligned_base); |
| + // Try to reallocate part of the original allocation by first freeing it, |
| + // and then allocating with a specific target address in the middle of |
| + // the freed area. |
| + // This can fail in the rare case that someone else in the same process |
| + // allocates the same memory between the VirtualFree and VirtualAlloc |
| + // calls. In that case, just try again. |
| + VirtualFree(reservation, 0, MEM_RELEASE); |
| + reservation = VirtualAlloc(aligned_base, size, MEM_RESERVE, PAGE_NOACCESS); |
| + result = static_cast<Address>(reservation); |
| + ASSERT(result == NULL || result == aligned_base); |
| + } while (result == NULL); |
|
Vyacheslav Egorov (Chromium)
2011/09/12 13:42:48
this looks too fragile and might go into infinite
Lasse Reichstein
2011/09/12 19:18:02
This was an attempt to avoid finding a place to st
|
| + |
| + return static_cast<void*>(result); |
| +} |
| + |
| + |
| bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { |
| int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
| if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) { |
| @@ -1515,12 +1544,12 @@ bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { |
| bool VirtualMemory::UncommitRegion(void* base, size_t size) { |
| - return VirtualFree(base, size, MEM_DECOMMIT) != false; |
| + return VirtualFree(base, size, MEM_DECOMMIT) != 0; |
| } |
| bool VirtualMemory::ReleaseRegion(void* base, size_t size) { |
| - return VirtualFree(base, size, MEM_DECOMMIT) != false; |
| + return VirtualFree(base, 0, MEM_DECOMMIT) != 0; |
|
Vyacheslav Egorov (Chromium)
2011/09/12 13:42:48
Should not it become MEM_RELEASE?
Lasse Reichstein
2011/09/12 19:18:02
Absolutely! It should have been that all along! Th
|
| } |