1#include "../builtins/assembly.h" 2#include "../sanitizer_common/sanitizer_asm.h" 3 4.macro SAVE_REGISTERS 5 stp x1, x2, [sp, #-16]! 6 stp x3, x4, [sp, #-16]! 7 stp x5, x6, [sp, #-16]! 8 stp x7, x30, [sp, #-16]! 9 stp q0, q1, [sp, #-32]! 10 stp q2, q3, [sp, #-32]! 11 stp q4, q5, [sp, #-32]! 12 stp q6, q7, [sp, #-32]! 13 // x8 is the indirect result register and needs to be preserved for the body of the function to use. 14 stp x8, x0, [sp, #-16]! 15.endm 16 17.macro RESTORE_REGISTERS 18 ldp x8, x0, [sp], #16 19 ldp q6, q7, [sp], #32 20 ldp q4, q5, [sp], #32 21 ldp q2, q3, [sp], #32 22 ldp q0, q1, [sp], #32 23 ldp x7, x30, [sp], #16 24 ldp x5, x6, [sp], #16 25 ldp x3, x4, [sp], #16 26 ldp x1, x2, [sp], #16 27.endm 28 29.text 30.p2align 2 31.global ASM_SYMBOL(__xray_FunctionEntry) 32ASM_HIDDEN(__xray_FunctionEntry) 33ASM_TYPE_FUNCTION(__xray_FunctionEntry) 34ASM_SYMBOL(__xray_FunctionEntry): 35 /* Move the return address beyond the end of sled data. The 12 bytes of 36 data are inserted in the code of the runtime patch, between the call 37 instruction and the instruction returned into. The data contains 32 38 bits of instrumented function ID and 64 bits of the address of 39 the current trampoline. */ 40 add x30, x30, #12 41 // Push the registers which may be modified by the handler function. 42 SAVE_REGISTERS 43 44 // Load the handler function pointer. 45 adrp x2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE) 46 ldr x2, [x2, #:lo12:ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)] 47 cbz x2, 1f 48 // Set w0 to the function ID (w17). Set x1 to XRayEntryType::ENTRY = 0. 49 mov w0, w17 50 mov x1, #0 51 // Call the handler with 2 parameters. 52 blr x2 531: 54 RESTORE_REGISTERS 55 ret 56ASM_SIZE(__xray_FunctionEntry) 57 58.p2align 2 59.global ASM_SYMBOL(__xray_FunctionExit) 60ASM_HIDDEN(__xray_FunctionExit) 61ASM_TYPE_FUNCTION(__xray_FunctionExit) 62ASM_SYMBOL(__xray_FunctionExit): 63 /* Move the return address beyond the end of sled data. The 12 bytes of 64 data are inserted in the code of the runtime patch, between the call 65 instruction and the instruction returned into. The data contains 32 66 bits of instrumented function ID and 64 bits of the address of 67 the current trampoline. */ 68 add x30, x30, #12 69 SAVE_REGISTERS 70 71 // Load the handler function pointer into x2. 72 adrp x2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE) 73 ldr x2, [x2, #:lo12:ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)] 74 cbz x2, 1f 75 // Set w0 to the function ID (w17). Set x1 to XRayEntryType::EXIT = 1. 76 mov w0, w17 77 mov x1, #1 78 // Call the handler with 2 parameters. 79 blr x2 801: 81 RESTORE_REGISTERS 82 ret 83ASM_SIZE(__xray_FunctionExit) 84 85.p2align 2 86.global ASM_SYMBOL(__xray_FunctionTailExit) 87ASM_HIDDEN(__xray_FunctionTailExit) 88ASM_TYPE_FUNCTION(__xray_FunctionTailExit) 89ASM_SYMBOL(__xray_FunctionTailExit): 90 /* Move the return address beyond the end of sled data. The 12 bytes of 91 data are inserted in the code of the runtime patch, between the call 92 instruction and the instruction returned into. The data contains 32 93 bits of instrumented function ID and 64 bits of the address of 94 the current trampoline. */ 95 add x30, x30, #12 96 // Save the registers which may be modified by the handler function. 97 SAVE_REGISTERS 98 // Load the handler function pointer into x2. 99 adrp x2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE) 100 ldr x2, [x2, #:lo12:ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)] 101 cbz x2, 1f 102 // Set w0 to the function ID (w17). Set x1 to XRayEntryType::TAIL = 2. 103 mov w0, w17 104 mov x1, #2 105 // Call the handler with 2 parameters. 106 blr x2 1071: 108 RESTORE_REGISTERS 109 ret 110ASM_SIZE(__xray_FunctionTailExit) 111 112.p2align 2 113.global ASM_SYMBOL(__xray_ArgLoggerEntry) 114ASM_HIDDEN(__xray_ArgLoggerEntry) 115ASM_TYPE_FUNCTION(__xray_ArgLoggerEntry) 116ASM_SYMBOL(__xray_ArgLoggerEntry): 117 add x30, x30, #12 118 // Push the registers which may be modified by the handler function. 119 SAVE_REGISTERS 120 121 adrp x8, ASM_SYMBOL(_ZN6__xray13XRayArgLoggerE) 122 ldr x8, [x8, #:lo12:ASM_SYMBOL(_ZN6__xray13XRayArgLoggerE)] 123 cbnz x8, 2f 124 125 // Load the handler function pointer. 126 adrp x8, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE) 127 ldr x8, [x8, #:lo12:ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)] 128 cbz x8, 1f 129 1302: 131 mov x2, x0 132 mov x1, #3 // XRayEntryType::LOG_ARGS_ENTRY 133 mov w0, w17 134 blr x8 135 1361: 137 RESTORE_REGISTERS 138 ret 139ASM_SIZE(__xray_ArgLoggerEntry) 140 141// __xray_*Event have default visibility so that they can be referenced by user 142// DSOs that do not link against the runtime. 143.global ASM_SYMBOL(__xray_CustomEvent) 144ASM_TYPE_FUNCTION(__xray_CustomEvent) 145ASM_SYMBOL(__xray_CustomEvent): 146 SAVE_REGISTERS 147 adrp x8, ASM_SYMBOL(_ZN6__xray22XRayPatchedCustomEventE) 148 ldr x8, [x8, #:lo12:ASM_SYMBOL(_ZN6__xray22XRayPatchedCustomEventE)] 149 cbz x8, 1f 150 blr x8 1511: 152 RESTORE_REGISTERS 153 ret 154ASM_SIZE(__xray_CustomEvent) 155 156.global ASM_SYMBOL(__xray_TypedEvent) 157ASM_TYPE_FUNCTION(__xray_TypedEvent) 158ASM_SYMBOL(__xray_TypedEvent): 159 SAVE_REGISTERS 160 adrp x8, ASM_SYMBOL(_ZN6__xray21XRayPatchedTypedEventE) 161 ldr x8, [x8, #:lo12:ASM_SYMBOL(_ZN6__xray21XRayPatchedTypedEventE)] 162 cbz x8, 1f 163 blr x8 1641: 165 RESTORE_REGISTERS 166 ret 167ASM_SIZE(__xray_TypedEvent) 168 169NO_EXEC_STACK_DIRECTIVE 170