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

Side by Side Diff: tools/memory_watcher/memory_hook.cc

Issue 55833004: Mark memory_watcher as chromium_code. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/memory_watcher/memory_watcher.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 210 }
211 211
212 static LPVOID WINAPI Perftools_HeapReAlloc(HANDLE hHeap, DWORD dwFlags, 212 static LPVOID WINAPI Perftools_HeapReAlloc(HANDLE hHeap, DWORD dwFlags,
213 LPVOID lpMem, SIZE_T dwBytes) { 213 LPVOID lpMem, SIZE_T dwBytes) {
214 // Don't call realloc, but instead do a free/malloc. The problem is that 214 // Don't call realloc, but instead do a free/malloc. The problem is that
215 // the builtin realloc may either expand a buffer, or it may simply 215 // the builtin realloc may either expand a buffer, or it may simply
216 // just call free/malloc. If so, we will already have tracked the new 216 // just call free/malloc. If so, we will already have tracked the new
217 // block via Perftools_HeapAlloc. 217 // block via Perftools_HeapAlloc.
218 218
219 LPVOID rv = Perftools_HeapAlloc(hHeap, dwFlags, dwBytes); 219 LPVOID rv = Perftools_HeapAlloc(hHeap, dwFlags, dwBytes);
220 DCHECK_EQ((HEAP_REALLOC_IN_PLACE_ONLY & dwFlags), 0); 220 DCHECK_EQ((HEAP_REALLOC_IN_PLACE_ONLY & dwFlags), 0u);
221 221
222 // If there was an old buffer, now copy the data to the new buffer. 222 // If there was an old buffer, now copy the data to the new buffer.
223 if (lpMem != 0) { 223 if (lpMem != 0) {
224 size_t size = HeapSize(hHeap, 0, lpMem); 224 size_t size = HeapSize(hHeap, 0, lpMem);
225 if (size > dwBytes) 225 if (size > dwBytes)
226 size = dwBytes; 226 size = dwBytes;
227 // Note: size could be 0; HeapAlloc does allocate 0 length buffers. 227 // Note: size could be 0; HeapAlloc does allocate 0 length buffers.
228 memcpy(rv, lpMem, size); 228 memcpy(rv, lpMem, size);
229 Perftools_HeapFree(hHeap, dwFlags, lpMem); 229 Perftools_HeapFree(hHeap, dwFlags, lpMem);
230 } 230 }
(...skipping 28 matching lines...) Expand all
259 return result; 259 return result;
260 } 260 }
261 261
262 static BOOL WINAPI Perftools_VirtualFreeEx(HANDLE process, LPVOID address, 262 static BOOL WINAPI Perftools_VirtualFreeEx(HANDLE process, LPVOID address,
263 SIZE_T size, DWORD type) { 263 SIZE_T size, DWORD type) {
264 int chunk_size = size; 264 int chunk_size = size;
265 MEMORY_BASIC_INFORMATION info; 265 MEMORY_BASIC_INFORMATION info;
266 CHECK(VirtualQuery(address, &info, sizeof(info))); 266 CHECK(VirtualQuery(address, &info, sizeof(info)));
267 if (chunk_size == 0) 267 if (chunk_size == 0)
268 chunk_size = info.RegionSize; 268 chunk_size = info.RegionSize;
269 bool decommit = (info.State & MEM_COMMIT); 269 bool decommit = (info.State & MEM_COMMIT) != 0;
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 base::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;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « no previous file | tools/memory_watcher/memory_watcher.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698