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