1177526Sjeff/*- 2177526Sjeff * Copyright (C) 2001 Julian Elischer <julian@freebsd.org> 3177526Sjeff * for the FreeBSD Foundation. 4177526Sjeff * 5177526Sjeff * All rights reserved. 6177526Sjeff * 7177526Sjeff * Redistribution and use in source and binary forms, with or without 8177526Sjeff * modification, are permitted provided that the following conditions 9177526Sjeff * are met: 10177526Sjeff * 1. Redistributions of source code must retain the above copyright 11177526Sjeff * notice(s), this list of conditions and the following disclaimer as 12177526Sjeff * the first lines of this file unmodified other than the possible 13177526Sjeff * addition of one or more copyright notices. 14177526Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15177526Sjeff * notice(s), this list of conditions and the following disclaimer in the 16177526Sjeff * documentation and/or other materials provided with the distribution. 17177526Sjeff * 18177526Sjeff * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 19177526Sjeff * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20177526Sjeff * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21177526Sjeff * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 22177526Sjeff * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23177526Sjeff * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24177526Sjeff * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25177526Sjeff * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26177526Sjeff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27177526Sjeff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 28177526Sjeff * DAMAGE. 29177526Sjeff * 30177526Sjeff * $FreeBSD$ 31177526Sjeff */ 32177526Sjeff 33177526Sjeff#ifndef _SYS_KSE_H_ 34177526Sjeff#define _SYS_KSE_H_ 35177526Sjeff 36177526Sjeff#include <sys/ucontext.h> 37177526Sjeff#include <sys/time.h> 38177526Sjeff#include <sys/signal.h> 39177526Sjeff 40177526Sjeff/* 41177526Sjeff * This file defines the structures needed for communication between 42177526Sjeff * the userland and the kernel when running a KSE-based threading system. 43177526Sjeff * The only programs that should see this file are the user thread 44177526Sjeff * scheduler (UTS) and the kernel. 45177526Sjeff */ 46177526Sjeffstruct kse_mailbox; 47177526Sjeff 48177526Sjefftypedef void kse_func_t(struct kse_mailbox *); 49177526Sjeff 50177526Sjeff/* 51177526Sjeff * Thread mailbox. 52177526Sjeff * 53177526Sjeff * This describes a user thread to the kernel scheduler. 54177526Sjeff */ 55177526Sjeffstruct kse_thr_mailbox { 56177526Sjeff ucontext_t tm_context; /* User and machine context */ 57177526Sjeff uint32_t tm_flags; /* Thread flags */ 58177526Sjeff struct kse_thr_mailbox *tm_next; /* Next thread in list */ 59177526Sjeff void *tm_udata; /* For use by the UTS */ 60177526Sjeff uint32_t tm_uticks; /* Time in userland */ 61177526Sjeff uint32_t tm_sticks; /* Time in kernel */ 62177526Sjeff siginfo_t tm_syncsig; 63177526Sjeff uint32_t tm_dflags; /* Debug flags */ 64177526Sjeff lwpid_t tm_lwp; /* kernel thread UTS runs on */ 65177526Sjeff uint32_t __spare__[6]; 66177526Sjeff}; 67177526Sjeff 68177526Sjeff/* 69177526Sjeff * KSE mailbox. 70177526Sjeff * 71177526Sjeff * Communication path between the UTS and the kernel scheduler specific to 72177526Sjeff * a single KSE. 73177526Sjeff */ 74177526Sjeffstruct kse_mailbox { 75177526Sjeff uint32_t km_version; /* Mailbox version */ 76177526Sjeff struct kse_thr_mailbox *km_curthread; /* Currently running thread */ 77177526Sjeff struct kse_thr_mailbox *km_completed; /* Threads back from kernel */ 78177526Sjeff sigset_t km_sigscaught; /* Caught signals */ 79177526Sjeff uint32_t km_flags; /* Mailbox flags */ 80177526Sjeff kse_func_t *km_func; /* UTS function */ 81177526Sjeff stack_t km_stack; /* UTS stack */ 82177526Sjeff void *km_udata; /* For use by the UTS */ 83177526Sjeff struct timespec km_timeofday; /* Time of day */ 84177526Sjeff uint32_t km_quantum; /* Upcall quantum in msecs */ 85177526Sjeff lwpid_t km_lwp; /* kernel thread UTS runs on */ 86177526Sjeff uint32_t __spare2__[7]; 87177526Sjeff}; 88177526Sjeff 89177526Sjeff#define KSE_VER_0 0 90177526Sjeff#define KSE_VERSION KSE_VER_0 91177526Sjeff 92177526Sjeff/* These flags are kept in km_flags */ 93177526Sjeff#define KMF_NOUPCALL 0x01 94177526Sjeff#define KMF_NOCOMPLETED 0x02 95177526Sjeff#define KMF_DONE 0x04 96177526Sjeff#define KMF_BOUND 0x08 97177526Sjeff#define KMF_WAITSIGEVENT 0x10 98177526Sjeff 99177526Sjeff/* These flags are kept in tm_flags */ 100177526Sjeff#define TMF_NOUPCALL 0x01 101177526Sjeff 102177526Sjeff/* These flags are kept in tm_dlfags */ 103177526Sjeff#define TMDF_SSTEP 0x01 104177526Sjeff#define TMDF_SUSPEND 0x02 105177526Sjeff 106177526Sjeff/* Flags for kse_switchin */ 107177526Sjeff#define KSE_SWITCHIN_SETTMBX 0x01 108177526Sjeff 109177526Sjeff/* Commands for kse_thr_interrupt */ 110177526Sjeff#define KSE_INTR_INTERRUPT 1 111177526Sjeff#define KSE_INTR_RESTART 2 112177526Sjeff#define KSE_INTR_SENDSIG 3 113177526Sjeff#define KSE_INTR_SIGEXIT 4 114177526Sjeff#define KSE_INTR_DBSUSPEND 5 115177526Sjeff#define KSE_INTR_EXECVE 6 116177526Sjeff 117177526Sjeffstruct kse_execve_args { 118177526Sjeff sigset_t sigmask; 119177526Sjeff sigset_t sigpend; 120177526Sjeff char *path; 121177526Sjeff char **argv; 122177526Sjeff char **envp; 123177526Sjeff void *reserved; 124177526Sjeff}; 125177526Sjeff 126177526Sjeff#ifndef _KERNEL 127177526Sjeffint kse_create(struct kse_mailbox *, int); 128177526Sjeffint kse_exit(void); 129177526Sjeffint kse_release(struct timespec *); 130177526Sjeffint kse_thr_interrupt(struct kse_thr_mailbox *, int, long); 131177526Sjeffint kse_wakeup(struct kse_mailbox *); 132177526Sjeffint kse_switchin(struct kse_thr_mailbox *, int flags); 133177526Sjeff#endif /* !_KERNEL */ 134177526Sjeff 135177526Sjeff#endif /* !_SYS_KSE_H_ */ 136