Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 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 13 matching lines...) Expand all Loading... | |
| 24 namespace testing { | 24 namespace testing { | 
| 25 | 25 | 
| 26 // Disable the intrinsic versions of the intercepted functions. | 26 // Disable the intrinsic versions of the intercepted functions. | 
| 27 #pragma function(memset, memcpy, strlen, strcmp) | 27 #pragma function(memset, memcpy, strlen, strcmp) | 
| 28 | 28 | 
| 29 // Helper function to make sure that a memory read access doesn't get | 29 // Helper function to make sure that a memory read access doesn't get | 
| 30 // instrumented. | 30 // instrumented. | 
| 31 // @tparam type The type of the value to be read. | 31 // @tparam type The type of the value to be read. | 
| 32 // @param location The location where to read from. | 32 // @param location The location where to read from. | 
| 33 // @returns the value at |location| | 33 // @returns the value at |location| | 
| 34 template<typename type> | 34 template <typename type> | 
| 35 #if defined(__clang__) | |
| 36 type __attribute__((no_sanitize_address)) NonInterceptedRead(type* location) { | |
| 37 #else | |
| 35 type NonInterceptedRead(type* location) { | 38 type NonInterceptedRead(type* location) { | 
| 39 #endif | |
| 36 // The try-except statement prevents the function from being instrumented. | 40 // The try-except statement prevents the function from being instrumented. | 
| 37 __try { | 41 __try { | 
| 38 return *location; | 42 return *location; | 
| 
 
chrisha
2017/08/30 16:55:32
You don't need the try/except for the Clang versio
 
 | |
| 39 } __except(EXCEPTION_CONTINUE_SEARCH) { | 43 } __except(EXCEPTION_CONTINUE_SEARCH) { | 
| 40 // Nothing to do here. | 44 // Nothing to do here. | 
| 41 } | 45 } | 
| 42 return static_cast<type>(0); | 46 return static_cast<type>(0); | 
| 43 } | 47 } | 
| 44 | 48 | 
| 45 // Helper function to do non instrumented reads from an array. | 49 // Helper function to do non instrumented reads from an array. | 
| 46 // @tparam type The type of the values to be read. | 50 // @tparam type The type of the values to be read. | 
| 47 // @param src The array where to read from. | 51 // @param src The array where to read from. | 
| 48 // @param size The size of the array. | 52 // @param size The size of the array. | 
| 49 // @param dst The destination array. | 53 // @param dst The destination array. | 
| 50 template<typename type> | 54 template<typename type> | 
| 51 void NonInterceptedReads(type* src, size_t size, type* dst) { | 55 void NonInterceptedReads(type* src, size_t size, type* dst) { | 
| 52 for (size_t i = 0; i < size; ++i) | 56 for (size_t i = 0; i < size; ++i) | 
| 53 *dst++ = NonInterceptedRead(src + i); | 57 *dst++ = NonInterceptedRead(src + i); | 
| 54 } | 58 } | 
| 55 | 59 | 
| 56 // Helper function to make sure that a memory write access didn't get | 60 // Helper function to make sure that a memory write access didn't get | 
| 57 // instrumented. | 61 // instrumented. | 
| 58 // @tparam type The type of the value to be written. | 62 // @tparam type The type of the value to be written. | 
| 59 // @param location The location where to write to. | 63 // @param location The location where to write to. | 
| 60 // @param val The value to write. | 64 // @param val The value to write. | 
| 61 template<typename type> | 65 template <typename type> | 
| 66 #if defined(__clang__) | |
| 67 void __attribute__((no_sanitize_address)) | |
| 68 NonInterceptedWrite(type* location, type val) { | |
| 69 *location = val; | |
| 70 } | |
| 71 #else | |
| 62 void NonInterceptedWrite(type* location, type val) { | 72 void NonInterceptedWrite(type* location, type val) { | 
| 63 // The try-except statement prevents the function from being instrumented. | 73 // The try-except statement prevents the function from being instrumented. | 
| 64 __try { | 74 __try { | 
| 65 *location = val; | 75 *location = val; | 
| 66 } __except(EXCEPTION_CONTINUE_SEARCH) { | 76 } __except(EXCEPTION_CONTINUE_SEARCH) { | 
| 67 // Nothing to do here. | 77 // Nothing to do here. | 
| 68 } | 78 } | 
| 69 } | 79 } | 
| 80 #endif | |
| 70 | 81 | 
| 71 // Helper function to do non instrumented writes from an array. | 82 // Helper function to do non instrumented writes from an array. | 
| 72 // @tparam type The type of the values to be written. | 83 // @tparam type The type of the values to be written. | 
| 73 // @param src The array where to read from. | 84 // @param src The array where to read from. | 
| 74 // @param size The size of the array. | 85 // @param size The size of the array. | 
| 75 // @param dst The address where to write to. | 86 // @param dst The address where to write to. | 
| 76 template<typename type> | 87 template<typename type> | 
| 77 void NonInterceptedWrites(type* src, size_t size, type* dst) { | 88 void NonInterceptedWrites(type* src, size_t size, type* dst) { | 
| 78 for (size_t i = 0; i < size; ++i) | 89 for (size_t i = 0; i < size; ++i) | 
| 79 NonInterceptedWrite(dst++, src[i]); | 90 NonInterceptedWrite(dst++, src[i]); | 
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 // "uninstrumented" tests will cause an access violation exception to be thrown. | 471 // "uninstrumented" tests will cause an access violation exception to be thrown. | 
| 461 size_t AsanNearNullptrAccessHeapCorruptionInstrumented(); | 472 size_t AsanNearNullptrAccessHeapCorruptionInstrumented(); | 
| 462 size_t AsanNearNullptrAccessHeapCorruptionUninstrumented(); | 473 size_t AsanNearNullptrAccessHeapCorruptionUninstrumented(); | 
| 463 size_t AsanNearNullptrAccessNoHeapCorruptionInstrumented(); | 474 size_t AsanNearNullptrAccessNoHeapCorruptionInstrumented(); | 
| 464 size_t AsanNearNullptrAccessNoHeapCorruptionUninstrumented(); | 475 size_t AsanNearNullptrAccessNoHeapCorruptionUninstrumented(); | 
| 465 size_t AsanNullptrAccessNoHeapCorruptionUninstrumented(); | 476 size_t AsanNullptrAccessNoHeapCorruptionUninstrumented(); | 
| 466 | 477 | 
| 467 } // namespace testing | 478 } // namespace testing | 
| 468 | 479 | 
| 469 #endif // SYZYGY_INTEGRATION_TESTS_ASAN_INTERCEPTORS_TESTS_H_ | 480 #endif // SYZYGY_INTEGRATION_TESTS_ASAN_INTERCEPTORS_TESTS_H_ | 
| OLD | NEW |