xray_trampoline_AArch64.S
5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "../builtins/assembly.h"
.text
/* The variable containing the handler function pointer */
.global _ZN6__xray19XRayPatchedFunctionE
/* Word-aligned function entry point */
.p2align 2
/* Let C/C++ see the symbol */
.global __xray_FunctionEntry
.type __xray_FunctionEntry, %function
/* In C++ it is void extern "C" __xray_FunctionEntry(uint32_t FuncId) with
FuncId passed in W0 register. */
__xray_FunctionEntry:
/* Move the return address beyond the end of sled data. The 12 bytes of
data are inserted in the code of the runtime patch, between the call
instruction and the instruction returned into. The data contains 32
bits of instrumented function ID and 64 bits of the address of
the current trampoline. */
ADD X30, X30, #12
/* Push the registers which may be modified by the handler function */
STP X1, X2, [SP, #-16]!
STP X3, X4, [SP, #-16]!
STP X5, X6, [SP, #-16]!
STP X7, X30, [SP, #-16]!
STP Q0, Q1, [SP, #-32]!
STP Q2, Q3, [SP, #-32]!
STP Q4, Q5, [SP, #-32]!
STP Q6, Q7, [SP, #-32]!
/* Load the address of _ZN6__xray19XRayPatchedFunctionE into X1 */
LDR X1, =_ZN6__xray19XRayPatchedFunctionE
/* Load the handler function pointer into X2 */
LDR X2, [X1]
/* Handler address is nullptr if handler is not set */
CMP X2, #0
BEQ FunctionEntry_restore
/* Function ID is already in W0 (the first parameter).
X1=0 means that we are tracing an entry event */
MOV X1, #0
/* Call the handler with 2 parameters in W0 and X1 */
BLR X2
FunctionEntry_restore:
/* Pop the saved registers */
LDP Q6, Q7, [SP], #32
LDP Q4, Q5, [SP], #32
LDP Q2, Q3, [SP], #32
LDP Q0, Q1, [SP], #32
LDP X7, X30, [SP], #16
LDP X5, X6, [SP], #16
LDP X3, X4, [SP], #16
LDP X1, X2, [SP], #16
RET
/* Word-aligned function entry point */
.p2align 2
/* Let C/C++ see the symbol */
.global __xray_FunctionExit
.type __xray_FunctionExit, %function
/* In C++ it is void extern "C" __xray_FunctionExit(uint32_t FuncId) with
FuncId passed in W0 register. */
__xray_FunctionExit:
/* Move the return address beyond the end of sled data. The 12 bytes of
data are inserted in the code of the runtime patch, between the call
instruction and the instruction returned into. The data contains 32
bits of instrumented function ID and 64 bits of the address of
the current trampoline. */
ADD X30, X30, #12
/* Push the registers which may be modified by the handler function */
STP X1, X2, [SP, #-16]!
STP X3, X4, [SP, #-16]!
STP X5, X6, [SP, #-16]!
STP X7, X30, [SP, #-16]!
STR Q0, [SP, #-16]!
/* Load the address of _ZN6__xray19XRayPatchedFunctionE into X1 */
LDR X1, =_ZN6__xray19XRayPatchedFunctionE
/* Load the handler function pointer into X2 */
LDR X2, [X1]
/* Handler address is nullptr if handler is not set */
CMP X2, #0
BEQ FunctionExit_restore
/* Function ID is already in W0 (the first parameter).
X1=1 means that we are tracing an exit event */
MOV X1, #1
/* Call the handler with 2 parameters in W0 and X1 */
BLR X2
FunctionExit_restore:
LDR Q0, [SP], #16
LDP X7, X30, [SP], #16
LDP X5, X6, [SP], #16
LDP X3, X4, [SP], #16
LDP X1, X2, [SP], #16
RET
/* Word-aligned function entry point */
.p2align 2
/* Let C/C++ see the symbol */
.global __xray_FunctionTailExit
.type __xray_FunctionTailExit, %function
/* In C++ it is void extern "C" __xray_FunctionTailExit(uint32_t FuncId)
with FuncId passed in W0 register. */
__xray_FunctionTailExit:
/* Move the return address beyond the end of sled data. The 12 bytes of
data are inserted in the code of the runtime patch, between the call
instruction and the instruction returned into. The data contains 32
bits of instrumented function ID and 64 bits of the address of
the current trampoline. */
ADD X30, X30, #12
/* Push the registers which may be modified by the handler function */
STP X1, X2, [SP, #-16]!
STP X3, X4, [SP, #-16]!
STP X5, X6, [SP, #-16]!
STP X7, X30, [SP, #-16]!
/* Push the parameters of the tail called function */
STP Q0, Q1, [SP, #-32]!
STP Q2, Q3, [SP, #-32]!
STP Q4, Q5, [SP, #-32]!
STP Q6, Q7, [SP, #-32]!
/* Load the address of _ZN6__xray19XRayPatchedFunctionE into X1 */
LDR X1, =_ZN6__xray19XRayPatchedFunctionE
/* Load the handler function pointer into X2 */
LDR X2, [X1]
/* Handler address is nullptr if handler is not set */
CMP X2, #0
BEQ FunctionTailExit_restore
/* Function ID is already in W0 (the first parameter).
X1=2 means that we are tracing a tail exit event, but before the
logging part of XRay is ready, we pretend that here a normal function
exit happens, so we give the handler code 1 */
MOV X1, #1
/* Call the handler with 2 parameters in W0 and X1 */
BLR X2
FunctionTailExit_restore:
/* Pop the parameters of the tail called function */
LDP Q6, Q7, [SP], #32
LDP Q4, Q5, [SP], #32
LDP Q2, Q3, [SP], #32
LDP Q0, Q1, [SP], #32
/* Pop the registers which may be modified by the handler function */
LDP X7, X30, [SP], #16
LDP X5, X6, [SP], #16
LDP X3, X4, [SP], #16
LDP X1, X2, [SP], #16
RET
NO_EXEC_STACK_DIRECTIVE