| 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 // Protected functions that we want to unittest directly. | 88 // Protected functions that we want to unittest directly. |
| 94 using Shadow::Reset; | 89 using Shadow::Reset; |
| 95 using Shadow::ScanLeftForBracketingBlockStart; | 90 using Shadow::ScanLeftForBracketingBlockStart; |
| 96 using Shadow::ScanRightForBracketingBlockEnd; | 91 using Shadow::ScanRightForBracketingBlockEnd; |
| 97 using Shadow::shadow_; | 92 using Shadow::shadow_; |
| 98 }; | 93 }; |
| 99 | 94 |
| 100 // A fixture for shadow memory tests. | 95 // A fixture for shadow memory tests. |
| 101 class ShadowTest : public testing::Test { | 96 class ShadowTest : public testing::Test { |
| 102 public: | 97 public: |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 2 * 8), | 395 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 2 * 8), |
| 401 kHeapLeftPaddingMarker); | 396 kHeapLeftPaddingMarker); |
| 402 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 3 * 8), | 397 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 3 * 8), |
| 403 0); | 398 0); |
| 404 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 4 * 8), | 399 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 4 * 8), |
| 405 7); | 400 7); |
| 406 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 5 * 8), | 401 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 5 * 8), |
| 407 kHeapRightPaddingMarker); | 402 kHeapRightPaddingMarker); |
| 408 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 6 * 8), | 403 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 6 * 8), |
| 409 kHeapRightPaddingMarker); | 404 kHeapRightPaddingMarker); |
| 405 #ifndef _WIN64 |
| 410 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 7 * 8), | 406 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 7 * 8), |
| 411 kHeapBlockEndMarker); | 407 kHeapBlockEndMarker); |
| 408 #else |
| 409 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 7 * 8), |
| 410 kHeapRightPaddingMarker); |
| 411 EXPECT_EQ(test_shadow.GetShadowMarkerForAddress(data + 8 * 8), |
| 412 kHeapBlockEndMarker); |
| 413 #endif |
| 412 | 414 |
| 413 uint8_t* cursor = info.RawHeader(); | 415 uint8_t* cursor = info.RawHeader(); |
| 414 for (; cursor < info.RawBody(); ++cursor) | 416 for (; cursor < info.RawBody(); ++cursor) |
| 415 EXPECT_FALSE(test_shadow.IsAccessible(cursor)); | 417 EXPECT_FALSE(test_shadow.IsAccessible(cursor)); |
| 416 for (; cursor < info.RawBody() + info.body_size; ++cursor) | 418 for (; cursor < info.RawBody() + info.body_size; ++cursor) |
| 417 EXPECT_TRUE(test_shadow.IsAccessible(cursor)); | 419 EXPECT_TRUE(test_shadow.IsAccessible(cursor)); |
| 418 for (; cursor < info.RawHeader() + info.block_size; ++cursor) | 420 for (; cursor < info.RawHeader() + info.block_size; ++cursor) |
| 419 EXPECT_FALSE(test_shadow.IsAccessible(cursor)); | 421 EXPECT_FALSE(test_shadow.IsAccessible(cursor)); |
| 420 test_shadow.Unpoison(info.RawBlock(), info.block_size); | 422 test_shadow.Unpoison(info.RawBlock(), info.block_size); |
| 421 | 423 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 EXPECT_EQ(0, ::memcmp(&i, &i2, sizeof(i))); | 917 EXPECT_EQ(0, ::memcmp(&i, &i2, sizeof(i))); |
| 916 EXPECT_FALSE(w1.Next(&i)); | 918 EXPECT_FALSE(w1.Next(&i)); |
| 917 EXPECT_EQ(-1, w1.nesting_depth()); | 919 EXPECT_EQ(-1, w1.nesting_depth()); |
| 918 | 920 |
| 919 test_shadow.Unpoison(data, data_size); | 921 test_shadow.Unpoison(data, data_size); |
| 920 delete [] data; | 922 delete [] data; |
| 921 } | 923 } |
| 922 | 924 |
| 923 } // namespace asan | 925 } // namespace asan |
| 924 } // namespace agent | 926 } // namespace agent |
| OLD | NEW |