6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <mdb/mdb_debug.h>
30 #include <mdb/mdb_string.h>
31 #include <mdb/mdb_modapi.h>
32 #include <mdb/mdb_err.h>
33 #include <mdb/mdb_nv.h>
34 #include <mdb/mdb.h>
35
36 #define NV_NAME(v) \
37 (((v)->v_flags & MDB_NV_EXTNAME) ? (v)->v_ename : (v)->v_lname)
38
39 #define NV_SIZE(v) \
40 (((v)->v_flags & MDB_NV_EXTNAME) ? sizeof (mdb_var_t) : \
41 sizeof (mdb_var_t) + MDB_NV_NAMELEN - 1)
42
43 #define NV_HASHSZ 211
44
45 static size_t
46 nv_hashstring(const char *key)
47 {
48 size_t g, h = 0;
49 const char *p;
50
51 ASSERT(key != NULL);
52
53 for (p = key; *p != '\0'; p++) {
54 h = (h << 4) + *p;
55
56 if ((g = (h & 0xf0000000)) != 0) {
57 h ^= (g >> 24);
58 h ^= g;
59 }
60 }
61
62 return (h);
63 }
64
65 static mdb_var_t *
66 nv_var_alloc(const char *name, const mdb_nv_disc_t *disc,
67 uintmax_t value, uint_t flags, uint_t um_flags, mdb_var_t *next)
68 {
69 size_t nbytes = (flags & MDB_NV_EXTNAME) ? sizeof (mdb_var_t) :
70 (sizeof (mdb_var_t) + MDB_NV_NAMELEN - 1);
71
72 mdb_var_t *v = mdb_alloc(nbytes, um_flags);
73
74 if (v == NULL)
75 return (NULL);
76
77 if (flags & MDB_NV_EXTNAME) {
78 v->v_ename = name;
79 v->v_lname[0] = 0;
80 } else {
81 (void) strncpy(v->v_lname, name, MDB_NV_NAMELEN - 1);
82 v->v_lname[MDB_NV_NAMELEN - 1] = '\0';
83 v->v_ename = NULL;
84 }
85
86 v->v_uvalue = value;
87 v->v_flags = flags & ~(MDB_NV_SILENT | MDB_NV_INTERPOS);
88 v->v_disc = disc;
89 v->v_next = next;
90
91 return (v);
92 }
93
94 static void
95 nv_var_free(mdb_var_t *v, uint_t um_flags)
96 {
97 if (um_flags & UM_GC)
98 return;
99
100 if (v->v_flags & MDB_NV_OVERLOAD) {
101 mdb_var_t *w, *nw;
102
|
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26 /*
27 * Copyright (c) 2013 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
28 */
29
30 #include <mdb/mdb_debug.h>
31 #include <mdb/mdb_string.h>
32 #include <mdb/mdb_modapi.h>
33 #include <mdb/mdb_err.h>
34 #include <mdb/mdb_nv.h>
35 #include <mdb/mdb.h>
36
37 #define NV_NAME(v) \
38 (((v)->v_flags & MDB_NV_EXTNAME) ? (v)->v_ename : (v)->v_lname)
39
40 #define NV_SIZE(v) \
41 (((v)->v_flags & MDB_NV_EXTNAME) ? sizeof (mdb_var_t) : \
42 sizeof (mdb_var_t) + strlen((v)->v_lname))
43
44 #define NV_HASHSZ 211
45
46 static size_t
47 nv_hashstring(const char *key)
48 {
49 size_t g, h = 0;
50 const char *p;
51
52 ASSERT(key != NULL);
53
54 for (p = key; *p != '\0'; p++) {
55 h = (h << 4) + *p;
56
57 if ((g = (h & 0xf0000000)) != 0) {
58 h ^= (g >> 24);
59 h ^= g;
60 }
61 }
62
63 return (h);
64 }
65
66 static mdb_var_t *
67 nv_var_alloc(const char *name, const mdb_nv_disc_t *disc,
68 uintmax_t value, uint_t flags, uint_t um_flags, mdb_var_t *next)
69 {
70 size_t nbytes;
71 mdb_var_t *v;
72
73 if (flags & MDB_NV_EXTNAME)
74 nbytes = sizeof (mdb_var_t);
75 else
76 nbytes = sizeof (mdb_var_t) + strlen(name);
77
78 v = mdb_alloc(nbytes, um_flags);
79
80 if (v == NULL)
81 return (NULL);
82
83 if (flags & MDB_NV_EXTNAME) {
84 v->v_ename = name;
85 v->v_lname[0] = '\0';
86 } else {
87 /*
88 * We don't overflow here since the mdb_var_t itself has
89 * room for the trailing \0.
90 */
91 (void) strcpy(v->v_lname, name);
92 v->v_ename = NULL;
93 }
94
95 v->v_uvalue = value;
96 v->v_flags = flags & ~(MDB_NV_SILENT | MDB_NV_INTERPOS);
97 v->v_disc = disc;
98 v->v_next = next;
99
100 return (v);
101 }
102
103 static void
104 nv_var_free(mdb_var_t *v, uint_t um_flags)
105 {
106 if (um_flags & UM_GC)
107 return;
108
109 if (v->v_flags & MDB_NV_OVERLOAD) {
110 mdb_var_t *w, *nw;
111
|