1*c9431fa1Sahl /*
2*c9431fa1Sahl * CDDL HEADER START
3*c9431fa1Sahl *
4*c9431fa1Sahl * The contents of this file are subject to the terms of the
5*c9431fa1Sahl * Common Development and Distribution License (the "License").
6*c9431fa1Sahl * You may not use this file except in compliance with the License.
7*c9431fa1Sahl *
8*c9431fa1Sahl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*c9431fa1Sahl * or http://www.opensolaris.org/os/licensing.
10*c9431fa1Sahl * See the License for the specific language governing permissions
11*c9431fa1Sahl * and limitations under the License.
12*c9431fa1Sahl *
13*c9431fa1Sahl * When distributing Covered Code, include this CDDL HEADER in each
14*c9431fa1Sahl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*c9431fa1Sahl * If applicable, add the following below this CDDL HEADER, with the
16*c9431fa1Sahl * fields enclosed by brackets "[]" replaced with your own identifying
17*c9431fa1Sahl * information: Portions Copyright [yyyy] [name of copyright owner]
18*c9431fa1Sahl *
19*c9431fa1Sahl * CDDL HEADER END
20*c9431fa1Sahl */
21*c9431fa1Sahl
22*c9431fa1Sahl /*
23*c9431fa1Sahl * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24*c9431fa1Sahl * Use is subject to license terms.
25*c9431fa1Sahl */
26*c9431fa1Sahl
27*c9431fa1Sahl #pragma ident "%Z%%M% %I% %E% SMI"
28*c9431fa1Sahl
29*c9431fa1Sahl #include <sys/systm.h>
30*c9431fa1Sahl #include <sys/cmn_err.h>
31*c9431fa1Sahl #include <sys/kobj.h>
32*c9431fa1Sahl #include <sys/kobj_impl.h>
33*c9431fa1Sahl
34*c9431fa1Sahl struct zchdr {
35*c9431fa1Sahl uint_t zch_magic;
36*c9431fa1Sahl uint_t zch_size;
37*c9431fa1Sahl };
38*c9431fa1Sahl
39*c9431fa1Sahl #define ZCH_MAGIC 0x3cc13cc1
40*c9431fa1Sahl
41*c9431fa1Sahl /*ARGSUSED*/
42*c9431fa1Sahl void *
zcalloc(void * opaque,uint_t items,uint_t size)43*c9431fa1Sahl zcalloc(void *opaque, uint_t items, uint_t size)
44*c9431fa1Sahl {
45*c9431fa1Sahl size_t nbytes = sizeof (struct zchdr) + items * size;
46*c9431fa1Sahl struct zchdr *z = kobj_zalloc(nbytes, KM_NOWAIT|KM_TMP);
47*c9431fa1Sahl
48*c9431fa1Sahl if (z == NULL)
49*c9431fa1Sahl return (NULL);
50*c9431fa1Sahl
51*c9431fa1Sahl z->zch_magic = ZCH_MAGIC;
52*c9431fa1Sahl z->zch_size = nbytes;
53*c9431fa1Sahl
54*c9431fa1Sahl return (z + 1);
55*c9431fa1Sahl }
56*c9431fa1Sahl
57*c9431fa1Sahl /*ARGSUSED*/
58*c9431fa1Sahl void
zcfree(void * opaque,void * ptr)59*c9431fa1Sahl zcfree(void *opaque, void *ptr)
60*c9431fa1Sahl {
61*c9431fa1Sahl struct zchdr *z = ((struct zchdr *)ptr) - 1;
62*c9431fa1Sahl
63*c9431fa1Sahl if (z->zch_magic != ZCH_MAGIC)
64*c9431fa1Sahl panic("zcfree region corrupt: hdr=%p ptr=%p", (void *)z, ptr);
65*c9431fa1Sahl
66*c9431fa1Sahl kobj_free(z, z->zch_size);
67*c9431fa1Sahl }
68*c9431fa1Sahl
69*c9431fa1Sahl void
zmemcpy(void * dest,const void * source,uint_t len)70*c9431fa1Sahl zmemcpy(void *dest, const void *source, uint_t len)
71*c9431fa1Sahl {
72*c9431fa1Sahl bcopy(source, dest, len);
73*c9431fa1Sahl }
74*c9431fa1Sahl
75*c9431fa1Sahl int
zmemcmp(const void * s1,const void * s2,uint_t len)76*c9431fa1Sahl zmemcmp(const void *s1, const void *s2, uint_t len)
77*c9431fa1Sahl {
78*c9431fa1Sahl return (bcmp(s1, s2, len));
79*c9431fa1Sahl }
80*c9431fa1Sahl
81*c9431fa1Sahl void
zmemzero(void * dest,uint_t len)82*c9431fa1Sahl zmemzero(void *dest, uint_t len)
83*c9431fa1Sahl {
84*c9431fa1Sahl bzero(dest, len);
85*c9431fa1Sahl }
86