2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / x86_64 / __start_context.S
blob37d391760ba891ae68d04b0fb17e67695e532992
1 /* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Andreas Jaeger <aj@suse.de>, 2002.
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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
22 /* This is the helper code which gets called if a function which is
23    registered with 'makecontext' returns.  In this case we have to
24    install the context listed in the uc_link element of the context
25    'makecontext' manipulated at the time of the 'makecontext' call.
26    If the pointer is NULL the process must terminate.  */
29 ENTRY(__start_context)
30         /* This removes the parameters passed to the function given to
31            'makecontext' from the stack.  RBX contains the address
32            on the stack pointer for the next context.  */
33         movq    %rbx, %rsp
35         popq    %rdi                    /* This is the next context.  */
36         cfi_adjust_cfa_offset(-8)
37         testq   %rdi, %rdi
38         je      2f                      /* If it is zero exit.  */
40         call    JUMPTARGET(__setcontext)
41         /* If this returns (which can happen if the syscall fails) we'll
42            exit the program with the return error value (-1).  */
44 2:      movq    %rax,%rdi
45         call    HIDDEN_JUMPTARGET(exit)
46         /* The 'exit' call should never return.  In case it does cause
47            the process to terminate.  */
48         hlt
49 END(__start_context)