Path: blob/main/contrib/llvm-project/compiler-rt/lib/hwasan/hwasan_setjmp_riscv64.S
35236 views
//===-- hwasan_setjmp_riscv64.S -------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of HWAddressSanitizer.9// setjmp interceptor for risc-v.10// HWAddressSanitizer runtime.11//===----------------------------------------------------------------------===//1213#include "sanitizer_common/sanitizer_asm.h"14#include "builtins/assembly.h"1516#if HWASAN_WITH_INTERCEPTORS && defined(__riscv) && (__riscv_xlen == 64)17#include "sanitizer_common/sanitizer_platform.h"1819// We want to save the context of the calling function.20// That requires21// 1) No modification of the link register by this function.22// 2) No modification of the stack pointer by this function.23// 3) (no modification of any other saved register, but that's not really going24// to occur, and hence isn't as much of a worry).25//26// There's essentially no way to ensure that the compiler will not modify the27// stack pointer when compiling a C function.28// Hence we have to write this function in assembly.2930.section .text31.file "hwasan_setjmp_riscv64.S"3233.global ASM_WRAPPER_NAME(setjmp)34ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(setjmp))35ASM_WRAPPER_NAME(setjmp):36CFI_STARTPROC37addi x11, x0, 038tail ASM_WRAPPER_NAME(sigsetjmp)39CFI_ENDPROC40ASM_SIZE(ASM_WRAPPER_NAME(setjmp))4142.global ASM_WRAPPER_NAME(sigsetjmp)43ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(sigsetjmp))44ASM_WRAPPER_NAME(sigsetjmp):45CFI_STARTPROC46sd ra, 0<<3(x10)47sd s0, 1<<3(x10)48sd s1, 2<<3(x10)49sd s2, 3<<3(x10)50sd s3, 4<<3(x10)51sd s4, 5<<3(x10)52sd s5, 6<<3(x10)53sd s6, 7<<3(x10)54sd s7, 8<<3(x10)55sd s8, 9<<3(x10)56sd s9, 10<<3(x10)57sd s10, 11<<3(x10)58sd s11, 12<<3(x10)59sd sp, 13<<3(x10)60#if __riscv_float_abi_double61fsd fs0, 14<<3(x10)62fsd fs1, 15<<3(x10)63fsd fs2, 16<<3(x10)64fsd fs3, 17<<3(x10)65fsd fs4, 18<<3(x10)66fsd fs5, 19<<3(x10)67fsd fs6, 20<<3(x10)68fsd fs7, 21<<3(x10)69fsd fs8, 22<<3(x10)70fsd fs9, 23<<3(x10)71fsd fs10, 24<<3(x10)72fsd fs11, 25<<3(x10)73#elif __riscv_float_abi_soft74#else75# error "Unsupported case"76#endif77// We always have the second argument to __sigjmp_save (savemask) set, since78// the _setjmp function above has set it for us as `false`.79// This function is defined in hwasan_interceptors.cc80tail __sigjmp_save81CFI_ENDPROC82ASM_SIZE(ASM_WRAPPER_NAME(sigsetjmp))8384ASM_INTERCEPTOR_TRAMPOLINE(sigsetjmp)85ASM_TRAMPOLINE_ALIAS(__sigsetjmp, sigsetjmp)86ASM_INTERCEPTOR_TRAMPOLINE(setjmp)87ASM_TRAMPOLINE_ALIAS(_setjmp, setjmp)88#endif8990// We do not need executable stack.91NO_EXEC_STACK_DIRECTIVE929394