1 1.1 mrg //===-- hwasan_setjmp_riscv64.S -------------------------------------------===// 2 1.1 mrg // 3 1.1 mrg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 1.1 mrg // See https://llvm.org/LICENSE.txt for license information. 5 1.1 mrg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 1.1 mrg // 7 1.1 mrg //===----------------------------------------------------------------------===// 8 1.1 mrg // 9 1.1 mrg // This file is a part of HWAddressSanitizer. 10 1.1 mrg // setjmp interceptor for risc-v. 11 1.1 mrg // HWAddressSanitizer runtime. 12 1.1 mrg //===----------------------------------------------------------------------===// 13 1.1 mrg 14 1.1 mrg #include "sanitizer_common/sanitizer_asm.h" 15 1.1 mrg #include "builtins/assembly.h" 16 1.1 mrg 17 1.1 mrg #if HWASAN_WITH_INTERCEPTORS && defined(__riscv) && (__riscv_xlen == 64) 18 1.1 mrg #include "sanitizer_common/sanitizer_platform.h" 19 1.1 mrg 20 1.1 mrg // We want to save the context of the calling function. 21 1.1 mrg // That requires 22 1.1 mrg // 1) No modification of the link register by this function. 23 1.1 mrg // 2) No modification of the stack pointer by this function. 24 1.1 mrg // 3) (no modification of any other saved register, but that's not really going 25 1.1 mrg // to occur, and hence isn't as much of a worry). 26 1.1 mrg // 27 1.1 mrg // There's essentially no way to ensure that the compiler will not modify the 28 1.1 mrg // stack pointer when compiling a C function. 29 1.1 mrg // Hence we have to write this function in assembly. 30 1.1 mrg 31 1.1 mrg .section .text 32 1.1 mrg .file "hwasan_setjmp_riscv64.S" 33 1.1 mrg 34 1.1 mrg .global ASM_WRAPPER_NAME(setjmp) 35 1.1 mrg ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(setjmp)) 36 1.1 mrg ASM_WRAPPER_NAME(setjmp): 37 1.1 mrg CFI_STARTPROC 38 1.1 mrg addi x11, x0, 0 39 1.1 mrg tail ASM_WRAPPER_NAME(sigsetjmp) 40 1.1 mrg CFI_ENDPROC 41 1.1 mrg ASM_SIZE(ASM_WRAPPER_NAME(setjmp)) 42 1.1 mrg 43 1.1 mrg .global ASM_WRAPPER_NAME(sigsetjmp) 44 1.1 mrg ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(sigsetjmp)) 45 1.1 mrg ASM_WRAPPER_NAME(sigsetjmp): 46 1.1 mrg CFI_STARTPROC 47 1.1 mrg sd ra, 0<<3(x10) 48 1.1 mrg sd s0, 1<<3(x10) 49 1.1 mrg sd s1, 2<<3(x10) 50 1.1 mrg sd s2, 3<<3(x10) 51 1.1 mrg sd s3, 4<<3(x10) 52 1.1 mrg sd s4, 5<<3(x10) 53 1.1 mrg sd s5, 6<<3(x10) 54 1.1 mrg sd s6, 7<<3(x10) 55 1.1 mrg sd s7, 8<<3(x10) 56 1.1 mrg sd s8, 9<<3(x10) 57 1.1 mrg sd s9, 10<<3(x10) 58 1.1 mrg sd s10, 11<<3(x10) 59 1.1 mrg sd s11, 12<<3(x10) 60 1.1 mrg sd sp, 13<<3(x10) 61 1.1 mrg #if __riscv_float_abi_double 62 1.1 mrg fsd fs0, 14<<3(x10) 63 1.1 mrg fsd fs1, 15<<3(x10) 64 1.1 mrg fsd fs2, 16<<3(x10) 65 1.1 mrg fsd fs3, 17<<3(x10) 66 1.1 mrg fsd fs4, 18<<3(x10) 67 1.1 mrg fsd fs5, 19<<3(x10) 68 1.1 mrg fsd fs6, 20<<3(x10) 69 1.1 mrg fsd fs7, 21<<3(x10) 70 1.1 mrg fsd fs8, 22<<3(x10) 71 1.1 mrg fsd fs9, 23<<3(x10) 72 1.1 mrg fsd fs10, 24<<3(x10) 73 1.1 mrg fsd fs11, 25<<3(x10) 74 1.1 mrg #elif __riscv_float_abi_soft 75 1.1 mrg #else 76 1.1 mrg # error "Unsupported case" 77 1.1 mrg #endif 78 1.1 mrg // We always have the second argument to __sigjmp_save (savemask) set, since 79 1.1 mrg // the _setjmp function above has set it for us as `false`. 80 1.1 mrg // This function is defined in hwasan_interceptors.cc 81 1.1 mrg tail __sigjmp_save 82 1.1 mrg CFI_ENDPROC 83 1.1 mrg ASM_SIZE(ASM_WRAPPER_NAME(sigsetjmp)) 84 1.1 mrg 85 1.1 mrg ASM_INTERCEPTOR_TRAMPOLINE(sigsetjmp) 86 1.1 mrg ASM_TRAMPOLINE_ALIAS(__sigsetjmp, sigsetjmp) 87 1.1 mrg ASM_INTERCEPTOR_TRAMPOLINE(setjmp) 88 1.1 mrg ASM_TRAMPOLINE_ALIAS(_setjmp, setjmp) 89 1.1 mrg #endif 90 1.1 mrg 91 1.1 mrg // We do not need executable stack. 92 1.1 mrg NO_EXEC_STACK_DIRECTIVE 93