Path: blob/main/contrib/llvm-project/compiler-rt/lib/xray/xray_trampoline_AArch64.S
35264 views
#include "../builtins/assembly.h"1#include "../sanitizer_common/sanitizer_asm.h"23.macro SAVE_REGISTERS4stp x1, x2, [sp, #-16]!5stp x3, x4, [sp, #-16]!6stp x5, x6, [sp, #-16]!7stp x7, x30, [sp, #-16]!8stp q0, q1, [sp, #-32]!9stp q2, q3, [sp, #-32]!10stp q4, q5, [sp, #-32]!11stp q6, q7, [sp, #-32]!12// x8 is the indirect result register and needs to be preserved for the body of the function to use.13stp x8, x0, [sp, #-16]!14.endm1516.macro RESTORE_REGISTERS17ldp x8, x0, [sp], #1618ldp q6, q7, [sp], #3219ldp q4, q5, [sp], #3220ldp q2, q3, [sp], #3221ldp q0, q1, [sp], #3222ldp x7, x30, [sp], #1623ldp x5, x6, [sp], #1624ldp x3, x4, [sp], #1625ldp x1, x2, [sp], #1626.endm2728.text29.p2align 230.global ASM_SYMBOL(__xray_FunctionEntry)31ASM_HIDDEN(__xray_FunctionEntry)32ASM_TYPE_FUNCTION(__xray_FunctionEntry)33ASM_SYMBOL(__xray_FunctionEntry):34/* Move the return address beyond the end of sled data. The 12 bytes of35data are inserted in the code of the runtime patch, between the call36instruction and the instruction returned into. The data contains 3237bits of instrumented function ID and 64 bits of the address of38the current trampoline. */39add x30, x30, #1240// Push the registers which may be modified by the handler function.41SAVE_REGISTERS4243// Load the handler function pointer.44adrp x2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)45ldr x2, [x2, #:lo12:ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)]46cbz x2, 1f47// Set w0 to the function ID (w17). Set x1 to XRayEntryType::ENTRY = 0.48mov w0, w1749mov x1, #050// Call the handler with 2 parameters.51blr x2521:53RESTORE_REGISTERS54ret55ASM_SIZE(__xray_FunctionEntry)5657.p2align 258.global ASM_SYMBOL(__xray_FunctionExit)59ASM_HIDDEN(__xray_FunctionExit)60ASM_TYPE_FUNCTION(__xray_FunctionExit)61ASM_SYMBOL(__xray_FunctionExit):62/* Move the return address beyond the end of sled data. The 12 bytes of63data are inserted in the code of the runtime patch, between the call64instruction and the instruction returned into. The data contains 3265bits of instrumented function ID and 64 bits of the address of66the current trampoline. */67add x30, x30, #1268SAVE_REGISTERS6970// Load the handler function pointer into x2.71adrp x2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)72ldr x2, [x2, #:lo12:ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)]73cbz x2, 1f74// Set w0 to the function ID (w17). Set x1 to XRayEntryType::EXIT = 1.75mov w0, w1776mov x1, #177// Call the handler with 2 parameters.78blr x2791:80RESTORE_REGISTERS81ret82ASM_SIZE(__xray_FunctionExit)8384.p2align 285.global ASM_SYMBOL(__xray_FunctionTailExit)86ASM_HIDDEN(__xray_FunctionTailExit)87ASM_TYPE_FUNCTION(__xray_FunctionTailExit)88ASM_SYMBOL(__xray_FunctionTailExit):89/* Move the return address beyond the end of sled data. The 12 bytes of90data are inserted in the code of the runtime patch, between the call91instruction and the instruction returned into. The data contains 3292bits of instrumented function ID and 64 bits of the address of93the current trampoline. */94add x30, x30, #1295// Save the registers which may be modified by the handler function.96SAVE_REGISTERS97// Load the handler function pointer into x2.98adrp x2, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)99ldr x2, [x2, #:lo12:ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)]100cbz x2, 1f101// Set w0 to the function ID (w17). Set x1 to XRayEntryType::TAIL = 2.102mov w0, w17103mov x1, #2104// Call the handler with 2 parameters.105blr x21061:107RESTORE_REGISTERS108ret109ASM_SIZE(__xray_FunctionTailExit)110111.p2align 2112.global ASM_SYMBOL(__xray_ArgLoggerEntry)113ASM_HIDDEN(__xray_ArgLoggerEntry)114ASM_TYPE_FUNCTION(__xray_ArgLoggerEntry)115ASM_SYMBOL(__xray_ArgLoggerEntry):116add x30, x30, #12117// Push the registers which may be modified by the handler function.118SAVE_REGISTERS119120adrp x8, ASM_SYMBOL(_ZN6__xray13XRayArgLoggerE)121ldr x8, [x8, #:lo12:ASM_SYMBOL(_ZN6__xray13XRayArgLoggerE)]122cbnz x8, 2f123124// Load the handler function pointer.125adrp x8, ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)126ldr x8, [x8, #:lo12:ASM_SYMBOL(_ZN6__xray19XRayPatchedFunctionE)]127cbz x8, 1f1281292:130mov x2, x0131mov x1, #3 // XRayEntryType::LOG_ARGS_ENTRY132mov w0, w17133blr x81341351:136RESTORE_REGISTERS137ret138ASM_SIZE(__xray_ArgLoggerEntry)139140// __xray_*Event have default visibility so that they can be referenced by user141// DSOs that do not link against the runtime.142.global ASM_SYMBOL(__xray_CustomEvent)143ASM_TYPE_FUNCTION(__xray_CustomEvent)144ASM_SYMBOL(__xray_CustomEvent):145SAVE_REGISTERS146adrp x8, ASM_SYMBOL(_ZN6__xray22XRayPatchedCustomEventE)147ldr x8, [x8, #:lo12:ASM_SYMBOL(_ZN6__xray22XRayPatchedCustomEventE)]148cbz x8, 1f149blr x81501:151RESTORE_REGISTERS152ret153ASM_SIZE(__xray_CustomEvent)154155.global ASM_SYMBOL(__xray_TypedEvent)156ASM_TYPE_FUNCTION(__xray_TypedEvent)157ASM_SYMBOL(__xray_TypedEvent):158SAVE_REGISTERS159adrp x8, ASM_SYMBOL(_ZN6__xray21XRayPatchedTypedEventE)160ldr x8, [x8, #:lo12:ASM_SYMBOL(_ZN6__xray21XRayPatchedTypedEventE)]161cbz x8, 1f162blr x81631:164RESTORE_REGISTERS165ret166ASM_SIZE(__xray_TypedEvent)167168NO_EXEC_STACK_DIRECTIVE169170171