17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7257d1b4Sraf  * Common Development and Distribution License (the "License").
6*7257d1b4Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*7257d1b4Sraf 
227c478bd9Sstevel@tonic-gate /*
23*7257d1b4Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
29*7257d1b4Sraf #include "lint.h"
307c478bd9Sstevel@tonic-gate #include "thr_uberdata.h"
317c478bd9Sstevel@tonic-gate #include "libc.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <alloca.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <thread.h>
367c478bd9Sstevel@tonic-gate #include <pthread.h>
377c478bd9Sstevel@tonic-gate #include <stdio.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <door.h>
407c478bd9Sstevel@tonic-gate #include <signal.h>
417c478bd9Sstevel@tonic-gate #include <ucred.h>
427c478bd9Sstevel@tonic-gate #include <sys/ucred.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate static door_server_func_t door_create_server;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * Global state -- the non-statics are accessed from the __door_return()
487c478bd9Sstevel@tonic-gate  * syscall wrapper.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate static mutex_t		door_state_lock = DEFAULTMUTEX;
517c478bd9Sstevel@tonic-gate door_server_func_t	*door_server_func = door_create_server;
527c478bd9Sstevel@tonic-gate pid_t			door_create_pid = 0;
537c478bd9Sstevel@tonic-gate static pid_t		door_create_first_pid = 0;
547c478bd9Sstevel@tonic-gate static pid_t		door_create_unref_pid = 0;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * The raw system call interfaces
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate extern int __door_create(void (*)(void *, char *, size_t, door_desc_t *,
607c478bd9Sstevel@tonic-gate     uint_t), void *, uint_t);
617c478bd9Sstevel@tonic-gate extern int __door_return(caddr_t, size_t, door_return_desc_t *, caddr_t,
627c478bd9Sstevel@tonic-gate     size_t);
637c478bd9Sstevel@tonic-gate extern int __door_ucred(ucred_t *);
647c478bd9Sstevel@tonic-gate extern int __door_unref(void);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * We park the ourselves in the kernel to serve as the "caller" for
687c478bd9Sstevel@tonic-gate  * unreferenced upcalls for this process.  If the call returns with
697c478bd9Sstevel@tonic-gate  * EINTR (e.g., someone did a forkall), we repeat as long as we're still
707c478bd9Sstevel@tonic-gate  * in the parent.  If the child creates an unref door it will create
717c478bd9Sstevel@tonic-gate  * a new thread.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate static void *
747c478bd9Sstevel@tonic-gate door_unref_func(void *arg)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate 	pid_t mypid = (pid_t)(uintptr_t)arg;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	sigset_t fillset;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	/* mask signals before diving into the kernel */
817c478bd9Sstevel@tonic-gate 	(void) sigfillset(&fillset);
827c478bd9Sstevel@tonic-gate 	(void) thr_sigsetmask(SIG_SETMASK, &fillset, NULL);
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	while (getpid() == mypid && __door_unref() && errno == EINTR)
857c478bd9Sstevel@tonic-gate 		continue;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	return (NULL);
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate int
917c478bd9Sstevel@tonic-gate door_create(void (*f)(void *, char *, size_t, door_desc_t *, uint_t),
927c478bd9Sstevel@tonic-gate     void *cookie, uint_t flags)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 	int d;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	int is_private = (flags & DOOR_PRIVATE);
977c478bd9Sstevel@tonic-gate 	int is_unref = (flags & (DOOR_UNREF | DOOR_UNREF_MULTI));
987c478bd9Sstevel@tonic-gate 	int do_create_first = 0;
997c478bd9Sstevel@tonic-gate 	int do_create_unref = 0;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	ulwp_t *self = curthread;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	pid_t mypid;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	if (self->ul_vfork) {
1067c478bd9Sstevel@tonic-gate 		errno = ENOTSUP;
1077c478bd9Sstevel@tonic-gate 		return (-1);
1087c478bd9Sstevel@tonic-gate 	}
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	/*
1117c478bd9Sstevel@tonic-gate 	 * Doors are associated with the processes which created them.  In
1127c478bd9Sstevel@tonic-gate 	 * the face of forkall(), this gets quite complicated.  To simplify
1137c478bd9Sstevel@tonic-gate 	 * it somewhat, we include the call to __door_create() in a critical
1147c478bd9Sstevel@tonic-gate 	 * section, and figure out what additional actions to take while
1157c478bd9Sstevel@tonic-gate 	 * still in the critical section.
1167c478bd9Sstevel@tonic-gate 	 */
1177c478bd9Sstevel@tonic-gate 	enter_critical(self);
1187c478bd9Sstevel@tonic-gate 	if ((d = __door_create(f, cookie, flags)) < 0) {
1197c478bd9Sstevel@tonic-gate 		exit_critical(self);
1207c478bd9Sstevel@tonic-gate 		return (-1);
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 	mypid = getpid();
1237c478bd9Sstevel@tonic-gate 	if (mypid != door_create_pid ||
1247c478bd9Sstevel@tonic-gate 	    (!is_private && mypid != door_create_first_pid) ||
1257c478bd9Sstevel@tonic-gate 	    (is_unref && mypid != door_create_unref_pid)) {
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 		lmutex_lock(&door_state_lock);
1287c478bd9Sstevel@tonic-gate 		door_create_pid = mypid;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 		if (!is_private && mypid != door_create_first_pid) {
1317c478bd9Sstevel@tonic-gate 			do_create_first = 1;
1327c478bd9Sstevel@tonic-gate 			door_create_first_pid = mypid;
1337c478bd9Sstevel@tonic-gate 		}
1347c478bd9Sstevel@tonic-gate 		if (is_unref && mypid != door_create_unref_pid) {
1357c478bd9Sstevel@tonic-gate 			do_create_unref = 1;
1367c478bd9Sstevel@tonic-gate 			door_create_unref_pid = mypid;
1377c478bd9Sstevel@tonic-gate 		}
1387c478bd9Sstevel@tonic-gate 		lmutex_unlock(&door_state_lock);
1397c478bd9Sstevel@tonic-gate 	}
1407c478bd9Sstevel@tonic-gate 	exit_critical(self);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	if (do_create_unref) {
1437c478bd9Sstevel@tonic-gate 		/*
1447c478bd9Sstevel@tonic-gate 		 * Create an unref thread the first time we create an
1457c478bd9Sstevel@tonic-gate 		 * unref door for this process.  Create it as a daemon
1467c478bd9Sstevel@tonic-gate 		 * thread, so that it doesn't interfere with normal exit
1477c478bd9Sstevel@tonic-gate 		 * processing.
1487c478bd9Sstevel@tonic-gate 		 */
1497c478bd9Sstevel@tonic-gate 		(void) thr_create(NULL, 0, door_unref_func,
1507c478bd9Sstevel@tonic-gate 		    (void *)(uintptr_t)mypid, THR_DAEMON, NULL);
1517c478bd9Sstevel@tonic-gate 	}
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	/*
1547c478bd9Sstevel@tonic-gate 	 * If this is the first door created in the process, or the door
1557c478bd9Sstevel@tonic-gate 	 * has a private pool, we need to kick off the thread pool now.
1567c478bd9Sstevel@tonic-gate 	 */
1577c478bd9Sstevel@tonic-gate 	if (do_create_first)
1587c478bd9Sstevel@tonic-gate 		(*door_server_func)(NULL);
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	if (is_private) {
1617c478bd9Sstevel@tonic-gate 		door_info_t di;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 		if (__door_info(d, &di) < 0)
1647c478bd9Sstevel@tonic-gate 			return (-1);
1657c478bd9Sstevel@tonic-gate 		(*door_server_func)(&di);
1667c478bd9Sstevel@tonic-gate 	}
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	return (d);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate int
1727c478bd9Sstevel@tonic-gate door_ucred(ucred_t **uc)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate 	ucred_t *ucp = *uc;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	if (ucp == NULL) {
1777c478bd9Sstevel@tonic-gate 		ucp = _ucred_alloc();
1787c478bd9Sstevel@tonic-gate 		if (ucp == NULL)
1797c478bd9Sstevel@tonic-gate 			return (-1);
1807c478bd9Sstevel@tonic-gate 	}
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	if (__door_ucred(ucp) != 0) {
1837c478bd9Sstevel@tonic-gate 		if (*uc == NULL)
1847c478bd9Sstevel@tonic-gate 			ucred_free(ucp);
1857c478bd9Sstevel@tonic-gate 		return (-1);
1867c478bd9Sstevel@tonic-gate 	}
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	*uc = ucp;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	return (0);
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate int
1947c478bd9Sstevel@tonic-gate door_cred(door_cred_t *dc)
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate 	/*
1977c478bd9Sstevel@tonic-gate 	 * Ucred size is small and alloca is fast
1987c478bd9Sstevel@tonic-gate 	 * and cannot fail.
1997c478bd9Sstevel@tonic-gate 	 */
2007c478bd9Sstevel@tonic-gate 	ucred_t *ucp = alloca(ucred_size());
2017c478bd9Sstevel@tonic-gate 	int ret;
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if ((ret = __door_ucred(ucp)) == 0) {
2047c478bd9Sstevel@tonic-gate 		dc->dc_euid = ucred_geteuid(ucp);
2057c478bd9Sstevel@tonic-gate 		dc->dc_ruid = ucred_getruid(ucp);
2067c478bd9Sstevel@tonic-gate 		dc->dc_egid = ucred_getegid(ucp);
2077c478bd9Sstevel@tonic-gate 		dc->dc_rgid = ucred_getrgid(ucp);
2087c478bd9Sstevel@tonic-gate 		dc->dc_pid = ucred_getpid(ucp);
2097c478bd9Sstevel@tonic-gate 	}
2107c478bd9Sstevel@tonic-gate 	return (ret);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate int
2147c478bd9Sstevel@tonic-gate door_return(char *data_ptr, size_t data_size,
2157c478bd9Sstevel@tonic-gate     door_desc_t *desc_ptr, uint_t num_desc)
2167c478bd9Sstevel@tonic-gate {
2177c478bd9Sstevel@tonic-gate 	caddr_t sp;
2187c478bd9Sstevel@tonic-gate 	size_t ssize;
2197c478bd9Sstevel@tonic-gate 	size_t reserve;
2207c478bd9Sstevel@tonic-gate 	ulwp_t *self = curthread;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	{
2237c478bd9Sstevel@tonic-gate 		stack_t s;
2247c478bd9Sstevel@tonic-gate 		if (thr_stksegment(&s) != 0) {
2257c478bd9Sstevel@tonic-gate 			errno = EINVAL;
2267c478bd9Sstevel@tonic-gate 			return (-1);
2277c478bd9Sstevel@tonic-gate 		}
2287c478bd9Sstevel@tonic-gate 		sp = s.ss_sp;
2297c478bd9Sstevel@tonic-gate 		ssize = s.ss_size;
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	if (!self->ul_door_noreserve) {
2337c478bd9Sstevel@tonic-gate 		/*
2347c478bd9Sstevel@tonic-gate 		 * When we return from the kernel, we must have enough stack
2357c478bd9Sstevel@tonic-gate 		 * available to handle the request.  Since the creator of
2367c478bd9Sstevel@tonic-gate 		 * the thread has control over its stack size, and larger
2377c478bd9Sstevel@tonic-gate 		 * stacks generally indicate bigger request queues, we
2387c478bd9Sstevel@tonic-gate 		 * use the heuristic of reserving 1/32nd of the stack size
2397c478bd9Sstevel@tonic-gate 		 * (up to the default stack size), with a minimum of 1/8th
2407c478bd9Sstevel@tonic-gate 		 * of MINSTACK.  Currently, this translates to:
2417c478bd9Sstevel@tonic-gate 		 *
2427c478bd9Sstevel@tonic-gate 		 *			_ILP32		_LP64
2437c478bd9Sstevel@tonic-gate 		 *	min resv	 512 bytes	1024 bytes
2447c478bd9Sstevel@tonic-gate 		 *	max resv	 32k bytes	 64k bytes
2457c478bd9Sstevel@tonic-gate 		 *
2467c478bd9Sstevel@tonic-gate 		 * This reservation can be disabled by setting
2477c478bd9Sstevel@tonic-gate 		 *	_THREAD_DOOR_NORESERVE=1
2487c478bd9Sstevel@tonic-gate 		 * in the environment, but shouldn't be.
2497c478bd9Sstevel@tonic-gate 		 */
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate #define	STACK_FRACTION		32
2527c478bd9Sstevel@tonic-gate #define	MINSTACK_FRACTION	8
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 		if (ssize < (MINSTACK * (STACK_FRACTION/MINSTACK_FRACTION)))
2557c478bd9Sstevel@tonic-gate 			reserve = MINSTACK / MINSTACK_FRACTION;
2567c478bd9Sstevel@tonic-gate 		else if (ssize < DEFAULTSTACK)
2577c478bd9Sstevel@tonic-gate 			reserve = ssize / STACK_FRACTION;
2587c478bd9Sstevel@tonic-gate 		else
2597c478bd9Sstevel@tonic-gate 			reserve = DEFAULTSTACK / STACK_FRACTION;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate #undef STACK_FRACTION
2627c478bd9Sstevel@tonic-gate #undef MINSTACK_FRACTION
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 		if (ssize > reserve)
2657c478bd9Sstevel@tonic-gate 			ssize -= reserve;
2667c478bd9Sstevel@tonic-gate 		else
2677c478bd9Sstevel@tonic-gate 			ssize = 0;
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	/*
2717c478bd9Sstevel@tonic-gate 	 * Historically, the __door_return() syscall wrapper subtracted
2727c478bd9Sstevel@tonic-gate 	 * some "slop" from the stack pointer before trapping into the
2737c478bd9Sstevel@tonic-gate 	 * kernel.  We now do this here, so that ssize can be adjusted
2747c478bd9Sstevel@tonic-gate 	 * correctly.  Eventually, this should be removed, since it is
2757c478bd9Sstevel@tonic-gate 	 * unnecessary.  (note that TNF on x86 currently relies upon this
2767c478bd9Sstevel@tonic-gate 	 * idiocy)
2777c478bd9Sstevel@tonic-gate 	 */
2787c478bd9Sstevel@tonic-gate #if defined(__sparc)
2797c478bd9Sstevel@tonic-gate 	reserve = SA(MINFRAME);
2807c478bd9Sstevel@tonic-gate #elif defined(__x86)
2817c478bd9Sstevel@tonic-gate 	reserve = SA(512);
2827c478bd9Sstevel@tonic-gate #else
2837c478bd9Sstevel@tonic-gate #error need to define stack base reserve
2847c478bd9Sstevel@tonic-gate #endif
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate #ifdef _STACK_GROWS_DOWNWARD
2877c478bd9Sstevel@tonic-gate 	sp -= reserve;
2887c478bd9Sstevel@tonic-gate #else
2897c478bd9Sstevel@tonic-gate #error stack does not grow downwards, routine needs update
2907c478bd9Sstevel@tonic-gate #endif
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	if (ssize > reserve)
2937c478bd9Sstevel@tonic-gate 		ssize -= reserve;
2947c478bd9Sstevel@tonic-gate 	else
2957c478bd9Sstevel@tonic-gate 		ssize = 0;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	/*
2987c478bd9Sstevel@tonic-gate 	 * Normally, the above will leave plenty of space in sp for a
2997c478bd9Sstevel@tonic-gate 	 * request.  Just in case some bozo overrides thr_stksegment() to
3007c478bd9Sstevel@tonic-gate 	 * return an uncommonly small stack size, we turn off stack size
3017c478bd9Sstevel@tonic-gate 	 * checking if there is less than 1k remaining.
3027c478bd9Sstevel@tonic-gate 	 */
3037c478bd9Sstevel@tonic-gate #define	MIN_DOOR_STACK	1024
3047c478bd9Sstevel@tonic-gate 	if (ssize < MIN_DOOR_STACK)
3057c478bd9Sstevel@tonic-gate 		ssize = 0;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate #undef MIN_DOOR_STACK
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 	/*
3107c478bd9Sstevel@tonic-gate 	 * We have to wrap the desc_* arguments for the syscall.  If there are
3117c478bd9Sstevel@tonic-gate 	 * no descriptors being returned, we can skip the wrapping.
3127c478bd9Sstevel@tonic-gate 	 */
3137c478bd9Sstevel@tonic-gate 	if (num_desc != 0) {
3147c478bd9Sstevel@tonic-gate 		door_return_desc_t d;
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 		d.desc_ptr = desc_ptr;
3177c478bd9Sstevel@tonic-gate 		d.desc_num = num_desc;
3187c478bd9Sstevel@tonic-gate 		return (__door_return(data_ptr, data_size, &d, sp, ssize));
3197c478bd9Sstevel@tonic-gate 	}
3207c478bd9Sstevel@tonic-gate 	return (__door_return(data_ptr, data_size, NULL, sp, ssize));
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate /*
3247c478bd9Sstevel@tonic-gate  * Install a new server creation function.
3257c478bd9Sstevel@tonic-gate  */
3267c478bd9Sstevel@tonic-gate door_server_func_t *
3277c478bd9Sstevel@tonic-gate door_server_create(door_server_func_t *create_func)
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate 	door_server_func_t *prev;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	lmutex_lock(&door_state_lock);
3327c478bd9Sstevel@tonic-gate 	prev = door_server_func;
3337c478bd9Sstevel@tonic-gate 	door_server_func = create_func;
3347c478bd9Sstevel@tonic-gate 	lmutex_unlock(&door_state_lock);
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 	return (prev);
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate /*
3407c478bd9Sstevel@tonic-gate  * Create door server threads with cancellation(5) disabled.
3417c478bd9Sstevel@tonic-gate  */
3427c478bd9Sstevel@tonic-gate static void *
3437c478bd9Sstevel@tonic-gate door_create_func(void *arg)
3447c478bd9Sstevel@tonic-gate {
3457c478bd9Sstevel@tonic-gate 	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
3467c478bd9Sstevel@tonic-gate 	(void) door_return(NULL, 0, NULL, 0);
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	return (arg);
3497c478bd9Sstevel@tonic-gate }
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate /*
3527c478bd9Sstevel@tonic-gate  * The default server thread creation routine.
3537c478bd9Sstevel@tonic-gate  */
3547c478bd9Sstevel@tonic-gate /* ARGSUSED */
3557c478bd9Sstevel@tonic-gate static void
3567c478bd9Sstevel@tonic-gate door_create_server(door_info_t *dip)
3577c478bd9Sstevel@tonic-gate {
3587c478bd9Sstevel@tonic-gate 	(void) thr_create(NULL, 0, door_create_func, NULL, THR_DETACHED, NULL);
3597c478bd9Sstevel@tonic-gate 	yield();	/* Gives server thread a chance to run */
3607c478bd9Sstevel@tonic-gate }
361