xref: /titanic_51/usr/src/lib/libproc/common/pr_pbind.c (revision b3697b90e692e3e5d859fb77d285d4c056d99eda)
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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/types.h>
27 #include <sys/procset.h>
28 #include <sys/processor.h>
29 #include <sys/pset.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <errno.h>
33 #include "libproc.h"
34 
35 int
36 pr_processor_bind(struct ps_prochandle *Pr, idtype_t idtype, id_t id,
37     int processorid, int *obind)
38 {
39 	sysret_t rval;			/* return value */
40 	argdes_t argd[4];		/* arg descriptors */
41 	argdes_t *adp = &argd[0];	/* first argument */
42 	int error;
43 
44 	if (Pr == NULL)		/* no subject process */
45 		return (processor_bind(idtype, id, processorid, obind));
46 
47 	adp->arg_value = idtype;	/* idtype */
48 	adp->arg_object = NULL;
49 	adp->arg_type = AT_BYVAL;
50 	adp->arg_inout = AI_INPUT;
51 	adp->arg_size = 0;
52 	adp++;
53 
54 	adp->arg_value = id;		/* id */
55 	adp->arg_object = NULL;
56 	adp->arg_type = AT_BYVAL;
57 	adp->arg_inout = AI_INPUT;
58 	adp->arg_size = 0;
59 	adp++;
60 
61 	adp->arg_value = processorid;	/* processorid */
62 	adp->arg_object = NULL;
63 	adp->arg_type = AT_BYVAL;
64 	adp->arg_inout = AI_INPUT;
65 	adp->arg_size = 0;
66 	adp++;
67 
68 	if (obind == NULL) {
69 		adp->arg_value = 0;	/* obind */
70 		adp->arg_object = NULL;
71 		adp->arg_type = AT_BYVAL;
72 		adp->arg_inout = AI_INPUT;
73 		adp->arg_size = 0;
74 	} else {
75 		adp->arg_value = 0;
76 		adp->arg_object = obind;
77 		adp->arg_type = AT_BYREF;
78 		adp->arg_inout = AI_INOUT;
79 		adp->arg_size = sizeof (int);
80 	}
81 
82 	error = Psyscall(Pr, &rval, SYS_processor_bind, 4, &argd[0]);
83 
84 	if (error) {
85 		errno = (error < 0)? ENOSYS : error;
86 		return (-1);
87 	}
88 	return (rval.sys_rval1);
89 }
90