4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
29 #include <sys/asm_linkage.h>
31 ANSI_PRAGMA_WEAK
(getcontext
,function
)
32 ANSI_PRAGMA_WEAK
(swapcontext
,function
)
38 * getcontext() is written in assembler since it has to capture the correct
39 * machine state of the calle.
41 * As swapcontext() is actually equivalent to getcontext() + setcontext(),
42 * swapcontext() shares the most code with getcontext().
45 #define GETCONTEXT_IMPL(offset) \
46 pushq
%rdi;
/* preserve the ucontext_t pointer */ \
48 /* call getcontext: syscall */ \
50 andl
%eax
, %eax;
/* if (error_return_from_syscall) */ \
53 ret;
/* then just return */ \
56 * fix up %rsp and %rip \
58 addq $UC_MCONTEXT_GREGS
, %rdx; \
59 /* &ucp->uc_mcontext.gregs */ \
60 movq offset+
0(%rsp
), %rax; \
61 /* read return PC from stack */ \
62 movq
%rax
, RIP_OFF
(%rdx
); \
63 /* store ret PC in EIP of env var */ \
64 leaq offset+
8(%rsp
), %rax; \
65 /* get caller's sp at time of call */ \
66 movq
%rax
, RSP_OFF
(%rdx
); \
67 /* store the sp into UESP of env var */ \
68 xorq
%rax
, %rax;
/* return 0 */ \
69 movq
%rax
, RAX_OFF
(%rdx
); \
70 /* getcontext returns 0 after setcontext */
73 * getcontext(ucontext_t *ucp)
82 * swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
86 pushq
%rsi
/* preserve the 2nd argument */