| ... | ... | @@ -208,19 +208,16 @@ |
| 208 | 208 | |
| 209 | 209 | // HARDENING { |
| 210 | 210 | |
| 211 | | // TODO(hardening): remove this in LLVM 18. |
| 212 | | // This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) |
| 213 | | // equivalent to setting the hardened mode. |
| 214 | | # ifdef _LIBCPP_ENABLE_ASSERTIONS |
| 215 | | # warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_ENABLE_HARDENED_MODE instead." |
| 216 | | # if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 |
| 217 | | # error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" |
| 218 | | # endif |
| 219 | | # if _LIBCPP_ENABLE_ASSERTIONS |
| 220 | | # define _LIBCPP_ENABLE_HARDENED_MODE 1 |
| 221 | | # endif |
| 211 | # ifndef _LIBCPP_ENABLE_ASSERTIONS |
| 212 | # define _LIBCPP_ENABLE_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS_DEFAULT |
| 213 | # endif |
| 214 | # if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 |
| 215 | # error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" |
| 222 | 216 | # endif |
| 223 | 217 | |
| 218 | // NOTE: These modes are experimental and are not stable yet in LLVM 17. Please refrain from using them and use the |
| 219 | // documented libc++ "safe" mode instead. |
| 220 | // |
| 224 | 221 | // Enables the hardened mode which consists of all checks intended to be used in production. Hardened mode prioritizes |
| 225 | 222 | // security-critical checks that can be done with relatively little overhead in constant time. Mutually exclusive with |
| 226 | 223 | // `_LIBCPP_ENABLE_DEBUG_MODE`. |
| ... | ... | @@ -275,6 +272,11 @@ |
| 275 | 272 | # error "Only one of _LIBCPP_ENABLE_HARDENED_MODE and _LIBCPP_ENABLE_DEBUG_MODE can be enabled." |
| 276 | 273 | # endif |
| 277 | 274 | |
| 275 | # if _LIBCPP_ENABLE_ASSERTIONS && (_LIBCPP_ENABLE_HARDENED_MODE || _LIBCPP_ENABLE_DEBUG_MODE) |
| 276 | # error \ |
| 277 | "_LIBCPP_ENABLE_ASSERTIONS is mutually exclusive with _LIBCPP_ENABLE_HARDENED_MODE and _LIBCPP_ENABLE_DEBUG_MODE." |
| 278 | # endif |
| 279 | |
| 278 | 280 | // Hardened mode checks. |
| 279 | 281 | |
| 280 | 282 | // clang-format off |
| ... | ... | @@ -303,6 +305,18 @@ |
| 303 | 305 | # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) |
| 304 | 306 | # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) |
| 305 | 307 | |
| 308 | // Safe mode checks. |
| 309 | |
| 310 | # elif _LIBCPP_ENABLE_ASSERTIONS |
| 311 | |
| 312 | // All checks enabled. |
| 313 | # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) |
| 314 | # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) |
| 315 | # define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) |
| 316 | # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) |
| 317 | # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) |
| 318 | # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) |
| 319 | |
| 306 | 320 | // Disable all checks if hardening is not enabled. |
| 307 | 321 | |
| 308 | 322 | # else |