xref: /illumos-gate/usr/src/uts/common/os/space.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * The intent of this file is to contain any data that must remain
31*7c478bd9Sstevel@tonic-gate  * resident in the kernel.
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  * space_store(), space_fetch(), and space_free() have been added to
34*7c478bd9Sstevel@tonic-gate  * easily store and retrieve kernel resident data.
35*7c478bd9Sstevel@tonic-gate  * These functions are recommended rather than adding new variables to
36*7c478bd9Sstevel@tonic-gate  * this file.
37*7c478bd9Sstevel@tonic-gate  *
38*7c478bd9Sstevel@tonic-gate  * Note that it's possible for name collisions to occur.  In order to
39*7c478bd9Sstevel@tonic-gate  * prevent collisions, it's recommended that the convention in
40*7c478bd9Sstevel@tonic-gate  * PSARC/1997/389 be used.  If a collision occurs, then space_store will
41*7c478bd9Sstevel@tonic-gate  * fail.
42*7c478bd9Sstevel@tonic-gate  */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/var.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/proc.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/signal.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/buf.h>
51*7c478bd9Sstevel@tonic-gate #include <sys/cred.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
53*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
54*7c478bd9Sstevel@tonic-gate #include <sys/sysinfo.h>
55*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
56*7c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
57*7c478bd9Sstevel@tonic-gate #include <sys/modhash.h>
58*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate #include <sys/strredir.h>
61*7c478bd9Sstevel@tonic-gate #include <sys/kbio.h>
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate struct	buf	bfreelist;	/* Head of the free list of buffers */
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate sysinfo_t	sysinfo;
66*7c478bd9Sstevel@tonic-gate vminfo_t	vminfo;		/* VM stats protected by sysinfolock mutex */
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #ifdef	lint
69*7c478bd9Sstevel@tonic-gate int	__lintzero;		/* Alway zero for shutting up lint */
70*7c478bd9Sstevel@tonic-gate #endif
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate  * The following describe the physical memory configuration.
74*7c478bd9Sstevel@tonic-gate  *
75*7c478bd9Sstevel@tonic-gate  *	physmem	 -  The amount of physical memory configured
76*7c478bd9Sstevel@tonic-gate  *		    in pages.  ptob(physmem) is the amount
77*7c478bd9Sstevel@tonic-gate  *		    of physical memory in bytes.  Defined in
78*7c478bd9Sstevel@tonic-gate  *		    .../os/startup.c.
79*7c478bd9Sstevel@tonic-gate  *
80*7c478bd9Sstevel@tonic-gate  *	physmax  -  The highest numbered physical page in memory.
81*7c478bd9Sstevel@tonic-gate  *
82*7c478bd9Sstevel@tonic-gate  *	maxmem	 -  Maximum available memory, in pages.  Defined
83*7c478bd9Sstevel@tonic-gate  *		    in main.c.
84*7c478bd9Sstevel@tonic-gate  *
85*7c478bd9Sstevel@tonic-gate  *	physinstalled
86*7c478bd9Sstevel@tonic-gate  *		 -  Pages of physical memory installed;
87*7c478bd9Sstevel@tonic-gate  *		    includes use by PROM/boot not counted in
88*7c478bd9Sstevel@tonic-gate  *		    physmem.
89*7c478bd9Sstevel@tonic-gate  */
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate pfn_t	physmax;
92*7c478bd9Sstevel@tonic-gate pgcnt_t	physinstalled;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate struct var v;
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>
97*7c478bd9Sstevel@tonic-gate #include <sys/conf.h>
98*7c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
99*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
100*7c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate /*
103*7c478bd9Sstevel@tonic-gate  * Data from swapgeneric.c that must be resident.
104*7c478bd9Sstevel@tonic-gate  */
105*7c478bd9Sstevel@tonic-gate struct vnode *rootvp;		/* vnode of the root device */
106*7c478bd9Sstevel@tonic-gate dev_t rootdev;			/* dev_t of the root device */
107*7c478bd9Sstevel@tonic-gate int root_is_svm;		/* root is a mirrored device flag */
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate int netboot;
110*7c478bd9Sstevel@tonic-gate int obpdebug;
111*7c478bd9Sstevel@tonic-gate char *dhcack;	/* Used to cache ascii form of DHCPACK handed up by boot */
112*7c478bd9Sstevel@tonic-gate char *netdev_path;	/* Used to cache the netdev_path handed up by boot */
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate /*
115*7c478bd9Sstevel@tonic-gate  * Data from arp.c that must be resident.
116*7c478bd9Sstevel@tonic-gate  */
117*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
118*7c478bd9Sstevel@tonic-gate #include <sys/errno.h>
119*7c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
120*7c478bd9Sstevel@tonic-gate #include <sys/stream.h>
121*7c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
122*7c478bd9Sstevel@tonic-gate #include <sys/dlpi.h>
123*7c478bd9Sstevel@tonic-gate #include <net/if.h>
124*7c478bd9Sstevel@tonic-gate #include <net/if_arp.h>
125*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
126*7c478bd9Sstevel@tonic-gate #include <netinet/in_var.h>
127*7c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h>
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate ether_addr_t etherbroadcastaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate /*
132*7c478bd9Sstevel@tonic-gate  * Data from timod that must be resident
133*7c478bd9Sstevel@tonic-gate  */
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate /*
136*7c478bd9Sstevel@tonic-gate  * state transition table for TI interface
137*7c478bd9Sstevel@tonic-gate  */
138*7c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate #define	nr	127		/* not reachable */
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate char ti_statetbl[TE_NOEVENTS][TS_NOSTATES] = {
143*7c478bd9Sstevel@tonic-gate 				/* STATES */
144*7c478bd9Sstevel@tonic-gate 	/* 0  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16 */
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	{ 1, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
147*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  2, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
148*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  4, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
149*7c478bd9Sstevel@tonic-gate 	{nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
150*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
151*7c478bd9Sstevel@tonic-gate 	{nr,  0,  3, nr,  3,  3, nr, nr,  7, nr, nr, nr,  6,  7,  9, 10, 11},
152*7c478bd9Sstevel@tonic-gate 	{nr, nr,  0, nr, nr,  6, nr, nr, nr, nr, nr, nr,  3, nr,  3,  3,  3},
153*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr,  9, nr, nr, nr, nr,  3, nr, nr, nr},
154*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr,  3, nr, nr, nr, nr,  3, nr, nr, nr},
155*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr,  7, nr, nr, nr, nr,  7, nr, nr, nr},
156*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  5, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
157*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr,  8, nr, nr, nr, nr, nr, nr, nr, nr, nr},
158*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, 12, 13, nr, 14, 15, 16, nr, nr, nr, nr, nr},
159*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, nr, 11, nr, nr, nr, nr, nr},
160*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, nr, 11, nr, nr, nr, nr, nr},
161*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr, 10, nr,  3, nr, nr, nr, nr, nr},
162*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  7, nr, nr, nr,  7, nr, nr, nr, nr, nr, nr, nr, nr, nr},
163*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr,  9, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
164*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, 10, nr, nr, nr, nr, nr, nr},
165*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr,  9, 10, nr, nr, nr, nr, nr, nr},
166*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr, nr, nr, 11,  3, nr, nr, nr, nr, nr, nr},
167*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr,  3, nr, nr,  3,  3,  3, nr, nr, nr, nr, nr},
168*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr},
169*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr, nr, nr, nr, nr,  7, nr, nr, nr, nr, nr, nr, nr, nr, nr},
170*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  9, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
171*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
172*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
173*7c478bd9Sstevel@tonic-gate 	{nr, nr, nr,  3, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr, nr},
174*7c478bd9Sstevel@tonic-gate };
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate #include <sys/sad.h>
178*7c478bd9Sstevel@tonic-gate #include <sys/tty.h>
179*7c478bd9Sstevel@tonic-gate #include <sys/ptyvar.h>
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate static void store_fetch_initspace();
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate /*
184*7c478bd9Sstevel@tonic-gate  * Allocate tunable structures at runtime.
185*7c478bd9Sstevel@tonic-gate  */
186*7c478bd9Sstevel@tonic-gate void
187*7c478bd9Sstevel@tonic-gate space_init(void)
188*7c478bd9Sstevel@tonic-gate {
189*7c478bd9Sstevel@tonic-gate 	sad_initspace();
190*7c478bd9Sstevel@tonic-gate 	pty_initspace();
191*7c478bd9Sstevel@tonic-gate 	store_fetch_initspace();
192*7c478bd9Sstevel@tonic-gate }
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate int ts_dispatch_extended = -1; /* set in ts_getdptbl or set_platform_default */
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate /*
197*7c478bd9Sstevel@tonic-gate  * Previously defined in consmsconf.c ...
198*7c478bd9Sstevel@tonic-gate  */
199*7c478bd9Sstevel@tonic-gate dev_t kbddev = NODEV;
200*7c478bd9Sstevel@tonic-gate dev_t mousedev = NODEV;
201*7c478bd9Sstevel@tonic-gate dev_t stdindev = NODEV;
202*7c478bd9Sstevel@tonic-gate struct vnode *wsconsvp;
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate dev_t fbdev = NODEV;
205*7c478bd9Sstevel@tonic-gate struct vnode *fbvp;
206*7c478bd9Sstevel@tonic-gate dev_info_t *fbdip;
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate /*
209*7c478bd9Sstevel@tonic-gate  * moved from cons.c because they must be resident in the kernel.
210*7c478bd9Sstevel@tonic-gate  */
211*7c478bd9Sstevel@tonic-gate vnode_t	*rconsvp;
212*7c478bd9Sstevel@tonic-gate dev_t	rconsdev;
213*7c478bd9Sstevel@tonic-gate dev_t	uconsdev = NODEV;
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate /*
216*7c478bd9Sstevel@tonic-gate  * This flag, when set marks rconsvp in a transition state.
217*7c478bd9Sstevel@tonic-gate  */
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate int	cn_conf;
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate /*
222*7c478bd9Sstevel@tonic-gate  * Moved from sad_conf.c because of the usual in loadable modules
223*7c478bd9Sstevel@tonic-gate  */
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate #ifndef NSTRPHASH
226*7c478bd9Sstevel@tonic-gate #define	NSTRPHASH	128
227*7c478bd9Sstevel@tonic-gate #endif
228*7c478bd9Sstevel@tonic-gate struct autopush **strpcache;
229*7c478bd9Sstevel@tonic-gate int strpmask = NSTRPHASH - 1;
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate /*
232*7c478bd9Sstevel@tonic-gate  * Moved here from wscons.c
233*7c478bd9Sstevel@tonic-gate  * Package the redirection-related routines into an ops vector of the form
234*7c478bd9Sstevel@tonic-gate  * that the redirecting driver expects.
235*7c478bd9Sstevel@tonic-gate  */
236*7c478bd9Sstevel@tonic-gate extern int wcvnget();
237*7c478bd9Sstevel@tonic-gate extern void wcvnrele();
238*7c478bd9Sstevel@tonic-gate srvnops_t	wscons_srvnops = {
239*7c478bd9Sstevel@tonic-gate 	wcvnget,
240*7c478bd9Sstevel@tonic-gate 	wcvnrele
241*7c478bd9Sstevel@tonic-gate };
242*7c478bd9Sstevel@tonic-gate 
243*7c478bd9Sstevel@tonic-gate /*
244*7c478bd9Sstevel@tonic-gate  * consconfig() in autoconf.c sets this; it's the vnode of the distinguished
245*7c478bd9Sstevel@tonic-gate  * keyboard/frame buffer combination, aka the workstation console.
246*7c478bd9Sstevel@tonic-gate  */
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate vnode_t *rwsconsvp;
249*7c478bd9Sstevel@tonic-gate dev_t	rwsconsdev;
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate /*
252*7c478bd9Sstevel@tonic-gate  * Platform console abort policy.
253*7c478bd9Sstevel@tonic-gate  * Platforms may override the default software policy, if such hardware
254*7c478bd9Sstevel@tonic-gate  * (e.g. keyswitches with a secure position) exists.
255*7c478bd9Sstevel@tonic-gate  */
256*7c478bd9Sstevel@tonic-gate int abort_enable = KIOCABORTENABLE;
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate /* from iwscons.c */
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate kthread_id_t	iwscn_thread;	/* thread that is allowed to push redirm */
261*7c478bd9Sstevel@tonic-gate wcm_data_t	*iwscn_wcm_data; /* allocated data for redirm */
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate /* from cpc.c */
264*7c478bd9Sstevel@tonic-gate uint_t kcpc_key;	/* TSD key for CPU performance counter context */
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate /*
267*7c478bd9Sstevel@tonic-gate  * storing and retrieving data by string key
268*7c478bd9Sstevel@tonic-gate  *
269*7c478bd9Sstevel@tonic-gate  * this mechanism allows a consumer to store and retrieve by name a pointer
270*7c478bd9Sstevel@tonic-gate  * to some space maintained by the consumer.
271*7c478bd9Sstevel@tonic-gate  * For example, a driver or module may want to have persistent data
272*7c478bd9Sstevel@tonic-gate  * over unloading/loading cycles. The pointer is typically to some
273*7c478bd9Sstevel@tonic-gate  * kmem_alloced space and it should not be pointing to data that will
274*7c478bd9Sstevel@tonic-gate  * be destroyed when the module is unloaded.
275*7c478bd9Sstevel@tonic-gate  */
276*7c478bd9Sstevel@tonic-gate static mod_hash_t *space_hash;
277*7c478bd9Sstevel@tonic-gate static char *space_hash_name = "space_hash";
278*7c478bd9Sstevel@tonic-gate static size_t	space_hash_nchains = 8;
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate static void
281*7c478bd9Sstevel@tonic-gate store_fetch_initspace()
282*7c478bd9Sstevel@tonic-gate {
283*7c478bd9Sstevel@tonic-gate 	space_hash = mod_hash_create_strhash(space_hash_name,
284*7c478bd9Sstevel@tonic-gate 		space_hash_nchains, mod_hash_null_valdtor);
285*7c478bd9Sstevel@tonic-gate 	ASSERT(space_hash);
286*7c478bd9Sstevel@tonic-gate }
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate int
289*7c478bd9Sstevel@tonic-gate space_store(char *key, uintptr_t ptr)
290*7c478bd9Sstevel@tonic-gate {
291*7c478bd9Sstevel@tonic-gate 	char *s;
292*7c478bd9Sstevel@tonic-gate 	int rval;
293*7c478bd9Sstevel@tonic-gate 	size_t l;
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 	/* some sanity checks first */
296*7c478bd9Sstevel@tonic-gate 	if (key == NULL) {
297*7c478bd9Sstevel@tonic-gate 		return (-1);
298*7c478bd9Sstevel@tonic-gate 	}
299*7c478bd9Sstevel@tonic-gate 	l = (size_t)strlen(key);
300*7c478bd9Sstevel@tonic-gate 	if (l == 0) {
301*7c478bd9Sstevel@tonic-gate 		return (-1);
302*7c478bd9Sstevel@tonic-gate 	}
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 	/* increment for null terminator */
305*7c478bd9Sstevel@tonic-gate 	l++;
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate 	/* alloc space for the string, mod_hash_insert will deallocate */
308*7c478bd9Sstevel@tonic-gate 	s = kmem_alloc(l, KM_SLEEP);
309*7c478bd9Sstevel@tonic-gate 	bcopy(key, s, l);
310*7c478bd9Sstevel@tonic-gate 
311*7c478bd9Sstevel@tonic-gate 	rval = mod_hash_insert(space_hash,
312*7c478bd9Sstevel@tonic-gate 		(mod_hash_key_t)s, (mod_hash_val_t)ptr);
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 	switch (rval) {
315*7c478bd9Sstevel@tonic-gate 	case 0:
316*7c478bd9Sstevel@tonic-gate 		break;
317*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
318*7c478bd9Sstevel@tonic-gate 	case MH_ERR_DUPLICATE:
319*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "space_store: duplicate key %s", key);
320*7c478bd9Sstevel@tonic-gate 		rval = -1;
321*7c478bd9Sstevel@tonic-gate 		break;
322*7c478bd9Sstevel@tonic-gate 	case MH_ERR_NOMEM:
323*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "space_store: no mem for key %s", key);
324*7c478bd9Sstevel@tonic-gate 		rval = -1;
325*7c478bd9Sstevel@tonic-gate 		break;
326*7c478bd9Sstevel@tonic-gate 	default:
327*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "space_store: unspecified error for key %s",
328*7c478bd9Sstevel@tonic-gate 		    key);
329*7c478bd9Sstevel@tonic-gate 		rval = -1;
330*7c478bd9Sstevel@tonic-gate 		break;
331*7c478bd9Sstevel@tonic-gate #else
332*7c478bd9Sstevel@tonic-gate 	default:
333*7c478bd9Sstevel@tonic-gate 		rval = -1;
334*7c478bd9Sstevel@tonic-gate 		break;
335*7c478bd9Sstevel@tonic-gate #endif
336*7c478bd9Sstevel@tonic-gate 	}
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 	return (rval);
339*7c478bd9Sstevel@tonic-gate }
340*7c478bd9Sstevel@tonic-gate 
341*7c478bd9Sstevel@tonic-gate uintptr_t
342*7c478bd9Sstevel@tonic-gate space_fetch(char *key)
343*7c478bd9Sstevel@tonic-gate {
344*7c478bd9Sstevel@tonic-gate 	uintptr_t ptr = 0;
345*7c478bd9Sstevel@tonic-gate 	mod_hash_val_t val;
346*7c478bd9Sstevel@tonic-gate 	int rval;
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate 	if (key) {
349*7c478bd9Sstevel@tonic-gate 		rval = mod_hash_find(space_hash, (mod_hash_key_t)key, &val);
350*7c478bd9Sstevel@tonic-gate 		if (rval == 0) {
351*7c478bd9Sstevel@tonic-gate 			ptr = (uintptr_t)val;
352*7c478bd9Sstevel@tonic-gate 		}
353*7c478bd9Sstevel@tonic-gate 	}
354*7c478bd9Sstevel@tonic-gate 
355*7c478bd9Sstevel@tonic-gate 	return (ptr);
356*7c478bd9Sstevel@tonic-gate }
357*7c478bd9Sstevel@tonic-gate 
358*7c478bd9Sstevel@tonic-gate void
359*7c478bd9Sstevel@tonic-gate space_free(char *key)
360*7c478bd9Sstevel@tonic-gate {
361*7c478bd9Sstevel@tonic-gate 	if (key) {
362*7c478bd9Sstevel@tonic-gate 		(void) mod_hash_destroy(space_hash, (mod_hash_key_t)key);
363*7c478bd9Sstevel@tonic-gate 	}
364*7c478bd9Sstevel@tonic-gate }
365*7c478bd9Sstevel@tonic-gate 
366*7c478bd9Sstevel@tonic-gate /*
367*7c478bd9Sstevel@tonic-gate  * Support for CRC32.  At present all calculations are done in simple
368*7c478bd9Sstevel@tonic-gate  * macros, so all we need is somewhere to declare the global lookup table.
369*7c478bd9Sstevel@tonic-gate  */
370*7c478bd9Sstevel@tonic-gate 
371*7c478bd9Sstevel@tonic-gate #include <sys/crc32.h>
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate const uint32_t crc32_table[256] = { CRC32_TABLE };
374