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