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 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
6 | 6 |
7 #include "base/process/memory.h" | 7 #include "base/process/memory.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... | |
40 typedef __int64 ssize_t; | 40 typedef __int64 ssize_t; |
41 #else | 41 #else |
42 typedef long ssize_t; | 42 typedef long ssize_t; |
43 #endif | 43 #endif |
44 #endif | 44 #endif |
45 | 45 |
46 // HeapQueryInformation function pointer. | 46 // HeapQueryInformation function pointer. |
47 typedef BOOL (WINAPI* HeapQueryFn) \ | 47 typedef BOOL (WINAPI* HeapQueryFn) \ |
48 (HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T); | 48 (HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T); |
49 | 49 |
50 const int kConstantInModule = 42; | 50 const int kConstantInModule = 42; |
sof
2016/04/04 07:32:44
This now appears unused -- https://build.chromium.
sof
2016/04/04 07:49:08
Removing in https://codereview.chromium.org/185769
| |
51 | 51 |
52 TEST(ProcessMemoryTest, GetModuleFromAddress) { | |
53 // Since the unit tests are their own EXE, this should be | |
54 // equivalent to the EXE's HINSTANCE. | |
55 // | |
56 // kConstantInModule is a constant in this file and | |
57 // therefore within the unit test EXE. | |
58 EXPECT_EQ(::GetModuleHandle(NULL), | |
59 base::GetModuleFromAddress( | |
60 const_cast<int*>(&kConstantInModule))); | |
61 | |
62 // Any address within the kernel32 module should return | |
63 // kernel32's HMODULE. Our only assumption here is that | |
64 // kernel32 is larger than 4 bytes. | |
65 HMODULE kernel32 = ::GetModuleHandle(L"kernel32.dll"); | |
66 HMODULE kernel32_from_address = | |
67 base::GetModuleFromAddress(reinterpret_cast<DWORD*>(kernel32) + 1); | |
68 EXPECT_EQ(kernel32, kernel32_from_address); | |
69 } | |
70 #endif // defined(OS_WIN) | 52 #endif // defined(OS_WIN) |
71 | 53 |
72 #if defined(OS_MACOSX) | 54 #if defined(OS_MACOSX) |
73 | 55 |
74 // For the following Mac tests: | 56 // For the following Mac tests: |
75 // Note that base::EnableTerminationOnHeapCorruption() is called as part of | 57 // Note that base::EnableTerminationOnHeapCorruption() is called as part of |
76 // test suite setup and does not need to be done again, else mach_override | 58 // test suite setup and does not need to be done again, else mach_override |
77 // will fail. | 59 // will fail. |
78 | 60 |
79 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) { | 61 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) | 408 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) |
427 EXPECT_EQ(0, bytes[i]); | 409 EXPECT_EQ(0, bytes[i]); |
428 free(value_); | 410 free(value_); |
429 | 411 |
430 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); | 412 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); |
431 EXPECT_TRUE(value_ == NULL); | 413 EXPECT_TRUE(value_ == NULL); |
432 } | 414 } |
433 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 415 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
434 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !(defined(OS_WIN) && | 416 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !(defined(OS_WIN) && |
435 // !defined(ALLOCATOR_SHIM)) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 417 // !defined(ALLOCATOR_SHIM)) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
OLD | NEW |