2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 2001 Julian Elischer <julian@freebsd.org>
5 * for the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice(s), this list of conditions and the following disclaimer as
14 * the first lines of this file unmodified other than the possible
15 * addition of one or more copyright notices.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice(s), this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38 #include <sys/ucontext.h>
40 #include <sys/signal.h>
43 * This file defines the structures needed for communication between
44 * the userland and the kernel when running a KSE-based threading system.
45 * The only programs that should see this file are the user thread
46 * scheduler (UTS) and the kernel.
50 typedef void kse_func_t(struct kse_mailbox *);
55 * This describes a user thread to the kernel scheduler.
57 struct kse_thr_mailbox {
58 ucontext_t tm_context; /* User and machine context */
59 uint32_t tm_flags; /* Thread flags */
60 struct kse_thr_mailbox *tm_next; /* Next thread in list */
61 void *tm_udata; /* For use by the UTS */
62 uint32_t tm_uticks; /* Time in userland */
63 uint32_t tm_sticks; /* Time in kernel */
65 uint32_t tm_dflags; /* Debug flags */
66 lwpid_t tm_lwp; /* kernel thread UTS runs on */
67 uint32_t __spare__[6];
73 * Communication path between the UTS and the kernel scheduler specific to
77 uint32_t km_version; /* Mailbox version */
78 struct kse_thr_mailbox *km_curthread; /* Currently running thread */
79 struct kse_thr_mailbox *km_completed; /* Threads back from kernel */
80 sigset_t km_sigscaught; /* Caught signals */
81 uint32_t km_flags; /* Mailbox flags */
82 kse_func_t *km_func; /* UTS function */
83 stack_t km_stack; /* UTS stack */
84 void *km_udata; /* For use by the UTS */
85 struct timespec km_timeofday; /* Time of day */
86 uint32_t km_quantum; /* Upcall quantum in msecs */
87 lwpid_t km_lwp; /* kernel thread UTS runs on */
88 uint32_t __spare2__[7];
92 #define KSE_VERSION KSE_VER_0
94 /* These flags are kept in km_flags */
95 #define KMF_NOUPCALL 0x01
96 #define KMF_NOCOMPLETED 0x02
98 #define KMF_BOUND 0x08
99 #define KMF_WAITSIGEVENT 0x10
101 /* These flags are kept in tm_flags */
102 #define TMF_NOUPCALL 0x01
104 /* These flags are kept in tm_dlfags */
105 #define TMDF_SSTEP 0x01
106 #define TMDF_SUSPEND 0x02
108 /* Flags for kse_switchin */
109 #define KSE_SWITCHIN_SETTMBX 0x01
111 /* Commands for kse_thr_interrupt */
112 #define KSE_INTR_INTERRUPT 1
113 #define KSE_INTR_RESTART 2
114 #define KSE_INTR_SENDSIG 3
115 #define KSE_INTR_SIGEXIT 4
116 #define KSE_INTR_DBSUSPEND 5
117 #define KSE_INTR_EXECVE 6
119 struct kse_execve_args {
129 int kse_create(struct kse_mailbox *, int);
131 int kse_release(struct timespec *);
132 int kse_thr_interrupt(struct kse_thr_mailbox *, int, long);
133 int kse_wakeup(struct kse_mailbox *);
134 int kse_switchin(struct kse_thr_mailbox *, int flags);
135 #endif /* !_KERNEL */
137 #endif /* !_SYS_KSE_H_ */