1 //===-- hwasan_setjmp_riscv64.S -------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of HWAddressSanitizer.
10 // setjmp interceptor for risc-v.
11 // HWAddressSanitizer runtime.
12 //===----------------------------------------------------------------------===//
14 #include "sanitizer_common/sanitizer_asm.h"
15 #include "builtins/assembly.h"
17 #if HWASAN_WITH_INTERCEPTORS && defined(__riscv) && (__riscv_xlen == 64)
18 #include "sanitizer_common/sanitizer_platform.h"
20 // We want to save the context of the calling function.
22 // 1) No modification of the link register by this function.
23 // 2) No modification of the stack pointer by this function.
24 // 3) (no modification of any other saved register, but that's not really going
25 // to occur, and hence isn't as much of a worry).
27 // There's essentially no way to ensure that the compiler will not modify the
28 // stack pointer when compiling a C function.
29 // Hence we have to write this function in assembly.
32 .file "hwasan_setjmp_riscv64.S"
34 .global __interceptor_setjmp
35 ASM_TYPE_FUNCTION(__interceptor_setjmp)
39 tail __interceptor_sigsetjmp
41 ASM_SIZE(__interceptor_setjmp)
43 .global __interceptor_sigsetjmp
44 ASM_TYPE_FUNCTION(__interceptor_sigsetjmp)
45 __interceptor_sigsetjmp:
61 #if __riscv_float_abi_double
74 #elif __riscv_float_abi_soft
76 # error "Unsupported case"
78 // We always have the second argument to __sigjmp_save (savemask) set, since
79 // the _setjmp function above has set it for us as `false`.
80 // This function is defined in hwasan_interceptors.cc
83 ASM_SIZE(__interceptor_sigsetjmp)
86 .macro WEAK_ALIAS first second
88 .equ \second\(), \first
91 WEAK_ALIAS __interceptor_sigsetjmp, __sigsetjmp
93 WEAK_ALIAS __interceptor_setjmp, _setjmp
96 // We do not need executable stack.
97 NO_EXEC_STACK_DIRECTIVE