Path: blob/main/contrib/llvm-project/compiler-rt/lib/hwasan/hwasan_setjmp_x86_64.S
35236 views
//===-- hwasan_setjmp_x86_64.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// setjmp interceptor for x86_64.9//10//===----------------------------------------------------------------------===//1112#include "sanitizer_common/sanitizer_asm.h"1314#if HWASAN_WITH_INTERCEPTORS && defined(__x86_64__)15#include "sanitizer_common/sanitizer_platform.h"1617// We want to save the context of the calling function.18// That requires19// 1) No modification of the return address by this function.20// 2) No modification of the stack pointer by this function.21// 3) (no modification of any other saved register, but that's not really going22// to occur, and hence isn't as much of a worry).23//24// There's essentially no way to ensure that the compiler will not modify the25// stack pointer when compiling a C function.26// Hence we have to write this function in assembly.27//28// TODO: Handle Intel CET.2930.section .text31.file "hwasan_setjmp_x86_64.S"3233.global ASM_WRAPPER_NAME(setjmp)34ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(setjmp))35ASM_WRAPPER_NAME(setjmp):36CFI_STARTPROC37_CET_ENDBR38xorl %esi, %esi39jmp .Linterceptor_sigsetjmp40CFI_ENDPROC41ASM_SIZE(ASM_WRAPPER_NAME(setjmp))4243.global ASM_WRAPPER_NAME(sigsetjmp)44ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(sigsetjmp))45ASM_WRAPPER_NAME(sigsetjmp):46.Linterceptor_sigsetjmp:47CFI_STARTPROC48_CET_ENDBR4950// Save callee save registers.51mov %rbx, (0*8)(%rdi)52mov %rbp, (1*8)(%rdi)53mov %r12, (2*8)(%rdi)54mov %r13, (3*8)(%rdi)55mov %r14, (4*8)(%rdi)56mov %r15, (5*8)(%rdi)5758// Save SP as it was in caller's frame.59lea 8(%rsp), %rdx60mov %rdx, (6*8)(%rdi)6162// Save return address.63mov (%rsp), %rax64mov %rax, (7*8)(%rdi)6566jmp __sigjmp_save6768CFI_ENDPROC69ASM_SIZE(ASM_WRAPPER_NAME(sigsetjmp))7071ASM_INTERCEPTOR_TRAMPOLINE(sigsetjmp)72ASM_TRAMPOLINE_ALIAS(__sigsetjmp, sigsetjmp)73ASM_INTERCEPTOR_TRAMPOLINE(setjmp)74ASM_TRAMPOLINE_ALIAS(_setjmp, setjmp)75#endif7677// We do not need executable stack.78NO_EXEC_STACK_DIRECTIVE798081