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