2 Copyright (C) 2001, 2002, 2005, 2007, 2008 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include "ucontext_i.h"
29 /* Load the address of the function we are supposed to run. */
32 /* Compute the address of the stack. The information comes from
33 to us_stack element. */
34 movl oSS_SP(%eax), %edx
36 addl oSS_SIZE(%eax), %edx
38 /* Remember the number of parameters for the exit handler since
39 it has to remove them. We store the number in the EBX register
40 which the function we will call must preserve. */
44 /* Make room on the new stack for the parameters.
45 Room for the arguments, return address (== L(exitcode)) and
46 oLINK pointer is needed. One of the pointer sizes is subtracted
47 after aligning the stack. */
49 leal -4(%edx,%ecx,4), %edx
52 /* Align the stack. */
53 andl $0xfffffff0, %edx
56 /* Store the future stack pointer. */
59 /* Put the next context on the new stack (from the uc_link
61 movl oLINK(%eax), %eax
62 movl %eax, 4(%edx,%ecx,4)
64 /* Copy all the parameters. */
66 1: movl 12(%esp,%ecx,4), %eax
67 movl %eax, (%edx,%ecx,4)
72 /* If the function we call returns we must continue with the
73 context which is given in the uc_link element. To do this
74 set the return address for the function the user provides
75 to a little bit of helper code which does the magic (see
79 cfi_adjust_cfa_offset (4)
81 cfi_adjust_cfa_offset (-4)
82 addl $L(exitcode)-1b, %ecx
85 movl $L(exitcode), (%edx)
87 /* 'makecontext' returns no value. */
90 /* This is the helper code which gets called if a function which
91 is registered with 'makecontext' returns. In this case we
92 have to install the context listed in the uc_link element of
93 the context 'makecontext' manipulated at the time of the
94 'makecontext' call. If the pointer is NULL the process must
98 /* This removes the parameters passed to the function given to
99 'makecontext' from the stack. EBX contains the number of
100 parameters (see above). */
101 leal (%esp,%ebx,4), %esp
106 addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
108 popl %eax /* This is the next context. */
110 je 2f /* If it is zero exit. */
113 call JUMPTARGET(__setcontext)
114 /* If this returns (which can happen if the syscall fails) we'll
115 exit the program with the return error value (-1). */
118 call HIDDEN_JUMPTARGET(exit)
119 /* The 'exit' call should never return. In case it does cause
120 the process to terminate. */
125 weak_alias (__makecontext, makecontext)