xref: /onnv-gate/usr/src/lib/libproc/common/pr_getrctl.c (revision 3684:a0773f73b68d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3684Srd117015  * Common Development and Distribution License (the "License").
6*3684Srd117015  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*3684Srd117015  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*3684Srd117015  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #define	_LARGEFILE64_SOURCE
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <stdlib.h>
310Sstevel@tonic-gate #include <unistd.h>
320Sstevel@tonic-gate #include <errno.h>
330Sstevel@tonic-gate #include <strings.h>
340Sstevel@tonic-gate #include "libproc.h"
35*3684Srd117015 #include <sys/rctl_impl.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate  * getrctl() system call -- executed by subject process
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate int
pr_getrctl(struct ps_prochandle * Pr,const char * rname,rctlblk_t * old_blk,rctlblk_t * new_blk,int rflag)410Sstevel@tonic-gate pr_getrctl(struct ps_prochandle *Pr, const char *rname,
420Sstevel@tonic-gate 	rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate 	sysret_t rval;
450Sstevel@tonic-gate 	argdes_t argd[6];
460Sstevel@tonic-gate 	argdes_t *adp;
470Sstevel@tonic-gate 	int error;
480Sstevel@tonic-gate 
490Sstevel@tonic-gate 	if (Pr == NULL)		/* no subject process */
500Sstevel@tonic-gate 		return (getrctl(rname, old_blk, new_blk, rflag));
510Sstevel@tonic-gate 
520Sstevel@tonic-gate 	adp = &argd[0];
530Sstevel@tonic-gate 	adp->arg_value = 0;	/* switch for getrctl in rctlsys */
540Sstevel@tonic-gate 	adp->arg_object = NULL;
550Sstevel@tonic-gate 	adp->arg_type = AT_BYVAL;
560Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
570Sstevel@tonic-gate 	adp->arg_size = 0;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	adp++;
600Sstevel@tonic-gate 	adp->arg_value = 0;
610Sstevel@tonic-gate 	adp->arg_object = (void *)rname;
620Sstevel@tonic-gate 	adp->arg_type = AT_BYREF;
630Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
640Sstevel@tonic-gate 	adp->arg_size = strlen(rname) + 1;
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 	adp++;
670Sstevel@tonic-gate 	if (old_blk == NULL) {
680Sstevel@tonic-gate 		adp->arg_value = 0;
690Sstevel@tonic-gate 		adp->arg_object = NULL;
700Sstevel@tonic-gate 		adp->arg_type = AT_BYVAL;
710Sstevel@tonic-gate 		adp->arg_inout = AI_INPUT;
720Sstevel@tonic-gate 		adp->arg_size = 0;
730Sstevel@tonic-gate 	} else {
740Sstevel@tonic-gate 		adp->arg_value = 0;
750Sstevel@tonic-gate 		adp->arg_object = old_blk;
760Sstevel@tonic-gate 		adp->arg_type = AT_BYREF;
770Sstevel@tonic-gate 		adp->arg_inout = AI_INPUT;
780Sstevel@tonic-gate 		adp->arg_size = rctlblk_size();
790Sstevel@tonic-gate 	}
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	adp++;
820Sstevel@tonic-gate 	if (new_blk == NULL) {
830Sstevel@tonic-gate 		adp->arg_value = 0;
840Sstevel@tonic-gate 		adp->arg_object = NULL;
850Sstevel@tonic-gate 		adp->arg_type = AT_BYVAL;
860Sstevel@tonic-gate 		adp->arg_inout = AI_OUTPUT;
870Sstevel@tonic-gate 		adp->arg_size = 0;
880Sstevel@tonic-gate 	} else {
890Sstevel@tonic-gate 		adp->arg_value = 0;
900Sstevel@tonic-gate 		adp->arg_object = new_blk;
910Sstevel@tonic-gate 		adp->arg_type = AT_BYREF;
920Sstevel@tonic-gate 		adp->arg_inout = AI_INOUT;
930Sstevel@tonic-gate 		adp->arg_size = rctlblk_size();
940Sstevel@tonic-gate 	}
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	adp++;
970Sstevel@tonic-gate 	adp->arg_value = 0;		/* obufsz isn't used by getrctl() */
980Sstevel@tonic-gate 	adp->arg_object = NULL;
990Sstevel@tonic-gate 	adp->arg_type = AT_BYVAL;
1000Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
1010Sstevel@tonic-gate 	adp->arg_size = 0;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	adp++;
1040Sstevel@tonic-gate 	adp->arg_value = rflag;
1050Sstevel@tonic-gate 	adp->arg_object = NULL;
1060Sstevel@tonic-gate 	adp->arg_type = AT_BYVAL;
1070Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
1080Sstevel@tonic-gate 	adp->arg_size = 0;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	error = Psyscall(Pr, &rval, SYS_rctlsys, 6, &argd[0]);
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	if (error) {
1130Sstevel@tonic-gate 		errno = (error > 0) ? error : ENOSYS;
1140Sstevel@tonic-gate 		return (-1);
1150Sstevel@tonic-gate 	}
1160Sstevel@tonic-gate 	return (rval.sys_rval1);
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate  * setrctl() system call -- executed by subject process
1210Sstevel@tonic-gate  */
1220Sstevel@tonic-gate int
pr_setrctl(struct ps_prochandle * Pr,const char * rname,rctlblk_t * old_blk,rctlblk_t * new_blk,int rflag)1230Sstevel@tonic-gate pr_setrctl(struct ps_prochandle *Pr, const char *rname,
1240Sstevel@tonic-gate 	rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag)
1250Sstevel@tonic-gate {
1260Sstevel@tonic-gate 	sysret_t rval;
1270Sstevel@tonic-gate 	argdes_t argd[6];
1280Sstevel@tonic-gate 	argdes_t *adp;
1290Sstevel@tonic-gate 	int error;
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	if (Pr == NULL)		/* no subject process */
1320Sstevel@tonic-gate 		return (setrctl(rname, old_blk, new_blk, rflag));
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	adp = &argd[0];
1350Sstevel@tonic-gate 	adp->arg_value = 1;	/* switch for setrctl in rctlsys */
1360Sstevel@tonic-gate 	adp->arg_object = NULL;
1370Sstevel@tonic-gate 	adp->arg_type = AT_BYVAL;
1380Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
1390Sstevel@tonic-gate 	adp->arg_size = 0;
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	adp++;
1420Sstevel@tonic-gate 	adp->arg_value = 0;
1430Sstevel@tonic-gate 	adp->arg_object = (void *)rname;
1440Sstevel@tonic-gate 	adp->arg_type = AT_BYREF;
1450Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
1460Sstevel@tonic-gate 	adp->arg_size = strlen(rname) + 1;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 	adp++;
1490Sstevel@tonic-gate 	if (old_blk == NULL) {
1500Sstevel@tonic-gate 		adp->arg_value = 0;
1510Sstevel@tonic-gate 		adp->arg_object = NULL;
1520Sstevel@tonic-gate 		adp->arg_type = AT_BYVAL;
1530Sstevel@tonic-gate 		adp->arg_inout = AI_INPUT;
1540Sstevel@tonic-gate 		adp->arg_size = 0;
1550Sstevel@tonic-gate 	} else {
1560Sstevel@tonic-gate 		adp->arg_value = 0;
1570Sstevel@tonic-gate 		adp->arg_object = old_blk;
1580Sstevel@tonic-gate 		adp->arg_type = AT_BYREF;
1590Sstevel@tonic-gate 		adp->arg_inout = AI_INPUT;
1600Sstevel@tonic-gate 		adp->arg_size = rctlblk_size();
1610Sstevel@tonic-gate 	}
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	adp++;
1640Sstevel@tonic-gate 	if (new_blk == NULL) {
1650Sstevel@tonic-gate 		adp->arg_value = 0;
1660Sstevel@tonic-gate 		adp->arg_object = NULL;
1670Sstevel@tonic-gate 		adp->arg_type = AT_BYVAL;
1680Sstevel@tonic-gate 		adp->arg_inout = AI_INPUT;
1690Sstevel@tonic-gate 		adp->arg_size = 0;
1700Sstevel@tonic-gate 	} else {
1710Sstevel@tonic-gate 		adp->arg_value = 0;
1720Sstevel@tonic-gate 		adp->arg_object = new_blk;
1730Sstevel@tonic-gate 		adp->arg_type = AT_BYREF;
1740Sstevel@tonic-gate 		adp->arg_inout = AI_INPUT;
1750Sstevel@tonic-gate 		adp->arg_size = rctlblk_size();
1760Sstevel@tonic-gate 	}
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	adp++;
1790Sstevel@tonic-gate 	adp->arg_value = 0;		/* obufsz isn't used by setrctl() */
1800Sstevel@tonic-gate 	adp->arg_object = NULL;
1810Sstevel@tonic-gate 	adp->arg_type = AT_BYVAL;
1820Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
1830Sstevel@tonic-gate 	adp->arg_size = 0;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	adp++;
1860Sstevel@tonic-gate 	adp->arg_value = rflag;
1870Sstevel@tonic-gate 	adp->arg_object = NULL;
1880Sstevel@tonic-gate 	adp->arg_type = AT_BYVAL;
1890Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
1900Sstevel@tonic-gate 	adp->arg_size = 0;
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 	error = Psyscall(Pr, &rval, SYS_rctlsys, 6, &argd[0]);
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 	if (error) {
1950Sstevel@tonic-gate 		errno = (error > 0) ? error : ENOSYS;
1960Sstevel@tonic-gate 		return (-1);
1970Sstevel@tonic-gate 	}
1980Sstevel@tonic-gate 	return (rval.sys_rval1);
1990Sstevel@tonic-gate }
200*3684Srd117015 
201*3684Srd117015 /*
202*3684Srd117015  * setprojrctl() system call -- executed by subject process
203*3684Srd117015  */
204*3684Srd117015 int
pr_setprojrctl(struct ps_prochandle * Pr,const char * rname,rctlblk_t * new_blk,size_t size,int rflag)205*3684Srd117015 pr_setprojrctl(struct ps_prochandle *Pr, const char *rname,
206*3684Srd117015 	rctlblk_t *new_blk, size_t size, int rflag)
207*3684Srd117015 {
208*3684Srd117015 	sysret_t rval;
209*3684Srd117015 	argdes_t argd[6];
210*3684Srd117015 	argdes_t *adp;
211*3684Srd117015 	int error;
212*3684Srd117015 
213*3684Srd117015 	if (Pr == NULL)		/* no subject process */
214*3684Srd117015 		return (setprojrctl(rname, new_blk, size, rflag));
215*3684Srd117015 
216*3684Srd117015 	adp = &argd[0];
217*3684Srd117015 	adp->arg_value = 4;	/* switch for setprojrctls in rctlsys */
218*3684Srd117015 	adp->arg_object = NULL;
219*3684Srd117015 	adp->arg_type = AT_BYVAL;
220*3684Srd117015 	adp->arg_inout = AI_INPUT;
221*3684Srd117015 	adp->arg_size = 0;
222*3684Srd117015 
223*3684Srd117015 	adp++;
224*3684Srd117015 	adp->arg_value = 0;
225*3684Srd117015 	adp->arg_object = (void *)rname;
226*3684Srd117015 	adp->arg_type = AT_BYREF;
227*3684Srd117015 	adp->arg_inout = AI_INPUT;
228*3684Srd117015 	adp->arg_size = strlen(rname) + 1;
229*3684Srd117015 
230*3684Srd117015 	adp++;
231*3684Srd117015 	adp->arg_value = 0;	/* old_blk is not used by setprojrctls() */
232*3684Srd117015 	adp->arg_object = NULL;
233*3684Srd117015 	adp->arg_type = AT_BYVAL;
234*3684Srd117015 	adp->arg_inout = AI_INPUT;
235*3684Srd117015 	adp->arg_size = 0;
236*3684Srd117015 
237*3684Srd117015 
238*3684Srd117015 	adp++;
239*3684Srd117015 	if (new_blk == NULL) {
240*3684Srd117015 		adp->arg_value = 0;
241*3684Srd117015 		adp->arg_object = NULL;
242*3684Srd117015 		adp->arg_type = AT_BYVAL;
243*3684Srd117015 		adp->arg_inout = AI_INPUT;
244*3684Srd117015 		adp->arg_size = 0;
245*3684Srd117015 	} else {
246*3684Srd117015 		adp->arg_value = 0;
247*3684Srd117015 		adp->arg_object = new_blk;
248*3684Srd117015 		adp->arg_type = AT_BYREF;
249*3684Srd117015 		adp->arg_inout = AI_INPUT;
250*3684Srd117015 		adp->arg_size = rctlblk_size() * size;
251*3684Srd117015 	}
252*3684Srd117015 
253*3684Srd117015 	adp++;
254*3684Srd117015 	adp->arg_value = size;		/* obufsz is used by setrctls() */
255*3684Srd117015 	adp->arg_object = NULL;
256*3684Srd117015 	adp->arg_type = AT_BYVAL;
257*3684Srd117015 	adp->arg_inout = AI_INPUT;
258*3684Srd117015 	adp->arg_size = 0;
259*3684Srd117015 
260*3684Srd117015 	adp++;
261*3684Srd117015 	adp->arg_value = rflag;
262*3684Srd117015 	adp->arg_object = NULL;
263*3684Srd117015 	adp->arg_type = AT_BYVAL;
264*3684Srd117015 	adp->arg_inout = AI_INPUT;
265*3684Srd117015 	adp->arg_size = 0;
266*3684Srd117015 
267*3684Srd117015 	error = Psyscall(Pr, &rval, SYS_rctlsys, 6, &argd[0]);
268*3684Srd117015 
269*3684Srd117015 	if (error) {
270*3684Srd117015 		errno = (error > 0) ? error : ENOSYS;
271*3684Srd117015 		return (-1);
272*3684Srd117015 	}
273*3684Srd117015 	return (rval.sys_rval1);
274*3684Srd117015 }
275