OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Static class for hooking Win32 API routines. | 5 // Static class for hooking Win32 API routines. |
6 | 6 |
7 // Some notes about how to hook Memory Allocation Routines in Windows. | 7 // Some notes about how to hook Memory Allocation Routines in Windows. |
8 // | 8 // |
9 // For our purposes we do not hook the libc routines. There are two | 9 // For our purposes we do not hook the libc routines. There are two |
10 // reasons for this. First, the libc routines all go through HeapAlloc | 10 // reasons for this. First, the libc routines all go through HeapAlloc |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 chunk_size = info.RegionSize; | 268 chunk_size = info.RegionSize; |
269 bool decommit = (info.State & MEM_COMMIT); | 269 bool decommit = (info.State & MEM_COMMIT); |
270 | 270 |
271 if (decommit) | 271 if (decommit) |
272 MemoryHook::hook()->OnUntrack(0, reinterpret_cast<int32>(address), | 272 MemoryHook::hook()->OnUntrack(0, reinterpret_cast<int32>(address), |
273 chunk_size); | 273 chunk_size); |
274 | 274 |
275 return patch_VirtualFreeEx()(process, address, size, type); | 275 return patch_VirtualFreeEx()(process, address, size, type); |
276 } | 276 } |
277 | 277 |
278 static Lock known_maps_lock; | 278 static base::Lock known_maps_lock; |
279 static std::map<void*, int> known_maps; | 279 static std::map<void*, int> known_maps; |
280 | 280 |
281 static LPVOID WINAPI Perftools_MapViewOfFileEx(HANDLE hFileMappingObject, | 281 static LPVOID WINAPI Perftools_MapViewOfFileEx(HANDLE hFileMappingObject, |
282 DWORD dwDesiredAccess, | 282 DWORD dwDesiredAccess, |
283 DWORD dwFileOffsetHigh, | 283 DWORD dwFileOffsetHigh, |
284 DWORD dwFileOffsetLow, | 284 DWORD dwFileOffsetLow, |
285 SIZE_T dwNumberOfBytesToMap, | 285 SIZE_T dwNumberOfBytesToMap, |
286 LPVOID lpBaseAddress) { | 286 LPVOID lpBaseAddress) { |
287 // For this function pair, you always deallocate the full block of | 287 // For this function pair, you always deallocate the full block of |
288 // data that you allocate, so NewHook/DeleteHook is the right API. | 288 // data that you allocate, so NewHook/DeleteHook is the right API. |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 } | 553 } |
554 | 554 |
555 void MemoryHook::OnUntrack(HANDLE heap, int32 id, int32 size) { | 555 void MemoryHook::OnUntrack(HANDLE heap, int32 id, int32 size) { |
556 // Don't notify about allocations to our internal heap. | 556 // Don't notify about allocations to our internal heap. |
557 if (heap == heap_) | 557 if (heap == heap_) |
558 return; | 558 return; |
559 | 559 |
560 if (watcher_) | 560 if (watcher_) |
561 watcher_->OnUntrack(heap, id, size); | 561 watcher_->OnUntrack(heap, id, size); |
562 } | 562 } |
OLD | NEW |