Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2877)

Unified Diff: base/allocator/win_allocator.cc

Issue 774683003: Remove tcmalloc when not being used. Restore shim on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resurrect tcmalloc_unittest on linux Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/allocator/win_allocator.cc
diff --git a/base/allocator/win_allocator.cc b/base/allocator/win_allocator.cc
index ee451f546101c008c0b081f4c880790c20027bd6..279606c26e4a675f314fd3e3a8eab39a3bc74ed8 100644
--- a/base/allocator/win_allocator.cc
+++ b/base/allocator/win_allocator.cc
@@ -6,27 +6,33 @@
extern "C" {
+const size_t kWindowsPageSize = 4096;
+size_t kMaxWindowsAllocation =
+ std::numeric_limits<int>::max() - kWindowsPageSize;
HANDLE win_heap;
-bool win_heap_init(bool use_lfh) {
- win_heap = HeapCreate(0, 0, 0);
+bool win_heap_init() {
+ win_heap = static_cast<HANDLE>(GetProcessHeap());
if (win_heap == NULL)
return false;
- if (use_lfh) {
- ULONG enable_lfh = 2;
- HeapSetInformation(win_heap, HeapCompatibilityInformation,
- &enable_lfh, sizeof(enable_lfh));
- // NOTE: Setting LFH may fail. Vista already has it enabled.
- // And under the debugger, it won't use LFH. So we
- // ignore any errors.
- }
+ ULONG enable_lfh = 2;
+ // NOTE: Setting LFH may fail. Vista already has it enabled.
+ // And under the debugger, it won't use LFH. So we
+ // ignore any errors.
+ HeapSetInformation(win_heap, HeapCompatibilityInformation, &enable_lfh,
+ sizeof(enable_lfh));
+ // In Debug, _mt_init() performs an allocation before _cinit is called to
+ // initalize C data, so manually initialize kMaxWindowsAllocation here.
+ kMaxWindowsAllocation = std::numeric_limits<int>::max() - kWindowsPageSize;
return true;
}
void* win_heap_malloc(size_t size) {
- return HeapAlloc(win_heap, 0, size);
+ if (size < kMaxWindowsAllocation)
+ return HeapAlloc(win_heap, 0, size);
+ return NULL;
}
void win_heap_free(void* size) {
@@ -40,7 +46,9 @@ void* win_heap_realloc(void* ptr, size_t size) {
win_heap_free(ptr);
return NULL;
}
- return HeapReAlloc(win_heap, 0, ptr, size);
+ if (size < kMaxWindowsAllocation)
+ return HeapReAlloc(win_heap, 0, ptr, size);
+ return NULL;
}
size_t win_heap_msize(void* ptr) {

Powered by Google App Engine
This is Rietveld 408576698