summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc/port/gen/rctlops.c
blob: 21e5133c18fd9fa6678b17148da5238fca21a364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include "lint.h"
#include <sys/rctl_impl.h>
#include <stdlib.h>
#include <string.h>
#include <rctl.h>

/*
 * Resource control routines
 *
 * rctl_walk(3C)
 *
 * Resource control block manipulation routines
 *   The setrctl(2) and getrctl(2) interfaces are accessed via opaque resource
 *   control blocks, the characteristics of which are in turn set and fetched
 *   using the following functions.  Applications using the following interfaces
 *   will be binary compatible across enhancements to the resource control
 *   subsystem that involve modification of the control block.
 */
int
rctl_walk(int (*callback)(const char *rctlname, void *walk_data),
    void *init_data)
{
	int ret = 0;
	char *ctl_names, *curr_name;
	size_t sz = rctllist(NULL, 0);

	if ((ctl_names = malloc(sz)) == NULL)
		return (-1);

	(void) rctllist(ctl_names, sz);

	for (curr_name = ctl_names;
	    curr_name < ctl_names + sz;
	    curr_name += strlen(curr_name) + 1) {
		ret = callback(curr_name, init_data);
		if (ret != 0) {
			free(ctl_names);
			return (ret);
		}
	}

	free(ctl_names);
	return (ret);
}

uint_t
rctlblk_get_global_action(rctlblk_t *rblk)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;

	return (ropaque->rcq_global_flagaction & (~RCTL_GLOBAL_ACTION_MASK));
}

uint_t
rctlblk_get_local_action(rctlblk_t *rblk, int *signal)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;

	if (signal != NULL)
		*signal = ropaque->rcq_local_signal;
	return (ropaque->rcq_local_flagaction & (~RCTL_LOCAL_ACTION_MASK));
}

uint_t
rctlblk_get_global_flags(rctlblk_t *rblk)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;

	return (ropaque->rcq_global_flagaction & RCTL_GLOBAL_ACTION_MASK);
}

uint_t
rctlblk_get_local_flags(rctlblk_t *rblk)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;

	return (ropaque->rcq_local_flagaction & RCTL_LOCAL_ACTION_MASK);
}

hrtime_t
rctlblk_get_firing_time(rctlblk_t *rblk)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;

	return (ropaque->rcq_firing_time);
}

id_t
rctlblk_get_recipient_pid(rctlblk_t *rblk)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;

	return (ropaque->rcq_local_recipient_pid);
}

rctl_priv_t
rctlblk_get_privilege(rctlblk_t *rblk)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
	return (ropaque->rcq_privilege);
}

rctl_qty_t
rctlblk_get_value(rctlblk_t *rblk)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
	return (ropaque->rcq_value);
}

rctl_qty_t
rctlblk_get_enforced_value(rctlblk_t *rblk)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
	return (ropaque->rcq_enforced_value);
}

void
rctlblk_set_local_action(rctlblk_t *rblk, uint_t action, int signal)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
	ropaque->rcq_local_signal = signal;
	ropaque->rcq_local_flagaction = (ropaque->rcq_local_flagaction &
	    RCTL_LOCAL_ACTION_MASK) | (action & ~RCTL_LOCAL_ACTION_MASK);
}

void
rctlblk_set_local_flags(rctlblk_t *rblk, uint_t flags)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
	ropaque->rcq_local_flagaction = (ropaque->rcq_local_flagaction &
	    ~RCTL_LOCAL_ACTION_MASK) | (flags & RCTL_LOCAL_ACTION_MASK);
}

void
rctlblk_set_recipient_pid(rctlblk_t *rblk, id_t pid)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
	ropaque->rcq_local_recipient_pid = pid;
}

void
rctlblk_set_privilege(rctlblk_t *rblk, rctl_priv_t privilege)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
	ropaque->rcq_privilege = privilege;
}

void
rctlblk_set_value(rctlblk_t *rblk, rctl_qty_t value)
{
	rctl_opaque_t *ropaque = (rctl_opaque_t *)rblk;
	ropaque->rcq_value = value;
}

size_t
rctlblk_size(void)
{
	return (sizeof (rctl_opaque_t));
}