FreeBSD/Linux Kernel Cross Reference
sys/sys/ucontext.h
1 /* $NetBSD: ucontext.h,v 1.4 2003/10/13 18:50:43 fvdl 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 #if defined(COMPAT_NETBSD32) && defined(_KERNEL)
63
64 typedef struct __ucontext32 ucontext32_t;
65
66 struct __ucontext32 {
67 unsigned int uc_flags; /* properties */
68 uint32_t uc_link; /* context to resume */
69 sigset_t uc_sigmask; /* signals blocked in this context */
70 stack32_t uc_stack; /* the stack used by this context */
71 mcontext32_t uc_mcontext; /* machine state */
72 #if defined(_UC_MACHINE32_PAD)
73 int __uc_pad[_UC_MACHINE32_PAD];
74 #endif
75 };
76
77 #endif /* COMPAT_NETBSD32 && _KERNEL */
78
79 /* uc_flags */
80 #define _UC_SIGMASK 0x01 /* valid uc_sigmask */
81 #define _UC_STACK 0x02 /* valid uc_stack */
82 #define _UC_CPU 0x04 /* valid GPR context in uc_mcontext */
83 #define _UC_FPU 0x08 /* valid FPU context in uc_mcontext */
84
85 /*
86 * The following macros are used to convert from a ucontext to sigcontext,
87 * and vice-versa. This is for building a sigcontext to deliver to old-style
88 * signal handlers, and converting back (in the event the handler modifies
89 * the context).
90 *
91 * The only valid use of these macros is to convert a ucontext to a
92 * sigcontext for old-style signal delivery and then back to the same
93 * ucontext after the handler has returned.
94 *
95 * The _MCONTEXT_TO_SIGCONTEXT() and _SIGCONTEXT_TO_MCONTEXT() macros
96 * should be provided by <machine/signal.h>.
97 */
98 #define _UCONTEXT_TO_SIGCONTEXT(uc, sc) \
99 do { \
100 (sc)->sc_mask = (uc)->uc_sigmask; \
101 if (((uc)->uc_flags & _UC_STACK) != 0 && \
102 ((uc)->uc_stack.ss_flags & SS_ONSTACK) != 0) \
103 (sc)->sc_onstack = 1; \
104 else \
105 (sc)->sc_onstack = 0; \
106 \
107 _MCONTEXT_TO_SIGCONTEXT(uc, sc); \
108 } while (/*CONSTCOND*/0)
109
110 #define _SIGCONTEXT_TO_UCONTEXT(sc, uc) \
111 do { \
112 (uc)->uc_sigmask = (sc)->sc_mask; \
113 \
114 /* \
115 * XXX What do do about uc_stack? See \
116 * XXX kern_sig.c:setucontext(). \
117 */ \
118 \
119 _SIGCONTEXT_TO_MCONTEXT(sc, uc); \
120 } while (/*CONSTCOND*/0)
121
122 #ifdef _KERNEL
123 struct lwp;
124
125 void getucontext(struct lwp *, ucontext_t *);
126 int setucontext(struct lwp *, const ucontext_t *);
127 void cpu_getmcontext(struct lwp *, mcontext_t *, unsigned int *);
128 int cpu_setmcontext(struct lwp *, const mcontext_t *, unsigned int);
129 #ifdef COMPAT_NETBSD32
130 void getucontext32(struct lwp *, ucontext32_t *);
131 int setucontext32(struct lwp *, const ucontext32_t *);
132 void cpu_getmcontext32(struct lwp *, mcontext32_t *, unsigned int *);
133 int cpu_setmcontext32(struct lwp *, const mcontext32_t *, unsigned int);
134 #endif /* COMPAT_NETBSD32 */
135 #endif /* _KERNEL */
136
137 #endif /* !_SYS_UCONTEXT_H_ */
Cache object: 504016112bad4db425eb2faf3b915bd4
|