| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/allocator/allocator_shim.h" | 5 #include "base/allocator/allocator_shim.h" |
| 6 | 6 |
| 7 #include <config.h> | 7 #include <config.h> |
| 8 #include "base/allocator/allocator_extension_thunks.h" | 8 #include "base/allocator/allocator_extension_thunks.h" |
| 9 #include "base/profiler/alternate_timer.h" | 9 #include "base/profiler/alternate_timer.h" |
| 10 #include "base/sysinfo.h" | 10 #include "base/sysinfo.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 TCMALLOC, // TCMalloc is the default allocator. | 34 TCMALLOC, // TCMalloc is the default allocator. |
| 35 WINHEAP, // Windows Heap (standard Windows allocator). | 35 WINHEAP, // Windows Heap (standard Windows allocator). |
| 36 WINLFH, // Windows LFH Heap. | 36 WINLFH, // Windows LFH Heap. |
| 37 } Allocator; | 37 } Allocator; |
| 38 | 38 |
| 39 // This is the default allocator. This value can be changed at startup by | 39 // This is the default allocator. This value can be changed at startup by |
| 40 // specifying environment variables shown below it. | 40 // specifying environment variables shown below it. |
| 41 // See SetupSubprocessAllocator() to specify a default secondary (subprocess) | 41 // See SetupSubprocessAllocator() to specify a default secondary (subprocess) |
| 42 // allocator. | 42 // allocator. |
| 43 // TODO(jar): Switch to using TCMALLOC for the renderer as well. | 43 // TODO(jar): Switch to using TCMALLOC for the renderer as well. |
| 44 #if (defined(ADDRESS_SANITIZER) && defined(OS_WIN)) | 44 #if defined(SYZYASAN) |
| 45 // The Windows implementation of Asan requires the use of "WINHEAP". | 45 // SyzyASan requires the use of "WINHEAP". |
| 46 static Allocator allocator = WINHEAP; | 46 static Allocator allocator = WINHEAP; |
| 47 #else | 47 #else |
| 48 static Allocator allocator = TCMALLOC; | 48 static Allocator allocator = TCMALLOC; |
| 49 #endif | 49 #endif |
| 50 // The names of the environment variables that can optionally control the | 50 // The names of the environment variables that can optionally control the |
| 51 // selection of the allocator. The primary may be used to control overall | 51 // selection of the allocator. The primary may be used to control overall |
| 52 // allocator selection, and the secondary can be used to specify an allocator | 52 // allocator selection, and the secondary can be used to specify an allocator |
| 53 // to use in sub-processes. | 53 // to use in sub-processes. |
| 54 static const char primary_name[] = "CHROME_ALLOCATOR"; | 54 static const char primary_name[] = "CHROME_ALLOCATOR"; |
| 55 static const char secondary_name[] = "CHROME_ALLOCATOR_2"; | 55 static const char secondary_name[] = "CHROME_ALLOCATOR_2"; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 static void get_stats_thunk(char* buffer, int buffer_length) { | 221 static void get_stats_thunk(char* buffer, int buffer_length) { |
| 222 MallocExtension::instance()->GetStats(buffer, buffer_length); | 222 MallocExtension::instance()->GetStats(buffer, buffer_length); |
| 223 } | 223 } |
| 224 | 224 |
| 225 static void release_free_memory_thunk() { | 225 static void release_free_memory_thunk() { |
| 226 MallocExtension::instance()->ReleaseFreeMemory(); | 226 MallocExtension::instance()->ReleaseFreeMemory(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 // The CRT heap initialization stub. | 229 // The CRT heap initialization stub. |
| 230 extern "C" int _heap_init() { | 230 extern "C" int _heap_init() { |
| 231 // Don't use the environment variable if ADDRESS_SANITIZER is defined on | 231 // Don't use the environment variable if SYZYASAN is defined, as the |
| 232 // Windows, as the implementation requires Winheap to be the allocator. | 232 // implementation requires Winheap to be the allocator. |
| 233 #if !(defined(ADDRESS_SANITIZER) && defined(OS_WIN)) | 233 #if !defined(SYZYASAN) |
| 234 const char* environment_value = GetenvBeforeMain(primary_name); | 234 const char* environment_value = GetenvBeforeMain(primary_name); |
| 235 if (environment_value) { | 235 if (environment_value) { |
| 236 if (!stricmp(environment_value, "winheap")) | 236 if (!stricmp(environment_value, "winheap")) |
| 237 allocator = WINHEAP; | 237 allocator = WINHEAP; |
| 238 else if (!stricmp(environment_value, "winlfh")) | 238 else if (!stricmp(environment_value, "winlfh")) |
| 239 allocator = WINLFH; | 239 allocator = WINLFH; |
| 240 else if (!stricmp(environment_value, "tcmalloc")) | 240 else if (!stricmp(environment_value, "tcmalloc")) |
| 241 allocator = TCMALLOC; | 241 allocator = TCMALLOC; |
| 242 } | 242 } |
| 243 #endif | 243 #endif |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 size_t primary_length = 0; | 349 size_t primary_length = 0; |
| 350 getenv_s(&primary_length, NULL, 0, primary_name); | 350 getenv_s(&primary_length, NULL, 0, primary_name); |
| 351 | 351 |
| 352 size_t secondary_length = 0; | 352 size_t secondary_length = 0; |
| 353 char buffer[20]; | 353 char buffer[20]; |
| 354 getenv_s(&secondary_length, buffer, sizeof(buffer), secondary_name); | 354 getenv_s(&secondary_length, buffer, sizeof(buffer), secondary_name); |
| 355 DCHECK_GT(sizeof(buffer), secondary_length); | 355 DCHECK_GT(sizeof(buffer), secondary_length); |
| 356 buffer[sizeof(buffer) - 1] = '\0'; | 356 buffer[sizeof(buffer) - 1] = '\0'; |
| 357 | 357 |
| 358 if (secondary_length || !primary_length) { | 358 if (secondary_length || !primary_length) { |
| 359 // Don't use the environment variable if ADDRESS_SANITIZER is defined on | 359 // Don't use the environment variable if SYZYASAN is defined, as the |
| 360 // Windows, as the implementation require Winheap to be the allocator. | 360 // implementation require Winheap to be the allocator. |
| 361 #if !(defined(ADDRESS_SANITIZER) && defined(OS_WIN)) | 361 #if !defined(SYZYASAN) |
| 362 const char* secondary_value = secondary_length ? buffer : "TCMALLOC"; | 362 const char* secondary_value = secondary_length ? buffer : "TCMALLOC"; |
| 363 // Force renderer (or other subprocesses) to use secondary_value. | 363 // Force renderer (or other subprocesses) to use secondary_value. |
| 364 #else | 364 #else |
| 365 const char* secondary_value = "WINHEAP"; | 365 const char* secondary_value = "WINHEAP"; |
| 366 #endif | 366 #endif |
| 367 int ret_val = _putenv_s(primary_name, secondary_value); | 367 int ret_val = _putenv_s(primary_name, secondary_value); |
| 368 DCHECK_EQ(0, ret_val); | 368 DCHECK_EQ(0, ret_val); |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 | 371 |
| 372 void* TCMallocDoMallocForTest(size_t size) { | 372 void* TCMallocDoMallocForTest(size_t size) { |
| 373 return do_malloc(size); | 373 return do_malloc(size); |
| 374 } | 374 } |
| 375 | 375 |
| 376 void TCMallocDoFreeForTest(void* ptr) { | 376 void TCMallocDoFreeForTest(void* ptr) { |
| 377 do_free(ptr); | 377 do_free(ptr); |
| 378 } | 378 } |
| 379 | 379 |
| 380 size_t ExcludeSpaceForMarkForTest(size_t size) { | 380 size_t ExcludeSpaceForMarkForTest(size_t size) { |
| 381 return ExcludeSpaceForMark(size); | 381 return ExcludeSpaceForMark(size); |
| 382 } | 382 } |
| 383 | 383 |
| 384 } // namespace allocator. | 384 } // namespace allocator. |
| 385 } // namespace base. | 385 } // namespace base. |
| OLD | NEW |