Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / lib / libproc / common / pr_tasksys.c
blob73edd9fe462636f4dbb8a384b6a9640495306c5e
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <sys/task.h>
28 #include <sys/types.h>
30 #include <zone.h>
31 #include <errno.h>
32 #include <project.h>
33 #include <stdlib.h>
34 #include <strings.h>
35 #include <unistd.h>
37 #include "libproc.h"
39 zoneid_t
40 pr_getzoneid(struct ps_prochandle *Pr)
42 sysret_t rval;
43 argdes_t argd[2];
44 argdes_t *adp;
45 int error;
47 if (Pr == NULL) /* no subject process */
48 return (getzoneid());
50 adp = &argd[0];
51 adp->arg_value = 6; /* switch for zone_lookup in zone */
52 adp->arg_object = NULL;
53 adp->arg_type = AT_BYVAL;
54 adp->arg_inout = AI_INPUT;
55 adp->arg_size = 0;
57 adp = &argd[1];
58 adp->arg_value = 0; /* arguement for zone_lookup in zone */
59 adp->arg_object = NULL;
60 adp->arg_type = AT_BYVAL;
61 adp->arg_inout = AI_INPUT;
62 adp->arg_size = 0;
64 error = Psyscall(Pr, &rval, SYS_zone, 2, &argd[0]);
66 if (error) {
67 errno = (error > 0) ? error : ENOSYS;
68 return (-1);
70 return (rval.sys_rval1);
73 projid_t
74 pr_getprojid(struct ps_prochandle *Pr)
76 sysret_t rval;
77 argdes_t argd[1];
78 argdes_t *adp;
79 int error;
81 if (Pr == NULL) /* no subject process */
82 return (getprojid());
84 adp = &argd[0];
85 adp->arg_value = 2; /* switch for getprojid in tasksys */
86 adp->arg_object = NULL;
87 adp->arg_type = AT_BYVAL;
88 adp->arg_inout = AI_INPUT;
89 adp->arg_size = 0;
91 error = Psyscall(Pr, &rval, SYS_tasksys, 1, &argd[0]);
93 if (error) {
94 errno = (error > 0) ? error : ENOSYS;
95 return (-1);
97 return (rval.sys_rval1);
100 taskid_t
101 pr_gettaskid(struct ps_prochandle *Pr)
103 sysret_t rval;
104 argdes_t argd[1];
105 argdes_t *adp;
106 int error;
108 if (Pr == NULL) /* no subject process */
109 return (gettaskid());
111 adp = &argd[0];
112 adp->arg_value = 1; /* switch for gettaskid in tasksys */
113 adp->arg_object = NULL;
114 adp->arg_type = AT_BYVAL;
115 adp->arg_inout = AI_INPUT;
116 adp->arg_size = 0;
118 error = Psyscall(Pr, &rval, SYS_tasksys, 1, &argd[0]);
120 if (error) {
121 errno = (error > 0) ? error : ENOSYS;
122 return (-1);
124 return (rval.sys_rval1);
127 taskid_t
128 pr_settaskid(struct ps_prochandle *Pr, projid_t project, int flags)
130 sysret_t rval;
131 argdes_t argd[3];
132 argdes_t *adp;
133 int error;
135 if (Pr == NULL) /* No subject process */
136 return (settaskid(project, flags));
138 adp = &argd[0];
139 adp->arg_value = 0; /* switch for settaskid in tasksys */
140 adp->arg_object = NULL;
141 adp->arg_type = AT_BYVAL;
142 adp->arg_inout = AI_INPUT;
143 adp->arg_size = 0;
145 adp++;
146 adp->arg_value = project;
147 adp->arg_object = NULL;
148 adp->arg_type = AT_BYVAL;
149 adp->arg_inout = AI_INPUT;
150 adp->arg_size = sizeof (project);
152 adp++;
153 adp->arg_value = flags;
154 adp->arg_object = NULL;
155 adp->arg_type = AT_BYVAL;
156 adp->arg_inout = AI_INPUT;
157 adp->arg_size = 0;
159 error = Psyscall(Pr, &rval, SYS_tasksys, 3, &argd[0]);
161 if (error) {
162 errno = (error > 0) ? error : ENOSYS;
163 return (-1);
165 return (rval.sys_rval1);