xref: /titanic_51/usr/src/uts/common/smbsrv/alloc.h (revision 9fb67ea305c66b6a297583b9b0db6796b0dfe497)
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 /*
22*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23da6c28aaSamw  * Use is subject to license terms.
24da6c28aaSamw  */
25da6c28aaSamw 
26da6c28aaSamw #ifndef	_SMBSRV_ALLOC_H
27da6c28aaSamw #define	_SMBSRV_ALLOC_H
28da6c28aaSamw 
29da6c28aaSamw #ifdef __cplusplus
30da6c28aaSamw extern "C" {
31da6c28aaSamw #endif
32da6c28aaSamw 
33da6c28aaSamw /*
34da6c28aaSamw  * Memory management macros to aid in developing code that can
35da6c28aaSamw  * be compiled for both user and kernel.
36da6c28aaSamw  *
37da6c28aaSamw  * Set the AREA parameter to a short text string that is a hint
38da6c28aaSamw  * about the subsystem calling the function. example: "smbrdr"
39da6c28aaSamw  *
40da6c28aaSamw  * Do not mix usage of these macros with malloc/free functions.
41da6c28aaSamw  * It will not work.
42da6c28aaSamw  *
43da6c28aaSamw  * All library code shared between user and kernel must use
44da6c28aaSamw  * these functions instead of malloc/free/kmem_*.
45da6c28aaSamw  *
46da6c28aaSamw  * Quick Summary
47da6c28aaSamw  * MEM_MALLOC - allocate memory
48da6c28aaSamw  * MEM_ZALLOC - allocate and zero memory
49da6c28aaSamw  * MEM_STRDUP - string copy
50da6c28aaSamw  * MEM_REALLOC - reallocate memory
51da6c28aaSamw  * MEM_FREE -  free memory
52da6c28aaSamw  */
53da6c28aaSamw 
54da6c28aaSamw #include <sys/types.h>
55da6c28aaSamw #include <sys/sysmacros.h>
56da6c28aaSamw 
57da6c28aaSamw #ifndef _KERNEL
58da6c28aaSamw #include <stdlib.h>
59da6c28aaSamw #include <string.h>
60da6c28aaSamw 
61da6c28aaSamw #define	MEM_MALLOC(AREA, SIZE) malloc(SIZE)
62da6c28aaSamw #define	MEM_ZALLOC(AREA, SIZE) calloc((SIZE), 1)
63da6c28aaSamw #define	MEM_STRDUP(AREA, PTR) strdup(PTR)
64da6c28aaSamw #define	MEM_REALLOC(AREA, PTR, SIZE) realloc((PTR), (SIZE))
65da6c28aaSamw #define	MEM_FREE(AREA, PTR) free(PTR)
66da6c28aaSamw 
67da6c28aaSamw #else /* _KERNEL */
68da6c28aaSamw 
69*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void *smb_mem_alloc(size_t);
70*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void *smb_mem_zalloc(size_t);
71*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void smb_mem_free(void *);
72*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States char *smb_mem_strdup(const char *);
73da6c28aaSamw 
74*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define	MEM_MALLOC(AREA, SIZE)	smb_mem_alloc(SIZE)
75*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define	MEM_ZALLOC(AREA, SIZE)	smb_mem_zalloc(SIZE)
76*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #define	MEM_FREE(AREA, PTR)	smb_mem_free(PTR)
77da6c28aaSamw 
78da6c28aaSamw #endif /* _KERNEL */
79da6c28aaSamw 
80da6c28aaSamw #ifdef __cplusplus
81da6c28aaSamw }
82da6c28aaSamw #endif
83da6c28aaSamw 
84da6c28aaSamw #endif	/* _SMBSRV_ALLOC_H */
85