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