brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.9 KiB · 5d951f3 Raw
174 lines · plain
1#include "../builtins/assembly.h"2#include "../sanitizer_common/sanitizer_asm.h"3 4.macro SAVE_REGISTERS5  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.endm16 17.macro RESTORE_REGISTERS18  ldp x8, x0, [sp], #1619  ldp q6, q7, [sp], #3220  ldp q4, q5, [sp], #3221  ldp q2, q3, [sp], #3222  ldp q0, q1, [sp], #3223  ldp x7, x30, [sp], #1624  ldp x5, x6, [sp], #1625  ldp x3, x4, [sp], #1626  ldp x1, x2, [sp], #1627.endm28 29.macro LOAD_HANDLER_ADDR reg handler30#if !defined(XRAY_PIC)31    adrp \reg, ASM_SYMBOL(\handler)32    ldr \reg, [\reg, :lo12:ASM_SYMBOL(\handler)]33#else34    adrp \reg, :got:ASM_SYMBOL(\handler)35    ldr \reg, [\reg, :got_lo12:ASM_SYMBOL(\handler)]36    ldr \reg, [\reg]37#endif38.endm39 40TEXT_SECTION41.p2align 242.global ASM_SYMBOL(__xray_FunctionEntry)43ASM_HIDDEN(__xray_FunctionEntry)44ASM_TYPE_FUNCTION(__xray_FunctionEntry)45ASM_SYMBOL(__xray_FunctionEntry):46    /* Move the return address beyond the end of sled data. The 12 bytes of47         data are inserted in the code of the runtime patch, between the call48         instruction and the instruction returned into. The data contains 3249         bits of instrumented function ID and 64 bits of the address of50         the current trampoline. */51  add x30, x30, #1252  // Push the registers which may be modified by the handler function.53  SAVE_REGISTERS54 55  // Load the handler function pointer.56  LOAD_HANDLER_ADDR x2, _ZN6__xray19XRayPatchedFunctionE57  cbz x2, 1f58  // Set w0 to the function ID (w17). Set x1 to XRayEntryType::ENTRY = 0.59  mov w0, w1760  mov x1, #061  // Call the handler with 2 parameters.62  blr x2631:64  RESTORE_REGISTERS65  ret66ASM_SIZE(__xray_FunctionEntry)67 68.p2align 269.global ASM_SYMBOL(__xray_FunctionExit)70ASM_HIDDEN(__xray_FunctionExit)71ASM_TYPE_FUNCTION(__xray_FunctionExit)72ASM_SYMBOL(__xray_FunctionExit):73    /* Move the return address beyond the end of sled data. The 12 bytes of74         data are inserted in the code of the runtime patch, between the call75         instruction and the instruction returned into. The data contains 3276         bits of instrumented function ID and 64 bits of the address of77         the current trampoline. */78  add x30, x30, #1279  SAVE_REGISTERS80 81  // Load the handler function pointer into x2.82  LOAD_HANDLER_ADDR x2, _ZN6__xray19XRayPatchedFunctionE83  cbz x2, 1f84  // Set w0 to the function ID (w17). Set x1 to XRayEntryType::EXIT = 1.85  mov w0, w1786  mov x1, #187  // Call the handler with 2 parameters.88  blr x2891:90  RESTORE_REGISTERS91  ret92ASM_SIZE(__xray_FunctionExit)93 94.p2align 295.global ASM_SYMBOL(__xray_FunctionTailExit)96ASM_HIDDEN(__xray_FunctionTailExit)97ASM_TYPE_FUNCTION(__xray_FunctionTailExit)98ASM_SYMBOL(__xray_FunctionTailExit):99    /* Move the return address beyond the end of sled data. The 12 bytes of100         data are inserted in the code of the runtime patch, between the call101         instruction and the instruction returned into. The data contains 32102         bits of instrumented function ID and 64 bits of the address of103         the current trampoline. */104  add x30, x30, #12105  // Save the registers which may be modified by the handler function.106  SAVE_REGISTERS107  // Load the handler function pointer into x2.108  LOAD_HANDLER_ADDR x2, _ZN6__xray19XRayPatchedFunctionE109  cbz x2, 1f110  // Set w0 to the function ID (w17). Set x1 to XRayEntryType::TAIL = 2.111  mov w0, w17112  mov x1, #2113  // Call the handler with 2 parameters.114  blr x21151:116  RESTORE_REGISTERS117  ret118ASM_SIZE(__xray_FunctionTailExit)119 120.p2align 2121.global ASM_SYMBOL(__xray_ArgLoggerEntry)122ASM_HIDDEN(__xray_ArgLoggerEntry)123ASM_TYPE_FUNCTION(__xray_ArgLoggerEntry)124ASM_SYMBOL(__xray_ArgLoggerEntry):125  add x30, x30, #12126  // Push the registers which may be modified by the handler function.127  SAVE_REGISTERS128 129  LOAD_HANDLER_ADDR x8, _ZN6__xray13XRayArgLoggerE130  cbnz x8, 2f131 132  // Load the handler function pointer.133  LOAD_HANDLER_ADDR x8, _ZN6__xray19XRayPatchedFunctionE134  cbz x8, 1f135 1362:137  mov x2, x0138  mov x1, #3  // XRayEntryType::LOG_ARGS_ENTRY139  mov w0, w17140  blr x8141 1421:143  RESTORE_REGISTERS144  ret145ASM_SIZE(__xray_ArgLoggerEntry)146 147// __xray_*Event have default visibility so that they can be referenced by user148// DSOs that do not link against the runtime.149.global ASM_SYMBOL(__xray_CustomEvent)150ASM_TYPE_FUNCTION(__xray_CustomEvent)151ASM_SYMBOL(__xray_CustomEvent):152  SAVE_REGISTERS153  LOAD_HANDLER_ADDR x8, _ZN6__xray22XRayPatchedCustomEventE154  cbz x8, 1f155  blr x81561:157  RESTORE_REGISTERS158  ret159ASM_SIZE(__xray_CustomEvent)160 161.global ASM_SYMBOL(__xray_TypedEvent)162ASM_TYPE_FUNCTION(__xray_TypedEvent)163ASM_SYMBOL(__xray_TypedEvent):164  SAVE_REGISTERS165  LOAD_HANDLER_ADDR x8, _ZN6__xray21XRayPatchedTypedEventE166  cbz x8, 1f167  blr x81681:169  RESTORE_REGISTERS170  ret171ASM_SIZE(__xray_TypedEvent)172 173NO_EXEC_STACK_DIRECTIVE174