Changeset View
Changeset View
Standalone View
Standalone View
sys/cddl/contrib/opensolaris/uts/common/zmod/zmod_subr.c
Show All 23 Lines | |||||
* Use is subject to license terms. | * Use is subject to license terms. | ||||
*/ | */ | ||||
#pragma ident "%Z%%M% %I% %E% SMI" | #pragma ident "%Z%%M% %I% %E% SMI" | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/cmn_err.h> | #include <sys/cmn_err.h> | ||||
#include <sys/kobj.h> | #include <sys/kobj.h> | ||||
#include <zlib.h> | |||||
struct zchdr { | struct zchdr { | ||||
uint_t zch_magic; | uint_t zch_magic; | ||||
uint_t zch_size; | uint_t zch_size; | ||||
}; | }; | ||||
#define ZCH_MAGIC 0x3cc13cc1 | #define ZCH_MAGIC 0x3cc13cc1 | ||||
/*ARGSUSED*/ | /*ARGSUSED*/ | ||||
void * | void * | ||||
zcalloc(void *opaque, uint_t items, uint_t size) | zmod_zcalloc(void *opaque, uint_t items, uint_t size) | ||||
{ | { | ||||
size_t nbytes = sizeof (struct zchdr) + items * size; | size_t nbytes = sizeof (struct zchdr) + items * size; | ||||
struct zchdr *z = kobj_zalloc(nbytes, KM_NOWAIT|KM_TMP); | struct zchdr *z = kobj_zalloc(nbytes, KM_NOWAIT|KM_TMP); | ||||
if (z == NULL) | if (z == NULL) | ||||
return (NULL); | return (NULL); | ||||
z->zch_magic = ZCH_MAGIC; | z->zch_magic = ZCH_MAGIC; | ||||
z->zch_size = nbytes; | z->zch_size = nbytes; | ||||
return (z + 1); | return (z + 1); | ||||
} | } | ||||
/*ARGSUSED*/ | /*ARGSUSED*/ | ||||
void | void | ||||
zcfree(void *opaque, void *ptr) | zmod_zcfree(void *opaque, void *ptr) | ||||
{ | { | ||||
struct zchdr *z = ((struct zchdr *)ptr) - 1; | struct zchdr *z = ((struct zchdr *)ptr) - 1; | ||||
if (z->zch_magic != ZCH_MAGIC) | if (z->zch_magic != ZCH_MAGIC) | ||||
panic("zcfree region corrupt: hdr=%p ptr=%p", (void *)z, ptr); | panic("zcfree region corrupt: hdr=%p ptr=%p", (void *)z, ptr); | ||||
kobj_free(z, z->zch_size); | kobj_free(z, z->zch_size); | ||||
} | |||||
void | |||||
zmemcpy(void *dest, const void *source, uint_t len) | |||||
{ | |||||
bcopy(source, dest, len); | |||||
} | |||||
int | |||||
zmemcmp(const void *s1, const void *s2, uint_t len) | |||||
{ | |||||
return (bcmp(s1, s2, len)); | |||||
} | |||||
void | |||||
zmemzero(void *dest, uint_t len) | |||||
{ | |||||
bzero(dest, len); | |||||
} | } |