1 /* 2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 #pragma ident "%Z%%M% %I% %E% SMI" 7 8 #include <sys/systm.h> 9 #include <sys/cmn_err.h> 10 #include <sys/kobj.h> 11 #include <sys/kobj_impl.h> 12 13 /* 14 * This module is used both during the normal operation of the kernel (i.e. 15 * after kmem has been initialized) and during boot (before unix`_start has 16 * been called). kobj_alloc is able to tell the difference between the two 17 * cases, and as such must be used instead of kmem_alloc. 18 */ 19 20 void 21 zmemcpy(uchar_t *dest, const uchar_t *source, uint_t len) 22 { 23 bcopy(source, dest, len); 24 } 25 26 struct zchdr { 27 uint_t zch_magic; 28 uint_t zch_size; 29 }; 30 31 #define ZCH_MAGIC 0x3cc13cc1 32 33 /*ARGSUSED*/ 34 void * 35 zcalloc(void *opaque, uint_t items, uint_t size) 36 { 37 size_t nbytes = sizeof (struct zchdr) + items * size; 38 struct zchdr *z = kobj_zalloc(nbytes, KM_NOWAIT|KM_TMP); 39 40 if (z == NULL) 41 return (NULL); 42 43 z->zch_magic = ZCH_MAGIC; 44 z->zch_size = nbytes; 45 46 return (z + 1); 47 } 48 49 /*ARGSUSED*/ 50 void 51 zcfree(void *opaque, void *ptr) 52 { 53 struct zchdr *z = ((struct zchdr *)ptr) - 1; 54 55 if (z->zch_magic != ZCH_MAGIC) 56 panic("zcfree region corrupt: hdr=%p ptr=%p", (void *)z, ptr); 57 58 kobj_free(z, z->zch_size); 59 } 60