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