1 | /* Install given 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(__setcontext) |
25 | /* Load address of the context data structure. */ |
26 | movl 4(%esp), %eax |
27 | |
28 | /* Get the current signal mask. Note that we preserve EBX in case |
29 | the system call fails and we return from the function with an |
30 | error. */ |
31 | pushl %ebx |
32 | cfi_adjust_cfa_offset (4) |
33 | xorl %edx, %edx |
34 | leal oSIGMASK(%eax), %ecx |
35 | movl $SIG_SETMASK, %ebx |
36 | cfi_rel_offset (ebx, 0) |
37 | movl $__NR_sigprocmask, %eax |
38 | ENTER_KERNEL |
39 | popl %ebx |
40 | cfi_adjust_cfa_offset (-4) |
41 | cfi_restore (ebx) |
42 | cmpl $-4095, %eax /* Check %eax for error. */ |
43 | jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */ |
44 | |
45 | /* EAX was modified, reload it. */ |
46 | movl 4(%esp), %eax |
47 | |
48 | /* Restore the floating-point context. Not the registers, only the |
49 | rest. */ |
50 | movl oFPREGS(%eax), %ecx |
51 | fldenv (%ecx) |
52 | |
53 | /* Restore the FS segment register. We don't touch the GS register |
54 | since it is used for threads. */ |
55 | movl oFS(%eax), %ecx |
56 | movw %cx, %fs |
57 | |
58 | /* Fetch the address to return to. */ |
59 | movl oEIP(%eax), %ecx |
60 | |
61 | /* Load the new stack pointer. */ |
62 | cfi_def_cfa (eax, 0) |
63 | cfi_offset (edi, oEDI) |
64 | cfi_offset (esi, oESI) |
65 | cfi_offset (ebp, oEBP) |
66 | cfi_offset (ebx, oEBX) |
67 | movl oESP(%eax), %esp |
68 | |
69 | /* Push the return address on the new stack so we can return there. */ |
70 | pushl %ecx |
71 | |
72 | /* Load the values of all the preserved registers (except ESP). */ |
73 | movl oEDI(%eax), %edi |
74 | movl oESI(%eax), %esi |
75 | movl oEBP(%eax), %ebp |
76 | movl oEBX(%eax), %ebx |
77 | |
78 | /* All done, return 0 for success. */ |
79 | xorl %eax, %eax |
80 | |
81 | /* End FDE here, we fall into another context. */ |
82 | cfi_endproc |
83 | cfi_startproc |
84 | |
85 | /* The following 'ret' will pop the address of the code and jump |
86 | to it. */ |
87 | |
88 | ret |
89 | PSEUDO_END(__setcontext) |
90 | libc_hidden_def (__setcontext) |
91 | |
92 | weak_alias (__setcontext, setcontext) |
93 | |