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. | |
79 // 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 |
80 // 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. |
81 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ | 80 // This function is explicitly disabled if we compile with AddressSanitizer, |
82 defined(THREAD_SANITIZER) || (defined(OS_LINUX) && defined(NO_TCMALLOC)) | 81 // MemorySanitizer or ThreadSanitizer. |
| 82 #if defined(OS_LINUX) && defined(NO_TCMALLOC) && \ |
| 83 (!defined(ADDRESS_SANITIZER) && \ |
| 84 !defined(MEMORY_SANITIZER) && \ |
| 85 !defined(THREAD_SANITIZER)) |
83 return true; | 86 return true; |
84 #else | 87 #else |
85 return false; | 88 return false; |
86 #endif | 89 #endif |
87 } | 90 } |
88 | 91 |
89 // Fake test that allow to know the state of TCMalloc by looking at bots. | 92 // Fake test that allow to know the state of TCMalloc by looking at bots. |
90 TEST(SecurityTest, TCMALLOC_TEST(IsTCMallocDynamicallyBypassed)) { | 93 TEST(SecurityTest, TCMALLOC_TEST(IsTCMallocDynamicallyBypassed)) { |
91 printf("Malloc is dynamically bypassed: %s\n", | 94 printf("Malloc is dynamically bypassed: %s\n", |
92 IsTcMallocBypassed() ? "yes." : "no."); | 95 IsTcMallocBypassed() ? "yes." : "no."); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // kRandomMask, so we use it as an additional detection mechanism. | 297 // kRandomMask, so we use it as an additional detection mechanism. |
295 const uintptr_t kRandomMask = 0x3fffffffffffULL; | 298 const uintptr_t kRandomMask = 0x3fffffffffffULL; |
296 bool impossible_random_address = | 299 bool impossible_random_address = |
297 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; | 300 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; |
298 EXPECT_FALSE(impossible_random_address); | 301 EXPECT_FALSE(impossible_random_address); |
299 } | 302 } |
300 | 303 |
301 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) | 304 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) |
302 | 305 |
303 } // namespace | 306 } // namespace |
OLD | NEW |