OLD | NEW |
1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 ASSERT_FALSE(internal::IsZeroBufferImpl<AccessType>(buf + i, end - j)); | 72 ASSERT_FALSE(internal::IsZeroBufferImpl<AccessType>(buf + i, end - j)); |
73 buf[k] = 0; | 73 buf[k] = 0; |
74 } | 74 } |
75 } | 75 } |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 // A derived class to expose protected members for unit-testing. | 79 // A derived class to expose protected members for unit-testing. |
80 class TestShadow : public Shadow { | 80 class TestShadow : public Shadow { |
81 public: | 81 public: |
82 TestShadow() : Shadow(kDefaultTestShadowSize) { | 82 TestShadow() : Shadow() {} |
83 } | |
84 | 83 |
85 TestShadow(size_t digits, size_t power) | 84 TestShadow(size_t digits, size_t power) |
86 : Shadow(digits << (power - kShadowRatioLog)) { | 85 : Shadow(digits << (power - kShadowRatioLog)) { |
87 } | 86 } |
88 | 87 |
89 // We'll simulate memory as being 1GB in size. | |
90 static const size_t kDefaultTestShadowSize = | |
91 (1 * 1024 * 1024 * 1024) >> kShadowRatioLog; | |
92 | |
93 TestShadow(void* shadow, size_t length) : Shadow(shadow, length) {} | 88 TestShadow(void* shadow, size_t length) : Shadow(shadow, length) {} |
94 | 89 |
95 // Protected functions that we want to unittest directly. | 90 // Protected functions that we want to unittest directly. |
96 using Shadow::Reset; | 91 using Shadow::Reset; |
97 using Shadow::ScanLeftForBracketingBlockStart; | 92 using Shadow::ScanLeftForBracketingBlockStart; |
98 using Shadow::ScanRightForBracketingBlockEnd; | 93 using Shadow::ScanRightForBracketingBlockEnd; |
99 using Shadow::shadow_; | 94 using Shadow::shadow_; |
100 }; | 95 }; |
101 | 96 |
102 // A fixture for shadow memory tests. | 97 // A fixture for shadow memory tests. |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 2 * 8), | 397 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 2 * 8), |
403 kHeapLeftPaddingMarker); | 398 kHeapLeftPaddingMarker); |
404 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 3 * 8), | 399 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 3 * 8), |
405 0); | 400 0); |
406 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 4 * 8), | 401 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 4 * 8), |
407 7); | 402 7); |
408 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 5 * 8), | 403 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 5 * 8), |
409 kHeapRightPaddingMarker); | 404 kHeapRightPaddingMarker); |
410 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 6 * 8), | 405 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 6 * 8), |
411 kHeapRightPaddingMarker); | 406 kHeapRightPaddingMarker); |
| 407 #ifndef _WIN64 |
412 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 7 * 8), | 408 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 7 * 8), |
413 kHeapBlockEndMarker); | 409 kHeapBlockEndMarker); |
| 410 #else |
| 411 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 7 * 8), |
| 412 kHeapRightPaddingMarker); |
| 413 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 8 * 8), |
| 414 kHeapBlockEndMarker); |
| 415 #endif |
414 | 416 |
415 uint8_t* cursor = info.RawHeader(); | 417 uint8_t* cursor = info.RawHeader(); |
416 for (; cursor < info.RawBody(); ++cursor) | 418 for (; cursor < info.RawBody(); ++cursor) |
417 EXPECT_FALSE(test_shadow.IsAccessible(cursor)); | 419 EXPECT_FALSE(test_shadow.IsAccessible(cursor)); |
418 for (; cursor < info.RawBody() + info.body_size; ++cursor) | 420 for (; cursor < info.RawBody() + info.body_size; ++cursor) |
419 EXPECT_TRUE(test_shadow.IsAccessible(cursor)); | 421 EXPECT_TRUE(test_shadow.IsAccessible(cursor)); |
420 for (; cursor < info.RawHeader() + info.block_size; ++cursor) | 422 for (; cursor < info.RawHeader() + info.block_size; ++cursor) |
421 EXPECT_FALSE(test_shadow.IsAccessible(cursor)); | 423 EXPECT_FALSE(test_shadow.IsAccessible(cursor)); |
422 test_shadow.Unpoison(info.RawBlock(), info.block_size); | 424 test_shadow.Unpoison(info.RawBlock(), info.block_size); |
423 | 425 |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 block_count++; | 985 block_count++; |
984 } | 986 } |
985 EXPECT_EQ(block_info_vec.size(), block_count); | 987 EXPECT_EQ(block_info_vec.size(), block_count); |
986 EXPECT_FALSE(w.Next(&i)); | 988 EXPECT_FALSE(w.Next(&i)); |
987 | 989 |
988 EXPECT_GT(::VirtualFree(shadow_memory, 0, MEM_RELEASE), 0U); | 990 EXPECT_GT(::VirtualFree(shadow_memory, 0, MEM_RELEASE), 0U); |
989 } | 991 } |
990 | 992 |
991 } // namespace asan | 993 } // namespace asan |
992 } // namespace agent | 994 } // namespace agent |
OLD | NEW |