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 #define	_LARGEFILE64_SOURCE
28 
29 #include <sys/task.h>
30 #include <sys/types.h>
31 
32 #include <zone.h>
33 #include <errno.h>
34 #include <project.h>
35 #include <stdlib.h>
36 #include <strings.h>
37 #include <unistd.h>
38 
39 #include "libproc.h"
40 
41 zoneid_t
pr_getzoneid(struct ps_prochandle * Pr)42 pr_getzoneid(struct ps_prochandle *Pr)
43 {
44 	sysret_t rval;
45 	argdes_t argd[2];
46 	argdes_t *adp;
47 	int error;
48 
49 	if (Pr == NULL)		/* no subject process */
50 		return (getzoneid());
51 
52 	adp = &argd[0];
53 	adp->arg_value = 6;	/* switch for zone_lookup in zone */
54 	adp->arg_object = NULL;
55 	adp->arg_type = AT_BYVAL;
56 	adp->arg_inout = AI_INPUT;
57 	adp->arg_size = 0;
58 
59 	adp = &argd[1];
60 	adp->arg_value = 0;	/* arguement for zone_lookup in zone */
61 	adp->arg_object = NULL;
62 	adp->arg_type = AT_BYVAL;
63 	adp->arg_inout = AI_INPUT;
64 	adp->arg_size = 0;
65 
66 	error = Psyscall(Pr, &rval, SYS_zone, 2, &argd[0]);
67 
68 	if (error) {
69 		errno = (error > 0) ? error : ENOSYS;
70 		return (-1);
71 	}
72 	return (rval.sys_rval1);
73 }
74 
75 projid_t
pr_getprojid(struct ps_prochandle * Pr)76 pr_getprojid(struct ps_prochandle *Pr)
77 {
78 	sysret_t rval;
79 	argdes_t argd[1];
80 	argdes_t *adp;
81 	int error;
82 
83 	if (Pr == NULL)		/* no subject process */
84 		return (getprojid());
85 
86 	adp = &argd[0];
87 	adp->arg_value = 2;	/* switch for getprojid in tasksys */
88 	adp->arg_object = NULL;
89 	adp->arg_type = AT_BYVAL;
90 	adp->arg_inout = AI_INPUT;
91 	adp->arg_size = 0;
92 
93 	error = Psyscall(Pr, &rval, SYS_tasksys, 1, &argd[0]);
94 
95 	if (error) {
96 		errno = (error > 0) ? error : ENOSYS;
97 		return (-1);
98 	}
99 	return (rval.sys_rval1);
100 }
101 
102 taskid_t
pr_gettaskid(struct ps_prochandle * Pr)103 pr_gettaskid(struct ps_prochandle *Pr)
104 {
105 	sysret_t rval;
106 	argdes_t argd[1];
107 	argdes_t *adp;
108 	int error;
109 
110 	if (Pr == NULL)		/* no subject process */
111 		return (gettaskid());
112 
113 	adp = &argd[0];
114 	adp->arg_value = 1;	/* switch for gettaskid in tasksys */
115 	adp->arg_object = NULL;
116 	adp->arg_type = AT_BYVAL;
117 	adp->arg_inout = AI_INPUT;
118 	adp->arg_size = 0;
119 
120 	error = Psyscall(Pr, &rval, SYS_tasksys, 1, &argd[0]);
121 
122 	if (error) {
123 		errno = (error > 0) ? error : ENOSYS;
124 		return (-1);
125 	}
126 	return (rval.sys_rval1);
127 }
128 
129 taskid_t
pr_settaskid(struct ps_prochandle * Pr,projid_t project,int flags)130 pr_settaskid(struct ps_prochandle *Pr, projid_t project, int flags)
131 {
132 	sysret_t rval;
133 	argdes_t argd[3];
134 	argdes_t *adp;
135 	int error;
136 
137 	if (Pr == NULL)		/* No subject process */
138 		return (settaskid(project, flags));
139 
140 	adp = &argd[0];
141 	adp->arg_value = 0;	/* switch for settaskid in tasksys */
142 	adp->arg_object = NULL;
143 	adp->arg_type = AT_BYVAL;
144 	adp->arg_inout = AI_INPUT;
145 	adp->arg_size = 0;
146 
147 	adp++;
148 	adp->arg_value = project;
149 	adp->arg_object = NULL;
150 	adp->arg_type = AT_BYVAL;
151 	adp->arg_inout = AI_INPUT;
152 	adp->arg_size = sizeof (project);
153 
154 	adp++;
155 	adp->arg_value = flags;
156 	adp->arg_object = NULL;
157 	adp->arg_type = AT_BYVAL;
158 	adp->arg_inout = AI_INPUT;
159 	adp->arg_size = 0;
160 
161 	error = Psyscall(Pr, &rval, SYS_tasksys, 3, &argd[0]);
162 
163 	if (error) {
164 		errno = (error > 0) ? error : ENOSYS;
165 		return (-1);
166 	}
167 	return (rval.sys_rval1);
168 }
169