1*e3723e1fSApple OSS Distributions /*===---- ptrcheck.h - Pointer bounds hints & specifications ----------------=== 2*e3723e1fSApple OSS Distributions * 3*e3723e1fSApple OSS Distributions * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*e3723e1fSApple OSS Distributions * See https://llvm.org/LICENSE.txt for license information. 5*e3723e1fSApple OSS Distributions * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*e3723e1fSApple OSS Distributions * 7*e3723e1fSApple OSS Distributions *===-----------------------------------------------------------------------=== 8*e3723e1fSApple OSS Distributions */ 9*e3723e1fSApple OSS Distributions 10*e3723e1fSApple OSS Distributions #ifndef __PTRCHECK_H 11*e3723e1fSApple OSS Distributions #define __PTRCHECK_H 12*e3723e1fSApple OSS Distributions 13*e3723e1fSApple OSS Distributions /* __has_ptrcheck can be used in preprocessor macros (and other parts of the 14*e3723e1fSApple OSS Distributions language expecting constant expressions) to test if bounds attributes 15*e3723e1fSApple OSS Distributions exist. */ 16*e3723e1fSApple OSS Distributions #if defined(__has_feature) && __has_feature(bounds_attributes) 17*e3723e1fSApple OSS Distributions #define __has_ptrcheck 1 18*e3723e1fSApple OSS Distributions #else 19*e3723e1fSApple OSS Distributions #define __has_ptrcheck 0 20*e3723e1fSApple OSS Distributions #endif 21*e3723e1fSApple OSS Distributions 22*e3723e1fSApple OSS Distributions #if __has_ptrcheck 23*e3723e1fSApple OSS Distributions 24*e3723e1fSApple OSS Distributions /* An attribute that modifies a pointer type such that its ABI is three pointer 25*e3723e1fSApple OSS Distributions components: the pointer value itself (the pointer value); one-past-the-end of 26*e3723e1fSApple OSS Distributions the object it is derived from (the upper bound); and the base address of the 27*e3723e1fSApple OSS Distributions object it is derived from (the lower bound). The pointer value is allowed to 28*e3723e1fSApple OSS Distributions lie outside the [lower bound, upper bound) interval, and it supports the 29*e3723e1fSApple OSS Distributions entire range of arithmetic operations that are usually applicable to 30*e3723e1fSApple OSS Distributions pointers. Bounds are implicitly checked only when the pointer is dereferenced 31*e3723e1fSApple OSS Distributions or converted to a different representation. */ 32*e3723e1fSApple OSS Distributions #define __bidi_indexable __attribute__((__bidi_indexable__)) 33*e3723e1fSApple OSS Distributions 34*e3723e1fSApple OSS Distributions /* An attribute that modifies a pointer type such that its ABI is two pointer 35*e3723e1fSApple OSS Distributions components: the pointer value itself (the lower bound); and one-past-the-end 36*e3723e1fSApple OSS Distributions of the object it is derived from (the upper bound). Indexable pointers do not 37*e3723e1fSApple OSS Distributions support negative arithmetic operations: it is a compile-time error to use a 38*e3723e1fSApple OSS Distributions subtraction or add a negative quantity to them, and it is a runtime error if 39*e3723e1fSApple OSS Distributions the same happens at runtime while it can't be detected at compile-time. Same 40*e3723e1fSApple OSS Distributions as __bidi_indexable pointers, __indexable pointers are bounds-checked when 41*e3723e1fSApple OSS Distributions dereferenced or converted to another representation. */ 42*e3723e1fSApple OSS Distributions #define __indexable __attribute__((__indexable__)) 43*e3723e1fSApple OSS Distributions 44*e3723e1fSApple OSS Distributions /* An attribute that modifies a pointer type such than it has the ABI of a 45*e3723e1fSApple OSS Distributions regular C pointer, without allowing pointer arithmetic. Pointer arithmetic is 46*e3723e1fSApple OSS Distributions a compile-time error. A __single pointer is expected to be either NULL or 47*e3723e1fSApple OSS Distributions point to exactly one valid value. */ 48*e3723e1fSApple OSS Distributions #define __single __attribute__((__single__)) 49*e3723e1fSApple OSS Distributions 50*e3723e1fSApple OSS Distributions /* An attribute that modifies a pointer type such than it can be used exactly 51*e3723e1fSApple OSS Distributions like a regular C pointer, with unchecked arithmetic and dereferencing. An 52*e3723e1fSApple OSS Distributions __unsafe_indexable pointer cannot convert implicitly to another type of 53*e3723e1fSApple OSS Distributions pointer since that would require information that is not available to the 54*e3723e1fSApple OSS Distributions program. You must use __unsafe_forge_bidi_indexable or __unsafe_forge_single 55*e3723e1fSApple OSS Distributions to convert __unsafe_indexable pointers to so-called safe pointers. */ 56*e3723e1fSApple OSS Distributions #define __unsafe_indexable __attribute__((__unsafe_indexable__)) 57*e3723e1fSApple OSS Distributions 58*e3723e1fSApple OSS Distributions /* An attribute that modifies a pointer type such that it has the ABI of a 59*e3723e1fSApple OSS Distributions regular C pointer, but it implicitly converts to a __bidi_indexable pointer 60*e3723e1fSApple OSS Distributions with bounds that assume there are N valid elements starting at its address. 61*e3723e1fSApple OSS Distributions The conversion happens at the same point the object converts to an rvalue, or 62*e3723e1fSApple OSS Distributions immediately for values which cannot be lvalues (such as function calls). */ 63*e3723e1fSApple OSS Distributions 64*e3723e1fSApple OSS Distributions /* Assignments to the pointer object must be accompanied with an assignment to 65*e3723e1fSApple OSS Distributions N if it is assignable. */ 66*e3723e1fSApple OSS Distributions 67*e3723e1fSApple OSS Distributions /* N must either be an expression that evaluates to a constant, or an integer 68*e3723e1fSApple OSS Distributions declaration from the same scope, or (for structure fields) a declaration 69*e3723e1fSApple OSS Distributions contained in basic arithmetic. */ 70*e3723e1fSApple OSS Distributions #define __counted_by(N) __attribute__((__counted_by__(N))) 71*e3723e1fSApple OSS Distributions 72*e3723e1fSApple OSS Distributions /* Identical to __counted_by(N), aside that the pointer may be null for 73*e3723e1fSApple OSS Distributions * non-zero values of N. */ 74*e3723e1fSApple OSS Distributions #define __counted_by_or_null(N) __attribute__((__counted_by_or_null__(N))) 75*e3723e1fSApple OSS Distributions 76*e3723e1fSApple OSS Distributions /* Identical to __counted_by(N), aside that N is a byte count instead of an 77*e3723e1fSApple OSS Distributions object count. */ 78*e3723e1fSApple OSS Distributions #define __sized_by(N) __attribute__((__sized_by__(N))) 79*e3723e1fSApple OSS Distributions 80*e3723e1fSApple OSS Distributions /* Identical to __sized_by(N), aside that the pointer may be null for non-zero 81*e3723e1fSApple OSS Distributions * values of N. */ 82*e3723e1fSApple OSS Distributions #define __sized_by_or_null(N) __attribute__((__sized_by_or_null__(N))) 83*e3723e1fSApple OSS Distributions 84*e3723e1fSApple OSS Distributions /* An attribute that modifies a pointer type such that it has the ABI of a 85*e3723e1fSApple OSS Distributions regular C pointer, but it implicitly converts to a __bidi_indexable pointer 86*e3723e1fSApple OSS Distributions with bounds that assume that E is one-past-the-end of the original object. 87*e3723e1fSApple OSS Distributions Implicitly, referencing E in the same scope will create a pointer that 88*e3723e1fSApple OSS Distributions converts to a __bidi_indexable pointer one-past-the-end of the original 89*e3723e1fSApple OSS Distributions object, but with a lower bound set to the value of the pointer that is 90*e3723e1fSApple OSS Distributions attributed. */ 91*e3723e1fSApple OSS Distributions 92*e3723e1fSApple OSS Distributions /* Assignments to the pointer object must be accompanied with an assignment to 93*e3723e1fSApple OSS Distributions E if it is assignable. */ 94*e3723e1fSApple OSS Distributions #define __ended_by(E) __attribute__((__ended_by__(E))) 95*e3723e1fSApple OSS Distributions 96*e3723e1fSApple OSS Distributions /* The __terminated_by(T) attribute can be applied to arrays and pointers. The 97*e3723e1fSApple OSS Distributions argument T specifies the terminator and must be an integer constant 98*e3723e1fSApple OSS Distributions expression. Even though T has to be an integer constant, __terminated_by(T) 99*e3723e1fSApple OSS Distributions can be applied to pointer arrays as well. For convenience, the 100*e3723e1fSApple OSS Distributions __null_terminated macro is provided, which is equivalent to 101*e3723e1fSApple OSS Distributions __terminated_by(0). 102*e3723e1fSApple OSS Distributions 103*e3723e1fSApple OSS Distributions The __terminated_by(T) attribute can be applied only to __single pointers. If 104*e3723e1fSApple OSS Distributions the pointer attribute is not specified, it is automatically set to __single. 105*e3723e1fSApple OSS Distributions A __terminated_by(T) pointer points to the first element of an array that is 106*e3723e1fSApple OSS Distributions terminated with T. 107*e3723e1fSApple OSS Distributions 108*e3723e1fSApple OSS Distributions Arithmetic on __terminated_by(T) pointers is restricted to only incrementing 109*e3723e1fSApple OSS Distributions the pointer by one, and must be able to be evaluated at compile-time. 110*e3723e1fSApple OSS Distributions Pointer arithmetic generates a runtime check to ensure that the pointer 111*e3723e1fSApple OSS Distributions doesn't point pass the terminator. 112*e3723e1fSApple OSS Distributions 113*e3723e1fSApple OSS Distributions A __terminated_by(T) pointer has the ABI of a regular C pointer. 114*e3723e1fSApple OSS Distributions 115*e3723e1fSApple OSS Distributions When __terminated_by(T) is applied to an array, the compiler checks if the 116*e3723e1fSApple OSS Distributions array is terminated with the given terminator T during the initialization. 117*e3723e1fSApple OSS Distributions Moreover, a __terminated_by(T) array decays to a __terminated_by(T) __single 118*e3723e1fSApple OSS Distributions pointer, instead of decaying to a __bidi_indexable pointer. */ 119*e3723e1fSApple OSS Distributions #define __terminated_by(T) __attribute__((__terminated_by__(T))) 120*e3723e1fSApple OSS Distributions #define __null_terminated __terminated_by(0) 121*e3723e1fSApple OSS Distributions 122*e3723e1fSApple OSS Distributions /* Directives that tells the compiler to assume that subsequent pointer types 123*e3723e1fSApple OSS Distributions have the ABI specified by the ABI parameter, which may be one of single, 124*e3723e1fSApple OSS Distributions indexable, bidi_indexable or unsafe_indexable. */ 125*e3723e1fSApple OSS Distributions 126*e3723e1fSApple OSS Distributions /* In project files, the ABI is assumed to be single by default. In headers 127*e3723e1fSApple OSS Distributions included from libraries or the SDK, the ABI is assumed to be unsafe_indexable 128*e3723e1fSApple OSS Distributions by default. */ 129*e3723e1fSApple OSS Distributions #define __ptrcheck_abi_assume_single() \ 130*e3723e1fSApple OSS Distributions _Pragma("clang abi_ptr_attr set(single)") 131*e3723e1fSApple OSS Distributions 132*e3723e1fSApple OSS Distributions #define __ptrcheck_abi_assume_indexable() \ 133*e3723e1fSApple OSS Distributions _Pragma("clang abi_ptr_attr set(indexable)") 134*e3723e1fSApple OSS Distributions 135*e3723e1fSApple OSS Distributions #define __ptrcheck_abi_assume_bidi_indexable() \ 136*e3723e1fSApple OSS Distributions _Pragma("clang abi_ptr_attr set(bidi_indexable)") 137*e3723e1fSApple OSS Distributions 138*e3723e1fSApple OSS Distributions #define __ptrcheck_abi_assume_unsafe_indexable() \ 139*e3723e1fSApple OSS Distributions _Pragma("clang abi_ptr_attr set(unsafe_indexable)") 140*e3723e1fSApple OSS Distributions 141*e3723e1fSApple OSS Distributions /* Create a __bidi_indexable pointer of a given pointer type (T), starting at 142*e3723e1fSApple OSS Distributions address P, pointing to S bytes of valid memory. T must be a pointer type. */ 143*e3723e1fSApple OSS Distributions #define __unsafe_forge_bidi_indexable(T, P, S) \ 144*e3723e1fSApple OSS Distributions ((T __bidi_indexable)__builtin_unsafe_forge_bidi_indexable((P), (S))) 145*e3723e1fSApple OSS Distributions 146*e3723e1fSApple OSS Distributions /* Create a __single pointer of a given type (T), starting at address P. T must 147*e3723e1fSApple OSS Distributions be a pointer type. */ 148*e3723e1fSApple OSS Distributions #define __unsafe_forge_single(T, P) \ 149*e3723e1fSApple OSS Distributions ((T __single)__builtin_unsafe_forge_single((P))) 150*e3723e1fSApple OSS Distributions 151*e3723e1fSApple OSS Distributions /* Create a __terminated_by pointer of a given pointer type (T), starting at 152*e3723e1fSApple OSS Distributions address P, terminated by E. T must be a pointer type. */ 153*e3723e1fSApple OSS Distributions #define __unsafe_forge_terminated_by(T, P, E) \ 154*e3723e1fSApple OSS Distributions ((T __terminated_by(E))__builtin_unsafe_forge_terminated_by((P), (E))) 155*e3723e1fSApple OSS Distributions 156*e3723e1fSApple OSS Distributions /* Create a __terminated_by pointer of a given pointer type (T), starting at 157*e3723e1fSApple OSS Distributions address P, terminated by 0. T must be a pointer type. */ 158*e3723e1fSApple OSS Distributions #define __unsafe_forge_null_terminated(T, P) __unsafe_forge_terminated_by(T, P, 0) 159*e3723e1fSApple OSS Distributions 160*e3723e1fSApple OSS Distributions /* Create a wide pointer with the same lower bound and upper bounds as X, but 161*e3723e1fSApple OSS Distributions with a pointer component also equal to the lower bound. */ 162*e3723e1fSApple OSS Distributions #define __ptr_lower_bound(X) __builtin_get_pointer_lower_bound(X) 163*e3723e1fSApple OSS Distributions 164*e3723e1fSApple OSS Distributions /* Create a wide pointer with the same lower bound and upper bounds as X, but 165*e3723e1fSApple OSS Distributions with a pointer component also equal to the upper bound. */ 166*e3723e1fSApple OSS Distributions #define __ptr_upper_bound(X) __builtin_get_pointer_upper_bound(X) 167*e3723e1fSApple OSS Distributions 168*e3723e1fSApple OSS Distributions /* Convert a __terminated_by(T) pointer to an __indexable pointer. These 169*e3723e1fSApple OSS Distributions operations will calculate the upper bound by iterating over the memory 170*e3723e1fSApple OSS Distributions pointed to by P in order to find the terminator. 171*e3723e1fSApple OSS Distributions 172*e3723e1fSApple OSS Distributions The __terminated_by_to_indexable(P) does NOT include the terminator within 173*e3723e1fSApple OSS Distributions bounds of the __indexable pointer. Consequently, the terminator cannot be 174*e3723e1fSApple OSS Distributions erased (or even accessed) through the __indexable pointer. The address one 175*e3723e1fSApple OSS Distributions past the end of the array (pointing to the terminator) can be found with 176*e3723e1fSApple OSS Distributions __ptr_upper_bound(). 177*e3723e1fSApple OSS Distributions 178*e3723e1fSApple OSS Distributions The __unsafe_terminated_by_to_indexable(P) does include the terminator within 179*e3723e1fSApple OSS Distributions the bounds of the __indexable pointer. This makes the operation unsafe, since 180*e3723e1fSApple OSS Distributions the terminator can be erased, and thus using P might result in out-of-bounds 181*e3723e1fSApple OSS Distributions access. */ 182*e3723e1fSApple OSS Distributions #define __terminated_by_to_indexable(P) \ 183*e3723e1fSApple OSS Distributions __builtin_terminated_by_to_indexable(P) 184*e3723e1fSApple OSS Distributions #define __unsafe_terminated_by_to_indexable(P) \ 185*e3723e1fSApple OSS Distributions __builtin_unsafe_terminated_by_to_indexable(P) 186*e3723e1fSApple OSS Distributions 187*e3723e1fSApple OSS Distributions #define __null_terminated_to_indexable(P) \ 188*e3723e1fSApple OSS Distributions ({ \ 189*e3723e1fSApple OSS Distributions __typeof__(*(P)) *__null_terminated __ptr = (P); \ 190*e3723e1fSApple OSS Distributions __terminated_by_to_indexable(__ptr); \ 191*e3723e1fSApple OSS Distributions }) 192*e3723e1fSApple OSS Distributions 193*e3723e1fSApple OSS Distributions #define __unsafe_null_terminated_to_indexable(P) \ 194*e3723e1fSApple OSS Distributions ({ \ 195*e3723e1fSApple OSS Distributions __typeof__(*(P)) *__null_terminated __ptr = (P); \ 196*e3723e1fSApple OSS Distributions __unsafe_terminated_by_to_indexable(__ptr); \ 197*e3723e1fSApple OSS Distributions }) 198*e3723e1fSApple OSS Distributions 199*e3723e1fSApple OSS Distributions /* __unsafe_terminated_by_from_indexable(T, PTR [, PTR_TO_TERM]) converts an 200*e3723e1fSApple OSS Distributions __indexable pointer to a __terminated_by(T) pointer. The operation will 201*e3723e1fSApple OSS Distributions check if the given terminator T occurs in the memory pointed to by PTR. 202*e3723e1fSApple OSS Distributions If so, the operation evaluates to __terminated_by(T) pointer. Otherwise, it 203*e3723e1fSApple OSS Distributions traps. 204*e3723e1fSApple OSS Distributions 205*e3723e1fSApple OSS Distributions The operation has an optional parameter PTR_TO_TERM, which changes the way 206*e3723e1fSApple OSS Distributions how the check for the terminator existence is generated. PTR_TO_TERM must 207*e3723e1fSApple OSS Distributions point to the terminator element and be within the bounds of PTR. 208*e3723e1fSApple OSS Distributions If PTR_TO_TERM is provided, the runtime will check if it is in fact within 209*e3723e1fSApple OSS Distributions the bounds and points to an element that equals to T. If PTR_TO_TERM is not 210*e3723e1fSApple OSS Distributions provided, the runtime will iterate over the memory pointed to by PTR to find 211*e3723e1fSApple OSS Distributions the terminator. 212*e3723e1fSApple OSS Distributions 213*e3723e1fSApple OSS Distributions The operation is unsafe, since the terminator can be erased through PTR after 214*e3723e1fSApple OSS Distributions the conversion. This can result in out-of-bounds access through the newly 215*e3723e1fSApple OSS Distributions created __terminated_by(T) pointer. 216*e3723e1fSApple OSS Distributions 217*e3723e1fSApple OSS Distributions For convenience, the 218*e3723e1fSApple OSS Distributions __unsafe_null_terminated_from_indexable(PTR [, PTR_TO_TERM]) macro is 219*e3723e1fSApple OSS Distributions provided, which assumes that the terminator is 0. */ 220*e3723e1fSApple OSS Distributions #define __unsafe_terminated_by_from_indexable(T, ...) \ 221*e3723e1fSApple OSS Distributions __builtin_unsafe_terminated_by_from_indexable((T), __VA_ARGS__) 222*e3723e1fSApple OSS Distributions #define __unsafe_null_terminated_from_indexable(...) \ 223*e3723e1fSApple OSS Distributions __builtin_unsafe_terminated_by_from_indexable(0, __VA_ARGS__) 224*e3723e1fSApple OSS Distributions 225*e3723e1fSApple OSS Distributions /* Instruct the compiler to disregard the bounds of an array used in a function 226*e3723e1fSApple OSS Distributions prototype and allow the decayed pointer to use __counted_by. This is a niche 227*e3723e1fSApple OSS Distributions capability that is only useful in limited patterns (the way that `mig` uses 228*e3723e1fSApple OSS Distributions arrays being one of them). */ 229*e3723e1fSApple OSS Distributions #define __array_decay_dicards_count_in_parameters \ 230*e3723e1fSApple OSS Distributions __attribute__((__decay_discards_count_in_parameters__)) 231*e3723e1fSApple OSS Distributions 232*e3723e1fSApple OSS Distributions /* An attribute to indicate a variable to be effectively constant (or data const) 233*e3723e1fSApple OSS Distributions that it is allocated in a const section so cannot be modified after an early 234*e3723e1fSApple OSS Distributions stage of bootup, for example. Adding this attribute allows a global variable 235*e3723e1fSApple OSS Distributions to be used in __counted_by attribute of struct fields, function parameter, or 236*e3723e1fSApple OSS Distributions local variable just like actual constants. 237*e3723e1fSApple OSS Distributions Note that ensuring the value never changes once it is used is the user's 238*e3723e1fSApple OSS Distributions responsibility. One way to achieve this is the xnu model, in which certain 239*e3723e1fSApple OSS Distributions variables are placed in a segment that is remapped as read-only after 240*e3723e1fSApple OSS Distributions initialization. */ 241*e3723e1fSApple OSS Distributions #define __unsafe_late_const __attribute__((__unsafe_late_const__)) 242*e3723e1fSApple OSS Distributions 243*e3723e1fSApple OSS Distributions /* An attribute to indicate that a function is unavailable when -fbounds-safety 244*e3723e1fSApple OSS Distributions is enabled because it is unsafe. Calls to functions annotated with this 245*e3723e1fSApple OSS Distributions attribute are errors when -fbounds-safety is enabled, but are allowed when 246*e3723e1fSApple OSS Distributions -fbounds-safety is disabled. 247*e3723e1fSApple OSS Distributions 248*e3723e1fSApple OSS Distributions Example: 249*e3723e1fSApple OSS Distributions 250*e3723e1fSApple OSS Distributions void* __ptrcheck_unavailable some_unsafe_api(void*); 251*e3723e1fSApple OSS Distributions */ 252*e3723e1fSApple OSS Distributions #define __ptrcheck_unavailable \ 253*e3723e1fSApple OSS Distributions __attribute__((__unavailable__("unavailable with -fbounds-safety."))) 254*e3723e1fSApple OSS Distributions 255*e3723e1fSApple OSS Distributions /* __ptrcheck_unavailable_r is the same as __ptrcheck_unavailable but it takes 256*e3723e1fSApple OSS Distributions as an argument the name of replacement function that is safe for use with 257*e3723e1fSApple OSS Distributions -fbounds-safety enabled. 258*e3723e1fSApple OSS Distributions 259*e3723e1fSApple OSS Distributions Example: 260*e3723e1fSApple OSS Distributions 261*e3723e1fSApple OSS Distributions void* __counted_by(size) safe_api(void* __counted_by(size), size_t size); 262*e3723e1fSApple OSS Distributions 263*e3723e1fSApple OSS Distributions void* __ptrcheck_unavailable_r(safe_api) some_unsafe_api(void*); 264*e3723e1fSApple OSS Distributions */ 265*e3723e1fSApple OSS Distributions #define __ptrcheck_unavailable_r(REPLACEMENT) \ 266*e3723e1fSApple OSS Distributions __attribute__((__unavailable__( \ 267*e3723e1fSApple OSS Distributions "unavailable with -fbounds-safety. Use " #REPLACEMENT " instead."))) 268*e3723e1fSApple OSS Distributions 269*e3723e1fSApple OSS Distributions #else 270*e3723e1fSApple OSS Distributions 271*e3723e1fSApple OSS Distributions /* We intentionally define to nothing pointer attributes which do not have an 272*e3723e1fSApple OSS Distributions impact on the ABI. __indexable and __bidi_indexable are not defined because 273*e3723e1fSApple OSS Distributions of the ABI incompatibility that makes the diagnostic preferable. */ 274*e3723e1fSApple OSS Distributions #define __single 275*e3723e1fSApple OSS Distributions #define __unsafe_indexable 276*e3723e1fSApple OSS Distributions #define __counted_by(N) 277*e3723e1fSApple OSS Distributions #define __counted_by_or_null(N) 278*e3723e1fSApple OSS Distributions #define __sized_by(N) 279*e3723e1fSApple OSS Distributions #define __sized_by_or_null(N) 280*e3723e1fSApple OSS Distributions #define __ended_by(E) 281*e3723e1fSApple OSS Distributions 282*e3723e1fSApple OSS Distributions /* We intentionally define the terminated_by attributes to nothing. */ 283*e3723e1fSApple OSS Distributions #define __terminated_by(T) 284*e3723e1fSApple OSS Distributions #define __null_terminated 285*e3723e1fSApple OSS Distributions 286*e3723e1fSApple OSS Distributions /* Similarly, we intentionally define to nothing the 287*e3723e1fSApple OSS Distributions __ptrcheck_abi_assume_single and __ptrcheck_abi_assume_unsafe_indexable 288*e3723e1fSApple OSS Distributions macros because they do not lead to an ABI incompatibility. However, we do not 289*e3723e1fSApple OSS Distributions define the indexable and unsafe_indexable ones because the diagnostic is 290*e3723e1fSApple OSS Distributions better than the silent ABI break. */ 291*e3723e1fSApple OSS Distributions #define __ptrcheck_abi_assume_single() 292*e3723e1fSApple OSS Distributions #define __ptrcheck_abi_assume_unsafe_indexable() 293*e3723e1fSApple OSS Distributions 294*e3723e1fSApple OSS Distributions /* __unsafe_forge intrinsics are defined as regular C casts. */ 295*e3723e1fSApple OSS Distributions #define __unsafe_forge_bidi_indexable(T, P, S) ((T)(P)) 296*e3723e1fSApple OSS Distributions #define __unsafe_forge_single(T, P) ((T)(P)) 297*e3723e1fSApple OSS Distributions #define __unsafe_forge_terminated_by(T, P, E) ((T)(P)) 298*e3723e1fSApple OSS Distributions #define __unsafe_forge_null_terminated(T, P) ((T)(P)) 299*e3723e1fSApple OSS Distributions 300*e3723e1fSApple OSS Distributions /* The conversion between terminated_by pointers just evaluates to the pointer 301*e3723e1fSApple OSS Distributions argument. */ 302*e3723e1fSApple OSS Distributions #define __terminated_by_to_indexable(P) (P) 303*e3723e1fSApple OSS Distributions #define __unsafe_terminated_by_to_indexable(P) (P) 304*e3723e1fSApple OSS Distributions #define __null_terminated_to_indexable(P) (P) 305*e3723e1fSApple OSS Distributions #define __unsafe_null_terminated_to_indexable(P) (P) 306*e3723e1fSApple OSS Distributions #define __unsafe_terminated_by_from_indexable(T, P, ...) (P) 307*e3723e1fSApple OSS Distributions #define __unsafe_null_terminated_from_indexable(P, ...) (P) 308*e3723e1fSApple OSS Distributions 309*e3723e1fSApple OSS Distributions /* decay operates normally; attribute is meaningless without pointer checks. */ 310*e3723e1fSApple OSS Distributions #define __array_decay_dicards_count_in_parameters 311*e3723e1fSApple OSS Distributions 312*e3723e1fSApple OSS Distributions /* The APIs marked with these attributes are available outside the context of 313*e3723e1fSApple OSS Distributions pointer checks, so do nothing. */ 314*e3723e1fSApple OSS Distributions #define __ptrcheck_unavailable 315*e3723e1fSApple OSS Distributions #define __ptrcheck_unavailable_r(REPLACEMENT) 316*e3723e1fSApple OSS Distributions 317*e3723e1fSApple OSS Distributions #endif /* __has_ptrcheck */ 318*e3723e1fSApple OSS Distributions 319*e3723e1fSApple OSS Distributions #endif /* __PTRCHECK_H */ 320