Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 #include "wtf/build_config.h" | 42 #include "wtf/build_config.h" |
| 43 #include <stdarg.h> | 43 #include <stdarg.h> |
| 44 | 44 |
| 45 #if OS(WIN) | 45 #if OS(WIN) |
| 46 #include <windows.h> | 46 #include <windows.h> |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code | 49 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code |
| 50 // testing this macro has included this header. | 50 // testing this macro has included this header. |
| 51 #ifndef ENABLE_ASSERT | 51 #ifndef ENABLE_ASSERT |
| 52 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 52 #define ENABLE_ASSERT DCHECK_IS_ON() |
| 53 /* Disable ASSERT* macros in release mode by default. */ | |
| 54 #define ENABLE_ASSERT 0 | |
| 55 #else | |
| 56 #define ENABLE_ASSERT 1 | |
| 57 #endif /* defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) */ | |
| 58 #endif | 53 #endif |
| 59 | 54 |
| 60 #ifndef LOG_DISABLED | 55 #ifndef LOG_DISABLED |
| 61 #define LOG_DISABLED !ENABLE(ASSERT) | 56 #define LOG_DISABLED !ENABLE(ASSERT) |
| 62 #endif | 57 #endif |
| 63 | 58 |
| 64 // These helper functions are always declared, but not necessarily always | 59 // These helper functions are always declared, but not necessarily always |
| 65 // defined if the corresponding function is disabled. | 60 // defined if the corresponding function is disabled. |
| 66 | 61 |
| 67 WTF_EXPORT void WTFReportAssertionFailure(const char* file, | 62 WTF_EXPORT void WTFReportAssertionFailure(const char* file, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 } // namespace WTF | 126 } // namespace WTF |
| 132 | 127 |
| 133 // CRASH() - Raises a fatal error resulting in program termination and | 128 // CRASH() - Raises a fatal error resulting in program termination and |
| 134 // triggering either the debugger or the crash reporter. | 129 // triggering either the debugger or the crash reporter. |
| 135 // | 130 // |
| 136 // Use CRASH() in response to known, unrecoverable errors like out-of-memory. | 131 // Use CRASH() in response to known, unrecoverable errors like out-of-memory. |
| 137 // Macro is enabled in both debug and release mode. | 132 // Macro is enabled in both debug and release mode. |
| 138 // To test for unknown errors and verify assumptions, use ASSERT instead, to | 133 // To test for unknown errors and verify assumptions, use ASSERT instead, to |
| 139 // avoid impacting performance in release builds. | 134 // avoid impacting performance in release builds. |
| 140 #ifndef CRASH | 135 #ifndef CRASH |
| 141 #if COMPILER(MSVC) | 136 #define CRASH() IMMEDIATE_CRASH() |
| 142 #define CRASH() (__debugbreak(), IMMEDIATE_CRASH()) | |
| 143 #else | |
| 144 #define CRASH() (WTFReportBacktrace(), IMMEDIATE_CRASH()) | |
| 145 #endif | |
| 146 #endif | 137 #endif |
| 147 | 138 |
| 148 // ASSERT and ASSERT_NOT_REACHED | 139 // ASSERT and ASSERT_NOT_REACHED |
| 149 // These macros are compiled out of release builds. | 140 // These macros are compiled out of release builds. |
| 150 // Expressions inside them are evaluated in debug builds only. | 141 // Expressions inside them are evaluated in debug builds only. |
| 151 // They are deprecated. We should use: | 142 // They are deprecated. We should use: |
| 152 // - DCHECK() for ASSERT() | 143 // - DCHECK() for ASSERT() |
| 153 // - NOTREACHED() for ASSERT_NOT_REACHED() | 144 // - NOTREACHED() for ASSERT_NOT_REACHED() |
| 154 #if OS(WIN) | 145 #if OS(WIN) |
| 155 // FIXME: Change to use something other than ASSERT to avoid this conflict with | 146 // FIXME: Change to use something other than ASSERT to avoid this conflict with |
| 156 // the underlying platform. | 147 // the underlying platform. |
| 157 #undef ASSERT | 148 #undef ASSERT |
| 158 #endif | 149 #endif |
| 159 | 150 |
| 160 #define DCHECK_AT(assertion, file, line) \ | 151 #define DCHECK_AT(assertion, file, line) \ |
| 161 LAZY_STREAM(logging::LogMessage(file, line, #assertion).stream(), \ | 152 LAZY_STREAM(logging::LogMessage(file, line, #assertion).stream(), \ |
| 162 DCHECK_IS_ON() ? !(assertion) : false) | 153 DCHECK_IS_ON() ? !(assertion) : false) |
| 163 | 154 |
| 164 #if ENABLE(ASSERT) | 155 #if ENABLE(ASSERT) |
| 165 | 156 #define ASSERT(assertion) DCHECK(assertion) |
| 166 #define ASSERT(assertion) \ | 157 #define ASSERT_NOT_REACHED() NOTREACHED() |
| 167 (!(assertion) ? (WTFReportAssertionFailure(__FILE__, __LINE__, \ | |
| 168 WTF_PRETTY_FUNCTION, #assertion), \ | |
| 169 CRASH()) \ | |
| 170 : (void)0) | |
| 171 | |
| 172 #define ASSERT_NOT_REACHED() \ | |
| 173 do { \ | |
| 174 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \ | |
|
tkent
2017/01/13 00:17:40
We can remove WTFReportAssertionFailure.
Wez
2017/01/13 21:18:54
Oh, good point! Removed that and WTFReportBacktrac
| |
| 175 CRASH(); \ | |
| 176 } while (0) | |
| 177 | |
| 178 #else | 158 #else |
| 179 | |
| 180 #define ASSERT(assertion) ((void)0) | 159 #define ASSERT(assertion) ((void)0) |
| 181 #define ASSERT_NOT_REACHED() ((void)0) | 160 #define ASSERT_NOT_REACHED() ((void)0) |
| 182 | |
| 183 #endif | 161 #endif |
| 184 | 162 |
| 185 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure | 163 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure |
| 186 // that code testing this macro has included this header. | 164 // that code testing this macro has included this header. |
| 187 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT) | 165 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT) |
| 188 #define ENABLE_SECURITY_ASSERT 1 | 166 #define ENABLE_SECURITY_ASSERT 1 |
| 189 #else | 167 #else |
| 190 #define ENABLE_SECURITY_ASSERT 0 | 168 #define ENABLE_SECURITY_ASSERT 0 |
| 191 #endif | 169 #endif |
| 192 | 170 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 205 #else | 183 #else |
| 206 #define SECURITY_DCHECK(condition) ((void)0) | 184 #define SECURITY_DCHECK(condition) ((void)0) |
| 207 #define SECURITY_CHECK(condition) CHECK(condition) | 185 #define SECURITY_CHECK(condition) CHECK(condition) |
| 208 #endif | 186 #endif |
| 209 | 187 |
| 210 // RELEASE_ASSERT | 188 // RELEASE_ASSERT |
| 211 // Use in places where failure of an assertion indicates a definite security | 189 // Use in places where failure of an assertion indicates a definite security |
| 212 // vulnerability from which execution must not continue even in a release build. | 190 // vulnerability from which execution must not continue even in a release build. |
| 213 // Please sure to file bugs for these failures using the security template: | 191 // Please sure to file bugs for these failures using the security template: |
| 214 // http://code.google.com/p/chromium/issues/entry?template=Security%20Bug | 192 // http://code.google.com/p/chromium/issues/entry?template=Security%20Bug |
| 215 // | 193 #if defined(ADDRESS_SANITIZER) |
| 216 // WARNING: CHECK is slower than RELEASE_ASSERT on MSVC. We should not replace | |
| 217 // RELEASE_ASSERT with CHECK until the performance issue is fixed | |
| 218 // (crbug.com/596760). | |
| 219 #if ENABLE(ASSERT) | |
| 220 #define RELEASE_ASSERT(assertion) ASSERT(assertion) | |
| 221 #elif defined(ADDRESS_SANITIZER) | |
| 222 #define RELEASE_ASSERT(condition) SECURITY_CHECK(condition) | 194 #define RELEASE_ASSERT(condition) SECURITY_CHECK(condition) |
| 223 #else | 195 #else |
| 224 #define RELEASE_ASSERT(assertion) \ | 196 #define RELEASE_ASSERT(condition) CHECK(condition) |
| 225 (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0) | |
| 226 #endif | 197 #endif |
| 227 | 198 |
| 228 // DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES | 199 // DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES |
| 229 // Allow equality comparisons of Objects by reference or pointer, | 200 // Allow equality comparisons of Objects by reference or pointer, |
| 230 // interchangeably. This can be only used on types whose equality makes no | 201 // interchangeably. This can be only used on types whose equality makes no |
| 231 // other sense than pointer equality. | 202 // other sense than pointer equality. |
| 232 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \ | 203 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \ |
| 233 inline bool operator==(const thisType& a, const thisType& b) { \ | 204 inline bool operator==(const thisType& a, const thisType& b) { \ |
| 234 return &a == &b; \ | 205 return &a == &b; \ |
| 235 } \ | 206 } \ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 return static_cast<thisType&>(argument); \ | 263 return static_cast<thisType&>(argument); \ |
| 293 } \ | 264 } \ |
| 294 inline const thisType& to##thisType##OrDie(const argumentType& argument) { \ | 265 inline const thisType& to##thisType##OrDie(const argumentType& argument) { \ |
| 295 CHECK(referencePredicate); \ | 266 CHECK(referencePredicate); \ |
| 296 return static_cast<const thisType&>(argument); \ | 267 return static_cast<const thisType&>(argument); \ |
| 297 } \ | 268 } \ |
| 298 void to##thisType##OrDie(const thisType*); \ | 269 void to##thisType##OrDie(const thisType*); \ |
| 299 void to##thisType##OrDie(const thisType&) | 270 void to##thisType##OrDie(const thisType&) |
| 300 | 271 |
| 301 #endif // WTF_Assertions_h | 272 #endif // WTF_Assertions_h |
| OLD | NEW |