10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
56247Sraf * Common Development and Distribution License (the "License").
66247Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
216247Sraf
220Sstevel@tonic-gate /*
236247Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
30*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI"
31*6812Sraf
32*6812Sraf #include "lint.h"
336247Sraf #include <sys/types.h>
346247Sraf #include <sys/procset.h>
356247Sraf #include <sys/priocntl.h>
366247Sraf #include <stdarg.h>
376247Sraf #include <errno.h>
380Sstevel@tonic-gate
390Sstevel@tonic-gate /*
406247Sraf * The declarations of __priocntlset() and __priocntl() were in prior releases
416247Sraf * in <sys/priocntl.h>. They are used to define PC_VERSION at compile time,
426247Sraf * based on the contents of the header file. This behavior is now changed.
436247Sraf * Old binaries call __priocntl() and __priocntlset() instead of priocntl()
446247Sraf * and priocntlset(). New binaries call priocntl() and priocntlset().
450Sstevel@tonic-gate */
460Sstevel@tonic-gate
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate * defined in priocntlset.s
490Sstevel@tonic-gate */
500Sstevel@tonic-gate extern long __priocntlset(int, procset_t *, int, caddr_t, ...);
510Sstevel@tonic-gate
520Sstevel@tonic-gate static int pc_vaargs2parms(va_list valist, pc_vaparms_t *vp);
530Sstevel@tonic-gate
540Sstevel@tonic-gate long
__priocntl(int pc_version,idtype_t idtype,id_t id,int cmd,caddr_t arg)550Sstevel@tonic-gate __priocntl(int pc_version, idtype_t idtype, id_t id, int cmd, caddr_t arg)
560Sstevel@tonic-gate {
570Sstevel@tonic-gate procset_t procset;
580Sstevel@tonic-gate
590Sstevel@tonic-gate setprocset(&procset, POP_AND, idtype, id, P_ALL, 0);
600Sstevel@tonic-gate
610Sstevel@tonic-gate return (__priocntlset(pc_version, &procset, cmd, arg, 0));
620Sstevel@tonic-gate }
630Sstevel@tonic-gate
640Sstevel@tonic-gate
650Sstevel@tonic-gate /*VARARGS3*/
660Sstevel@tonic-gate long
priocntl(idtype_t idtype,id_t id,int cmd,...)670Sstevel@tonic-gate priocntl(idtype_t idtype, id_t id, int cmd, ...)
680Sstevel@tonic-gate {
690Sstevel@tonic-gate procset_t procset;
700Sstevel@tonic-gate va_list valist;
710Sstevel@tonic-gate pc_vaparms_t varparms;
720Sstevel@tonic-gate caddr_t arg;
730Sstevel@tonic-gate int error;
740Sstevel@tonic-gate
750Sstevel@tonic-gate setprocset(&procset, POP_AND, idtype, id, P_ALL, 0);
760Sstevel@tonic-gate
770Sstevel@tonic-gate va_start(valist, cmd);
780Sstevel@tonic-gate arg = va_arg(valist, caddr_t);
790Sstevel@tonic-gate
800Sstevel@tonic-gate if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) {
810Sstevel@tonic-gate va_end(valist);
820Sstevel@tonic-gate return (__priocntlset(PC_VERSION, &procset, cmd, arg, 0));
830Sstevel@tonic-gate }
840Sstevel@tonic-gate
850Sstevel@tonic-gate error = pc_vaargs2parms(valist, &varparms);
860Sstevel@tonic-gate va_end(valist);
870Sstevel@tonic-gate
880Sstevel@tonic-gate if (error) {
890Sstevel@tonic-gate errno = error;
900Sstevel@tonic-gate return (-1);
910Sstevel@tonic-gate }
920Sstevel@tonic-gate
930Sstevel@tonic-gate return (__priocntlset(PC_VERSION, &procset, cmd, arg, &varparms));
940Sstevel@tonic-gate }
950Sstevel@tonic-gate
960Sstevel@tonic-gate
970Sstevel@tonic-gate /*VARARGS2*/
980Sstevel@tonic-gate long
priocntlset(procset_t * procsetp,int cmd,...)990Sstevel@tonic-gate priocntlset(procset_t *procsetp, int cmd, ...)
1000Sstevel@tonic-gate {
1010Sstevel@tonic-gate va_list valist;
1020Sstevel@tonic-gate pc_vaparms_t varparms;
1030Sstevel@tonic-gate caddr_t arg;
1040Sstevel@tonic-gate int error;
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate va_start(valist, cmd);
1070Sstevel@tonic-gate arg = va_arg(valist, caddr_t);
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) {
1100Sstevel@tonic-gate va_end(valist);
1110Sstevel@tonic-gate return (__priocntlset(PC_VERSION, procsetp, cmd, arg, 0));
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate error = pc_vaargs2parms(valist, &varparms);
1150Sstevel@tonic-gate va_end(valist);
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate if (error) {
1180Sstevel@tonic-gate errno = error;
1190Sstevel@tonic-gate return (-1);
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate return (__priocntlset(PC_VERSION, procsetp, cmd, arg, &varparms));
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate static int
pc_vaargs2parms(va_list valist,pc_vaparms_t * vp)1270Sstevel@tonic-gate pc_vaargs2parms(va_list valist, pc_vaparms_t *vp)
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate pc_vaparm_t *vpp = &vp->pc_parms[0];
1300Sstevel@tonic-gate int key;
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate for (vp->pc_vaparmscnt = 0;
1330Sstevel@tonic-gate (key = va_arg(valist, int)) != PC_KY_NULL; vpp++) {
1340Sstevel@tonic-gate if (++vp->pc_vaparmscnt > PC_VAPARMCNT)
1350Sstevel@tonic-gate return (EINVAL);
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate vpp->pc_key = key;
1380Sstevel@tonic-gate vpp->pc_parm = va_arg(valist, uintptr_t);
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate return (0);
1420Sstevel@tonic-gate }
143