]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/getcontext.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / getcontext.S
1 /* Save current context.
2 Copyright (C) 2001-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20 #include <sysdep.h>
21
22 #include "ucontext_i.h"
23
24
25 ENTRY(__getcontext)
26 /* Load address of the context data structure. */
27 movl 4(%esp), %eax
28
29 /* Return value of getcontext. EAX is the only register whose
30 value is not preserved. */
31 movl $0, oEAX(%eax)
32
33 /* Save the 32-bit register values and the return address. */
34 movl %ecx, oECX(%eax)
35 movl %edx, oEDX(%eax)
36 movl %edi, oEDI(%eax)
37 movl %esi, oESI(%eax)
38 movl %ebp, oEBP(%eax)
39 movl (%esp), %ecx
40 movl %ecx, oEIP(%eax)
41 leal 4(%esp), %ecx /* Exclude the return address. */
42 movl %ecx, oESP(%eax)
43 movl %ebx, oEBX(%eax)
44
45 /* Save the FS segment register. We don't touch the GS register
46 since it is used for threads. */
47 xorl %edx, %edx
48 movw %fs, %dx
49 movl %edx, oFS(%eax)
50
51 /* We have separate floating-point register content memory on the
52 stack. We use the __fpregs_mem block in the context. Set the
53 links up correctly. */
54 leal oFPREGSMEM(%eax), %ecx
55 movl %ecx, oFPREGS(%eax)
56 /* Save the floating-point context. */
57 fnstenv (%ecx)
58 /* And load it right back since the processor changes the mask.
59 Intel thought this opcode to be used in interrupt handlers which
60 would block all exceptions. */
61 fldenv (%ecx)
62
63 /* Save the current signal mask. */
64 pushl %ebx
65 cfi_adjust_cfa_offset (4)
66 cfi_rel_offset (ebx, 0)
67 leal oSIGMASK(%eax), %edx
68 xorl %ecx, %ecx
69 movl $SIG_BLOCK, %ebx
70 movl $__NR_sigprocmask, %eax
71 ENTER_KERNEL
72 popl %ebx
73 cfi_adjust_cfa_offset (-4)
74 cfi_restore (ebx)
75 cmpl $-4095, %eax /* Check %eax for error. */
76 jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
77
78 /* All done, return 0 for success. */
79 xorl %eax, %eax
80 ret
81 PSEUDO_END(__getcontext)
82
83 weak_alias (__getcontext, getcontext)