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 |
| 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 (size > pagesize && |
| 278 VirtualProtect(start, pagesize, PAGE_READONLY | PAGE_GUARD, |
| 279 &permissions)) { |
| 280 return pagesize; |
| 281 } |
| 282 |
| 283 return 0; |
| 284 } |
| 285 |
261 void TCMalloc_SystemRelease(void* start, size_t length) { | 286 void TCMalloc_SystemRelease(void* start, size_t length) { |
262 if (VirtualFree(start, length, MEM_DECOMMIT)) | 287 if (VirtualFree(start, length, MEM_DECOMMIT)) |
263 return; | 288 return; |
264 | 289 |
265 // The decommit may fail if the memory region consists of allocations | 290 // 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 | 291 // from more than one call to VirtualAlloc. In this case, fall back to |
267 // using VirtualQuery to retrieve the allocation boundaries and decommit | 292 // using VirtualQuery to retrieve the allocation boundaries and decommit |
268 // them each individually. | 293 // them each individually. |
269 | 294 |
270 char* ptr = static_cast<char*>(start); | 295 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) && | 353 if ((strlen(fname) >= prefix_length) && |
329 (memcmp(fname, prefix, prefix_length) == 0)) { | 354 (memcmp(fname, prefix, prefix_length) == 0)) { |
330 RAW_VLOG(0, "Removing old heap profile %s\n", fname); | 355 RAW_VLOG(0, "Removing old heap profile %s\n", fname); |
331 // TODO(csilvers): we really need to unlink dirname + fname | 356 // TODO(csilvers): we really need to unlink dirname + fname |
332 _unlink(fname); | 357 _unlink(fname); |
333 } | 358 } |
334 } while (FindNextFileA(hFind, &found) != FALSE); // A is for Ansi | 359 } while (FindNextFileA(hFind, &found) != FALSE); // A is for Ansi |
335 FindClose(hFind); | 360 FindClose(hFind); |
336 } | 361 } |
337 } | 362 } |
OLD | NEW |