xref: /illumos-gate/usr/src/lib/libc/port/threads/pthread.c (revision 7c478bd95313f5f23a4c958a745db2134aa0324)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include "lint.h"
30*7c478bd9Sstevel@tonic-gate #include "thr_uberdata.h"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate  * pthread_once related data
34*7c478bd9Sstevel@tonic-gate  * This structure is exported as pthread_once_t in pthread.h.
35*7c478bd9Sstevel@tonic-gate  * We export only the size of this structure. so check
36*7c478bd9Sstevel@tonic-gate  * pthread_once_t in pthread.h before making a change here.
37*7c478bd9Sstevel@tonic-gate  */
38*7c478bd9Sstevel@tonic-gate typedef struct  __once {
39*7c478bd9Sstevel@tonic-gate 	mutex_t	mlock;
40*7c478bd9Sstevel@tonic-gate 	union {
41*7c478bd9Sstevel@tonic-gate 		uint32_t	pad32_flag[2];
42*7c478bd9Sstevel@tonic-gate 		uint64_t	pad64_flag;
43*7c478bd9Sstevel@tonic-gate 	} oflag;
44*7c478bd9Sstevel@tonic-gate } __once_t;
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #define	once_flag	oflag.pad32_flag[1]
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate  * Default attribute object for pthread_create() with NULL attr pointer.
50*7c478bd9Sstevel@tonic-gate  * Note that the 'guardsize' field is initialized on the first call
51*7c478bd9Sstevel@tonic-gate  * to pthread_create() with a NULL attr pointer.
52*7c478bd9Sstevel@tonic-gate  */
53*7c478bd9Sstevel@tonic-gate static thrattr_t _defattr =
54*7c478bd9Sstevel@tonic-gate 	{0, NULL, PTHREAD_CREATE_JOINABLE, PTHREAD_SCOPE_PROCESS,
55*7c478bd9Sstevel@tonic-gate 	0, SCHED_OTHER, PTHREAD_EXPLICIT_SCHED, 0};
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  * pthread_create: creates a thread in the current process.
59*7c478bd9Sstevel@tonic-gate  * calls common _thrp_create() after copying the attributes.
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate #pragma weak	pthread_create			= _pthread_create
62*7c478bd9Sstevel@tonic-gate int
63*7c478bd9Sstevel@tonic-gate _pthread_create(pthread_t *thread, const pthread_attr_t *attr,
64*7c478bd9Sstevel@tonic-gate 	void * (*start_routine)(void *), void *arg)
65*7c478bd9Sstevel@tonic-gate {
66*7c478bd9Sstevel@tonic-gate 	ulwp_t		*self = curthread;
67*7c478bd9Sstevel@tonic-gate 	uberdata_t	*udp = self->ul_uberdata;
68*7c478bd9Sstevel@tonic-gate 	long		flag;
69*7c478bd9Sstevel@tonic-gate 	thrattr_t	*ap;
70*7c478bd9Sstevel@tonic-gate 	pthread_t	tid;
71*7c478bd9Sstevel@tonic-gate 	int		policy;
72*7c478bd9Sstevel@tonic-gate 	pri_t		priority;
73*7c478bd9Sstevel@tonic-gate 	int		error;
74*7c478bd9Sstevel@tonic-gate 	int		mapped = 0;
75*7c478bd9Sstevel@tonic-gate 	int		mappedpri;
76*7c478bd9Sstevel@tonic-gate 	int		rt = 0;
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 	if (attr == NULL) {
79*7c478bd9Sstevel@tonic-gate 		ap = &_defattr;
80*7c478bd9Sstevel@tonic-gate 		if (ap->guardsize == 0) {
81*7c478bd9Sstevel@tonic-gate 			if (_lpagesize == 0)
82*7c478bd9Sstevel@tonic-gate 				_lpagesize = _sysconf(_SC_PAGESIZE);
83*7c478bd9Sstevel@tonic-gate 			ap->guardsize = _lpagesize;
84*7c478bd9Sstevel@tonic-gate 		}
85*7c478bd9Sstevel@tonic-gate 	} else if ((ap = attr->__pthread_attrp) == NULL) {
86*7c478bd9Sstevel@tonic-gate 		return (EINVAL);
87*7c478bd9Sstevel@tonic-gate 	}
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 	if (ap->inherit == PTHREAD_INHERIT_SCHED) {
90*7c478bd9Sstevel@tonic-gate 		policy = self->ul_policy;
91*7c478bd9Sstevel@tonic-gate 		priority = self->ul_pri;
92*7c478bd9Sstevel@tonic-gate 		mapped = self->ul_pri_mapped;
93*7c478bd9Sstevel@tonic-gate 		mappedpri = self->ul_mappedpri;
94*7c478bd9Sstevel@tonic-gate 	} else {
95*7c478bd9Sstevel@tonic-gate 		policy = ap->policy;
96*7c478bd9Sstevel@tonic-gate 		priority = ap->prio;
97*7c478bd9Sstevel@tonic-gate 		if (policy == SCHED_OTHER) {
98*7c478bd9Sstevel@tonic-gate 			if (priority < THREAD_MIN_PRIORITY ||
99*7c478bd9Sstevel@tonic-gate 			    priority > THREAD_MAX_PRIORITY) {
100*7c478bd9Sstevel@tonic-gate 				if (_validate_rt_prio(policy, priority))
101*7c478bd9Sstevel@tonic-gate 					return (EINVAL);
102*7c478bd9Sstevel@tonic-gate 				mapped = 1;
103*7c478bd9Sstevel@tonic-gate 				mappedpri = priority;
104*7c478bd9Sstevel@tonic-gate 				priority = _map_rtpri_to_gp(priority);
105*7c478bd9Sstevel@tonic-gate 				ASSERT(priority >= THREAD_MIN_PRIORITY &&
106*7c478bd9Sstevel@tonic-gate 				    priority <= THREAD_MAX_PRIORITY);
107*7c478bd9Sstevel@tonic-gate 			}
108*7c478bd9Sstevel@tonic-gate 		} else if (policy == SCHED_FIFO || policy == SCHED_RR) {
109*7c478bd9Sstevel@tonic-gate 			if (_validate_rt_prio(policy, priority))
110*7c478bd9Sstevel@tonic-gate 				return (EINVAL);
111*7c478bd9Sstevel@tonic-gate 			if (_private_geteuid() == 0)
112*7c478bd9Sstevel@tonic-gate 				rt = 1;
113*7c478bd9Sstevel@tonic-gate 		} else {
114*7c478bd9Sstevel@tonic-gate 			return (EINVAL);
115*7c478bd9Sstevel@tonic-gate 		}
116*7c478bd9Sstevel@tonic-gate 	}
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	flag = ap->scope | ap->detachstate | THR_SUSPENDED;
119*7c478bd9Sstevel@tonic-gate 	error = _thrp_create(ap->stkaddr, ap->stksize, start_routine, arg,
120*7c478bd9Sstevel@tonic-gate 		flag, &tid, priority, policy, ap->guardsize);
121*7c478bd9Sstevel@tonic-gate 	if (error == 0) {
122*7c478bd9Sstevel@tonic-gate 		if (mapped) {
123*7c478bd9Sstevel@tonic-gate 			ulwp_t *ulwp = find_lwp(tid);
124*7c478bd9Sstevel@tonic-gate 			ulwp->ul_pri_mapped = 1;
125*7c478bd9Sstevel@tonic-gate 			ulwp->ul_mappedpri = mappedpri;
126*7c478bd9Sstevel@tonic-gate 			ulwp_unlock(ulwp, udp);
127*7c478bd9Sstevel@tonic-gate 		}
128*7c478bd9Sstevel@tonic-gate 		if (rt && _thrp_setlwpprio(tid, policy, priority))
129*7c478bd9Sstevel@tonic-gate 			thr_panic("_thrp_setlwpprio() failed");
130*7c478bd9Sstevel@tonic-gate 		if (thread)
131*7c478bd9Sstevel@tonic-gate 			*thread = tid;
132*7c478bd9Sstevel@tonic-gate 		(void) _thr_continue(tid);
133*7c478bd9Sstevel@tonic-gate 	}
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	/* posix version expects EAGAIN for lack of memory */
136*7c478bd9Sstevel@tonic-gate 	if (error == ENOMEM)
137*7c478bd9Sstevel@tonic-gate 		error = EAGAIN;
138*7c478bd9Sstevel@tonic-gate 	return (error);
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate /*
142*7c478bd9Sstevel@tonic-gate  * pthread_once: calls given function only once.
143*7c478bd9Sstevel@tonic-gate  * it synchronizes via mutex in pthread_once_t structure
144*7c478bd9Sstevel@tonic-gate  */
145*7c478bd9Sstevel@tonic-gate #pragma weak	pthread_once			= _pthread_once
146*7c478bd9Sstevel@tonic-gate int
147*7c478bd9Sstevel@tonic-gate _pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
148*7c478bd9Sstevel@tonic-gate {
149*7c478bd9Sstevel@tonic-gate 	__once_t *once = (__once_t *)once_control;
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 	if (once == NULL || init_routine == NULL)
152*7c478bd9Sstevel@tonic-gate 		return (EINVAL);
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate 	if (once->once_flag == PTHREAD_ONCE_NOTDONE) {
155*7c478bd9Sstevel@tonic-gate 		(void) _private_mutex_lock(&once->mlock);
156*7c478bd9Sstevel@tonic-gate 		if (once->once_flag == PTHREAD_ONCE_NOTDONE) {
157*7c478bd9Sstevel@tonic-gate 			pthread_cleanup_push(_private_mutex_unlock,
158*7c478bd9Sstevel@tonic-gate 			    &once->mlock);
159*7c478bd9Sstevel@tonic-gate 			(*init_routine)();
160*7c478bd9Sstevel@tonic-gate 			pthread_cleanup_pop(0);
161*7c478bd9Sstevel@tonic-gate 			once->once_flag = PTHREAD_ONCE_DONE;
162*7c478bd9Sstevel@tonic-gate 		}
163*7c478bd9Sstevel@tonic-gate 		(void) _private_mutex_unlock(&once->mlock);
164*7c478bd9Sstevel@tonic-gate 	}
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	return (0);
167*7c478bd9Sstevel@tonic-gate }
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate /*
170*7c478bd9Sstevel@tonic-gate  * pthread_equal: equates two thread ids.
171*7c478bd9Sstevel@tonic-gate  */
172*7c478bd9Sstevel@tonic-gate #pragma weak	pthread_equal			= _pthread_equal
173*7c478bd9Sstevel@tonic-gate int
174*7c478bd9Sstevel@tonic-gate _pthread_equal(pthread_t t1, pthread_t t2)
175*7c478bd9Sstevel@tonic-gate {
176*7c478bd9Sstevel@tonic-gate 	return (t1 == t2);
177*7c478bd9Sstevel@tonic-gate }
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate /*
180*7c478bd9Sstevel@tonic-gate  * pthread_getschedparam: gets the sched parameters in a struct.
181*7c478bd9Sstevel@tonic-gate  */
182*7c478bd9Sstevel@tonic-gate #pragma weak	pthread_getschedparam		= _pthread_getschedparam
183*7c478bd9Sstevel@tonic-gate int
184*7c478bd9Sstevel@tonic-gate _pthread_getschedparam(pthread_t tid, int *policy, struct sched_param *param)
185*7c478bd9Sstevel@tonic-gate {
186*7c478bd9Sstevel@tonic-gate 	uberdata_t *udp = curthread->ul_uberdata;
187*7c478bd9Sstevel@tonic-gate 	ulwp_t *ulwp;
188*7c478bd9Sstevel@tonic-gate 	int error = 0;
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 	if (param == NULL || policy == NULL)
191*7c478bd9Sstevel@tonic-gate 		error = EINVAL;
192*7c478bd9Sstevel@tonic-gate 	else if ((ulwp = find_lwp(tid)) == NULL)
193*7c478bd9Sstevel@tonic-gate 		error = ESRCH;
194*7c478bd9Sstevel@tonic-gate 	else {
195*7c478bd9Sstevel@tonic-gate 		if (ulwp->ul_pri_mapped)
196*7c478bd9Sstevel@tonic-gate 			param->sched_priority = ulwp->ul_mappedpri;
197*7c478bd9Sstevel@tonic-gate 		else
198*7c478bd9Sstevel@tonic-gate 			param->sched_priority = ulwp->ul_pri;
199*7c478bd9Sstevel@tonic-gate 		*policy = ulwp->ul_policy;
200*7c478bd9Sstevel@tonic-gate 		ulwp_unlock(ulwp, udp);
201*7c478bd9Sstevel@tonic-gate 	}
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate 	return (error);
204*7c478bd9Sstevel@tonic-gate }
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate /*
207*7c478bd9Sstevel@tonic-gate  * Besides the obvious arguments, the inheritflag needs to be explained:
208*7c478bd9Sstevel@tonic-gate  * If set to PRIO_SET or PRIO_SET_PRIO, it does the normal, expected work
209*7c478bd9Sstevel@tonic-gate  * of setting thread's assigned scheduling parameters and policy.
210*7c478bd9Sstevel@tonic-gate  * If set to PRIO_INHERIT, it sets the thread's effective priority values
211*7c478bd9Sstevel@tonic-gate  * (t_epri, t_empappedpri), and does not update the assigned priority values
212*7c478bd9Sstevel@tonic-gate  * (t_pri, t_mappedpri).  If set to PRIO_DISINHERIT, it clears the thread's
213*7c478bd9Sstevel@tonic-gate  * effective priority values, and reverts the thread, if necessary, back
214*7c478bd9Sstevel@tonic-gate  * to the assigned priority values.
215*7c478bd9Sstevel@tonic-gate  */
216*7c478bd9Sstevel@tonic-gate int
217*7c478bd9Sstevel@tonic-gate _thread_setschedparam_main(pthread_t tid, int policy,
218*7c478bd9Sstevel@tonic-gate     const struct sched_param *param, int inheritflag)
219*7c478bd9Sstevel@tonic-gate {
220*7c478bd9Sstevel@tonic-gate 	uberdata_t *udp = curthread->ul_uberdata;
221*7c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp;
222*7c478bd9Sstevel@tonic-gate 	int	error = 0;
223*7c478bd9Sstevel@tonic-gate 	int	prio;
224*7c478bd9Sstevel@tonic-gate 	int	opolicy;
225*7c478bd9Sstevel@tonic-gate 	int	mappedprio;
226*7c478bd9Sstevel@tonic-gate 	int	mapped = 0;
227*7c478bd9Sstevel@tonic-gate 	pri_t	*mappedprip;
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate 	if (param == NULL)
230*7c478bd9Sstevel@tonic-gate 		return (EINVAL);
231*7c478bd9Sstevel@tonic-gate 	if ((ulwp = find_lwp(tid)) == NULL)
232*7c478bd9Sstevel@tonic-gate 		return (ESRCH);
233*7c478bd9Sstevel@tonic-gate 	prio = param->sched_priority;
234*7c478bd9Sstevel@tonic-gate 	opolicy = ulwp->ul_policy;
235*7c478bd9Sstevel@tonic-gate 	if (inheritflag == PRIO_SET_PRIO) {	/* don't change policy */
236*7c478bd9Sstevel@tonic-gate 		policy = opolicy;
237*7c478bd9Sstevel@tonic-gate 		inheritflag = PRIO_SET;
238*7c478bd9Sstevel@tonic-gate 	}
239*7c478bd9Sstevel@tonic-gate 	ASSERT(inheritflag == PRIO_SET || opolicy == policy);
240*7c478bd9Sstevel@tonic-gate 	if (inheritflag == PRIO_DISINHERIT) {
241*7c478bd9Sstevel@tonic-gate 		ulwp->ul_emappedpri = 0;
242*7c478bd9Sstevel@tonic-gate 		ulwp->ul_epri = 0;
243*7c478bd9Sstevel@tonic-gate 		prio = ulwp->ul_pri;	/* ignore prio in sched_param */
244*7c478bd9Sstevel@tonic-gate 	}
245*7c478bd9Sstevel@tonic-gate 	if (policy == SCHED_OTHER) {
246*7c478bd9Sstevel@tonic-gate 		/*
247*7c478bd9Sstevel@tonic-gate 		 * Set thread's policy to OTHER
248*7c478bd9Sstevel@tonic-gate 		 */
249*7c478bd9Sstevel@tonic-gate 		if (prio < THREAD_MIN_PRIORITY || prio > THREAD_MAX_PRIORITY) {
250*7c478bd9Sstevel@tonic-gate 			if (_validate_rt_prio(policy, prio)) {
251*7c478bd9Sstevel@tonic-gate 				error = EINVAL;
252*7c478bd9Sstevel@tonic-gate 				goto out;
253*7c478bd9Sstevel@tonic-gate 			}
254*7c478bd9Sstevel@tonic-gate 			mapped = 1;
255*7c478bd9Sstevel@tonic-gate 			mappedprio = prio;
256*7c478bd9Sstevel@tonic-gate 			prio = _map_rtpri_to_gp(prio);
257*7c478bd9Sstevel@tonic-gate 			ASSERT(prio >= THREAD_MIN_PRIORITY &&
258*7c478bd9Sstevel@tonic-gate 			    prio <= THREAD_MAX_PRIORITY);
259*7c478bd9Sstevel@tonic-gate 		}
260*7c478bd9Sstevel@tonic-gate 		/*
261*7c478bd9Sstevel@tonic-gate 		 * Thread changing from FIFO/RR to OTHER
262*7c478bd9Sstevel@tonic-gate 		 */
263*7c478bd9Sstevel@tonic-gate 		if (opolicy == SCHED_FIFO || opolicy == SCHED_RR) {
264*7c478bd9Sstevel@tonic-gate 			if ((error = _thrp_setlwpprio(tid, policy, prio)) != 0)
265*7c478bd9Sstevel@tonic-gate 				goto out;
266*7c478bd9Sstevel@tonic-gate 		}
267*7c478bd9Sstevel@tonic-gate 		if (inheritflag != PRIO_DISINHERIT) {
268*7c478bd9Sstevel@tonic-gate 			if (inheritflag == PRIO_INHERIT)
269*7c478bd9Sstevel@tonic-gate 				mappedprip = &ulwp->ul_emappedpri;
270*7c478bd9Sstevel@tonic-gate 			else
271*7c478bd9Sstevel@tonic-gate 				mappedprip = &ulwp->ul_mappedpri;
272*7c478bd9Sstevel@tonic-gate 			if (mapped) {
273*7c478bd9Sstevel@tonic-gate 				ulwp->ul_pri_mapped = 1;
274*7c478bd9Sstevel@tonic-gate 				*mappedprip = mappedprio;
275*7c478bd9Sstevel@tonic-gate 			} else {
276*7c478bd9Sstevel@tonic-gate 				ulwp->ul_pri_mapped = 0;
277*7c478bd9Sstevel@tonic-gate 				*mappedprip = 0;
278*7c478bd9Sstevel@tonic-gate 			}
279*7c478bd9Sstevel@tonic-gate 		}
280*7c478bd9Sstevel@tonic-gate 		ulwp->ul_policy = policy;
281*7c478bd9Sstevel@tonic-gate 		if (inheritflag == PRIO_INHERIT)
282*7c478bd9Sstevel@tonic-gate 			ulwp->ul_epri = prio;
283*7c478bd9Sstevel@tonic-gate 		else
284*7c478bd9Sstevel@tonic-gate 			ulwp->ul_pri = prio;
285*7c478bd9Sstevel@tonic-gate 	} else if (policy == SCHED_FIFO || policy == SCHED_RR) {
286*7c478bd9Sstevel@tonic-gate 		if (_validate_rt_prio(policy, prio))
287*7c478bd9Sstevel@tonic-gate 			error = EINVAL;
288*7c478bd9Sstevel@tonic-gate 		else {
289*7c478bd9Sstevel@tonic-gate 			if (_private_geteuid() == 0 &&
290*7c478bd9Sstevel@tonic-gate 			    _thrp_setlwpprio(tid, policy, prio))
291*7c478bd9Sstevel@tonic-gate 				thr_panic("_thrp_setlwpprio failed");
292*7c478bd9Sstevel@tonic-gate 			ulwp->ul_policy = policy;
293*7c478bd9Sstevel@tonic-gate 			if (inheritflag == PRIO_INHERIT)
294*7c478bd9Sstevel@tonic-gate 				ulwp->ul_epri = prio;
295*7c478bd9Sstevel@tonic-gate 			else
296*7c478bd9Sstevel@tonic-gate 				ulwp->ul_pri = prio;
297*7c478bd9Sstevel@tonic-gate 		}
298*7c478bd9Sstevel@tonic-gate 	} else {
299*7c478bd9Sstevel@tonic-gate 		error = EINVAL;
300*7c478bd9Sstevel@tonic-gate 	}
301*7c478bd9Sstevel@tonic-gate 
302*7c478bd9Sstevel@tonic-gate out:
303*7c478bd9Sstevel@tonic-gate 	ulwp_unlock(ulwp, udp);
304*7c478bd9Sstevel@tonic-gate 	return (error);
305*7c478bd9Sstevel@tonic-gate }
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate /*
308*7c478bd9Sstevel@tonic-gate  * pthread_setschedparam: sets the sched parameters for a thread.
309*7c478bd9Sstevel@tonic-gate  */
310*7c478bd9Sstevel@tonic-gate #pragma weak	pthread_setschedparam		= _pthread_setschedparam
311*7c478bd9Sstevel@tonic-gate int
312*7c478bd9Sstevel@tonic-gate _pthread_setschedparam(pthread_t tid,
313*7c478bd9Sstevel@tonic-gate 	int policy, const struct sched_param *param)
314*7c478bd9Sstevel@tonic-gate {
315*7c478bd9Sstevel@tonic-gate 	return (_thread_setschedparam_main(tid, policy, param, PRIO_SET));
316*7c478bd9Sstevel@tonic-gate }
317