xref: /illumos-gate/usr/src/lib/libc/i386/sys/door.S (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
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/*
23 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2021 Tintri by DDN, Inc. All rights reserved.
27 */
28
29	.file	"door.s"
30
31#include "SYS.h"
32#include <sys/door.h>
33
34	/*
35	 * weak aliases for public interfaces
36	 */
37	ANSI_PRAGMA_WEAK2(door_bind,__door_bind,function)
38	ANSI_PRAGMA_WEAK2(door_getparam,__door_getparam,function)
39	ANSI_PRAGMA_WEAK2(door_info,__door_info,function)
40	ANSI_PRAGMA_WEAK2(door_revoke,__door_revoke,function)
41	ANSI_PRAGMA_WEAK2(door_setparam,__door_setparam,function)
42
43/*
44 * Offsets within struct door_results
45 */
46#define	DOOR_COOKIE	_MUL(0, CLONGSIZE)
47#define	DOOR_DATA_PTR	_MUL(1, CLONGSIZE)
48#define	DOOR_DATA_SIZE	_MUL(2, CLONGSIZE)
49#define	DOOR_DESC_PTR	_MUL(3, CLONGSIZE)
50#define	DOOR_DESC_SIZE	_MUL(4, CLONGSIZE)
51#define	DOOR_PC		_MUL(5, CLONGSIZE)
52#define	DOOR_SERVERS	_MUL(6, CLONGSIZE)
53#define	DOOR_INFO_PTR	_MUL(7, CLONGSIZE)
54
55/*
56 * All of the syscalls except door_return() follow the same pattern.
57 * The subcode goes in argument 6, which means we have to copy our
58 * arguments into a new bit of stack, large enough to include the
59 * subcode.  We fill the unused positions with zeros.
60 */
61#define	DOOR_SYSCALL(name, code, copy_args)				\
62	ENTRY(name);							\
63	pushl	%ebp;							\
64	movl	%esp, %ebp;						\
65	pushl	$code;		/* syscall subcode, arg 6 */		\
66	pushl	$0;		/* dummy arg 5 */			\
67	pushl	$0;		/* dummy arg 4 */			\
68	copy_args;		/* args 1, 2, 3 */			\
69	pushl	$0;		/* dummy return PC */			\
70	SYSTRAP_RVAL1(door);						\
71	jae	1f;							\
72	addl	$28, %esp;						\
73	leave;								\
74	jmp	__cerror;						\
751:									\
76	addl	$28, %esp;						\
77	leave;								\
78	ret;								\
79	SET_SIZE(name)
80
81#define	COPY_0								\
82	pushl	$0;		/* dummy */				\
83	pushl	$0;		/* dummy */				\
84	pushl	$0		/* dummy */
85
86#define	COPY_1								\
87	pushl	$0;		/* dummy */				\
88	pushl	$0;		/* dummy */				\
89	pushl	8(%ebp)		/* 1 */
90
91#define	COPY_2								\
92	pushl	$0;		/* dummy */				\
93	pushl	12(%ebp);	/* 2 */					\
94	pushl	8(%ebp)		/* 1 */
95
96#define	COPY_3								\
97	pushl	16(%ebp);	/* 3 */					\
98	pushl	12(%ebp);	/* 2 */					\
99	pushl	8(%ebp)		/* 1 */
100
101	DOOR_SYSCALL(__door_bind,	DOOR_BIND,	COPY_1)
102	DOOR_SYSCALL(__door_call,	DOOR_CALL,	COPY_2)
103	DOOR_SYSCALL(__door_create,	DOOR_CREATE,	COPY_3)
104	DOOR_SYSCALL(__door_getparam,	DOOR_GETPARAM,	COPY_3)
105	DOOR_SYSCALL(__door_info,	DOOR_INFO,	COPY_2)
106	DOOR_SYSCALL(__door_revoke,	DOOR_REVOKE,	COPY_1)
107	DOOR_SYSCALL(__door_setparam,	DOOR_SETPARAM,	COPY_3)
108	DOOR_SYSCALL(__door_ucred,	DOOR_UCRED,	COPY_1)
109	DOOR_SYSCALL(__door_unbind,	DOOR_UNBIND,	COPY_0)
110	DOOR_SYSCALL(__door_unref,	DOOR_UNREFSYS,	COPY_0)
111
112/*
113 * int
114 * __door_return(
115 *	void			*data_ptr,
116 *	size_t			data_size,	(in bytes)
117 *	door_return_desc_t	*door_ptr,	(holds returned desc info)
118 *	caddr_t			stack_base,
119 *	size_t			stack_size)
120 */
121	ENTRY(__door_return)
122	movl	%esp, %edx		/ Save pointer to args
123
124	pushl	%edi			/ save old %edi and %esi
125	pushl	%esi			/ and use them to hold the
126	movl	16(%edx), %esi		/ stack pointer and
127	movl	20(%edx), %edi		/ size.
128
129	pushl	$DOOR_RETURN		/ syscall subcode
130	pushl	%edi			/ size of user stack
131	pushl	%esi			/ base of user stack
132	pushl	12(%edx)		/ desc arguments ptr
133	pushl	8(%edx)			/ data size
134	pushl	4(%edx)			/ data ptr
135	pushl	0(%edx)			/ dummy return PC
136
137door_restart:
138	SYSTRAP_RVAL1(door)
139	jb	2f			/* errno is set */
140	/*
141	 * On return, we're serving a door_call.  Our stack looks like this:
142	 *
143	 *		descriptors (if any)
144	 *		data (if any)
145	 *	 sp->	struct door_results
146	 *
147	 * The stack will be aligned to 16 bytes; we must maintain that
148	 * alignment prior to any call instruction.
149	 * struct door_results has the arguments in place for the server proc,
150	 * so we just call it directly.
151	 */
152	movl	DOOR_SERVERS(%esp), %eax
153	andl	%eax, %eax	/* test nservers */
154	jg	1f
155	/*
156	 * this is the last server thread - call creation func for more
157	 */
158	movl	DOOR_INFO_PTR(%esp), %eax
159	subl	$12, %esp
160	pushl	%eax		/* door_info_t * */
161	call	door_depletion_cb@PLT
162	addl	$16, %esp
1631:
164	/* Call the door server function now */
165	movl	DOOR_PC(%esp), %eax
166	call	*%eax
167	/* Exit the thread if we return here */
168	subl	$12, %esp
169	pushl	$0
170	call	_thrp_terminate
171	/* NOTREACHED */
1722:
173	/*
174	 * Error during door_return call.  Repark the thread in the kernel if
175	 * the error code is EINTR (or ERESTART) and this lwp is still part
176	 * of the same process.
177	 *
178	 * If the error code is EINTR or ERESTART, our stack may have been
179	 * corrupted by a partial door call, so we refresh the system call
180	 * arguments.
181	 */
182	cmpl	$ERESTART, %eax		/* ERESTART is same as EINTR */
183	jne	3f
184	movl	$EINTR, %eax
1853:
186	cmpl	$EINTR, %eax		/* interrupted while waiting? */
187	jne	4f			/* if not, return the error */
188	_prologue_
189	call	getpid
190	movl	_daref_(door_create_pid), %edx
191	movl	0(%edx), %edx
192	_epilogue_
193	cmpl	%eax, %edx		/* same process? */
194	movl	$EINTR, %eax	/* if no, return EINTR (child of forkall) */
195	jne	4f
196	movl	$0, 4(%esp)		/* clear arguments and restart */
197	movl	$0, 8(%esp)
198	movl	$0, 12(%esp)
199	movl	%esi, 16(%esp)		/* refresh sp */
200	movl	%edi, 20(%esp)		/* refresh ssize */
201	movl	$DOOR_RETURN, 24(%esp)	/* refresh syscall subcode */
202	jmp	door_restart
2034:
204	/* Something bad happened during the door_return */
205	addl	$28, %esp
206	popl	%esi
207	popl	%edi
208	jmp	__cerror
209	SET_SIZE(__door_return)
210