Path: blob/main/contrib/llvm-project/compiler-rt/lib/hwasan/hwasan_setjmp_aarch64.S
35236 views
//===-- hwasan_setjmp_aarch64.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//10// HWAddressSanitizer runtime.11//===----------------------------------------------------------------------===//1213#include "sanitizer_common/sanitizer_asm.h"14#include "builtins/assembly.h"1516#if HWASAN_WITH_INTERCEPTORS && defined(__aarch64__)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_aarch64.S"3233.global ASM_WRAPPER_NAME(setjmp)34ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(setjmp))35ASM_WRAPPER_NAME(setjmp):36CFI_STARTPROC37BTI_C38mov x1, #039b ASM_WRAPPER_NAME(sigsetjmp)40CFI_ENDPROC41ASM_SIZE(ASM_WRAPPER_NAME(setjmp))4243ASM_INTERCEPTOR_TRAMPOLINE(setjmp)4445#if SANITIZER_ANDROID46// Bionic also defines a function `setjmp` that calls `sigsetjmp` saving the47// current signal.48.global ASM_WRAPPER_NAME(setjmp_bionic)49ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(setjmp_bionic))50ASM_WRAPPER_NAME(setjmp_bionic):51CFI_STARTPROC52BTI_C53mov x1, #154b ASM_WRAPPER_NAME(sigsetjmp)55CFI_ENDPROC56ASM_SIZE(ASM_WRAPPER_NAME(setjmp_bionic))5758ASM_INTERCEPTOR_TRAMPOLINE(setjmp_bionic)59#endif6061.global ASM_WRAPPER_NAME(sigsetjmp)62ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(sigsetjmp))63ASM_WRAPPER_NAME(sigsetjmp):64CFI_STARTPROC65BTI_C66stp x19, x20, [x0, #0<<3]67stp x21, x22, [x0, #2<<3]68stp x23, x24, [x0, #4<<3]69stp x25, x26, [x0, #6<<3]70stp x27, x28, [x0, #8<<3]71stp x29, x30, [x0, #10<<3]72stp d8, d9, [x0, #14<<3]73stp d10, d11, [x0, #16<<3]74stp d12, d13, [x0, #18<<3]75stp d14, d15, [x0, #20<<3]76mov x2, sp77str x2, [x0, #13<<3]78// We always have the second argument to __sigjmp_save (savemask) set, since79// the _setjmp function above has set it for us as `false`.80// This function is defined in hwasan_interceptors.cc81b __sigjmp_save82CFI_ENDPROC83ASM_SIZE(ASM_WRAPPER_NAME(sigsetjmp))8485ASM_INTERCEPTOR_TRAMPOLINE(sigsetjmp)868788#if SANITIZER_ANDROID89ASM_TRAMPOLINE_ALIAS(sigsetjmp, sigsetjmp)90ASM_TRAMPOLINE_ALIAS(setjmp, setjmp_bionic)91#else92ASM_TRAMPOLINE_ALIAS(__sigsetjmp, sigsetjmp)93#endif9495ASM_TRAMPOLINE_ALIAS(_setjmp, setjmp)96#endif9798// We do not need executable stack.99NO_EXEC_STACK_DIRECTIVE100101GNU_PROPERTY_BTI_PAC102103104