Blame sysdeps/mach/hurd/i386/____longjmp_chk.S

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 <asm-syntax.h>
Packit 6c4009
Packit 6c4009
#include <signal-defines.h>
Packit 6c4009
/* #include <signal.h> */
Packit 6c4009
#define SS_ONSTACK 1
Packit 6c4009
Packit 6c4009
Packit 6c4009
	.section .rodata.str1.1,"aMS",@progbits,1
Packit 6c4009
	.type	longjmp_msg,@object
Packit 6c4009
longjmp_msg:
Packit 6c4009
	.string "longjmp causes uninitialized stack frame"
Packit 6c4009
	.size	longjmp_msg, .-longjmp_msg
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifdef PIC
Packit 6c4009
# define CALL_FAIL	movl	%ebx, %ecx; /* TODO: what's this mov good for? */ \
Packit 6c4009
			cfi_register(%ebx,%ecx);			      \
Packit 6c4009
			LOAD_PIC_REG (bx);				      \
Packit 6c4009
			leal	longjmp_msg@GOTOFF(%ebx), %eax;		      \
Packit 6c4009
			movl	%eax, (%esp);				      \
Packit 6c4009
			call	HIDDEN_JUMPTARGET(__fortify_fail)
Packit 6c4009
#else
Packit 6c4009
# define CALL_FAIL	movl	$longjmp_msg, %eax;			      \
Packit 6c4009
			movl	%eax, (%esp);				      \
Packit 6c4009
			call	HIDDEN_JUMPTARGET(__fortify_fail)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
	.text
Packit 6c4009
ENTRY (____longjmp_chk)
Packit 6c4009
	movl	4(%esp), %ecx	/* User's jmp_buf in %ecx.  */
Packit 6c4009
Packit 6c4009
	/* Save the return address now.  */
Packit 6c4009
	movl	(JB_PC*4)(%ecx), %edx
Packit 6c4009
	/* Get the stack pointer.  */
Packit 6c4009
	movl	(JB_SP*4)(%ecx), %edi
Packit 6c4009
	cfi_undefined(%edi)
Packit 6c4009
#ifdef PTR_DEMANGLE
Packit 6c4009
	PTR_DEMANGLE (%edx)
Packit 6c4009
	PTR_DEMANGLE (%edi)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
	cmpl	%edi, %esp
Packit 6c4009
	/* Jumping to a higher-address frame is always allowed.  */
Packit 6c4009
	jbe	.Lok
Packit 6c4009
Packit 6c4009
	/* Passing here, we're either about to do something invalid, or we're
Packit 6c4009
	executing on an alternative signal stack.  */
Packit 6c4009
Packit 6c4009
	/* TODO: need locking?  */
Packit 6c4009
	/* struct hurd_sigstate * _hurd_self_sigstate (void) */
Packit 6c4009
	call	HIDDEN_JUMPTARGET(_hurd_self_sigstate)
Packit 6c4009
	/* TODO: %eax and %eax->sigaltstack are always valid?  */
Packit 6c4009
Packit 6c4009
	testl	$SS_ONSTACK, (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_FLAGS__OFFSET)(%eax)
Packit 6c4009
	/* Fail if SS_ONSTACK is not set.  */
Packit 6c4009
	jz	.Lfail
Packit 6c4009
Packit 6c4009
	movl	(HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SP__OFFSET)(%eax), %ebx
Packit 6c4009
	addl	(HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx
Packit 6c4009
	subl	%edi, %ebx
Packit 6c4009
	cmpl	(HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx
Packit 6c4009
	/* TODO: comment this calculation.  */
Packit 6c4009
	jae	.Lok
Packit 6c4009
Packit 6c4009
.Lfail:	CALL_FAIL
Packit 6c4009
Packit 6c4009
.Lok:	/* We add unwind information for the target here.  */
Packit 6c4009
	cfi_def_cfa(%ecx, 0)
Packit 6c4009
	cfi_register(%eip, %edx)
Packit 6c4009
	cfi_register(%esp, %edi)
Packit 6c4009
	cfi_offset(%ebx, JB_BX*4)
Packit 6c4009
	cfi_offset(%esi, JB_SI*4)
Packit 6c4009
	cfi_offset(%edi, JB_DI*4)
Packit 6c4009
	cfi_offset(%ebp, JB_BP*4)
Packit 6c4009
Packit 6c4009
	movl	8(%esp), %eax	/* Second argument is return value.  */
Packit 6c4009
	movl	%edi, %esp
Packit 6c4009
Packit 6c4009
	/* Restore registers.  */
Packit 6c4009
	movl	(JB_BX*4)(%ecx), %ebx
Packit 6c4009
	movl	(JB_SI*4)(%ecx), %esi
Packit 6c4009
	movl	(JB_DI*4)(%ecx), %edi
Packit 6c4009
	movl	(JB_BP*4)(%ecx), %ebp
Packit 6c4009
	cfi_restore(%ebx)
Packit 6c4009
	cfi_restore(%esi)
Packit 6c4009
	cfi_restore(%edi)
Packit 6c4009
	cfi_restore(%ebp)
Packit 6c4009
Packit 6c4009
	/* Jump to saved PC.  */
Packit 6c4009
	jmp	*%edx
Packit 6c4009
END (____longjmp_chk)