|
Packit |
6c4009 |
/* Save current context.
|
|
Packit |
6c4009 |
Copyright (C) 2001-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
|
|
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 |
|
|
Packit |
6c4009 |
#include "ucontext_i.h"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ENTRY(__getcontext)
|
|
Packit |
6c4009 |
/* Load address of the context data structure. */
|
|
Packit |
6c4009 |
movl 4(%esp), %eax
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Return value of getcontext. EAX is the only register whose
|
|
Packit |
6c4009 |
value is not preserved. */
|
|
Packit |
6c4009 |
movl $0, oEAX(%eax)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Save the 32-bit register values and the return address. */
|
|
Packit |
6c4009 |
movl %ecx, oECX(%eax)
|
|
Packit |
6c4009 |
movl %edx, oEDX(%eax)
|
|
Packit |
6c4009 |
movl %edi, oEDI(%eax)
|
|
Packit |
6c4009 |
movl %esi, oESI(%eax)
|
|
Packit |
6c4009 |
movl %ebp, oEBP(%eax)
|
|
Packit |
6c4009 |
movl (%esp), %ecx
|
|
Packit |
6c4009 |
movl %ecx, oEIP(%eax)
|
|
Packit |
6c4009 |
leal 4(%esp), %ecx /* Exclude the return address. */
|
|
Packit |
6c4009 |
movl %ecx, oESP(%eax)
|
|
Packit |
6c4009 |
movl %ebx, oEBX(%eax)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Save the FS segment register. We don't touch the GS register
|
|
Packit |
6c4009 |
since it is used for threads. */
|
|
Packit |
6c4009 |
xorl %edx, %edx
|
|
Packit |
6c4009 |
movw %fs, %dx
|
|
Packit |
6c4009 |
movl %edx, oFS(%eax)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We have separate floating-point register content memory on the
|
|
Packit |
6c4009 |
stack. We use the __fpregs_mem block in the context. Set the
|
|
Packit |
6c4009 |
links up correctly. */
|
|
Packit |
6c4009 |
leal oFPREGSMEM(%eax), %ecx
|
|
Packit |
6c4009 |
movl %ecx, oFPREGS(%eax)
|
|
Packit |
6c4009 |
/* Save the floating-point context. */
|
|
Packit |
6c4009 |
fnstenv (%ecx)
|
|
Packit |
6c4009 |
/* And load it right back since the processor changes the mask.
|
|
Packit |
6c4009 |
Intel thought this opcode to be used in interrupt handlers which
|
|
Packit |
6c4009 |
would block all exceptions. */
|
|
Packit |
6c4009 |
fldenv (%ecx)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Save the current signal mask. */
|
|
Packit |
6c4009 |
pushl %ebx
|
|
Packit |
6c4009 |
cfi_adjust_cfa_offset (4)
|
|
Packit |
6c4009 |
cfi_rel_offset (ebx, 0)
|
|
Packit |
6c4009 |
leal oSIGMASK(%eax), %edx
|
|
Packit |
6c4009 |
xorl %ecx, %ecx
|
|
Packit |
6c4009 |
movl $SIG_BLOCK, %ebx
|
|
Packit |
6c4009 |
movl $__NR_sigprocmask, %eax
|
|
Packit |
6c4009 |
ENTER_KERNEL
|
|
Packit |
6c4009 |
popl %ebx
|
|
Packit |
6c4009 |
cfi_adjust_cfa_offset (-4)
|
|
Packit |
6c4009 |
cfi_restore (ebx)
|
|
Packit |
6c4009 |
cmpl $-4095, %eax /* Check %eax for error. */
|
|
Packit |
6c4009 |
jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* All done, return 0 for success. */
|
|
Packit |
6c4009 |
xorl %eax, %eax
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
PSEUDO_END(__getcontext)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
weak_alias (__getcontext, getcontext)
|