| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } else { | 223 } else { |
| 224 // It's also ok for calloc to just terminate the process. | 224 // It's also ok for calloc to just terminate the process. |
| 225 #if defined(GTEST_HAS_DEATH_TEST) | 225 #if defined(GTEST_HAS_DEATH_TEST) |
| 226 EXPECT_DEATH(CallocReturnsNull(kArraySize, kArraySize2), ""); | 226 EXPECT_DEATH(CallocReturnsNull(kArraySize, kArraySize2), ""); |
| 227 EXPECT_DEATH(CallocReturnsNull(kArraySize2, kArraySize), ""); | 227 EXPECT_DEATH(CallocReturnsNull(kArraySize2, kArraySize), ""); |
| 228 #endif // GTEST_HAS_DEATH_TEST | 228 #endif // GTEST_HAS_DEATH_TEST |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 | 231 |
| 232 #if (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) | 232 #if (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) |
| 233 // Useful for debugging. | |
| 234 void PrintProcSelfMaps() { | |
| 235 int fd = open("/proc/self/maps", O_RDONLY); | |
| 236 file_util::ScopedFD fd_closer(&fd); | |
| 237 ASSERT_GE(fd, 0); | |
| 238 char buffer[1<<13]; | |
| 239 int ret; | |
| 240 ret = read(fd, buffer, sizeof(buffer) - 1); | |
| 241 ASSERT_GT(ret, 0); | |
| 242 buffer[ret - 1] = 0; | |
| 243 fprintf(stdout, "%s\n", buffer); | |
| 244 } | |
| 245 | |
| 246 // Check if ptr1 and ptr2 are separated by less than size chars. | 233 // Check if ptr1 and ptr2 are separated by less than size chars. |
| 247 bool ArePointersToSameArea(void* ptr1, void* ptr2, size_t size) { | 234 bool ArePointersToSameArea(void* ptr1, void* ptr2, size_t size) { |
| 248 ptrdiff_t ptr_diff = reinterpret_cast<char*>(std::max(ptr1, ptr2)) - | 235 ptrdiff_t ptr_diff = reinterpret_cast<char*>(std::max(ptr1, ptr2)) - |
| 249 reinterpret_cast<char*>(std::min(ptr1, ptr2)); | 236 reinterpret_cast<char*>(std::min(ptr1, ptr2)); |
| 250 return static_cast<size_t>(ptr_diff) <= size; | 237 return static_cast<size_t>(ptr_diff) <= size; |
| 251 } | 238 } |
| 252 | 239 |
| 253 // Check if TCMalloc uses an underlying random memory allocator. | 240 // Check if TCMalloc uses an underlying random memory allocator. |
| 254 TEST(SecurityTest, TCMALLOC_TEST(RandomMemoryAllocations)) { | 241 TEST(SecurityTest, TCMALLOC_TEST(RandomMemoryAllocations)) { |
| 255 if (IsTcMallocBypassed()) | 242 if (IsTcMallocBypassed()) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // kRandomMask, so we use it as an additional detection mechanism. | 281 // kRandomMask, so we use it as an additional detection mechanism. |
| 295 const uintptr_t kRandomMask = 0x3fffffffffffULL; | 282 const uintptr_t kRandomMask = 0x3fffffffffffULL; |
| 296 bool impossible_random_address = | 283 bool impossible_random_address = |
| 297 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; | 284 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; |
| 298 EXPECT_FALSE(impossible_random_address); | 285 EXPECT_FALSE(impossible_random_address); |
| 299 } | 286 } |
| 300 | 287 |
| 301 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) | 288 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) |
| 302 | 289 |
| 303 } // namespace | 290 } // namespace |
| OLD | NEW |