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
5d4204c85Sraf * Common Development and Distribution License (the "License").
6d4204c85Sraf * 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 /* Copyright (c) 1988 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
30*7257d1b4Sraf #pragma ident "%Z%%M% %I% %E% SMI"
31*7257d1b4Sraf
32*7257d1b4Sraf #include "lint.h"
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/procset.h>
357c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
367c478bd9Sstevel@tonic-gate #include <stdarg.h>
377c478bd9Sstevel@tonic-gate #include <errno.h>
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate /*
40d4204c85Sraf * The declarations of __priocntlset() and __priocntl() were in prior releases
417c478bd9Sstevel@tonic-gate * in <sys/priocntl.h>. They are used to define PC_VERSION at compile time,
427c478bd9Sstevel@tonic-gate * based on the contents of the header file. This behavior is now changed.
43d4204c85Sraf * Old binaries call __priocntl() and __priocntlset() instead of priocntl()
44d4204c85Sraf * and priocntlset(). New binaries call priocntl() and priocntlset().
457c478bd9Sstevel@tonic-gate */
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate * defined in priocntlset.s
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate extern long __priocntlset(int, procset_t *, int, caddr_t, ...);
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate static int pc_vaargs2parms(va_list valist, pc_vaparms_t *vp);
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate long
__priocntl(int pc_version,idtype_t idtype,id_t id,int cmd,caddr_t arg)557c478bd9Sstevel@tonic-gate __priocntl(int pc_version, idtype_t idtype, id_t id, int cmd, caddr_t arg)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate procset_t procset;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate setprocset(&procset, POP_AND, idtype, id, P_ALL, 0);
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate return (__priocntlset(pc_version, &procset, cmd, arg, 0));
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate /*VARARGS3*/
667c478bd9Sstevel@tonic-gate long
priocntl(idtype_t idtype,id_t id,int cmd,...)677c478bd9Sstevel@tonic-gate priocntl(idtype_t idtype, id_t id, int cmd, ...)
687c478bd9Sstevel@tonic-gate {
697c478bd9Sstevel@tonic-gate procset_t procset;
707c478bd9Sstevel@tonic-gate va_list valist;
717c478bd9Sstevel@tonic-gate pc_vaparms_t varparms;
727c478bd9Sstevel@tonic-gate caddr_t arg;
737c478bd9Sstevel@tonic-gate int error;
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate setprocset(&procset, POP_AND, idtype, id, P_ALL, 0);
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate va_start(valist, cmd);
787c478bd9Sstevel@tonic-gate arg = va_arg(valist, caddr_t);
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) {
817c478bd9Sstevel@tonic-gate va_end(valist);
827c478bd9Sstevel@tonic-gate return (__priocntlset(PC_VERSION, &procset, cmd, arg, 0));
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate error = pc_vaargs2parms(valist, &varparms);
867c478bd9Sstevel@tonic-gate va_end(valist);
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate if (error) {
897c478bd9Sstevel@tonic-gate errno = error;
907c478bd9Sstevel@tonic-gate return (-1);
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate return (__priocntlset(PC_VERSION, &procset, cmd, arg, &varparms));
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate /*VARARGS2*/
987c478bd9Sstevel@tonic-gate long
priocntlset(procset_t * procsetp,int cmd,...)997c478bd9Sstevel@tonic-gate priocntlset(procset_t *procsetp, int cmd, ...)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate va_list valist;
1027c478bd9Sstevel@tonic-gate pc_vaparms_t varparms;
1037c478bd9Sstevel@tonic-gate caddr_t arg;
1047c478bd9Sstevel@tonic-gate int error;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate va_start(valist, cmd);
1077c478bd9Sstevel@tonic-gate arg = va_arg(valist, caddr_t);
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) {
1107c478bd9Sstevel@tonic-gate va_end(valist);
1117c478bd9Sstevel@tonic-gate return (__priocntlset(PC_VERSION, procsetp, cmd, arg, 0));
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate error = pc_vaargs2parms(valist, &varparms);
1157c478bd9Sstevel@tonic-gate va_end(valist);
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate if (error) {
1187c478bd9Sstevel@tonic-gate errno = error;
1197c478bd9Sstevel@tonic-gate return (-1);
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate return (__priocntlset(PC_VERSION, procsetp, cmd, arg, &varparms));
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate static int
pc_vaargs2parms(va_list valist,pc_vaparms_t * vp)1277c478bd9Sstevel@tonic-gate pc_vaargs2parms(va_list valist, pc_vaparms_t *vp)
1287c478bd9Sstevel@tonic-gate {
1297c478bd9Sstevel@tonic-gate pc_vaparm_t *vpp = &vp->pc_parms[0];
1307c478bd9Sstevel@tonic-gate int key;
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate for (vp->pc_vaparmscnt = 0;
1337c478bd9Sstevel@tonic-gate (key = va_arg(valist, int)) != PC_KY_NULL; vpp++) {
1347c478bd9Sstevel@tonic-gate if (++vp->pc_vaparmscnt > PC_VAPARMCNT)
1357c478bd9Sstevel@tonic-gate return (EINVAL);
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate vpp->pc_key = key;
1387c478bd9Sstevel@tonic-gate vpp->pc_parm = va_arg(valist, uintptr_t);
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate return (0);
1427c478bd9Sstevel@tonic-gate }
143