]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39236c6e | 2 | * Copyright (c) 2000-2013 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */ | |
29 | /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */ | |
30 | /* | |
31 | * Copyright (c) 1987, 1993 | |
32 | * The Regents of the University of California. All rights reserved. | |
33 | * | |
34 | * Redistribution and use in source and binary forms, with or without | |
35 | * modification, are permitted provided that the following conditions | |
36 | * are met: | |
37 | * 1. Redistributions of source code must retain the above copyright | |
38 | * notice, this list of conditions and the following disclaimer. | |
39 | * 2. Redistributions in binary form must reproduce the above copyright | |
40 | * notice, this list of conditions and the following disclaimer in the | |
41 | * documentation and/or other materials provided with the distribution. | |
42 | * 3. All advertising materials mentioning features or use of this software | |
43 | * must display the following acknowledgement: | |
44 | * This product includes software developed by the University of | |
45 | * California, Berkeley and its contributors. | |
46 | * 4. Neither the name of the University nor the names of its contributors | |
47 | * may be used to endorse or promote products derived from this software | |
48 | * without specific prior written permission. | |
49 | * | |
50 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
51 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
53 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
54 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
55 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
56 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
57 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
58 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
59 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
60 | * SUCH DAMAGE. | |
61 | * | |
62 | * @(#)malloc.h 8.5 (Berkeley) 5/3/95 | |
63 | */ | |
2d21ac55 A |
64 | /* |
65 | * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce | |
66 | * support for mandatory and extensible security protections. This notice | |
67 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
68 | * Version 2.0. | |
69 | */ | |
1c79356b A |
70 | |
71 | #ifndef _SYS_MALLOC_H_ | |
72 | #define _SYS_MALLOC_H_ | |
73 | ||
9bccf70c A |
74 | #include <sys/appleapiopts.h> |
75 | ||
1c79356b | 76 | |
91447636 | 77 | #ifdef KERNEL |
1c79356b A |
78 | /* |
79 | * flags to malloc | |
80 | */ | |
81 | #define M_WAITOK 0x0000 | |
82 | #define M_NOWAIT 0x0001 | |
55e303ae | 83 | #define M_ZERO 0x0004 /* bzero the allocation */ |
813fb2f6 | 84 | #define M_NULL 0x0008 /* return NULL if space is unavailable*/ |
91447636 A |
85 | |
86 | #ifdef BSD_KERNEL_PRIVATE | |
87 | ||
2d21ac55 | 88 | #define KMEMSTATS 0 |
91447636 | 89 | |
1c79356b A |
90 | /* |
91 | * Types of memory to be allocated (not all are used by us) | |
92 | */ | |
93 | #define M_FREE 0 /* should be on free list */ | |
94 | #define M_MBUF 1 /* mbuf */ | |
95 | #define M_DEVBUF 2 /* device driver memory */ | |
96 | #define M_SOCKET 3 /* socket structure */ | |
97 | #define M_PCB 4 /* protocol control block */ | |
98 | #define M_RTABLE 5 /* routing tables */ | |
99 | #define M_HTABLE 6 /* IMP host tables */ | |
100 | #define M_FTABLE 7 /* fragment reassembly header */ | |
101 | #define M_ZOMBIE 8 /* zombie proc status */ | |
102 | #define M_IFADDR 9 /* interface address */ | |
103 | #define M_SOOPTS 10 /* socket options */ | |
104 | #define M_SONAME 11 /* socket name */ | |
105 | #define M_NAMEI 12 /* namei path name buffer */ | |
106 | #define M_GPROF 13 /* kernel profiling buffer */ | |
107 | #define M_IOCTLOPS 14 /* ioctl data buffer */ | |
108 | #define M_MAPMEM 15 /* mapped memory descriptors */ | |
109 | #define M_CRED 16 /* credentials */ | |
110 | #define M_PGRP 17 /* process group header */ | |
111 | #define M_SESSION 18 /* session header */ | |
91447636 | 112 | #define M_IOV32 19 /* large iov's for 32 bit process */ |
1c79356b A |
113 | #define M_MOUNT 20 /* vfs mount struct */ |
114 | #define M_FHANDLE 21 /* network file handle */ | |
115 | #define M_NFSREQ 22 /* NFS request header */ | |
116 | #define M_NFSMNT 23 /* NFS mount structure */ | |
117 | #define M_NFSNODE 24 /* NFS vnode private part */ | |
118 | #define M_VNODE 25 /* Dynamically allocated vnodes */ | |
119 | #define M_CACHE 26 /* Dynamically allocated cache entries */ | |
120 | #define M_DQUOT 27 /* UFS quota entries */ | |
39236c6e | 121 | #define M_PROC_UUID_POLICY 28 /* proc UUID policy entries */ |
1c79356b | 122 | #define M_SHM 29 /* SVID compatible shared memory segments */ |
2d21ac55 A |
123 | #define M_PLIMIT 30 /* plimit structures */ |
124 | #define M_SIGACTS 31 /* sigacts structures */ | |
1c79356b A |
125 | #define M_VMOBJ 32 /* VM object structure */ |
126 | #define M_VMOBJHASH 33 /* VM object hash structure */ | |
127 | #define M_VMPMAP 34 /* VM pmap */ | |
128 | #define M_VMPVENT 35 /* VM phys-virt mapping entry */ | |
129 | #define M_VMPAGER 36 /* XXX: VM pager struct */ | |
130 | #define M_VMPGDATA 37 /* XXX: VM pager private data */ | |
91447636 | 131 | #define M_FILEPROC 38 /* Open file structure */ |
1c79356b A |
132 | #define M_FILEDESC 39 /* Open file descriptor table */ |
133 | #define M_LOCKF 40 /* Byte-range locking structures */ | |
134 | #define M_PROC 41 /* Proc structures */ | |
2d21ac55 | 135 | #define M_PSTATS 42 /* pstats proc sub-structures */ |
1c79356b A |
136 | #define M_SEGMENT 43 /* Segment for LFS */ |
137 | #define M_LFSNODE 44 /* LFS vnode private part */ | |
138 | #define M_FFSNODE 45 /* FFS vnode private part */ | |
139 | #define M_MFSNODE 46 /* MFS vnode private part */ | |
91447636 A |
140 | #define M_NQLEASE 47 /* XXX: Nqnfs lease */ |
141 | #define M_NQMHOST 48 /* XXX: Nqnfs host address table */ | |
1c79356b | 142 | #define M_NETADDR 49 /* Export host address structure */ |
2d21ac55 A |
143 | #define M_NFSSVC 50 /* NFS server structure */ |
144 | #define M_NFSUID 51 /* XXX: NFS uid mapping structure */ | |
145 | #define M_NFSD 52 /* NFS server daemon structure */ | |
1c79356b A |
146 | #define M_IPMOPTS 53 /* internet multicast options */ |
147 | #define M_IPMADDR 54 /* internet multicast address */ | |
148 | #define M_IFMADDR 55 /* link-level multicast address */ | |
149 | #define M_MRTABLE 56 /* multicast routing tables */ | |
150 | #define M_ISOFSMNT 57 /* ISOFS mount structure */ | |
151 | #define M_ISOFSNODE 58 /* ISOFS vnode private part */ | |
152 | #define M_NFSRVDESC 59 /* NFS server socket descriptor */ | |
153 | #define M_NFSDIROFF 60 /* NFS directory offset data */ | |
154 | #define M_NFSBIGFH 61 /* NFS version 3 file handle */ | |
155 | #define M_MSDOSFSMNT 62 /* MSDOS FS mount structure */ | |
156 | #define M_MSDOSFSFAT 63 /* MSDOS FS fat table */ | |
157 | #define M_MSDOSFSNODE 64 /* MSDOS FS vnode private part */ | |
158 | #define M_TTYS 65 /* allocated tty structures */ | |
159 | #define M_EXEC 66 /* argument lists & other mem used by exec */ | |
160 | #define M_MISCFSMNT 67 /* miscfs mount structures */ | |
161 | #define M_MISCFSNODE 68 /* miscfs vnode private part */ | |
162 | #define M_ADOSFSMNT 69 /* adosfs mount structures */ | |
163 | #define M_ADOSFSNODE 70 /* adosfs vnode private part */ | |
164 | #define M_ANODE 71 /* adosfs anode structures and tables. */ | |
165 | #define M_BUFHDR 72 /* File buffer cache headers */ | |
166 | #define M_OFILETABL 73 /* Open file descriptor table */ | |
167 | #define M_MCLUST 74 /* mbuf cluster buffers */ | |
39037602 A |
168 | /* unused 75 */ |
169 | /* unused 76 */ | |
170 | /* unused 77 */ | |
39236c6e A |
171 | /* unused 78 */ |
172 | /* unused 79 */ | |
1c79356b A |
173 | #define M_TEMP 80 /* misc temporary data buffers */ |
174 | #define M_SECA 81 /* security associations, key management */ | |
175 | #define M_DEVFS 82 | |
176 | #define M_IPFW 83 /* IP Forwarding/NAT */ | |
9bccf70c A |
177 | #define M_UDFNODE 84 /* UDF inodes */ |
178 | #define M_UDFMNT 85 /* UDF mount structures */ | |
179 | #define M_IP6NDP 86 /* IPv6 Neighbour Discovery*/ | |
180 | #define M_IP6OPT 87 /* IPv6 options management */ | |
181 | #define M_IP6MISC 88 /* IPv6 misc. memory */ | |
fe8ab488 | 182 | /* unused 89 */ |
9bccf70c | 183 | #define M_IGMP 90 |
39037602 A |
184 | /* unused 91 */ |
185 | /* unused 92 */ | |
55e303ae | 186 | #define M_SPECINFO 93 /* special file node */ |
39037602 A |
187 | #define M_KQUEUE 94 /* kqueue system */ |
188 | /* unused 95 */ | |
91447636 A |
189 | #define M_CLRDAHEAD 96 /* storage for cluster read-ahead state */ |
190 | #define M_CLWRBEHIND 97 /* storage for cluster write-behind state */ | |
191 | #define M_IOV64 98 /* large iov's for 64 bit process */ | |
192 | #define M_FILEGLOB 99 /* fileglobal */ | |
193 | #define M_KAUTH 100 /* kauth subsystem */ | |
194 | #define M_DUMMYNET 101 /* dummynet */ | |
39236c6e | 195 | /* M_UNSAFEFS 102 */ |
2d21ac55 A |
196 | #define M_MACPIPELABEL 103 /* MAC pipe labels */ |
197 | #define M_MACTEMP 104 /* MAC framework */ | |
198 | #define M_SBUF 105 /* string buffers */ | |
199 | #define M_EXTATTR 106 /* extended attribute */ | |
3e170ce0 A |
200 | #define M_SELECT 107 /* per-thread select memory */ |
201 | /* M_TRAFFIC_MGT 108 */ | |
39037602 | 202 | #if FS_COMPRESSION |
b0d623f7 | 203 | #define M_DECMPFS_CNODE 109 /* decmpfs cnode structures */ |
39037602 | 204 | #endif /* FS_COMPRESSION */ |
6d2010ae A |
205 | #define M_INMFILTER 110 /* IPv4 multicast PCB-layer source filter */ |
206 | #define M_IPMSOURCE 111 /* IPv4 multicast IGMP-layer source filter */ | |
207 | #define M_IN6MFILTER 112 /* IPv6 multicast PCB-layer source filter */ | |
208 | #define M_IP6MOPTS 113 /* IPv6 multicast options */ | |
209 | #define M_IP6MSOURCE 114 /* IPv6 multicast MLD-layer source filter */ | |
39236c6e A |
210 | #define M_FLOW_DIVERT_PCB 115 /* flow divert control block */ |
211 | #define M_FLOW_DIVERT_GROUP 116 /* flow divert socket group */ | |
212 | #define M_IP6CGA 117 | |
fe8ab488 A |
213 | #define M_NECP 118 /* General NECP policy data */ |
214 | #define M_NECP_SESSION_POLICY 119 /* NECP session policies */ | |
215 | #define M_NECP_SOCKET_POLICY 120 /* NECP socket-level policies */ | |
216 | #define M_NECP_IP_POLICY 121 /* NECP IP-level policies */ | |
217 | #define M_FD_VN_DATA 122 /* Per fd vnode data */ | |
218 | #define M_FD_DIRBUF 123 /* Directory entries' buffer */ | |
3e170ce0 | 219 | #define M_NETAGENT 124 /* Network Agents */ |
5ba3f43e A |
220 | #define M_EVENTHANDLER 125 /* Eventhandler */ |
221 | #define M_LLTABLE 126 /* Link layer table */ | |
222 | #define M_NWKWQ 127 /* Network work queue */ | |
2d21ac55 | 223 | |
5ba3f43e | 224 | #define M_LAST 128 /* Must be last type + 1 */ |
1c79356b | 225 | |
91447636 A |
226 | #else /* BSD_KERNEL_PRIVATE */ |
227 | ||
228 | #define M_RTABLE 5 /* routing tables */ | |
229 | #define M_IFADDR 9 /* interface address (IOFireWireIP)*/ | |
230 | #define M_LOCKF 40 /* Byte-range locking structures (msdos) */ | |
231 | #define M_TEMP 80 /* misc temporary data buffers */ | |
91447636 A |
232 | #define M_KAUTH 100 /* kauth subsystem (smb) */ |
233 | #define M_SONAME 11 /* socket name (smb) */ | |
234 | #define M_PCB 4 /* protocol control block (smb) */ | |
235 | #define M_UDFNODE 84 /* UDF inodes (udf)*/ | |
236 | #define M_UDFMNT 85 /* UDF mount structures (udf)*/ | |
237 | ||
238 | #endif /* BSD_KERNEL_PRIVATE */ | |
239 | ||
240 | #ifdef BSD_KERNEL_PRIVATE | |
241 | ||
2d21ac55 | 242 | #if KMEMSTATS |
1c79356b A |
243 | struct kmemstats { |
244 | long ks_inuse; /* # of packets of this type currently | |
245 | * in use */ | |
246 | long ks_calls; /* total packets of this type ever allocated */ | |
247 | long ks_memuse; /* total memory held in bytes */ | |
248 | u_short ks_limblocks; /* number of times blocked for hitting limit */ | |
249 | u_short ks_mapblocks; /* number of times blocked for kernel map */ | |
250 | long ks_maxused; /* maximum number ever used */ | |
251 | long ks_limit; /* most that are allowed to exist */ | |
252 | long ks_size; /* sizes of this thing that are allocated */ | |
253 | long ks_spare; | |
254 | }; | |
255 | ||
1c79356b | 256 | extern struct kmemstats kmemstats[]; |
2d21ac55 | 257 | #endif /* KMEMSTATS */ |
91447636 A |
258 | |
259 | #endif /* BSD_KERNEL_PRIVATE */ | |
1c79356b A |
260 | |
261 | /* | |
262 | * The malloc/free primatives used | |
263 | * by the BSD kernel code. | |
264 | */ | |
813fb2f6 | 265 | #ifdef XNU_KERNEL_PRIVATE |
3e170ce0 A |
266 | |
267 | #include <mach/vm_types.h> | |
268 | ||
5ba3f43e A |
269 | #define MALLOC(space, cast, size, type, flags) \ |
270 | ({ VM_ALLOC_SITE_STATIC(0, 0); \ | |
3e170ce0 | 271 | (space) = (cast)__MALLOC(size, type, flags, &site); }) |
5ba3f43e A |
272 | |
273 | #define REALLOC(space, cast, addr, size, type, flags) \ | |
274 | ({ VM_ALLOC_SITE_STATIC(0, 0); \ | |
3e170ce0 A |
275 | (space) = (cast)__REALLOC(addr, size, type, flags, &site); }) |
276 | ||
5ba3f43e A |
277 | #define _MALLOC(size, type, flags) \ |
278 | ({ VM_ALLOC_SITE_STATIC(0, 0); \ | |
3e170ce0 | 279 | __MALLOC(size, type, flags, &site); }) |
5ba3f43e A |
280 | #define _REALLOC(addr, size, type, flags) \ |
281 | ({ VM_ALLOC_SITE_STATIC(0, 0); \ | |
3e170ce0 A |
282 | __REALLOC(addr, size, type, flags, &site); }) |
283 | ||
5ba3f43e A |
284 | #define _MALLOC_ZONE(size, type, flags) \ |
285 | ({ VM_ALLOC_SITE_STATIC(0, 0); \ | |
3e170ce0 A |
286 | __MALLOC_ZONE(size, type, flags, &site); }) |
287 | ||
288 | #define FREE(addr, type) \ | |
289 | _FREE((void *)addr, type) | |
290 | ||
291 | #define MALLOC_ZONE(space, cast, size, type, flags) \ | |
292 | (space) = (cast)_MALLOC_ZONE(size, type, flags) | |
293 | ||
294 | #define FREE_ZONE(addr, size, type) \ | |
295 | _FREE_ZONE((void *)addr, size, type) | |
296 | ||
297 | extern void *__MALLOC( | |
298 | size_t size, | |
299 | int type, | |
300 | int flags, | |
5ba3f43e | 301 | vm_allocation_site_t *site) __attribute__((alloc_size(1))); |
3e170ce0 A |
302 | |
303 | extern void _FREE( | |
304 | void *addr, | |
305 | int type); | |
306 | ||
307 | extern void *__REALLOC( | |
308 | void *addr, | |
309 | size_t size, | |
310 | int type, | |
311 | int flags, | |
5ba3f43e | 312 | vm_allocation_site_t *site) __attribute__((alloc_size(2))); |
3e170ce0 A |
313 | |
314 | extern void *__MALLOC_ZONE( | |
315 | size_t size, | |
316 | int type, | |
317 | int flags, | |
318 | vm_allocation_site_t *site); | |
319 | ||
320 | extern void _FREE_ZONE( | |
321 | void *elem, | |
322 | size_t size, | |
323 | int type); | |
324 | ||
325 | #else /* XNU_KERNEL_PRIVATE */ | |
326 | ||
1c79356b A |
327 | #define MALLOC(space, cast, size, type, flags) \ |
328 | (space) = (cast)_MALLOC(size, type, flags) | |
329 | ||
330 | #define FREE(addr, type) \ | |
331 | _FREE((void *)addr, type) | |
332 | ||
6d2010ae A |
333 | #define REALLOC(space, cast, addr, size, type, flags) \ |
334 | (space) = (cast)_REALLOC(addr, size, type, flags) | |
335 | ||
1c79356b A |
336 | #define MALLOC_ZONE(space, cast, size, type, flags) \ |
337 | (space) = (cast)_MALLOC_ZONE(size, type, flags) | |
338 | ||
339 | #define FREE_ZONE(addr, size, type) \ | |
340 | _FREE_ZONE((void *)addr, size, type) | |
341 | ||
91447636 | 342 | extern void *_MALLOC( |
1c79356b A |
343 | size_t size, |
344 | int type, | |
91447636 | 345 | int flags); |
1c79356b | 346 | |
91447636 | 347 | extern void _FREE( |
1c79356b | 348 | void *addr, |
91447636 | 349 | int type); |
1c79356b | 350 | |
6d2010ae A |
351 | extern void *_REALLOC( |
352 | void *addr, | |
353 | size_t size, | |
354 | int type, | |
355 | int flags); | |
356 | ||
91447636 | 357 | extern void *_MALLOC_ZONE( |
1c79356b A |
358 | size_t size, |
359 | int type, | |
91447636 | 360 | int flags); |
1c79356b | 361 | |
91447636 | 362 | extern void _FREE_ZONE( |
1c79356b A |
363 | void *elem, |
364 | size_t size, | |
91447636 | 365 | int type); |
1c79356b | 366 | |
3e170ce0 A |
367 | |
368 | #endif /* !XNU_KERNEL_PRIVATE */ | |
369 | ||
1c79356b A |
370 | #endif /* KERNEL */ |
371 | ||
372 | #endif /* _SYS_MALLOC_H_ */ |