import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / gen / priocntl.c
blob71bf943b40f8877b1b20a379292378fba76a1c20
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
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>
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().
48 * defined in priocntlset.s
50 extern long __priocntlset(int, procset_t *, int, caddr_t, ...);
52 static int pc_vaargs2parms(va_list valist, pc_vaparms_t *vp);
54 long
55 __priocntl(int pc_version, idtype_t idtype, id_t id, int cmd, caddr_t arg)
57 procset_t procset;
59 setprocset(&procset, POP_AND, idtype, id, P_ALL, 0);
61 return (__priocntlset(pc_version, &procset, cmd, arg, 0));
65 /*VARARGS3*/
66 long
67 priocntl(idtype_t idtype, id_t id, int cmd, ...)
69 procset_t procset;
70 va_list valist;
71 pc_vaparms_t varparms;
72 caddr_t arg;
73 int error;
75 setprocset(&procset, POP_AND, idtype, id, P_ALL, 0);
77 va_start(valist, cmd);
78 arg = va_arg(valist, caddr_t);
80 if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) {
81 va_end(valist);
82 return (__priocntlset(PC_VERSION, &procset, cmd, arg, 0));
85 error = pc_vaargs2parms(valist, &varparms);
86 va_end(valist);
88 if (error) {
89 errno = error;
90 return (-1);
93 return (__priocntlset(PC_VERSION, &procset, cmd, arg, &varparms));
97 /*VARARGS2*/
98 long
99 priocntlset(procset_t *procsetp, int cmd, ...)
101 va_list valist;
102 pc_vaparms_t varparms;
103 caddr_t arg;
104 int error;
106 va_start(valist, cmd);
107 arg = va_arg(valist, caddr_t);
109 if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) {
110 va_end(valist);
111 return (__priocntlset(PC_VERSION, procsetp, cmd, arg, 0));
114 error = pc_vaargs2parms(valist, &varparms);
115 va_end(valist);
117 if (error) {
118 errno = error;
119 return (-1);
122 return (__priocntlset(PC_VERSION, procsetp, cmd, arg, &varparms));
126 static int
127 pc_vaargs2parms(va_list valist, pc_vaparms_t *vp)
129 pc_vaparm_t *vpp = &vp->pc_parms[0];
130 int key;
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);
137 vpp->pc_key = key;
138 vpp->pc_parm = va_arg(valist, uintptr_t);
141 return (0);