xref: /titanic_44/usr/src/lib/libc/port/gen/priocntl.c (revision 01335b0d1c4e0c0f16325a830b24ea2a4076fd38)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include "lint.h"
33 #include <sys/types.h>
34 #include <sys/procset.h>
35 #include <sys/priocntl.h>
36 #include <stdarg.h>
37 #include <errno.h>
38 
39 /*
40  * The declarations of __priocntlset() and __priocntl() were in prior releases
41  * in <sys/priocntl.h>.  They are used to define PC_VERSION at compile time,
42  * based on the contents of the header file.  This behavior is now changed.
43  * Old binaries call __priocntl() and __priocntlset() instead of priocntl()
44  * and priocntlset().  New binaries call priocntl() and priocntlset().
45  */
46 
47 /*
48  * defined in priocntlset.s
49  */
50 extern long __priocntlset(int, procset_t *, int, caddr_t, ...);
51 
52 static int pc_vaargs2parms(va_list valist, pc_vaparms_t *vp);
53 
54 long
55 __priocntl(int pc_version, idtype_t idtype, id_t id, int cmd, caddr_t arg)
56 {
57 	procset_t	procset;
58 
59 	setprocset(&procset, POP_AND, idtype, id, P_ALL, 0);
60 
61 	return (__priocntlset(pc_version, &procset, cmd, arg, 0));
62 }
63 
64 
65 /*VARARGS3*/
66 long
67 priocntl(idtype_t idtype, id_t id, int cmd, ...)
68 {
69 	procset_t	procset;
70 	va_list		valist;
71 	pc_vaparms_t	varparms;
72 	caddr_t		arg;
73 	int		error;
74 
75 	setprocset(&procset, POP_AND, idtype, id, P_ALL, 0);
76 
77 	va_start(valist, cmd);
78 	arg = va_arg(valist, caddr_t);
79 
80 	if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) {
81 		va_end(valist);
82 		return (__priocntlset(PC_VERSION, &procset, cmd, arg, 0));
83 	}
84 
85 	error = pc_vaargs2parms(valist, &varparms);
86 	va_end(valist);
87 
88 	if (error) {
89 		errno = error;
90 		return (-1);
91 	}
92 
93 	return (__priocntlset(PC_VERSION, &procset, cmd, arg, &varparms));
94 }
95 
96 
97 /*VARARGS2*/
98 long
99 priocntlset(procset_t *procsetp, int cmd, ...)
100 {
101 	va_list		valist;
102 	pc_vaparms_t	varparms;
103 	caddr_t		arg;
104 	int		error;
105 
106 	va_start(valist, cmd);
107 	arg = va_arg(valist, caddr_t);
108 
109 	if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) {
110 		va_end(valist);
111 		return (__priocntlset(PC_VERSION, procsetp, cmd, arg, 0));
112 	}
113 
114 	error = pc_vaargs2parms(valist, &varparms);
115 	va_end(valist);
116 
117 	if (error) {
118 		errno = error;
119 		return (-1);
120 	}
121 
122 	return (__priocntlset(PC_VERSION, procsetp, cmd, arg, &varparms));
123 }
124 
125 
126 static int
127 pc_vaargs2parms(va_list valist, pc_vaparms_t *vp)
128 {
129 	pc_vaparm_t	*vpp = &vp->pc_parms[0];
130 	int		key;
131 
132 	for (vp->pc_vaparmscnt = 0;
133 	    (key = va_arg(valist, int)) != PC_KY_NULL; vpp++) {
134 		if (++vp->pc_vaparmscnt > PC_VAPARMCNT)
135 			return (EINVAL);
136 
137 		vpp->pc_key = key;
138 		vpp->pc_parm = va_arg(valist, uintptr_t);
139 	}
140 
141 	return (0);
142 }
143