1da6c28aaSamw /* 2da6c28aaSamw * CDDL HEADER START 3da6c28aaSamw * 4da6c28aaSamw * The contents of this file are subject to the terms of the 5da6c28aaSamw * Common Development and Distribution License (the "License"). 6da6c28aaSamw * You may not use this file except in compliance with the License. 7da6c28aaSamw * 8da6c28aaSamw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9da6c28aaSamw * or http://www.opensolaris.org/os/licensing. 10da6c28aaSamw * See the License for the specific language governing permissions 11da6c28aaSamw * and limitations under the License. 12da6c28aaSamw * 13da6c28aaSamw * When distributing Covered Code, include this CDDL HEADER in each 14da6c28aaSamw * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15da6c28aaSamw * If applicable, add the following below this CDDL HEADER, with the 16da6c28aaSamw * fields enclosed by brackets "[]" replaced with your own identifying 17da6c28aaSamw * information: Portions Copyright [yyyy] [name of copyright owner] 18da6c28aaSamw * 19da6c28aaSamw * CDDL HEADER END 20da6c28aaSamw */ 21da6c28aaSamw /* 229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23da6c28aaSamw * Use is subject to license terms. 24*b819cea2SGordon Ross * 25*b819cea2SGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 26da6c28aaSamw */ 27da6c28aaSamw 28da6c28aaSamw #ifndef _SMBSRV_ALLOC_H 29da6c28aaSamw #define _SMBSRV_ALLOC_H 30da6c28aaSamw 31da6c28aaSamw #ifdef __cplusplus 32da6c28aaSamw extern "C" { 33da6c28aaSamw #endif 34da6c28aaSamw 35da6c28aaSamw /* 36da6c28aaSamw * Memory management macros to aid in developing code that can 37da6c28aaSamw * be compiled for both user and kernel. 38da6c28aaSamw * 39da6c28aaSamw * Set the AREA parameter to a short text string that is a hint 40da6c28aaSamw * about the subsystem calling the function. example: "smbrdr" 41da6c28aaSamw * 42da6c28aaSamw * Do not mix usage of these macros with malloc/free functions. 43da6c28aaSamw * It will not work. 44da6c28aaSamw * 45da6c28aaSamw * All library code shared between user and kernel must use 46da6c28aaSamw * these functions instead of malloc/free/kmem_*. 47da6c28aaSamw * 48da6c28aaSamw * Quick Summary 49da6c28aaSamw * MEM_MALLOC - allocate memory 50da6c28aaSamw * MEM_ZALLOC - allocate and zero memory 51da6c28aaSamw * MEM_STRDUP - string copy 52da6c28aaSamw * MEM_REALLOC - reallocate memory 53da6c28aaSamw * MEM_FREE - free memory 54da6c28aaSamw */ 55da6c28aaSamw 56da6c28aaSamw #include <sys/types.h> 57da6c28aaSamw 58*b819cea2SGordon Ross #if !defined(_KERNEL) && !defined(_FAKE_KERNEL) 59da6c28aaSamw #include <stdlib.h> 60da6c28aaSamw #include <string.h> 61da6c28aaSamw 62da6c28aaSamw #define MEM_MALLOC(AREA, SIZE) malloc(SIZE) 63da6c28aaSamw #define MEM_ZALLOC(AREA, SIZE) calloc((SIZE), 1) 64da6c28aaSamw #define MEM_STRDUP(AREA, PTR) strdup(PTR) 65da6c28aaSamw #define MEM_REALLOC(AREA, PTR, SIZE) realloc((PTR), (SIZE)) 66da6c28aaSamw #define MEM_FREE(AREA, PTR) free(PTR) 67da6c28aaSamw 68da6c28aaSamw #else /* _KERNEL */ 69da6c28aaSamw 709fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void *smb_mem_alloc(size_t); 719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void *smb_mem_zalloc(size_t); 729fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void smb_mem_free(void *); 739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States char *smb_mem_strdup(const char *); 74da6c28aaSamw 759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define MEM_MALLOC(AREA, SIZE) smb_mem_alloc(SIZE) 769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define MEM_ZALLOC(AREA, SIZE) smb_mem_zalloc(SIZE) 779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define MEM_FREE(AREA, PTR) smb_mem_free(PTR) 78da6c28aaSamw 79da6c28aaSamw #endif /* _KERNEL */ 80da6c28aaSamw 81da6c28aaSamw #ifdef __cplusplus 82da6c28aaSamw } 83da6c28aaSamw #endif 84da6c28aaSamw 85da6c28aaSamw #endif /* _SMBSRV_ALLOC_H */ 86