FreeBSD/Linux Kernel Cross Reference
sys/sys/ucontext.h
1 /* $NetBSD: ucontext.h,v 1.6 2005/02/26 22:25:34 perry Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Klaus Klein, and by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _SYS_UCONTEXT_H_
40 #define _SYS_UCONTEXT_H_
41
42 #if defined(_KERNEL_OPT)
43 #include "opt_compat_netbsd32.h"
44 #endif
45
46 #include <sys/sigtypes.h>
47 #include <machine/mcontext.h>
48
49 typedef struct __ucontext ucontext_t;
50
51 struct __ucontext {
52 unsigned int uc_flags; /* properties */
53 ucontext_t * uc_link; /* context to resume */
54 sigset_t uc_sigmask; /* signals blocked in this context */
55 stack_t uc_stack; /* the stack used by this context */
56 mcontext_t uc_mcontext; /* machine state */
57 #if defined(_UC_MACHINE_PAD)
58 long __uc_pad[_UC_MACHINE_PAD];
59 #endif
60 };
61
62 #ifndef _UC_UCONTEXT_ALIGN
63 #define _UC_UCONTEXT_ALIGN (~0)
64 #endif
65
66 #if defined(COMPAT_NETBSD32) && defined(_KERNEL)
67
68 typedef struct __ucontext32 ucontext32_t;
69
70 struct __ucontext32 {
71 unsigned int uc_flags; /* properties */
72 uint32_t uc_link; /* context to resume */
73 sigset_t uc_sigmask; /* signals blocked in this context */
74 stack32_t uc_stack; /* the stack used by this context */
75 mcontext32_t uc_mcontext; /* machine state */
76 #if defined(_UC_MACHINE32_PAD)
77 int __uc_pad[_UC_MACHINE32_PAD];
78 #endif
79 };
80
81 #endif /* COMPAT_NETBSD32 && _KERNEL */
82
83 /* uc_flags */
84 #define _UC_SIGMASK 0x01 /* valid uc_sigmask */
85 #define _UC_STACK 0x02 /* valid uc_stack */
86 #define _UC_CPU 0x04 /* valid GPR context in uc_mcontext */
87 #define _UC_FPU 0x08 /* valid FPU context in uc_mcontext */
88
89 /*
90 * The following macros are used to convert from a ucontext to sigcontext,
91 * and vice-versa. This is for building a sigcontext to deliver to old-style
92 * signal handlers, and converting back (in the event the handler modifies
93 * the context).
94 *
95 * The only valid use of these macros is to convert a ucontext to a
96 * sigcontext for old-style signal delivery and then back to the same
97 * ucontext after the handler has returned.
98 *
99 * The _MCONTEXT_TO_SIGCONTEXT() and _SIGCONTEXT_TO_MCONTEXT() macros
100 * should be provided by <machine/signal.h>.
101 */
102 #define _UCONTEXT_TO_SIGCONTEXT(uc, sc) \
103 do { \
104 (sc)->sc_mask = (uc)->uc_sigmask; \
105 if (((uc)->uc_flags & _UC_STACK) != 0 && \
106 ((uc)->uc_stack.ss_flags & SS_ONSTACK) != 0) \
107 (sc)->sc_onstack = 1; \
108 else \
109 (sc)->sc_onstack = 0; \
110 \
111 _MCONTEXT_TO_SIGCONTEXT(uc, sc); \
112 } while (/*CONSTCOND*/0)
113
114 #define _SIGCONTEXT_TO_UCONTEXT(sc, uc) \
115 do { \
116 (uc)->uc_sigmask = (sc)->sc_mask; \
117 \
118 /* \
119 * XXX What do do about uc_stack? See \
120 * XXX kern_sig.c:setucontext(). \
121 */ \
122 \
123 _SIGCONTEXT_TO_MCONTEXT(sc, uc); \
124 } while (/*CONSTCOND*/0)
125
126 #ifdef _KERNEL
127 struct lwp;
128
129 void getucontext(struct lwp *, ucontext_t *);
130 int setucontext(struct lwp *, const ucontext_t *);
131 void cpu_getmcontext(struct lwp *, mcontext_t *, unsigned int *);
132 int cpu_setmcontext(struct lwp *, const mcontext_t *, unsigned int);
133 #ifdef COMPAT_NETBSD32
134 void getucontext32(struct lwp *, ucontext32_t *);
135 int setucontext32(struct lwp *, const ucontext32_t *);
136 void cpu_getmcontext32(struct lwp *, mcontext32_t *, unsigned int *);
137 int cpu_setmcontext32(struct lwp *, const mcontext32_t *, unsigned int);
138 #endif /* COMPAT_NETBSD32 */
139 #endif /* _KERNEL */
140
141 #endif /* !_SYS_UCONTEXT_H_ */
Cache object: 91fa40c222c5a17089dc000dc9f290f2
|