1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 // Based on race_arm64.s; see commentary there.
17 #define REPEAT_2(a) a a
18 #define REPEAT_8(a) REPEAT_2(REPEAT_2(REPEAT_2(a)))
19 #define REPEAT_128(a) REPEAT_2(REPEAT_8(REPEAT_8(a)))
21 // void runtime·libfuzzerCallTraceIntCmp(fn, arg0, arg1, fakePC uintptr)
22 // Calls C function fn from libFuzzer and passes 2 arguments to it after
23 // manipulating the return address so that libfuzzer's integer compare hooks
25 // The problem statement and solution are documented in detail in libfuzzer_amd64.s.
26 // See commentary there.
27 TEXT runtime·libfuzzerCallTraceIntCmp(SB), NOSPLIT, $8-32
29 MOVD arg0+8(FP), RARG0
30 MOVD arg1+16(FP), RARG1
31 MOVD fakePC+24(FP), R8
32 // Save the original return address in a local variable
33 MOVD R30, savedRetAddr-8(SP)
37 // Switch to g0 stack.
38 MOVD RSP, R19 // callee-saved, preserved across the CALL
41 BEQ call // already on g0
42 MOVD (g_sched+gobuf_sp)(R11), R12
45 // Load address of the ret sled into the default register for the return
48 // Clear the lowest 2 bits of fakePC. All ARM64 instructions are four
49 // bytes long, so we cannot get better return address granularity than
52 // Add the offset of the fake_pc-th ret.
54 // Call the function by jumping to it and reusing all registers except
55 // for the modified return address register R30.
58 // The ret sled for ARM64 consists of 128 br instructions jumping to the
59 // end of the function. Each instruction is 4 bytes long. The sled thus
60 // has the same byte length of 4 * 128 = 512 as the x86_64 sled, but
61 // coarser granularity.
70 MOVD savedRetAddr-8(SP), R30
73 // void runtime·libfuzzerCall4(fn, hookId int, s1, s2 unsafe.Pointer, result uintptr)
74 // Calls C function fn from libFuzzer and passes 4 arguments to it.
75 TEXT runtime·libfuzzerCall4(SB), NOSPLIT, $0-40
77 MOVD hookId+8(FP), RARG0
80 MOVD result+32(FP), RARG3
84 // Switch to g0 stack.
85 MOVD RSP, R19 // callee-saved, preserved across the CALL
88 BEQ call // already on g0
89 MOVD (g_sched+gobuf_sp)(R11), R12
96 // void runtime·libfuzzerCallWithTwoByteBuffers(fn, start, end *byte)
97 // Calls C function fn from libFuzzer and passes 2 arguments of type *byte to it.
98 TEXT runtime·libfuzzerCallWithTwoByteBuffers(SB), NOSPLIT, $0-24
105 // Switch to g0 stack.
106 MOVD RSP, R19 // callee-saved, preserved across the CALL
109 BEQ call // already on g0
110 MOVD (g_sched+gobuf_sp)(R11), R12