1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (C) 2001 Julian Elischer <julian@freebsd.org> 5 * for the FreeBSD Foundation. 6 * 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 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. 19 * 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 30 * DAMAGE. 31 * 32 * $FreeBSD$ 33 */ 34 35 #ifndef _SYS_KSE_H_ 36 #define _SYS_KSE_H_ 37 38 #include <sys/ucontext.h> 39 #include <sys/time.h> 40 #include <sys/signal.h> 41 42 /* 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. 47 */ 48 struct kse_mailbox; 49 50 typedef void kse_func_t(struct kse_mailbox *); 51 52 /* 53 * Thread mailbox. 54 * 55 * This describes a user thread to the kernel scheduler. 56 */ 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 */ 64 siginfo_t tm_syncsig; 65 uint32_t tm_dflags; /* Debug flags */ 66 lwpid_t tm_lwp; /* kernel thread UTS runs on */ 67 uint32_t __spare__[6]; 68 }; 69 70 /* 71 * KSE mailbox. 72 * 73 * Communication path between the UTS and the kernel scheduler specific to 74 * a single KSE. 75 */ 76 struct kse_mailbox { 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]; 89 }; 90 91 #define KSE_VER_0 0 92 #define KSE_VERSION KSE_VER_0 93 94 /* These flags are kept in km_flags */ 95 #define KMF_NOUPCALL 0x01 96 #define KMF_NOCOMPLETED 0x02 97 #define KMF_DONE 0x04 98 #define KMF_BOUND 0x08 99 #define KMF_WAITSIGEVENT 0x10 100 101 /* These flags are kept in tm_flags */ 102 #define TMF_NOUPCALL 0x01 103 104 /* These flags are kept in tm_dlfags */ 105 #define TMDF_SSTEP 0x01 106 #define TMDF_SUSPEND 0x02 107 108 /* Flags for kse_switchin */ 109 #define KSE_SWITCHIN_SETTMBX 0x01 110 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 118 119 struct kse_execve_args { 120 sigset_t sigmask; 121 sigset_t sigpend; 122 char *path; 123 char **argv; 124 char **envp; 125 void *reserved; 126 }; 127 128 #ifndef _KERNEL 129 int kse_create(struct kse_mailbox *, int); 130 int kse_exit(void); 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 */ 136 137 #endif /* !_SYS_KSE_H_ */ 138