xref: /onnv-gate/usr/src/lib/libc/port/gen/rctlops.c (revision 1219:f89f56c2d9ac)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*1219Sraf 
230Sstevel@tonic-gate /*
24*1219Sraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate 
30*1219Sraf #include "synonyms.h"
310Sstevel@tonic-gate #include <sys/rctl_impl.h>
320Sstevel@tonic-gate #include <stdlib.h>
330Sstevel@tonic-gate #include <string.h>
340Sstevel@tonic-gate #include <rctl.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * Resource control routines
380Sstevel@tonic-gate  *
390Sstevel@tonic-gate  * rctl_walk(3C)
400Sstevel@tonic-gate  *
410Sstevel@tonic-gate  * Resource control block manipulation routines
420Sstevel@tonic-gate  *   The setrctl(2) and getrctl(2) interfaces are accessed via opaque resource
430Sstevel@tonic-gate  *   control blocks, the characteristics of which are in turn set and fetched
440Sstevel@tonic-gate  *   using the following functions.  Applications using the following interfaces
450Sstevel@tonic-gate  *   will be binary compatible across enhancements to the resource control
460Sstevel@tonic-gate  *   subsystem that involve modification of the control block.
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate int
490Sstevel@tonic-gate rctl_walk(int (*callback)(const char *rctlname, void *walk_data),
500Sstevel@tonic-gate     void *init_data)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate 	int ret = 0;
530Sstevel@tonic-gate 	char *ctl_names, *curr_name;
540Sstevel@tonic-gate 	size_t sz = rctllist(NULL, 0);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	if ((ctl_names = malloc(sz)) == NULL)
570Sstevel@tonic-gate 		return (-1);
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	(void) rctllist(ctl_names, sz);
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 	for (curr_name = ctl_names;
620Sstevel@tonic-gate 	    curr_name < ctl_names + sz;
630Sstevel@tonic-gate 	    curr_name += strlen(curr_name) + 1) {
640Sstevel@tonic-gate 		if (ret = callback(curr_name, init_data)) {
650Sstevel@tonic-gate 			free(ctl_names);
660Sstevel@tonic-gate 			return (ret);
670Sstevel@tonic-gate 		}
680Sstevel@tonic-gate 	}
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	free(ctl_names);
710Sstevel@tonic-gate 	return (ret);
720Sstevel@tonic-gate }
730Sstevel@tonic-gate 
740Sstevel@tonic-gate uint_t
750Sstevel@tonic-gate rctlblk_get_global_action(rctlblk_t *rblk)
760Sstevel@tonic-gate {
770Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	return (ropaque->rcq_global_flagaction & (~RCTL_GLOBAL_ACTION_MASK));
800Sstevel@tonic-gate }
810Sstevel@tonic-gate 
820Sstevel@tonic-gate uint_t
830Sstevel@tonic-gate rctlblk_get_local_action(rctlblk_t *rblk, int *signal)
840Sstevel@tonic-gate {
850Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	if (signal != NULL)
880Sstevel@tonic-gate 		*signal = ropaque->rcq_local_signal;
890Sstevel@tonic-gate 	return (ropaque->rcq_local_flagaction & (~RCTL_LOCAL_ACTION_MASK));
900Sstevel@tonic-gate }
910Sstevel@tonic-gate 
920Sstevel@tonic-gate uint_t
930Sstevel@tonic-gate rctlblk_get_global_flags(rctlblk_t *rblk)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	return (ropaque->rcq_global_flagaction & RCTL_GLOBAL_ACTION_MASK);
980Sstevel@tonic-gate }
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate uint_t
1010Sstevel@tonic-gate rctlblk_get_local_flags(rctlblk_t *rblk)
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	return (ropaque->rcq_local_flagaction & RCTL_LOCAL_ACTION_MASK);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate hrtime_t
1090Sstevel@tonic-gate rctlblk_get_firing_time(rctlblk_t *rblk)
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	return (ropaque->rcq_firing_time);
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate id_t
1170Sstevel@tonic-gate rctlblk_get_recipient_pid(rctlblk_t *rblk)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	return (ropaque->rcq_local_recipient_pid);
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate rctl_priv_t
1250Sstevel@tonic-gate rctlblk_get_privilege(rctlblk_t *rblk)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1280Sstevel@tonic-gate 	return (ropaque->rcq_privilege);
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate rctl_qty_t
1320Sstevel@tonic-gate rctlblk_get_value(rctlblk_t *rblk)
1330Sstevel@tonic-gate {
1340Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1350Sstevel@tonic-gate 	return (ropaque->rcq_value);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate rctl_qty_t
1390Sstevel@tonic-gate rctlblk_get_enforced_value(rctlblk_t *rblk)
1400Sstevel@tonic-gate {
1410Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1420Sstevel@tonic-gate 	return (ropaque->rcq_enforced_value);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate void
1460Sstevel@tonic-gate rctlblk_set_local_action(rctlblk_t *rblk, uint_t action, int signal)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1490Sstevel@tonic-gate 	ropaque->rcq_local_signal = signal;
1500Sstevel@tonic-gate 	ropaque->rcq_local_flagaction = (ropaque->rcq_local_flagaction &
1510Sstevel@tonic-gate 	    RCTL_LOCAL_ACTION_MASK) | (action & ~RCTL_LOCAL_ACTION_MASK);
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate void
1550Sstevel@tonic-gate rctlblk_set_local_flags(rctlblk_t *rblk, uint_t flags)
1560Sstevel@tonic-gate {
1570Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1580Sstevel@tonic-gate 	ropaque->rcq_local_flagaction = (ropaque->rcq_local_flagaction &
1590Sstevel@tonic-gate 	    ~RCTL_LOCAL_ACTION_MASK) | (flags & RCTL_LOCAL_ACTION_MASK);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate void
1630Sstevel@tonic-gate rctlblk_set_recipient_pid(rctlblk_t *rblk, id_t pid)
1640Sstevel@tonic-gate {
1650Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1660Sstevel@tonic-gate 	ropaque->rcq_local_recipient_pid = pid;
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate void
1700Sstevel@tonic-gate rctlblk_set_privilege(rctlblk_t *rblk, rctl_priv_t privilege)
1710Sstevel@tonic-gate {
1720Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1730Sstevel@tonic-gate 	ropaque->rcq_privilege = privilege;
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate void
1770Sstevel@tonic-gate rctlblk_set_value(rctlblk_t *rblk, rctl_qty_t value)
1780Sstevel@tonic-gate {
1790Sstevel@tonic-gate 	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
1800Sstevel@tonic-gate 	ropaque->rcq_value = value;
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate size_t
1840Sstevel@tonic-gate rctlblk_size(void)
1850Sstevel@tonic-gate {
1860Sstevel@tonic-gate 	return (sizeof (rctl_opaque_t));
1870Sstevel@tonic-gate }
188