OLD | NEW |
---|---|
1 /* Copyright (c) 2007, Google Inc. | 1 /* Copyright (c) 2007, Google Inc. |
2 * All rights reserved. | 2 * All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 if (result == NULL) | 251 if (result == NULL) |
252 return NULL; | 252 return NULL; |
253 | 253 |
254 // If the result is not aligned memory fragmentation will result which can | 254 // If the result is not aligned memory fragmentation will result which can |
255 // lead to pathological memory use. | 255 // lead to pathological memory use. |
256 assert((reinterpret_cast<uintptr_t>(result) & (alignment - 1)) == 0); | 256 assert((reinterpret_cast<uintptr_t>(result) & (alignment - 1)) == 0); |
257 | 257 |
258 return result; | 258 return result; |
259 } | 259 } |
260 | 260 |
261 size_t TCMalloc_SystemAddGuard(void* start, size_t size) { | |
262 static size_t pagesize = 0; | |
263 if (pagesize == 0) { | |
264 SYSTEM_INFO system_info; | |
265 GetSystemInfo(&system_info); | |
266 pagesize = system_info.dwPageSize; | |
267 } | |
268 | |
jar (doing other things)
2011/11/24 00:30:54
You need to exit if size < pagesize.
You might as
jschuh
2011/11/24 01:02:05
Ugh. That was dumb.
| |
269 // We know that TCMalloc_SystemAlloc will give us a correct page alignment | |
270 // regardless, so we can just assert to detect erroneous callers. | |
271 assert(reinterpret_cast<size_t>(start) % pagesize == 0); | |
272 | |
273 // Add a guard page to catch metadata corruption. We're using the | |
274 // PAGE_GUARD flag rather than NO_ACCESS because we want the unique | |
275 // exception in crash reports. | |
276 DWORD permissions = 0; | |
277 if (VirtualProtect(start, pagesize, PAGE_READONLY | PAGE_GUARD, | |
278 &permissions)) { | |
279 return pagesize; | |
280 } | |
281 | |
282 return 0; | |
283 } | |
284 | |
261 void TCMalloc_SystemRelease(void* start, size_t length) { | 285 void TCMalloc_SystemRelease(void* start, size_t length) { |
262 if (VirtualFree(start, length, MEM_DECOMMIT)) | 286 if (VirtualFree(start, length, MEM_DECOMMIT)) |
263 return; | 287 return; |
264 | 288 |
265 // The decommit may fail if the memory region consists of allocations | 289 // The decommit may fail if the memory region consists of allocations |
266 // from more than one call to VirtualAlloc. In this case, fall back to | 290 // from more than one call to VirtualAlloc. In this case, fall back to |
267 // using VirtualQuery to retrieve the allocation boundaries and decommit | 291 // using VirtualQuery to retrieve the allocation boundaries and decommit |
268 // them each individually. | 292 // them each individually. |
269 | 293 |
270 char* ptr = static_cast<char*>(start); | 294 char* ptr = static_cast<char*>(start); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 if ((strlen(fname) >= prefix_length) && | 352 if ((strlen(fname) >= prefix_length) && |
329 (memcmp(fname, prefix, prefix_length) == 0)) { | 353 (memcmp(fname, prefix, prefix_length) == 0)) { |
330 RAW_VLOG(0, "Removing old heap profile %s\n", fname); | 354 RAW_VLOG(0, "Removing old heap profile %s\n", fname); |
331 // TODO(csilvers): we really need to unlink dirname + fname | 355 // TODO(csilvers): we really need to unlink dirname + fname |
332 _unlink(fname); | 356 _unlink(fname); |
333 } | 357 } |
334 } while (FindNextFileA(hFind, &found) != FALSE); // A is for Ansi | 358 } while (FindNextFileA(hFind, &found) != FALSE); // A is for Ansi |
335 FindClose(hFind); | 359 FindClose(hFind); |
336 } | 360 } |
337 } | 361 } |
OLD | NEW |