xref: /onnv-gate/usr/src/lib/libc/port/gen/rctlops.c (revision 6812:febeba71273d)
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*6812Sraf  * Common Development and Distribution License (the "License").
6*6812Sraf  * 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  */
211219Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
29*6812Sraf #include "lint.h"
300Sstevel@tonic-gate #include <sys/rctl_impl.h>
310Sstevel@tonic-gate #include <stdlib.h>
320Sstevel@tonic-gate #include <string.h>
330Sstevel@tonic-gate #include <rctl.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * Resource control routines
370Sstevel@tonic-gate  *
380Sstevel@tonic-gate  * rctl_walk(3C)
390Sstevel@tonic-gate  *
400Sstevel@tonic-gate  * Resource control block manipulation routines
410Sstevel@tonic-gate  *   The setrctl(2) and getrctl(2) interfaces are accessed via opaque resource
420Sstevel@tonic-gate  *   control blocks, the characteristics of which are in turn set and fetched
430Sstevel@tonic-gate  *   using the following functions.  Applications using the following interfaces
440Sstevel@tonic-gate  *   will be binary compatible across enhancements to the resource control
450Sstevel@tonic-gate  *   subsystem that involve modification of the control block.
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate int
rctl_walk(int (* callback)(const char * rctlname,void * walk_data),void * init_data)480Sstevel@tonic-gate rctl_walk(int (*callback)(const char *rctlname, void *walk_data),
490Sstevel@tonic-gate     void *init_data)
500Sstevel@tonic-gate {
510Sstevel@tonic-gate 	int ret = 0;
520Sstevel@tonic-gate 	char *ctl_names, *curr_name;
530Sstevel@tonic-gate 	size_t sz = rctllist(NULL, 0);
540Sstevel@tonic-gate 
550Sstevel@tonic-gate 	if ((ctl_names = malloc(sz)) == NULL)
560Sstevel@tonic-gate 		return (-1);
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	(void) rctllist(ctl_names, sz);
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	for (curr_name = ctl_names;
610Sstevel@tonic-gate 	    curr_name < ctl_names + sz;
620Sstevel@tonic-gate 	    curr_name += strlen(curr_name) + 1) {
630Sstevel@tonic-gate 		if (ret = callback(curr_name, init_data)) {
640Sstevel@tonic-gate 			free(ctl_names);
650Sstevel@tonic-gate 			return (ret);
660Sstevel@tonic-gate 		}
670Sstevel@tonic-gate 	}
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	free(ctl_names);
700Sstevel@tonic-gate 	return (ret);
710Sstevel@tonic-gate }
720Sstevel@tonic-gate 
730Sstevel@tonic-gate uint_t
rctlblk_get_global_action(rctlblk_t * rblk)740Sstevel@tonic-gate rctlblk_get_global_action(rctlblk_t *rblk)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	return (ropaque->rcq_global_flagaction & (~RCTL_GLOBAL_ACTION_MASK));
790Sstevel@tonic-gate }
800Sstevel@tonic-gate 
810Sstevel@tonic-gate uint_t
rctlblk_get_local_action(rctlblk_t * rblk,int * signal)820Sstevel@tonic-gate rctlblk_get_local_action(rctlblk_t *rblk, int *signal)
830Sstevel@tonic-gate {
840Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 	if (signal != NULL)
870Sstevel@tonic-gate 		*signal = ropaque->rcq_local_signal;
880Sstevel@tonic-gate 	return (ropaque->rcq_local_flagaction & (~RCTL_LOCAL_ACTION_MASK));
890Sstevel@tonic-gate }
900Sstevel@tonic-gate 
910Sstevel@tonic-gate uint_t
rctlblk_get_global_flags(rctlblk_t * rblk)920Sstevel@tonic-gate rctlblk_get_global_flags(rctlblk_t *rblk)
930Sstevel@tonic-gate {
940Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	return (ropaque->rcq_global_flagaction & RCTL_GLOBAL_ACTION_MASK);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate 
990Sstevel@tonic-gate uint_t
rctlblk_get_local_flags(rctlblk_t * rblk)1000Sstevel@tonic-gate rctlblk_get_local_flags(rctlblk_t *rblk)
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	return (ropaque->rcq_local_flagaction & RCTL_LOCAL_ACTION_MASK);
1050Sstevel@tonic-gate }
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate hrtime_t
rctlblk_get_firing_time(rctlblk_t * rblk)1080Sstevel@tonic-gate rctlblk_get_firing_time(rctlblk_t *rblk)
1090Sstevel@tonic-gate {
1100Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	return (ropaque->rcq_firing_time);
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate id_t
rctlblk_get_recipient_pid(rctlblk_t * rblk)1160Sstevel@tonic-gate rctlblk_get_recipient_pid(rctlblk_t *rblk)
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	return (ropaque->rcq_local_recipient_pid);
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate rctl_priv_t
rctlblk_get_privilege(rctlblk_t * rblk)1240Sstevel@tonic-gate rctlblk_get_privilege(rctlblk_t *rblk)
1250Sstevel@tonic-gate {
1260Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1270Sstevel@tonic-gate 	return (ropaque->rcq_privilege);
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate rctl_qty_t
rctlblk_get_value(rctlblk_t * rblk)1310Sstevel@tonic-gate rctlblk_get_value(rctlblk_t *rblk)
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1340Sstevel@tonic-gate 	return (ropaque->rcq_value);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate rctl_qty_t
rctlblk_get_enforced_value(rctlblk_t * rblk)1380Sstevel@tonic-gate rctlblk_get_enforced_value(rctlblk_t *rblk)
1390Sstevel@tonic-gate {
1400Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1410Sstevel@tonic-gate 	return (ropaque->rcq_enforced_value);
1420Sstevel@tonic-gate }
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate void
rctlblk_set_local_action(rctlblk_t * rblk,uint_t action,int signal)1450Sstevel@tonic-gate rctlblk_set_local_action(rctlblk_t *rblk, uint_t action, int signal)
1460Sstevel@tonic-gate {
1470Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1480Sstevel@tonic-gate 	ropaque->rcq_local_signal = signal;
1490Sstevel@tonic-gate 	ropaque->rcq_local_flagaction = (ropaque->rcq_local_flagaction &
1500Sstevel@tonic-gate 	    RCTL_LOCAL_ACTION_MASK) | (action & ~RCTL_LOCAL_ACTION_MASK);
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate void
rctlblk_set_local_flags(rctlblk_t * rblk,uint_t flags)1540Sstevel@tonic-gate rctlblk_set_local_flags(rctlblk_t *rblk, uint_t flags)
1550Sstevel@tonic-gate {
1560Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1570Sstevel@tonic-gate 	ropaque->rcq_local_flagaction = (ropaque->rcq_local_flagaction &
1580Sstevel@tonic-gate 	    ~RCTL_LOCAL_ACTION_MASK) | (flags & RCTL_LOCAL_ACTION_MASK);
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate void
rctlblk_set_recipient_pid(rctlblk_t * rblk,id_t pid)1620Sstevel@tonic-gate rctlblk_set_recipient_pid(rctlblk_t *rblk, id_t pid)
1630Sstevel@tonic-gate {
1640Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1650Sstevel@tonic-gate 	ropaque->rcq_local_recipient_pid = pid;
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate void
rctlblk_set_privilege(rctlblk_t * rblk,rctl_priv_t privilege)1690Sstevel@tonic-gate rctlblk_set_privilege(rctlblk_t *rblk, rctl_priv_t privilege)
1700Sstevel@tonic-gate {
1710Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1720Sstevel@tonic-gate 	ropaque->rcq_privilege = privilege;
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate void
rctlblk_set_value(rctlblk_t * rblk,rctl_qty_t value)1760Sstevel@tonic-gate rctlblk_set_value(rctlblk_t *rblk, rctl_qty_t value)
1770Sstevel@tonic-gate {
1780Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1790Sstevel@tonic-gate 	ropaque->rcq_value = value;
1800Sstevel@tonic-gate }
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate size_t
rctlblk_size(void)1830Sstevel@tonic-gate rctlblk_size(void)
1840Sstevel@tonic-gate {
1850Sstevel@tonic-gate 	return (sizeof (rctl_opaque_t));
1860Sstevel@tonic-gate }
187