Blame sysdeps/x86_64/setjmp.S

Packit 6c4009
/* setjmp for x86-64.
Packit 6c4009
   Copyright (C) 2001-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
#include <jmpbuf-offsets.h>
Packit 6c4009
#include <jmp_buf-ssp.h>
Packit 6c4009
#include <asm-syntax.h>
Packit 6c4009
#include <stap-probe.h>
Packit 6c4009
Packit 6c4009
/* Don't save shadow stack register if shadow stack isn't enabled.  */
Packit 6c4009
#if !SHSTK_ENABLED
Packit 6c4009
# undef SHADOW_STACK_POINTER_OFFSET
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
ENTRY (__sigsetjmp)
Packit 6c4009
	/* Save registers.  */
Packit 6c4009
	movq %rbx, (JB_RBX*8)(%rdi)
Packit 6c4009
#ifdef PTR_MANGLE
Packit 6c4009
# ifdef __ILP32__
Packit 6c4009
	/* Save the high bits of %rbp first, since PTR_MANGLE will
Packit 6c4009
	   only handle the low bits but we cannot presume %rbp is
Packit 6c4009
	   being used as a pointer and truncate it.  Here we write all
Packit 6c4009
	   of %rbp, but the low bits will be overwritten below.  */
Packit 6c4009
	movq %rbp, (JB_RBP*8)(%rdi)
Packit 6c4009
# endif
Packit 6c4009
	mov %RBP_LP, %RAX_LP
Packit 6c4009
	PTR_MANGLE (%RAX_LP)
Packit 6c4009
	mov %RAX_LP, (JB_RBP*8)(%rdi)
Packit 6c4009
#else
Packit 6c4009
	movq %rbp, (JB_RBP*8)(%rdi)
Packit 6c4009
#endif
Packit 6c4009
	movq %r12, (JB_R12*8)(%rdi)
Packit 6c4009
	movq %r13, (JB_R13*8)(%rdi)
Packit 6c4009
	movq %r14, (JB_R14*8)(%rdi)
Packit 6c4009
	movq %r15, (JB_R15*8)(%rdi)
Packit 6c4009
	lea 8(%rsp), %RDX_LP	/* Save SP as it will be after we return.  */
Packit 6c4009
#ifdef PTR_MANGLE
Packit 6c4009
	PTR_MANGLE (%RDX_LP)
Packit 6c4009
#endif
Packit 6c4009
	movq %rdx, (JB_RSP*8)(%rdi)
Packit 6c4009
	mov (%rsp), %RAX_LP	/* Save PC we are returning to now.  */
Packit 6c4009
	LIBC_PROBE (setjmp, 3, LP_SIZE@%RDI_LP, -4@%esi, LP_SIZE@%RAX_LP)
Packit 6c4009
#ifdef PTR_MANGLE
Packit 6c4009
	PTR_MANGLE (%RAX_LP)
Packit 6c4009
#endif
Packit 6c4009
	movq %rax, (JB_PC*8)(%rdi)
Packit 6c4009
Packit 6c4009
#ifdef SHADOW_STACK_POINTER_OFFSET
Packit 6c4009
# if IS_IN (libc) && defined SHARED && defined FEATURE_1_OFFSET
Packit 6c4009
	/* Check if Shadow Stack is enabled.  */
Packit 6c4009
	testl $X86_FEATURE_1_SHSTK, %fs:FEATURE_1_OFFSET
Packit 6c4009
	jz L(skip_ssp)
Packit 6c4009
# else
Packit 6c4009
	xorl %eax, %eax
Packit 6c4009
# endif
Packit 6c4009
	/* Get the current Shadow-Stack-Pointer and save it.  */
Packit 6c4009
	rdsspq %rax
Packit 6c4009
	movq %rax, SHADOW_STACK_POINTER_OFFSET(%rdi)
Packit 6c4009
# if IS_IN (libc) && defined SHARED && defined FEATURE_1_OFFSET
Packit 6c4009
L(skip_ssp):
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
#if IS_IN (rtld)
Packit 6c4009
	/* In ld.so we never save the signal mask.  */
Packit 6c4009
	xorl %eax, %eax
Packit 6c4009
	retq
Packit 6c4009
#else
Packit 6c4009
	/* Make a tail call to __sigjmp_save; it takes the same args.  */
Packit 6c4009
	jmp __sigjmp_save
Packit 6c4009
#endif
Packit 6c4009
END (__sigsetjmp)
Packit 6c4009
hidden_def (__sigsetjmp)