1 //===-- hwasan_setjmp_x86_64.S --------------------------------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
9 // setjmp interceptor for x86_64.
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_common/sanitizer_asm.h"
15 #if HWASAN_WITH_INTERCEPTORS && defined(__x86_64__)
16 #include "sanitizer_common/sanitizer_platform.h"
18 // We want to save the context of the calling function.
20 // 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 going
23 // to occur, and hence isn't as much of a worry).
25 // There's essentially no way to ensure that the compiler will not modify the
26 // stack pointer when compiling a C function.
27 // Hence we have to write this function in assembly.
29 // TODO: Handle Intel CET.
32 .file "hwasan_setjmp_x86_64.S"
34 .global ASM_WRAPPER_NAME(setjmp)
35 ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(setjmp))
36 ASM_WRAPPER_NAME(setjmp):
40 jmp .Linterceptor_sigsetjmp
42 ASM_SIZE(ASM_WRAPPER_NAME(setjmp))
44 .global ASM_WRAPPER_NAME(sigsetjmp)
45 ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(sigsetjmp))
46 ASM_WRAPPER_NAME(sigsetjmp):
47 .Linterceptor_sigsetjmp:
51 // Save callee save registers.
59 // Save SP as it was in caller's frame.
63 // Save return address.
70 ASM_SIZE(ASM_WRAPPER_NAME(sigsetjmp))
72 ASM_INTERCEPTOR_TRAMPOLINE(sigsetjmp)
73 ASM_TRAMPOLINE_ALIAS(__sigsetjmp, sigsetjmp)
74 ASM_INTERCEPTOR_TRAMPOLINE(setjmp)
75 ASM_TRAMPOLINE_ALIAS(_setjmp, setjmp)
78 // We do not need executable stack.
79 NO_EXEC_STACK_DIRECTIVE