|
94 | 94 | // integer and an authenticated function pointer, so we need this helper |
95 | 95 | // function to keep things clean. |
96 | 96 | static _Unwind_Personality_Fn get_handler_function(unw_proc_info_t *frameInfo) { |
97 | | - union { |
98 | | - void *opaque_handler; |
99 | | - _Unwind_Personality_Fn __ptrauth_unwind_upi_handler *handler; |
100 | | - } u; |
101 | | - u.opaque_handler = (void *)&frameInfo->handler; |
102 | | - return *u.handler; |
| 97 | + // Converting from an authenticated integer to a _Unwind_Personality_Fn |
| 98 | + // requires multiple steps, but as the schema of _Unwind_Personality_Fn is |
| 99 | + // not address diversified we can mostly just rely on automatic re-signing |
| 100 | + // by clang. |
| 101 | + |
| 102 | + // Step 1. Assign from the address diversified integer in frameInfo->handler |
| 103 | + // to the non-address diversified schema of `_Unwind_Personality_Fn` |
| 104 | + uintptr_t __unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, |
| 105 | + 0, |
| 106 | + ptrauth_function_pointer_type_discriminator(_Unwind_Personality_Fn)) |
| 107 | + reauthenticatedIntegerHandler = frameInfo->handler; |
| 108 | + |
| 109 | + // Step 2. Memcpy from our re-signed integer typed handler to an |
| 110 | + // _Unwind_Personality_Fn typed local - this avoids any confused |
| 111 | + // re-signing of values that already have a signature. |
| 112 | + _Unwind_Personality_Fn handler; |
| 113 | + uintptr_t __unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 0, |
| 114 | + ptrauth_function_pointer_type_discriminator(_Unwind_Personality_Fn)) |
| 115 | + f; |
| 116 | + memcpy(&handler, (void *)&reauthenticatedIntegerHandler, |
| 117 | + sizeof(_Unwind_Personality_Fn)); |
| 118 | + |
| 119 | + // Step 3. Finally return the correctly typed and signed value. |
| 120 | + return handler; |
103 | 121 | } |
104 | 122 |
|
105 | 123 | static _Unwind_Reason_Code |
|
0 commit comments