xref: /illumos-gate/usr/src/uts/common/smbsrv/alloc.h (revision cf9691b98ccefac465372c1b1b779ed4834d8020)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SMBSRV_ALLOC_H
27 #define	_SMBSRV_ALLOC_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Memory management macros to aid in developing code that can
37  * be compiled for both user and kernel.
38  *
39  * Set the AREA parameter to a short text string that is a hint
40  * about the subsystem calling the function. example: "smbrdr"
41  *
42  * Do not mix usage of these macros with malloc/free functions.
43  * It will not work.
44  *
45  * All library code shared between user and kernel must use
46  * these functions instead of malloc/free/kmem_*.
47  *
48  * Quick Summary
49  * MEM_MALLOC - allocate memory
50  * MEM_ZALLOC - allocate and zero memory
51  * MEM_STRDUP - string copy
52  * MEM_REALLOC - reallocate memory
53  * MEM_FREE -  free memory
54  */
55 
56 #include <sys/types.h>
57 #include <sys/sysmacros.h>
58 
59 #ifndef _KERNEL
60 #include <stdlib.h>
61 #include <string.h>
62 
63 #define	MEM_MALLOC(AREA, SIZE) malloc(SIZE)
64 #define	MEM_ZALLOC(AREA, SIZE) calloc((SIZE), 1)
65 #define	MEM_STRDUP(AREA, PTR) strdup(PTR)
66 #define	MEM_REALLOC(AREA, PTR, SIZE) realloc((PTR), (SIZE))
67 #define	MEM_FREE(AREA, PTR) free(PTR)
68 
69 #else /* _KERNEL */
70 
71 void *mem_malloc(uint32_t size);
72 void *mem_zalloc(uint32_t size);
73 char *mem_strdup(const char *ptr);
74 void *mem_realloc(void *ptr, uint32_t size);
75 void smb_mem_free(void *ptr);
76 
77 #define	MEM_MALLOC(AREA, SIZE) mem_malloc(SIZE)
78 #define	MEM_ZALLOC(AREA, SIZE) mem_zalloc(SIZE)
79 #define	MEM_STRDUP(AREA, PTR) mem_strdup(PTR)
80 #define	MEM_REALLOC(AREA, PTR, SIZE) mem_realloc((PTR), (SIZE))
81 #define	MEM_FREE(AREA, PTR) smb_mem_free(PTR)
82 
83 #endif /* _KERNEL */
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif	/* _SMBSRV_ALLOC_H */
90