xref: /titanic_51/usr/src/lib/libproc/common/pr_getrctl.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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 (c) 2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #define	_LARGEFILE64_SOURCE
30 
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <errno.h>
34 #include <strings.h>
35 #include "libproc.h"
36 
37 /*
38  * getrctl() system call -- executed by subject process
39  */
40 int
41 pr_getrctl(struct ps_prochandle *Pr, const char *rname,
42 	rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag)
43 {
44 	sysret_t rval;
45 	argdes_t argd[6];
46 	argdes_t *adp;
47 	int error;
48 
49 	if (Pr == NULL)		/* no subject process */
50 		return (getrctl(rname, old_blk, new_blk, rflag));
51 
52 	adp = &argd[0];
53 	adp->arg_value = 0;	/* switch for getrctl in rctlsys */
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++;
60 	adp->arg_value = 0;
61 	adp->arg_object = (void *)rname;
62 	adp->arg_type = AT_BYREF;
63 	adp->arg_inout = AI_INPUT;
64 	adp->arg_size = strlen(rname) + 1;
65 
66 	adp++;
67 	if (old_blk == NULL) {
68 		adp->arg_value = 0;
69 		adp->arg_object = NULL;
70 		adp->arg_type = AT_BYVAL;
71 		adp->arg_inout = AI_INPUT;
72 		adp->arg_size = 0;
73 	} else {
74 		adp->arg_value = 0;
75 		adp->arg_object = old_blk;
76 		adp->arg_type = AT_BYREF;
77 		adp->arg_inout = AI_INPUT;
78 		adp->arg_size = rctlblk_size();
79 	}
80 
81 	adp++;
82 	if (new_blk == NULL) {
83 		adp->arg_value = 0;
84 		adp->arg_object = NULL;
85 		adp->arg_type = AT_BYVAL;
86 		adp->arg_inout = AI_OUTPUT;
87 		adp->arg_size = 0;
88 	} else {
89 		adp->arg_value = 0;
90 		adp->arg_object = new_blk;
91 		adp->arg_type = AT_BYREF;
92 		adp->arg_inout = AI_INOUT;
93 		adp->arg_size = rctlblk_size();
94 	}
95 
96 	adp++;
97 	adp->arg_value = 0;		/* obufsz isn't used by getrctl() */
98 	adp->arg_object = NULL;
99 	adp->arg_type = AT_BYVAL;
100 	adp->arg_inout = AI_INPUT;
101 	adp->arg_size = 0;
102 
103 	adp++;
104 	adp->arg_value = rflag;
105 	adp->arg_object = NULL;
106 	adp->arg_type = AT_BYVAL;
107 	adp->arg_inout = AI_INPUT;
108 	adp->arg_size = 0;
109 
110 	error = Psyscall(Pr, &rval, SYS_rctlsys, 6, &argd[0]);
111 
112 	if (error) {
113 		errno = (error > 0) ? error : ENOSYS;
114 		return (-1);
115 	}
116 	return (rval.sys_rval1);
117 }
118 
119 /*
120  * setrctl() system call -- executed by subject process
121  */
122 int
123 pr_setrctl(struct ps_prochandle *Pr, const char *rname,
124 	rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag)
125 {
126 	sysret_t rval;
127 	argdes_t argd[6];
128 	argdes_t *adp;
129 	int error;
130 
131 	if (Pr == NULL)		/* no subject process */
132 		return (setrctl(rname, old_blk, new_blk, rflag));
133 
134 	adp = &argd[0];
135 	adp->arg_value = 1;	/* switch for setrctl in rctlsys */
136 	adp->arg_object = NULL;
137 	adp->arg_type = AT_BYVAL;
138 	adp->arg_inout = AI_INPUT;
139 	adp->arg_size = 0;
140 
141 	adp++;
142 	adp->arg_value = 0;
143 	adp->arg_object = (void *)rname;
144 	adp->arg_type = AT_BYREF;
145 	adp->arg_inout = AI_INPUT;
146 	adp->arg_size = strlen(rname) + 1;
147 
148 	adp++;
149 	if (old_blk == NULL) {
150 		adp->arg_value = 0;
151 		adp->arg_object = NULL;
152 		adp->arg_type = AT_BYVAL;
153 		adp->arg_inout = AI_INPUT;
154 		adp->arg_size = 0;
155 	} else {
156 		adp->arg_value = 0;
157 		adp->arg_object = old_blk;
158 		adp->arg_type = AT_BYREF;
159 		adp->arg_inout = AI_INPUT;
160 		adp->arg_size = rctlblk_size();
161 	}
162 
163 	adp++;
164 	if (new_blk == NULL) {
165 		adp->arg_value = 0;
166 		adp->arg_object = NULL;
167 		adp->arg_type = AT_BYVAL;
168 		adp->arg_inout = AI_INPUT;
169 		adp->arg_size = 0;
170 	} else {
171 		adp->arg_value = 0;
172 		adp->arg_object = new_blk;
173 		adp->arg_type = AT_BYREF;
174 		adp->arg_inout = AI_INPUT;
175 		adp->arg_size = rctlblk_size();
176 	}
177 
178 	adp++;
179 	adp->arg_value = 0;		/* obufsz isn't used by setrctl() */
180 	adp->arg_object = NULL;
181 	adp->arg_type = AT_BYVAL;
182 	adp->arg_inout = AI_INPUT;
183 	adp->arg_size = 0;
184 
185 	adp++;
186 	adp->arg_value = rflag;
187 	adp->arg_object = NULL;
188 	adp->arg_type = AT_BYVAL;
189 	adp->arg_inout = AI_INPUT;
190 	adp->arg_size = 0;
191 
192 	error = Psyscall(Pr, &rval, SYS_rctlsys, 6, &argd[0]);
193 
194 	if (error) {
195 		errno = (error > 0) ? error : ENOSYS;
196 		return (-1);
197 	}
198 	return (rval.sys_rval1);
199 }
200