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