xref: /titanic_41/usr/src/lib/libproc/common/pr_pbind.c (revision 2654012f83cec5dc15b61dfe3e4a4915f186e7a6)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/procset.h>
31 #include <sys/processor.h>
32 #include <sys/pset.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <errno.h>
36 #include "libproc.h"
37 
38 int
39 pr_processor_bind(struct ps_prochandle *Pr, idtype_t idtype, id_t id,
40     int processorid, int *obind)
41 {
42 	sysret_t rval;			/* return value */
43 	argdes_t argd[4];		/* arg descriptors */
44 	argdes_t *adp = &argd[0];	/* first argument */
45 	int error;
46 
47 	if (Pr == NULL)		/* no subject process */
48 		return (processor_bind(idtype, id, processorid, obind));
49 
50 	adp->arg_value = idtype;	/* idtype */
51 	adp->arg_object = NULL;
52 	adp->arg_type = AT_BYVAL;
53 	adp->arg_inout = AI_INPUT;
54 	adp->arg_size = 0;
55 	adp++;
56 
57 	adp->arg_value = id;		/* id */
58 	adp->arg_object = NULL;
59 	adp->arg_type = AT_BYVAL;
60 	adp->arg_inout = AI_INPUT;
61 	adp->arg_size = 0;
62 	adp++;
63 
64 	adp->arg_value = processorid;	/* processorid */
65 	adp->arg_object = NULL;
66 	adp->arg_type = AT_BYVAL;
67 	adp->arg_inout = AI_INPUT;
68 	adp->arg_size = 0;
69 	adp++;
70 
71 	if (obind == NULL) {
72 		adp->arg_value = 0;	/* obind */
73 		adp->arg_object = NULL;
74 		adp->arg_type = AT_BYVAL;
75 		adp->arg_inout = AI_INPUT;
76 		adp->arg_size = 0;
77 	} else {
78 		adp->arg_value = 0;
79 		adp->arg_object = obind;
80 		adp->arg_type = AT_BYREF;
81 		adp->arg_inout = AI_INOUT;
82 		adp->arg_size = sizeof (int);
83 	}
84 
85 	error = Psyscall(Pr, &rval, SYS_processor_bind, 4, &argd[0]);
86 
87 	if (error) {
88 		errno = (error < 0)? ENOSYS : error;
89 		return (-1);
90 	}
91 	return (rval.sys_rval1);
92 }
93 
94 int
95 pr_pset_bind(struct ps_prochandle *Pr, int pset, idtype_t idtype, id_t id,
96     int *opset)
97 {
98 	sysret_t rval;			/* return value */
99 	argdes_t argd[5];		/* arg descriptors */
100 	argdes_t *adp = &argd[0];	/* first argument */
101 	int error;
102 
103 	if (Pr == NULL)		/* no subject process */
104 		return (pset_bind(pset, idtype, id, opset));
105 
106 	adp->arg_value = PSET_BIND;	/* PSET_BIND */
107 	adp->arg_object = NULL;
108 	adp->arg_type = AT_BYVAL;
109 	adp->arg_inout = AI_INPUT;
110 	adp->arg_size = 0;
111 	adp++;
112 
113 	adp->arg_value = pset;		/* pset */
114 	adp->arg_object = NULL;
115 	adp->arg_type = AT_BYVAL;
116 	adp->arg_inout = AI_INPUT;
117 	adp->arg_size = 0;
118 	adp++;
119 
120 	adp->arg_value = idtype;	/* idtype */
121 	adp->arg_object = NULL;
122 	adp->arg_type = AT_BYVAL;
123 	adp->arg_inout = AI_INPUT;
124 	adp->arg_size = 0;
125 	adp++;
126 
127 	adp->arg_value = id;		/* id */
128 	adp->arg_object = NULL;
129 	adp->arg_type = AT_BYVAL;
130 	adp->arg_inout = AI_INPUT;
131 	adp->arg_size = 0;
132 	adp++;
133 
134 	if (opset == NULL) {
135 		adp->arg_value = 0;	/* opset */
136 		adp->arg_object = NULL;
137 		adp->arg_type = AT_BYVAL;
138 		adp->arg_inout = AI_INPUT;
139 		adp->arg_size = 0;
140 	} else {
141 		adp->arg_value = 0;
142 		adp->arg_object = opset;
143 		adp->arg_type = AT_BYREF;
144 		adp->arg_inout = AI_INOUT;
145 		adp->arg_size = sizeof (int);
146 	}
147 
148 	error = Psyscall(Pr, &rval, SYS_pset, 5, &argd[0]);
149 
150 	if (error) {
151 		errno = (error < 0)? ENOSYS : error;
152 		return (-1);
153 	}
154 	return (rval.sys_rval1);
155 }
156