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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // This should detect a TCMalloc bypass from setting | 68 // This should detect a TCMalloc bypass from setting |
69 // the CHROME_ALLOCATOR environment variable. | 69 // the CHROME_ALLOCATOR environment variable. |
70 char* allocator = getenv("CHROME_ALLOCATOR"); | 70 char* allocator = getenv("CHROME_ALLOCATOR"); |
71 if (allocator && strcmp(allocator, "tcmalloc")) | 71 if (allocator && strcmp(allocator, "tcmalloc")) |
72 return true; | 72 return true; |
73 #endif | 73 #endif |
74 return false; | 74 return false; |
75 } | 75 } |
76 | 76 |
77 bool CallocDiesOnOOM() { | 77 bool CallocDiesOnOOM() { |
| 78 // The sanitizers' calloc dies on OOM instead of returning NULL. |
78 // The wrapper function in base/process_util_linux.cc that is used when we | 79 // The wrapper function in base/process_util_linux.cc that is used when we |
79 // compile without TCMalloc will just die on OOM instead of returning NULL. | 80 // compile without TCMalloc will just die on OOM instead of returning NULL. |
80 // This function is explicitly disabled if we compile with AddressSanitizer, | 81 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ |
81 // MemorySanitizer or ThreadSanitizer. | 82 defined(THREAD_SANITIZER) || (defined(OS_LINUX) && defined(NO_TCMALLOC)) |
82 #if defined(OS_LINUX) && defined(NO_TCMALLOC) && \ | |
83 (!defined(ADDRESS_SANITIZER) && \ | |
84 !defined(MEMORY_SANITIZER) && \ | |
85 !defined(THREAD_SANITIZER)) | |
86 return true; | 83 return true; |
87 #else | 84 #else |
88 return false; | 85 return false; |
89 #endif | 86 #endif |
90 } | 87 } |
91 | 88 |
92 // Fake test that allow to know the state of TCMalloc by looking at bots. | 89 // Fake test that allow to know the state of TCMalloc by looking at bots. |
93 TEST(SecurityTest, TCMALLOC_TEST(IsTCMallocDynamicallyBypassed)) { | 90 TEST(SecurityTest, TCMALLOC_TEST(IsTCMallocDynamicallyBypassed)) { |
94 printf("Malloc is dynamically bypassed: %s\n", | 91 printf("Malloc is dynamically bypassed: %s\n", |
95 IsTcMallocBypassed() ? "yes." : "no."); | 92 IsTcMallocBypassed() ? "yes." : "no."); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // kRandomMask, so we use it as an additional detection mechanism. | 294 // kRandomMask, so we use it as an additional detection mechanism. |
298 const uintptr_t kRandomMask = 0x3fffffffffffULL; | 295 const uintptr_t kRandomMask = 0x3fffffffffffULL; |
299 bool impossible_random_address = | 296 bool impossible_random_address = |
300 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; | 297 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; |
301 EXPECT_FALSE(impossible_random_address); | 298 EXPECT_FALSE(impossible_random_address); |
302 } | 299 } |
303 | 300 |
304 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) | 301 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) |
305 | 302 |
306 } // namespace | 303 } // namespace |
OLD | NEW |