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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Contracts
28 * ---------
29 *
30 * Contracts are a primitive which enrich the relationships between
31 * processes and system resources. The primary purpose of contracts is
32 * to provide a means for the system to negotiate the departure from a
33 * binding relationship (e.g. pages locked in memory or a thread bound
34 * to processor), but they can also be used as a purely asynchronous
35 * error reporting mechanism as they are with process contracts.
36 *
37 * More information on how one interfaces with contracts and what
38 * contracts can do for you can be found in:
39 * PSARC 2003/193 Solaris Contracts
40 * PSARC 2004/460 Contracts addendum
41 *
42 * This file contains the core contracts framework. By itself it is
43 * useless: it depends the contracts filesystem (ctfs) to provide an
270 * contract_ctor
271 *
272 * Called by a contract type to initialize a contract. Fails if the
273 * max-contract resource control would have been exceeded. After a
274 * successful call to contract_ctor, the contract is unlocked and
275 * visible in all namespaces; any type-specific initialization should
276 * be completed before calling contract_ctor. Returns 0 on success.
277 *
278 * Because not all callers can tolerate failure, a 0 value for canfail
279 * instructs contract_ctor to ignore the project.max-contracts resource
280 * control. Obviously, this "out" should only be employed by callers
281 * who are sufficiently constrained in other ways (e.g. newproc).
282 */
283 int
284 contract_ctor(contract_t *ct, ct_type_t *type, ct_template_t *tmpl, void *data,
285 ctflags_t flags, proc_t *author, int canfail)
286 {
287 avl_index_t where;
288 klwp_t *curlwp = ttolwp(curthread);
289
290 ASSERT(author == curproc);
291
292 mutex_init(&ct->ct_lock, NULL, MUTEX_DEFAULT, NULL);
293 mutex_init(&ct->ct_reflock, NULL, MUTEX_DEFAULT, NULL);
294 mutex_init(&ct->ct_evtlock, NULL, MUTEX_DEFAULT, NULL);
295 ct->ct_id = id_alloc(contract_ids);
296
297 cte_queue_create(&ct->ct_events, CTEL_CONTRACT, 20, 0);
298 list_create(&ct->ct_vnodes, sizeof (contract_vnode_t),
299 offsetof(contract_vnode_t, ctv_node));
300
301 /*
302 * Instance data
303 */
304 ct->ct_ref = 2; /* one for the holder, one for "latest" */
305 ct->ct_cuid = crgetuid(CRED());
306 ct->ct_type = type;
307 ct->ct_data = data;
308 gethrestime(&ct->ct_ctime);
309 ct->ct_state = CTS_OWNED;
310 ct->ct_flags = flags;
|
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2016 Joyent, Inc.
25 */
26
27 /*
28 * Contracts
29 * ---------
30 *
31 * Contracts are a primitive which enrich the relationships between
32 * processes and system resources. The primary purpose of contracts is
33 * to provide a means for the system to negotiate the departure from a
34 * binding relationship (e.g. pages locked in memory or a thread bound
35 * to processor), but they can also be used as a purely asynchronous
36 * error reporting mechanism as they are with process contracts.
37 *
38 * More information on how one interfaces with contracts and what
39 * contracts can do for you can be found in:
40 * PSARC 2003/193 Solaris Contracts
41 * PSARC 2004/460 Contracts addendum
42 *
43 * This file contains the core contracts framework. By itself it is
44 * useless: it depends the contracts filesystem (ctfs) to provide an
271 * contract_ctor
272 *
273 * Called by a contract type to initialize a contract. Fails if the
274 * max-contract resource control would have been exceeded. After a
275 * successful call to contract_ctor, the contract is unlocked and
276 * visible in all namespaces; any type-specific initialization should
277 * be completed before calling contract_ctor. Returns 0 on success.
278 *
279 * Because not all callers can tolerate failure, a 0 value for canfail
280 * instructs contract_ctor to ignore the project.max-contracts resource
281 * control. Obviously, this "out" should only be employed by callers
282 * who are sufficiently constrained in other ways (e.g. newproc).
283 */
284 int
285 contract_ctor(contract_t *ct, ct_type_t *type, ct_template_t *tmpl, void *data,
286 ctflags_t flags, proc_t *author, int canfail)
287 {
288 avl_index_t where;
289 klwp_t *curlwp = ttolwp(curthread);
290
291 /*
292 * It's possible that author is not curproc if the zone is creating
293 * a new process as a child of zsched.
294 */
295
296 mutex_init(&ct->ct_lock, NULL, MUTEX_DEFAULT, NULL);
297 mutex_init(&ct->ct_reflock, NULL, MUTEX_DEFAULT, NULL);
298 mutex_init(&ct->ct_evtlock, NULL, MUTEX_DEFAULT, NULL);
299 ct->ct_id = id_alloc(contract_ids);
300
301 cte_queue_create(&ct->ct_events, CTEL_CONTRACT, 20, 0);
302 list_create(&ct->ct_vnodes, sizeof (contract_vnode_t),
303 offsetof(contract_vnode_t, ctv_node));
304
305 /*
306 * Instance data
307 */
308 ct->ct_ref = 2; /* one for the holder, one for "latest" */
309 ct->ct_cuid = crgetuid(CRED());
310 ct->ct_type = type;
311 ct->ct_data = data;
312 gethrestime(&ct->ct_ctime);
313 ct->ct_state = CTS_OWNED;
314 ct->ct_flags = flags;
|