15331Samw /* 25331Samw * CDDL HEADER START 35331Samw * 45331Samw * The contents of this file are subject to the terms of the 55331Samw * Common Development and Distribution License (the "License"). 65331Samw * You may not use this file except in compliance with the License. 75331Samw * 85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95331Samw * or http://www.opensolaris.org/os/licensing. 105331Samw * See the License for the specific language governing permissions 115331Samw * and limitations under the License. 125331Samw * 135331Samw * When distributing Covered Code, include this CDDL HEADER in each 145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155331Samw * If applicable, add the following below this CDDL HEADER, with the 165331Samw * fields enclosed by brackets "[]" replaced with your own identifying 175331Samw * information: Portions Copyright [yyyy] [name of copyright owner] 185331Samw * 195331Samw * CDDL HEADER END 205331Samw */ 215331Samw /* 22*11963SAfshin.Ardakani@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 235331Samw * Use is subject to license terms. 245331Samw */ 255331Samw 265331Samw #ifndef _SMBSRV_ALLOC_H 275331Samw #define _SMBSRV_ALLOC_H 285331Samw 295331Samw #ifdef __cplusplus 305331Samw extern "C" { 315331Samw #endif 325331Samw 335331Samw /* 345331Samw * Memory management macros to aid in developing code that can 355331Samw * be compiled for both user and kernel. 365331Samw * 375331Samw * Set the AREA parameter to a short text string that is a hint 385331Samw * about the subsystem calling the function. example: "smbrdr" 395331Samw * 405331Samw * Do not mix usage of these macros with malloc/free functions. 415331Samw * It will not work. 425331Samw * 435331Samw * All library code shared between user and kernel must use 445331Samw * these functions instead of malloc/free/kmem_*. 455331Samw * 465331Samw * Quick Summary 475331Samw * MEM_MALLOC - allocate memory 485331Samw * MEM_ZALLOC - allocate and zero memory 495331Samw * MEM_STRDUP - string copy 505331Samw * MEM_REALLOC - reallocate memory 515331Samw * MEM_FREE - free memory 525331Samw */ 535331Samw 545331Samw #include <sys/types.h> 555331Samw #include <sys/sysmacros.h> 565331Samw 575331Samw #ifndef _KERNEL 585331Samw #include <stdlib.h> 595331Samw #include <string.h> 605331Samw 615331Samw #define MEM_MALLOC(AREA, SIZE) malloc(SIZE) 625331Samw #define MEM_ZALLOC(AREA, SIZE) calloc((SIZE), 1) 635331Samw #define MEM_STRDUP(AREA, PTR) strdup(PTR) 645331Samw #define MEM_REALLOC(AREA, PTR, SIZE) realloc((PTR), (SIZE)) 655331Samw #define MEM_FREE(AREA, PTR) free(PTR) 665331Samw 675331Samw #else /* _KERNEL */ 685331Samw 69*11963SAfshin.Ardakani@Sun.COM void *smb_mem_alloc(size_t); 70*11963SAfshin.Ardakani@Sun.COM void *smb_mem_zalloc(size_t); 71*11963SAfshin.Ardakani@Sun.COM void smb_mem_free(void *); 72*11963SAfshin.Ardakani@Sun.COM char *smb_mem_strdup(const char *); 735331Samw 74*11963SAfshin.Ardakani@Sun.COM #define MEM_MALLOC(AREA, SIZE) smb_mem_alloc(SIZE) 75*11963SAfshin.Ardakani@Sun.COM #define MEM_ZALLOC(AREA, SIZE) smb_mem_zalloc(SIZE) 76*11963SAfshin.Ardakani@Sun.COM #define MEM_FREE(AREA, PTR) smb_mem_free(PTR) 775331Samw 785331Samw #endif /* _KERNEL */ 795331Samw 805331Samw #ifdef __cplusplus 815331Samw } 825331Samw #endif 835331Samw 845331Samw #endif /* _SMBSRV_ALLOC_H */ 85