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