1/* $NetBSD: ucontext.h,v 1.24 2024/05/25 13:44:48 riastradh Exp $ */
2
3/*-
4 * Copyright (c) 1999, 2003, 2024 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _SYS_UCONTEXT_H_
33#define _SYS_UCONTEXT_H_
34
35#include <sys/sigtypes.h>
36
37/* uc_flags */
38#define _UC_SIGMASK 0x01 /* valid uc_sigmask */
39#define _UC_STACK 0x02 /* valid uc_stack */
40#define _UC_CPU 0x04 /* valid GPR context in uc_mcontext */
41#define _UC_FPU 0x08 /* valid FPU context in uc_mcontext */
42#define _UC_MD_BIT5 0x00000020 /* MD bits. see below */
43#define _UC_MD_BIT16 0x00010000
44#define _UC_MD_BIT17 0x00020000
45#define _UC_MD_BIT18 0x00040000
46#define _UC_MD_BIT19 0x00080000
47#define _UC_MD_BIT20 0x00100000
48#define _UC_MD_BIT21 0x00200000
49#define _UC_MD_BIT30 0x40000000
50
51/*
52 * if your port needs more MD bits, please choose bits from _UC_MD_BIT*
53 * rather than picking random unused bits.
54 *
55 * For historical reasons, some common flags have machine-dependent
56 * definitions. All platforms must define and handle those flags,
57 * which are:
58 *
59 * _UC_TLSBASE Context contains valid pthread private pointer
60 *
61 * _UC_SETSTACK Context uses signal stack
62 *
63 * _UC_CLRSTACK Context does not use signal stack
64 */
65
66#include <machine/mcontext.h>
67
68typedef struct __ucontext ucontext_t;
69
70struct __ucontext {
71 unsigned int uc_flags; /* properties */
72 ucontext_t * uc_link; /* context to resume */
73 sigset_t uc_sigmask; /* signals blocked in this context */
74 stack_t uc_stack; /* the stack used by this context */
75 mcontext_t uc_mcontext; /* machine state */
76#if defined(_UC_MACHINE_PAD)
77 long __uc_pad[_UC_MACHINE_PAD];
78#endif
79};
80
81#ifndef _UC_UCONTEXT_ALIGN
82#define _UC_UCONTEXT_ALIGN (~0)
83#endif
84
85#ifndef __UCONTEXT_SIZE
86#define __UCONTEXT_SIZE sizeof(ucontext_t)
87#endif
88
89#ifndef _UC_TLSBASE
90#error _UC_TLSBASE not defined.
91#endif
92
93#ifndef _UC_SETSTACK
94#error _UC_SETSTACK not defined.
95#endif
96
97#ifndef _UC_CLRSTACK
98#error _UC_CLRSTACK not defined.
99#endif
100
101#ifdef _KERNEL
102struct lwp;
103
104void getucontext(struct lwp *, ucontext_t *);
105int setucontext(struct lwp *, const ucontext_t *);
106void cpu_getmcontext(struct lwp *, mcontext_t *, unsigned int *);
107int cpu_setmcontext(struct lwp *, const mcontext_t *, unsigned int);
108int cpu_mcontext_validate(struct lwp *, const mcontext_t *);
109
110#ifdef __UCONTEXT_SIZE
111__CTASSERT(sizeof(ucontext_t) == __UCONTEXT_SIZE);
112#endif
113#endif /* _KERNEL */
114
115#endif /* !_SYS_UCONTEXT_H_ */