1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3 * CDDL HEADER START
4 *
5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License, Version 1.0 only
7 * (the "License"). You may not use this file except in compliance
8 * with the License.
9 *
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or https://opensource.org/licenses/CDDL-1.0.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
14 *
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
20 *
21 * CDDL HEADER END
22 */
23 /*
24 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28
29
30 #include <rpc/types.h>
31 #include <sys/kmem.h>
32 #include <sys/nvpair.h>
33
34 static void *
nv_alloc_sys(nv_alloc_t * nva,size_t size)35 nv_alloc_sys(nv_alloc_t *nva, size_t size)
36 {
37 return (kmem_alloc(size, (int)(uintptr_t)nva->nva_arg));
38 }
39
40 static void
nv_free_sys(nv_alloc_t * nva,void * buf,size_t size)41 nv_free_sys(nv_alloc_t *nva, void *buf, size_t size)
42 {
43 (void) nva;
44 kmem_free(buf, size);
45 }
46
47 static const nv_alloc_ops_t system_ops = {
48 NULL, /* nv_ao_init() */
49 NULL, /* nv_ao_fini() */
50 nv_alloc_sys, /* nv_ao_alloc() */
51 nv_free_sys, /* nv_ao_free() */
52 NULL /* nv_ao_reset() */
53 };
54
55 static nv_alloc_t nv_alloc_sleep_def = {
56 &system_ops,
57 (void *)KM_SLEEP
58 };
59
60 static nv_alloc_t nv_alloc_nosleep_def = {
61 &system_ops,
62 (void *)KM_NOSLEEP
63 };
64
65 nv_alloc_t *const nv_alloc_sleep = &nv_alloc_sleep_def;
66 nv_alloc_t *const nv_alloc_nosleep = &nv_alloc_nosleep_def;
67