1 /* Save current context and install the given one.
2 Copyright (C) 2001-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
21 #include "ucontext_i.h"
25 /* Load address of the context data structure we save in. */
28 /* Return value of swapcontext. EAX is the only register whose
29 value is not preserved. */
32 /* Save the 32-bit register values and the return address. */
44 /* Save the FS segment register. */
49 leal oFPREGS(%eax), %ecx
50 /* Save the floating-point context. */
53 /* Load address of the context data structure we have to load. */
56 /* Save the current signal mask and install the new one. */
58 cfi_adjust_cfa_offset (12)
59 leal oSIGMASK(%eax), %eax
61 leal oSIGMASK(%ecx), %eax
63 movl $SIG_SETMASK, (%esp)
64 call HIDDEN_JUMPTARGET (__sigprocmask)
66 cfi_adjust_cfa_offset (-12)
70 /* EAX was modified, reload it. */
73 /* Restore the floating-point context. Not the registers, only the
75 leal oFPREGS(%eax), %ecx
78 /* Restore the FS segment register. We don't touch the GS register
79 since it is used for threads. */
83 /* Fetch the address to return to. */
86 /* Load the new stack pointer. */
89 /* Push the return address on the new stack so we can return there. */
92 /* Load the values of all the 32-bit registers (except ESP).
93 Since we are loading from EAX, it must be last. */
100 movl oEAX(%eax), %eax
102 /* The following 'ret' will pop the address of the code and jump
107 PSEUDO_END(__swapcontext)
109 weak_alias (__swapcontext, swapcontext)