xref: /titanic_44/usr/src/uts/common/sys/door.h (revision 734b6a94890be549309b21156f8ed6d4561cac51)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * The door lightweight RPC I/F.
29  */
30 
31 #ifndef	_SYS_DOOR_H
32 #define	_SYS_DOOR_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #if !defined(_ASM)
41 
42 #include <sys/types.h>
43 
44 #if defined(_KERNEL)
45 #include <sys/mutex.h>
46 #include <sys/vnode.h>
47 #include <sys/door_impl.h>
48 #endif /* defined(_KERNEL) */
49 
50 /* Basic door type information */
51 typedef unsigned long long door_ptr_t;	/* Handle 64 bit pointers */
52 typedef unsigned long long door_id_t;	/* Unique door identifier */
53 typedef	unsigned int	   door_attr_t;	/* Door attributes */
54 
55 #ifdef _KERNEL
56 struct __door_handle;
57 typedef struct __door_handle *door_handle_t;	/* opaque kernel door handle */
58 #endif
59 
60 #define	DOOR_INVAL -1			/* An invalid door descriptor */
61 #define	DOOR_UNREF_DATA ((void *)1)	/* Unreferenced invocation address */
62 
63 /* Door descriptor passed to door_info to get current thread's binding */
64 #define	DOOR_QUERY -2
65 
66 /*
67  * Attributes associated with doors.
68  */
69 
70 /* Attributes originally obtained from door_create operation */
71 #define	DOOR_UNREF	0x01	/* Deliver an unref notification with door */
72 #define	DOOR_PRIVATE	0x02	/* Use a private pool of server threads */
73 #define	DOOR_UNREF_MULTI 0x10	/* Deliver unref notification more than once */
74 #define	DOOR_REFUSE_DESC 0x40	/* Do not accept descriptors from callers */
75 #define	DOOR_NO_CANCEL	0x80	/* No server thread cancel on client abort */
76 
77 /* Attributes (additional) returned with door_info and door_desc_t data */
78 #define	DOOR_LOCAL	0x04	/* Descriptor is local to current process */
79 #define	DOOR_REVOKED	0x08	/* Door has been revoked */
80 #define	DOOR_IS_UNREF	0x20	/* Door is currently unreferenced */
81 
82 /* Masks of applicable flags */
83 #define	DOOR_CREATE_MASK	(DOOR_UNREF | DOOR_PRIVATE | \
84 	    DOOR_UNREF_MULTI | DOOR_REFUSE_DESC | DOOR_NO_CANCEL)
85 #define	DOOR_KI_CREATE_MASK	(DOOR_UNREF | DOOR_UNREF_MULTI)
86 
87 /* Mask of above attributes */
88 #define	DOOR_ATTR_MASK	(DOOR_CREATE_MASK | \
89 	    DOOR_LOCAL | DOOR_REVOKED | DOOR_IS_UNREF)
90 
91 /* Attributes used to describe door_desc_t data */
92 #define	DOOR_DESCRIPTOR	0x10000	/* A file descriptor is being passed */
93 #ifdef _KERNEL
94 #define	DOOR_HANDLE	0x20000 /* A kernel door handle is being passed */
95 #endif
96 #define	DOOR_RELEASE	0x40000	/* Passed references are also released */
97 
98 /* Misc attributes used internally */
99 #define	DOOR_DELAY	0x80000	/* Delayed unref delivery */
100 #define	DOOR_UNREF_ACTIVE 0x100000	/* Unreferenced call is active */
101 
102 /* door parameters */
103 #define	DOOR_PARAM_DESC_MAX	1	/* max number of request descriptors */
104 #define	DOOR_PARAM_DATA_MAX	2	/* max bytes of request data */
105 #define	DOOR_PARAM_DATA_MIN	3	/* min bytes of request data */
106 
107 /*
108  * On AMD64, 32-bit pack door_desc and door_info to avoid needing special
109  * copyin/copyout conversions due to differing alignment rules between
110  * 32-bit x86 and 64-bit amd64.
111  */
112 
113 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
114 #pragma pack(4)
115 #endif
116 
117 /*
118  * Structure used to pass descriptors/objects in door invocations
119  */
120 
121 typedef struct door_desc {
122 	door_attr_t	d_attributes;	/* Tag for union */
123 	union {
124 		/* File descriptor is passed */
125 		struct {
126 			int		d_descriptor;
127 			door_id_t	d_id;		/* unique id */
128 		} d_desc;
129 #ifdef _KERNEL
130 		/* Kernel passes handles referring to doors */
131 		door_handle_t d_handle;
132 #endif
133 		/* Reserved space */
134 		int		d_resv[5];
135 	} d_data;
136 } door_desc_t;
137 
138 /*
139  * Structure used to return info from door_info
140  */
141 typedef struct door_info {
142 	pid_t		di_target;	/* Server process */
143 	door_ptr_t	di_proc;	/* Server procedure */
144 	door_ptr_t	di_data;	/* Data cookie */
145 	door_attr_t	di_attributes;	/* Attributes associated with door */
146 	door_id_t	di_uniquifier;	/* Unique number */
147 	int		di_resv[4];	/* Future use */
148 } door_info_t;
149 
150 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
151 #pragma pack()
152 #endif
153 
154 /*
155  * Structure used to return info from door_cred
156  */
157 typedef struct door_cred {
158 	uid_t	dc_euid;	/* Effective uid of client */
159 	gid_t	dc_egid;	/* Effective gid of client */
160 	uid_t	dc_ruid;	/* Real uid of client */
161 	gid_t	dc_rgid;	/* Real gid of client */
162 	pid_t	dc_pid;		/* pid of client */
163 	int	dc_resv[4];	/* Future use */
164 } door_cred_t;
165 
166 /*
167  * Structure used to pass/return data from door_call
168  *
169  * All fields are in/out paramters. Upon return these fields
170  * are updated to reflect the true location and size of the results.
171  */
172 typedef struct door_arg {
173 	char		*data_ptr;	/* Argument/result data */
174 	size_t		data_size;	/* Argument/result data size */
175 	door_desc_t	*desc_ptr;	/* Argument/result descriptors */
176 	uint_t		desc_num;	/* Argument/result num discriptors */
177 	char		*rbuf;		/* Result area */
178 	size_t		rsize;		/* Result size */
179 } door_arg_t;
180 
181 #if defined(_SYSCALL32)
182 /*
183  * Structure to pass/return data from 32-bit program's door_call.
184  */
185 typedef struct door_arg32 {
186 	caddr32_t	data_ptr;	/* Argument/result data */
187 	size32_t	data_size;	/* Argument/result data size */
188 	caddr32_t	desc_ptr;	/* Argument/result descriptors */
189 	uint32_t	desc_num;	/* Argument/result num descriptors */
190 	caddr32_t	rbuf;		/* Result area */
191 	size32_t	rsize;		/* Result size */
192 } door_arg32_t;
193 #endif
194 
195 /*
196  * Structure used to pass door invocation information.
197  */
198 struct door_results {
199 	void		*cookie;
200 	char		*data_ptr;
201 	size_t		data_size;
202 	door_desc_t	*desc_ptr;
203 	size_t		desc_num;
204 	void		(*pc)();
205 	int		nservers;	/* zero if thread pool is empty */
206 	door_info_t	*door_info;
207 };
208 
209 #if defined(_SYSCALL32)
210 /*
211  * Structure used to pass door invocation information to 32-bit processes.
212  */
213 struct door_results32 {
214 	caddr32_t	cookie;
215 	caddr32_t	data_ptr;
216 	size32_t	data_size;
217 	caddr32_t	desc_ptr;
218 	size32_t	desc_num;
219 	caddr32_t	pc;
220 	int		nservers;
221 	caddr32_t	door_info;
222 };
223 #endif
224 
225 /*
226  * Structure used to pass a descriptor list to door_return.
227  */
228 typedef struct door_return_desc {
229 	door_desc_t	*desc_ptr;
230 	uint_t		desc_num;
231 } door_return_desc_t;
232 
233 #if defined(_SYSCALL32)
234 typedef struct door_return_desc32 {
235 	caddr32_t	desc_ptr;
236 	uint_t		desc_num;
237 } door_return_desc32_t;
238 #endif
239 
240 #if defined(_KERNEL)
241 
242 /*
243  * Errors used for doors. Negative numbers to avoid conflicts with errnos
244  */
245 #define	DOOR_WAIT	-1	/* Waiting for response */
246 #define	DOOR_EXIT	-2	/* Server thread has exited */
247 
248 #define	VTOD(v)	((struct door_node *)(v->v_data))
249 #define	DTOV(d) ((d)->door_vnode)
250 
251 /*
252  * Underlying 'filesystem' object definition
253  */
254 typedef struct door_node {
255 	vnode_t		*door_vnode;
256 	struct proc 	*door_target;	/* Proc handling this doors invoc's. */
257 	struct door_node *door_list;	/* List of active doors in proc */
258 	struct door_node *door_ulist;	/* Unref list */
259 	void		(*door_pc)();	/* Door server entry point */
260 	void		*door_data;	/* Cookie passed during invocations */
261 	door_id_t	door_index;	/* Used as a uniquifier */
262 	door_attr_t	door_flags;	/* State associated with door */
263 	uint_t		door_active;	/* Number of active invocations */
264 	door_pool_t	door_servers;	/* Private pool of server threads */
265 	size_t		door_data_max;	/* param: max request data size */
266 	size_t		door_data_min;	/* param: min request data size */
267 	uint_t		door_desc_max;	/* param: max request descriptors */
268 	uint_t		door_bound_threads; /* number of bound threads */
269 } door_node_t;
270 
271 /* Test if a door has been revoked */
272 #define	DOOR_INVALID(dp)	((dp)->door_flags & DOOR_REVOKED)
273 
274 struct file;
275 int	door_insert(struct file *, door_desc_t *);
276 int	door_finish_dispatch(caddr_t);
277 uintptr_t door_final_sp(uintptr_t, size_t, int);
278 int	door_upcall(vnode_t *, door_arg_t *);
279 void	door_slam(void);
280 void	door_exit(void);
281 void	door_revoke_all(void);
282 void	door_deliver_unref(door_node_t *);
283 void	door_list_delete(door_node_t *);
284 void	door_fork(kthread_t *, kthread_t *);
285 void	door_bind_thread(door_node_t *);
286 void	door_unbind_thread(door_node_t *);
287 
288 extern kmutex_t door_knob;
289 extern kcondvar_t door_cv;
290 extern size_t door_max_arg;
291 
292 /*
293  * In-kernel doors interface.  These functions are considered Sun Private
294  * and may change incompatibly in a minor release of Solaris.
295  */
296 int	door_ki_upcall(door_handle_t, door_arg_t *);
297 int	door_ki_create(void (*)(void *, door_arg_t *,
298     void (**)(void *, void *), void **, int *), void *, door_attr_t,
299     door_handle_t *);
300 void	door_ki_hold(door_handle_t);
301 void	door_ki_rele(door_handle_t);
302 int	door_ki_open(char *, door_handle_t *);
303 int	door_ki_info(door_handle_t, door_info_t *);
304 int	door_ki_getparam(door_handle_t, int, size_t *);
305 int	door_ki_setparam(door_handle_t, int, size_t);
306 door_handle_t door_ki_lookup(int did);
307 
308 #endif	/* defined(_KERNEL) */
309 #endif	/* !defined(_ASM) */
310 
311 /*
312  * System call subcodes
313  */
314 #define	DOOR_CREATE	0
315 #define	DOOR_REVOKE	1
316 #define	DOOR_INFO	2
317 #define	DOOR_CALL	3
318 #define	DOOR_BIND	6
319 #define	DOOR_UNBIND	7
320 #define	DOOR_UNREFSYS	8
321 #define	DOOR_UCRED	9
322 #define	DOOR_RETURN	10
323 #define	DOOR_GETPARAM	11
324 #define	DOOR_SETPARAM	12
325 
326 #ifdef	__cplusplus
327 }
328 #endif
329 
330 #endif	/* _SYS_DOOR_H */
331