OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <fcntl.h> | 5 #include <fcntl.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 28 matching lines...) Expand all Loading... |
39 // more robust than merely using "volatile". | 39 // more robust than merely using "volatile". |
40 __asm__ volatile ("" : "+r" (value)); | 40 __asm__ volatile ("" : "+r" (value)); |
41 #endif // __GNUC__ | 41 #endif // __GNUC__ |
42 return value; | 42 return value; |
43 } | 43 } |
44 | 44 |
45 // - NO_TCMALLOC (should be defined if we compile with linux_use_tcmalloc=0) | 45 // - NO_TCMALLOC (should be defined if we compile with linux_use_tcmalloc=0) |
46 // - ADDRESS_SANITIZER because it has its own memory allocator | 46 // - ADDRESS_SANITIZER because it has its own memory allocator |
47 // - IOS does not use tcmalloc | 47 // - IOS does not use tcmalloc |
48 // - OS_MACOSX does not use tcmalloc | 48 // - OS_MACOSX does not use tcmalloc |
49 // - OS_WIN does not use tcmalloc crbug.com/242304 | |
50 #if !defined(NO_TCMALLOC) && !defined(ADDRESS_SANITIZER) && \ | 49 #if !defined(NO_TCMALLOC) && !defined(ADDRESS_SANITIZER) && \ |
51 !defined(OS_IOS) && !defined(OS_MACOSX) && !defined(OS_WIN) | 50 !defined(OS_IOS) && !defined(OS_MACOSX) |
52 #define TCMALLOC_TEST(function) function | 51 #define TCMALLOC_TEST(function) function |
53 #else | 52 #else |
54 #define TCMALLOC_TEST(function) DISABLED_##function | 53 #define TCMALLOC_TEST(function) DISABLED_##function |
55 #endif | 54 #endif |
56 | 55 |
57 // TODO(jln): switch to std::numeric_limits<int>::max() when we switch to | 56 // TODO(jln): switch to std::numeric_limits<int>::max() when we switch to |
58 // C++11. | 57 // C++11. |
59 const size_t kTooBigAllocSize = INT_MAX; | 58 const size_t kTooBigAllocSize = INT_MAX; |
60 | 59 |
61 // Detect runtime TCMalloc bypasses. | 60 // Detect runtime TCMalloc bypasses. |
62 bool IsTcMallocBypassed() { | 61 bool IsTcMallocBypassed() { |
63 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | 62 #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
64 // This should detect a TCMalloc bypass from Valgrind. | 63 // This should detect a TCMalloc bypass from Valgrind. |
65 char* g_slice = getenv("G_SLICE"); | 64 char* g_slice = getenv("G_SLICE"); |
66 if (g_slice && !strcmp(g_slice, "always-malloc")) | 65 if (g_slice && !strcmp(g_slice, "always-malloc")) |
67 return true; | 66 return true; |
| 67 #elif defined(OS_WIN) |
| 68 // This should detect a TCMalloc bypass from setting |
| 69 // the CHROME_ALLOCATOR environment variable. |
| 70 char* allocator = getenv("CHROME_ALLOCATOR"); |
| 71 if (allocator && strcmp(allocator, "tcmalloc")) |
| 72 return true; |
68 #endif | 73 #endif |
69 return false; | 74 return false; |
70 } | 75 } |
71 | 76 |
72 bool CallocDiesOnOOM() { | 77 bool CallocDiesOnOOM() { |
73 // The wrapper function in base/process_util_linux.cc that is used when we | 78 // The wrapper function in base/process_util_linux.cc that is used when we |
74 // compile without TCMalloc will just die on OOM instead of returning NULL. | 79 // compile without TCMalloc will just die on OOM instead of returning NULL. |
75 // This function is explicitly disabled if we compile with AddressSanitizer, | 80 // This function is explicitly disabled if we compile with AddressSanitizer, |
76 // MemorySanitizer or ThreadSanitizer. | 81 // MemorySanitizer or ThreadSanitizer. |
77 #if defined(OS_LINUX) && defined(NO_TCMALLOC) && \ | 82 #if defined(OS_LINUX) && defined(NO_TCMALLOC) && \ |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 // kRandomMask, so we use it as an additional detection mechanism. | 297 // kRandomMask, so we use it as an additional detection mechanism. |
293 const uintptr_t kRandomMask = 0x3fffffffffffULL; | 298 const uintptr_t kRandomMask = 0x3fffffffffffULL; |
294 bool impossible_random_address = | 299 bool impossible_random_address = |
295 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; | 300 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; |
296 EXPECT_FALSE(impossible_random_address); | 301 EXPECT_FALSE(impossible_random_address); |
297 } | 302 } |
298 | 303 |
299 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) | 304 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) |
300 | 305 |
301 } // namespace | 306 } // namespace |
OLD | NEW |