brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · a5379d3 Raw
81 lines · plain
1//===-- hwasan_setjmp_x86_64.S --------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8//9// setjmp interceptor for x86_64.10//11//===----------------------------------------------------------------------===//12 13#include "sanitizer_common/sanitizer_asm.h"14 15#if HWASAN_WITH_INTERCEPTORS && defined(__x86_64__)16#include "sanitizer_common/sanitizer_platform.h"17 18// We want to save the context of the calling function.19// That requires20// 1) No modification of the return address by this function.21// 2) No modification of the stack pointer by this function.22// 3) (no modification of any other saved register, but that's not really going23// to occur, and hence isn't as much of a worry).24//25// There's essentially no way to ensure that the compiler will not modify the26// stack pointer when compiling a C function.27// Hence we have to write this function in assembly.28//29// TODO: Handle Intel CET.30 31.section .text32.file "hwasan_setjmp_x86_64.S"33.att_syntax34 35.global ASM_WRAPPER_NAME(setjmp)36ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(setjmp))37ASM_WRAPPER_NAME(setjmp):38  CFI_STARTPROC39  _CET_ENDBR40  xorl %esi, %esi41  jmp	.Linterceptor_sigsetjmp42  CFI_ENDPROC43ASM_SIZE(ASM_WRAPPER_NAME(setjmp))44 45.global ASM_WRAPPER_NAME(sigsetjmp)46ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(sigsetjmp))47ASM_WRAPPER_NAME(sigsetjmp):48.Linterceptor_sigsetjmp:49  CFI_STARTPROC50  _CET_ENDBR51 52  // Save callee save registers.53  mov %rbx, (0*8)(%rdi)54  mov %rbp, (1*8)(%rdi)55  mov %r12, (2*8)(%rdi)56  mov %r13, (3*8)(%rdi)57  mov %r14, (4*8)(%rdi)58  mov %r15, (5*8)(%rdi)59 60  // Save SP as it was in caller's frame.61  lea 8(%rsp), %rdx62  mov %rdx, (6*8)(%rdi)63 64  // Save return address.65  mov (%rsp), %rax66  mov %rax, (7*8)(%rdi)67 68  jmp __sigjmp_save69 70  CFI_ENDPROC71ASM_SIZE(ASM_WRAPPER_NAME(sigsetjmp))72 73ASM_INTERCEPTOR_TRAMPOLINE(sigsetjmp)74ASM_TRAMPOLINE_ALIAS(__sigsetjmp, sigsetjmp)75ASM_INTERCEPTOR_TRAMPOLINE(setjmp)76ASM_TRAMPOLINE_ALIAS(_setjmp, setjmp)77#endif78 79// We do not need executable stack.80NO_EXEC_STACK_DIRECTIVE81