4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <sys/rctl_impl.h>
36 * Resource control routines
40 * Resource control block manipulation routines
41 * The setrctl(2) and getrctl(2) interfaces are accessed via opaque resource
42 * control blocks, the characteristics of which are in turn set and fetched
43 * using the following functions. Applications using the following interfaces
44 * will be binary compatible across enhancements to the resource control
45 * subsystem that involve modification of the control block.
48 rctl_walk(int (*callback
)(const char *rctlname
, void *walk_data
),
52 char *ctl_names
, *curr_name
;
53 size_t sz
= rctllist(NULL
, 0);
55 if ((ctl_names
= malloc(sz
)) == NULL
)
58 (void) rctllist(ctl_names
, sz
);
60 for (curr_name
= ctl_names
;
61 curr_name
< ctl_names
+ sz
;
62 curr_name
+= strlen(curr_name
) + 1) {
63 if (ret
= callback(curr_name
, init_data
)) {
74 rctlblk_get_global_action(rctlblk_t
*rblk
)
76 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
78 return (ropaque
->rcq_global_flagaction
& (~RCTL_GLOBAL_ACTION_MASK
));
82 rctlblk_get_local_action(rctlblk_t
*rblk
, int *signal
)
84 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
87 *signal
= ropaque
->rcq_local_signal
;
88 return (ropaque
->rcq_local_flagaction
& (~RCTL_LOCAL_ACTION_MASK
));
92 rctlblk_get_global_flags(rctlblk_t
*rblk
)
94 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
96 return (ropaque
->rcq_global_flagaction
& RCTL_GLOBAL_ACTION_MASK
);
100 rctlblk_get_local_flags(rctlblk_t
*rblk
)
102 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
104 return (ropaque
->rcq_local_flagaction
& RCTL_LOCAL_ACTION_MASK
);
108 rctlblk_get_firing_time(rctlblk_t
*rblk
)
110 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
112 return (ropaque
->rcq_firing_time
);
116 rctlblk_get_recipient_pid(rctlblk_t
*rblk
)
118 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
120 return (ropaque
->rcq_local_recipient_pid
);
124 rctlblk_get_privilege(rctlblk_t
*rblk
)
126 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
127 return (ropaque
->rcq_privilege
);
131 rctlblk_get_value(rctlblk_t
*rblk
)
133 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
134 return (ropaque
->rcq_value
);
138 rctlblk_get_enforced_value(rctlblk_t
*rblk
)
140 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
141 return (ropaque
->rcq_enforced_value
);
145 rctlblk_set_local_action(rctlblk_t
*rblk
, uint_t action
, int signal
)
147 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
148 ropaque
->rcq_local_signal
= signal
;
149 ropaque
->rcq_local_flagaction
= (ropaque
->rcq_local_flagaction
&
150 RCTL_LOCAL_ACTION_MASK
) | (action
& ~RCTL_LOCAL_ACTION_MASK
);
154 rctlblk_set_local_flags(rctlblk_t
*rblk
, uint_t flags
)
156 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
157 ropaque
->rcq_local_flagaction
= (ropaque
->rcq_local_flagaction
&
158 ~RCTL_LOCAL_ACTION_MASK
) | (flags
& RCTL_LOCAL_ACTION_MASK
);
162 rctlblk_set_recipient_pid(rctlblk_t
*rblk
, id_t pid
)
164 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
165 ropaque
->rcq_local_recipient_pid
= pid
;
169 rctlblk_set_privilege(rctlblk_t
*rblk
, rctl_priv_t privilege
)
171 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
172 ropaque
->rcq_privilege
= privilege
;
176 rctlblk_set_value(rctlblk_t
*rblk
, rctl_qty_t value
)
178 rctl_opaque_t
*ropaque
= (rctl_opaque_t
*)rblk
;
179 ropaque
->rcq_value
= value
;
185 return (sizeof (rctl_opaque_t
));