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
59acbbeafSnn * Common Development and Distribution License (the "License").
69acbbeafSnn * 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 */
21d4204c85Sraf
227c478bd9Sstevel@tonic-gate /*
23d4204c85Sraf * 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 #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <sys/systm.h>
297c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
307c478bd9Sstevel@tonic-gate #include <sys/class.h>
317c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
327c478bd9Sstevel@tonic-gate #include <sys/cred.h>
337c478bd9Sstevel@tonic-gate #include <sys/proc.h>
347c478bd9Sstevel@tonic-gate #include <sys/procset.h>
357c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
367c478bd9Sstevel@tonic-gate #include <sys/disp.h>
377c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
38d4204c85Sraf #include <sys/schedctl.h>
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate static int getcidbyname_locked(char *, id_t *);
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * Allocate a cid given a class name if one is not already allocated.
447c478bd9Sstevel@tonic-gate * Returns 0 if the cid was already exists or if the allocation of a new
457c478bd9Sstevel@tonic-gate * cid was successful. Nonzero return indicates error.
467c478bd9Sstevel@tonic-gate */
477c478bd9Sstevel@tonic-gate int
alloc_cid(char * clname,id_t * cidp)487c478bd9Sstevel@tonic-gate alloc_cid(char *clname, id_t *cidp)
497c478bd9Sstevel@tonic-gate {
507c478bd9Sstevel@tonic-gate sclass_t *clp;
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&class_lock));
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate * If the clname doesn't already have a cid, allocate one.
567c478bd9Sstevel@tonic-gate */
577c478bd9Sstevel@tonic-gate if (getcidbyname_locked(clname, cidp) != 0) {
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate * Allocate a class entry and a lock for it.
607c478bd9Sstevel@tonic-gate */
617c478bd9Sstevel@tonic-gate for (clp = sclass; clp < &sclass[nclass]; clp++)
627c478bd9Sstevel@tonic-gate if (clp->cl_name[0] == '\0' && clp->cl_lock == NULL)
637c478bd9Sstevel@tonic-gate break;
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate if (clp == &sclass[nclass]) {
667c478bd9Sstevel@tonic-gate return (ENOSPC);
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate *cidp = clp - &sclass[0];
697c478bd9Sstevel@tonic-gate clp->cl_lock = kmem_alloc(sizeof (krwlock_t), KM_SLEEP);
707c478bd9Sstevel@tonic-gate clp->cl_name = kmem_alloc(strlen(clname) + 1, KM_SLEEP);
717c478bd9Sstevel@tonic-gate (void) strcpy(clp->cl_name, clname);
727c478bd9Sstevel@tonic-gate rw_init(clp->cl_lock, NULL, RW_DEFAULT, NULL);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate * At this point, *cidp will contain the index into the class
777c478bd9Sstevel@tonic-gate * array for the given class name.
787c478bd9Sstevel@tonic-gate */
797c478bd9Sstevel@tonic-gate return (0);
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate int
scheduler_load(char * clname,sclass_t * clp)837c478bd9Sstevel@tonic-gate scheduler_load(char *clname, sclass_t *clp)
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate int rv = 0;
86aaad92d0SKrishnendu Sadhukhan - Sun Microsystems char *tmp = clname + 1;
87aaad92d0SKrishnendu Sadhukhan - Sun Microsystems
88aaad92d0SKrishnendu Sadhukhan - Sun Microsystems /* Check if class name is "", ".", ".." or "`" */
89aaad92d0SKrishnendu Sadhukhan - Sun Microsystems if (*clname == '\0' || *clname == '`' || (*clname == '.' && *tmp == '\0') ||
90aaad92d0SKrishnendu Sadhukhan - Sun Microsystems (*clname == '.' && *tmp == '.' && *(++tmp) == '\0'))
91aaad92d0SKrishnendu Sadhukhan - Sun Microsystems return (EINVAL);
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate if (LOADABLE_SCHED(clp)) {
947c478bd9Sstevel@tonic-gate rw_enter(clp->cl_lock, RW_READER);
957c478bd9Sstevel@tonic-gate if (!SCHED_INSTALLED(clp)) {
967c478bd9Sstevel@tonic-gate rw_exit(clp->cl_lock);
977c478bd9Sstevel@tonic-gate if (modload("sched", clname) == -1)
987c478bd9Sstevel@tonic-gate return (EINVAL);
997c478bd9Sstevel@tonic-gate rw_enter(clp->cl_lock, RW_READER);
1007c478bd9Sstevel@tonic-gate /* did we really load a scheduling class? */
1017c478bd9Sstevel@tonic-gate if (!SCHED_INSTALLED(clp))
1027c478bd9Sstevel@tonic-gate rv = EINVAL;
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate rw_exit(clp->cl_lock);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate return (rv);
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate * Get class ID given class name.
1117c478bd9Sstevel@tonic-gate */
1127c478bd9Sstevel@tonic-gate int
getcid(char * clname,id_t * cidp)1137c478bd9Sstevel@tonic-gate getcid(char *clname, id_t *cidp)
1147c478bd9Sstevel@tonic-gate {
1157c478bd9Sstevel@tonic-gate sclass_t *clp;
1167c478bd9Sstevel@tonic-gate int retval;
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate mutex_enter(&class_lock);
1197c478bd9Sstevel@tonic-gate if ((retval = alloc_cid(clname, cidp)) == 0) {
1207c478bd9Sstevel@tonic-gate clp = &sclass[*cidp];
1217c478bd9Sstevel@tonic-gate clp->cl_count++;
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * If it returns zero, it's loaded & locked
1257c478bd9Sstevel@tonic-gate * or we found a statically installed scheduler
1267c478bd9Sstevel@tonic-gate * module.
1277c478bd9Sstevel@tonic-gate * If it returns EINVAL, modload() failed when
1287c478bd9Sstevel@tonic-gate * it tried to load the module.
1297c478bd9Sstevel@tonic-gate */
1307c478bd9Sstevel@tonic-gate mutex_exit(&class_lock);
1317c478bd9Sstevel@tonic-gate retval = scheduler_load(clname, clp);
1327c478bd9Sstevel@tonic-gate mutex_enter(&class_lock);
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate clp->cl_count--;
1357c478bd9Sstevel@tonic-gate if (retval != 0 && clp->cl_count == 0) {
1367c478bd9Sstevel@tonic-gate /* last guy out of scheduler_load frees the storage */
1377c478bd9Sstevel@tonic-gate kmem_free(clp->cl_name, strlen(clname) + 1);
1387c478bd9Sstevel@tonic-gate kmem_free(clp->cl_lock, sizeof (krwlock_t));
1397c478bd9Sstevel@tonic-gate clp->cl_name = "";
1407c478bd9Sstevel@tonic-gate clp->cl_lock = (krwlock_t *)NULL;
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate mutex_exit(&class_lock);
1447c478bd9Sstevel@tonic-gate return (retval);
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate static int
getcidbyname_locked(char * clname,id_t * cidp)1497c478bd9Sstevel@tonic-gate getcidbyname_locked(char *clname, id_t *cidp)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate sclass_t *clp;
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&class_lock));
1547c478bd9Sstevel@tonic-gate
155*7e12ceb3SToomas Soome if (*clname == '\0')
1567c478bd9Sstevel@tonic-gate return (EINVAL);
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate for (clp = &sclass[0]; clp < &sclass[nclass]; clp++) {
1597c478bd9Sstevel@tonic-gate if (strcmp(clp->cl_name, clname) == 0) {
1607c478bd9Sstevel@tonic-gate *cidp = clp - &sclass[0];
1617c478bd9Sstevel@tonic-gate return (0);
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate return (EINVAL);
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate * Lookup a module by name.
1697c478bd9Sstevel@tonic-gate */
1707c478bd9Sstevel@tonic-gate int
getcidbyname(char * clname,id_t * cidp)1717c478bd9Sstevel@tonic-gate getcidbyname(char *clname, id_t *cidp)
1727c478bd9Sstevel@tonic-gate {
1737c478bd9Sstevel@tonic-gate int retval;
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate mutex_enter(&class_lock);
1767c478bd9Sstevel@tonic-gate retval = getcidbyname_locked(clname, cidp);
1777c478bd9Sstevel@tonic-gate mutex_exit(&class_lock);
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate return (retval);
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate * Get the scheduling parameters of the thread pointed to by
1847c478bd9Sstevel@tonic-gate * tp into the buffer pointed to by parmsp.
1857c478bd9Sstevel@tonic-gate */
1867c478bd9Sstevel@tonic-gate void
parmsget(kthread_t * tp,pcparms_t * parmsp)187d4204c85Sraf parmsget(kthread_t *tp, pcparms_t *parmsp)
1887c478bd9Sstevel@tonic-gate {
1897c478bd9Sstevel@tonic-gate parmsp->pc_cid = tp->t_cid;
1907c478bd9Sstevel@tonic-gate CL_PARMSGET(tp, parmsp->pc_clparms);
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate /*
1957c478bd9Sstevel@tonic-gate * Check the validity of the scheduling parameters in the buffer
1967c478bd9Sstevel@tonic-gate * pointed to by parmsp.
1977c478bd9Sstevel@tonic-gate * Note that the format of the parameters may be changed by class
1987c478bd9Sstevel@tonic-gate * specific code which we call.
1997c478bd9Sstevel@tonic-gate */
2007c478bd9Sstevel@tonic-gate int
parmsin(pcparms_t * parmsp,pc_vaparms_t * vaparmsp)2017c478bd9Sstevel@tonic-gate parmsin(pcparms_t *parmsp, pc_vaparms_t *vaparmsp)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate if (parmsp->pc_cid >= loaded_classes || parmsp->pc_cid < 1)
2047c478bd9Sstevel@tonic-gate return (EINVAL);
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate * Call the class specific routine to validate class
2087c478bd9Sstevel@tonic-gate * specific parameters.
2097c478bd9Sstevel@tonic-gate * The input parameters are either in a pcparms structure (PC_SETPARMS)
2107c478bd9Sstevel@tonic-gate * or in a variable parameter structure (PC_SETXPARMS). In the
2117c478bd9Sstevel@tonic-gate * 'PC_SETPARMS' case vaparmsp is a NULL pointer and a CL_PARMSIN()
2127c478bd9Sstevel@tonic-gate * routine gets the parameter. Otherwise vaparmsp points to a variable
2137c478bd9Sstevel@tonic-gate * parameter structure and a CL_VAPARMSIN() routine gets the parameter.
2147c478bd9Sstevel@tonic-gate */
2157c478bd9Sstevel@tonic-gate if (vaparmsp != NULL)
2167c478bd9Sstevel@tonic-gate return (CL_VAPARMSIN(&sclass[parmsp->pc_cid],
2177c478bd9Sstevel@tonic-gate parmsp->pc_clparms, vaparmsp));
2187c478bd9Sstevel@tonic-gate else
2197c478bd9Sstevel@tonic-gate return (CL_PARMSIN(&sclass[parmsp->pc_cid],
2207c478bd9Sstevel@tonic-gate parmsp->pc_clparms));
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate * Call the class specific code to do the required processing
2267c478bd9Sstevel@tonic-gate * before the scheduling parameters are copied out to the user.
2277c478bd9Sstevel@tonic-gate * Note that the format of the parameters may be changed by the
2287c478bd9Sstevel@tonic-gate * class specific code.
2297c478bd9Sstevel@tonic-gate */
2307c478bd9Sstevel@tonic-gate int
parmsout(pcparms_t * parmsp,pc_vaparms_t * vaparmsp)2317c478bd9Sstevel@tonic-gate parmsout(pcparms_t *parmsp, pc_vaparms_t *vaparmsp)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate return (CL_PARMSOUT(&sclass[parmsp->pc_cid], parmsp->pc_clparms,
234d4204c85Sraf vaparmsp));
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate /*
2397c478bd9Sstevel@tonic-gate * Set the scheduling parameters of the thread pointed to by
2407c478bd9Sstevel@tonic-gate * targtp to those specified in the pcparms structure pointed
2417c478bd9Sstevel@tonic-gate * to by parmsp. If reqtp is non-NULL it points to the thread
2427c478bd9Sstevel@tonic-gate * that initiated the request for the parameter change and indicates
2437c478bd9Sstevel@tonic-gate * that our caller wants us to verify that the requesting thread
2447c478bd9Sstevel@tonic-gate * has the appropriate permissions.
2457c478bd9Sstevel@tonic-gate */
2467c478bd9Sstevel@tonic-gate int
parmsset(pcparms_t * parmsp,kthread_t * targtp)247d4204c85Sraf parmsset(pcparms_t *parmsp, kthread_t *targtp)
2487c478bd9Sstevel@tonic-gate {
2497c478bd9Sstevel@tonic-gate caddr_t clprocp;
2507c478bd9Sstevel@tonic-gate int error;
2517c478bd9Sstevel@tonic-gate cred_t *reqpcredp;
2527c478bd9Sstevel@tonic-gate proc_t *reqpp = ttoproc(curthread);
2537c478bd9Sstevel@tonic-gate proc_t *targpp = ttoproc(targtp);
2547c478bd9Sstevel@tonic-gate id_t oldcid;
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pidlock));
2577c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&targpp->p_lock));
2587c478bd9Sstevel@tonic-gate if (reqpp != NULL) {
2597c478bd9Sstevel@tonic-gate mutex_enter(&reqpp->p_crlock);
2607c478bd9Sstevel@tonic-gate crhold(reqpcredp = reqpp->p_cred);
2617c478bd9Sstevel@tonic-gate mutex_exit(&reqpp->p_crlock);
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate * Check basic permissions.
2657c478bd9Sstevel@tonic-gate */
2667c478bd9Sstevel@tonic-gate if (!prochasprocperm(targpp, reqpp, reqpcredp)) {
2677c478bd9Sstevel@tonic-gate crfree(reqpcredp);
2687c478bd9Sstevel@tonic-gate return (EPERM);
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate } else {
2717c478bd9Sstevel@tonic-gate reqpcredp = NULL;
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate if (parmsp->pc_cid != targtp->t_cid) {
2757c478bd9Sstevel@tonic-gate void *bufp = NULL;
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate * Target thread must change to new class.
2787c478bd9Sstevel@tonic-gate */
2797c478bd9Sstevel@tonic-gate clprocp = (caddr_t)targtp->t_cldata;
2807c478bd9Sstevel@tonic-gate oldcid = targtp->t_cid;
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate /*
2837c478bd9Sstevel@tonic-gate * Purpose: allow scheduling class to veto moves
2847c478bd9Sstevel@tonic-gate * to other classes. All the classes, except FSS,
2857c478bd9Sstevel@tonic-gate * do nothing except returning 0.
2867c478bd9Sstevel@tonic-gate */
2877c478bd9Sstevel@tonic-gate error = CL_CANEXIT(targtp, reqpcredp);
2887c478bd9Sstevel@tonic-gate if (error) {
2897c478bd9Sstevel@tonic-gate /*
2907c478bd9Sstevel@tonic-gate * Not allowed to leave the class, so return error.
2917c478bd9Sstevel@tonic-gate */
2927c478bd9Sstevel@tonic-gate crfree(reqpcredp);
2937c478bd9Sstevel@tonic-gate return (error);
2947c478bd9Sstevel@tonic-gate } else {
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate * Pre-allocate scheduling class data.
2977c478bd9Sstevel@tonic-gate */
2987c478bd9Sstevel@tonic-gate if (CL_ALLOC(&bufp, parmsp->pc_cid, KM_NOSLEEP) != 0) {
2997c478bd9Sstevel@tonic-gate error = ENOMEM; /* no memory available */
3007c478bd9Sstevel@tonic-gate crfree(reqpcredp);
3017c478bd9Sstevel@tonic-gate return (error);
3027c478bd9Sstevel@tonic-gate } else {
3037c478bd9Sstevel@tonic-gate error = CL_ENTERCLASS(targtp, parmsp->pc_cid,
3047c478bd9Sstevel@tonic-gate parmsp->pc_clparms, reqpcredp, bufp);
3057c478bd9Sstevel@tonic-gate crfree(reqpcredp);
3067c478bd9Sstevel@tonic-gate if (error) {
3077c478bd9Sstevel@tonic-gate CL_FREE(parmsp->pc_cid, bufp);
3087c478bd9Sstevel@tonic-gate return (error);
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate }
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate CL_EXITCLASS(oldcid, clprocp);
3137c478bd9Sstevel@tonic-gate } else {
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate /*
3167c478bd9Sstevel@tonic-gate * Not changing class
3177c478bd9Sstevel@tonic-gate */
3187c478bd9Sstevel@tonic-gate error = CL_PARMSSET(targtp, parmsp->pc_clparms,
319d4204c85Sraf curthread->t_cid, reqpcredp);
3207c478bd9Sstevel@tonic-gate crfree(reqpcredp);
3217c478bd9Sstevel@tonic-gate if (error)
3227c478bd9Sstevel@tonic-gate return (error);
3237c478bd9Sstevel@tonic-gate }
324d4204c85Sraf schedctl_set_cidpri(targtp);
3257c478bd9Sstevel@tonic-gate return (0);
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate /*
3307c478bd9Sstevel@tonic-gate * Copy all selected class parameters to the user.
3317c478bd9Sstevel@tonic-gate * The parameters are specified by a key.
3327c478bd9Sstevel@tonic-gate */
3337c478bd9Sstevel@tonic-gate int
vaparmsout(char * classp,pcparms_t * prmsp,pc_vaparms_t * vaparmsp,uio_seg_t seg)3349acbbeafSnn vaparmsout(char *classp, pcparms_t *prmsp, pc_vaparms_t *vaparmsp,
3359acbbeafSnn uio_seg_t seg)
3367c478bd9Sstevel@tonic-gate {
3377c478bd9Sstevel@tonic-gate char *clname;
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate ASSERT(MUTEX_NOT_HELD(&curproc->p_lock));
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate if (classp != NULL)
3427c478bd9Sstevel@tonic-gate return (CL_VAPARMSOUT(&sclass[prmsp->pc_cid],
3437c478bd9Sstevel@tonic-gate prmsp->pc_clparms, vaparmsp));
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate switch (vaparmsp->pc_vaparmscnt) {
3467c478bd9Sstevel@tonic-gate case 0:
3477c478bd9Sstevel@tonic-gate return (0);
3487c478bd9Sstevel@tonic-gate case 1:
3497c478bd9Sstevel@tonic-gate break;
3507c478bd9Sstevel@tonic-gate default:
3517c478bd9Sstevel@tonic-gate return (EINVAL);
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate if (vaparmsp->pc_parms[0].pc_key != PC_KY_CLNAME)
3557c478bd9Sstevel@tonic-gate return (EINVAL);
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate clname = sclass[prmsp->pc_cid].cl_name;
3589acbbeafSnn if ((seg == UIO_USERSPACE ? copyout : kcopy)(clname,
3599acbbeafSnn (void *)(uintptr_t)vaparmsp->pc_parms[0].pc_parm,
3607c478bd9Sstevel@tonic-gate MIN(strlen(clname) + 1, PC_CLNMSZ)))
3617c478bd9Sstevel@tonic-gate return (EFAULT);
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate return (0);
3647c478bd9Sstevel@tonic-gate }
365