xref: /illumos-gate/usr/src/uts/common/sys/door_data.h (revision dd72704bd9e794056c558153663c739e2012d721)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DOOR_DATA_H
27 #define	_SYS_DOOR_DATA_H
28 
29 #include <sys/types.h>
30 #include <sys/door.h>
31 
32 #if defined(_KERNEL)
33 #include <sys/thread.h>
34 #include <sys/file.h>
35 #endif
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #if defined(_KERNEL)
42 /* door_return() stack layout */
43 typedef struct door_layout {
44 	caddr_t		dl_descp;	/* start of descriptors (or 0) */
45 	caddr_t		dl_datap;	/* start of data (or 0) */
46 	caddr_t		dl_infop;	/* start of door_info_t (or 0) */
47 	caddr_t		dl_resultsp;	/* start of door_results{32}_t */
48 	caddr_t		dl_sp;		/* final stack pointer (non-biased) */
49 } door_layout_t;
50 
51 /* upcall invocation information */
52 typedef struct door_upcall_data {
53 	cred_t		*du_cred;	/* Credential associated w/ upcall */
54 	size_t		du_max_data;	/* Maximum amount of reply data */
55 	uint_t		du_max_descs;	/* Maximum number of reply descs */
56 } door_upcall_t;
57 
58 /*
59  * Per-thread data associated with door invocations.  Each door invocation
60  * effects the client structure of one thread and the server structure of
61  * another.  This way, the server thread for one door_call() can make door
62  * calls of its own without interference.
63  */
64 typedef struct door_client {
65 	door_arg_t	d_args;		/* Door arg/results */
66 	door_upcall_t	*d_upcall;	/* upcall information */
67 	caddr_t		d_buf;		/* Temp buffer for data transfer */
68 	int		d_bufsize;	/* Size of temp buffer */
69 	int		d_fpp_size;	/* Number of File ptrs */
70 	struct file	**d_fpp;	/* File ptrs  */
71 	int		d_error;	/* Error (if any) */
72 	kcondvar_t	d_cv;
73 	uchar_t		d_args_done;	/* server has processed client's args */
74 	uchar_t		d_hold;		/* Thread needs to stick around */
75 	uchar_t		d_noresults;	/* No results allowed */
76 	uchar_t		d_overflow;	/* Result overflow occurred */
77 	uchar_t		d_kernel;	/* Kernel door server */
78 } door_client_t;
79 
80 typedef struct door_server {
81 	struct _kthread	*d_caller;	/* Door caller */
82 	struct _kthread *d_servers;	/* List of door servers */
83 	struct door_node *d_active;	/* Active door */
84 	struct door_node *d_pool;	/* our server thread pool */
85 	door_layout_t	d_layout;
86 	caddr_t		d_sp;		/* Saved thread stack base */
87 	size_t		d_ssize;	/* Saved thread stack size */
88 	kcondvar_t	d_cv;
89 	uchar_t		d_hold;		/* Thread needs to stick around */
90 	uchar_t		d_invbound;	/* Thread is bound to invalid door */
91 	uchar_t		d_layout_done;	/* d_layout has been filled */
92 } door_server_t;
93 
94 typedef struct door_data {
95 	door_client_t d_client;
96 	door_server_t d_server;
97 } door_data_t;
98 
99 #define	DOOR_CLIENT(dp) (&(dp)->d_client)
100 #define	DOOR_SERVER(dp) (&(dp)->d_server)
101 
102 /*
103  * Macros for holding a thread in place.  Takes a door_server_t or
104  * door_client_t pointer as an argument.
105  */
106 #define	DOOR_T_HELD(cst)	((cst)->d_hold)
107 
108 #define	DOOR_T_HOLD(cst) \
109 	(ASSERT(!DOOR_T_HELD(cst)), ((cst)->d_hold = 1))
110 #define	DOOR_T_RELEASE(cst) \
111 	(ASSERT(DOOR_T_HELD(cst)), ((cst)->d_hold = 0), \
112 	    cv_broadcast(&(cst)->d_cv))
113 
114 /*
115  * Roundup buffer size when passing/returning data via kernel buffer.
116  * This cuts down on the number of overflows that occur on return
117  */
118 #define	DOOR_ROUND	128
119 
120 #endif	/* defined(_KERNEL) */
121 
122 #ifdef	__cplusplus
123 }
124 #endif
125 
126 #endif	/* _SYS_DOOR_DATA_H */
127