]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/malloc.h
4d7181d44a28ffab3fefc3dd028994ea65efac03
[apple/xnu.git] / bsd / sys / malloc.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
31 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
32 /*
33 * Copyright (c) 1987, 1993
34 * The Regents of the University of California. All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 * @(#)malloc.h 8.5 (Berkeley) 5/3/95
65 */
66
67 #ifndef _SYS_MALLOC_H_
68 #define _SYS_MALLOC_H_
69
70 #include <sys/appleapiopts.h>
71
72
73 #ifdef KERNEL
74 /*
75 * flags to malloc
76 */
77 #define M_WAITOK 0x0000
78 #define M_NOWAIT 0x0001
79 #define M_ZERO 0x0004 /* bzero the allocation */
80
81
82 #ifdef BSD_KERNEL_PRIVATE
83
84 #define KMEMSTATS
85
86 /*
87 * Types of memory to be allocated (not all are used by us)
88 */
89 #define M_FREE 0 /* should be on free list */
90 #define M_MBUF 1 /* mbuf */
91 #define M_DEVBUF 2 /* device driver memory */
92 #define M_SOCKET 3 /* socket structure */
93 #define M_PCB 4 /* protocol control block */
94 #define M_RTABLE 5 /* routing tables */
95 #define M_HTABLE 6 /* IMP host tables */
96 #define M_FTABLE 7 /* fragment reassembly header */
97 #define M_ZOMBIE 8 /* zombie proc status */
98 #define M_IFADDR 9 /* interface address */
99 #define M_SOOPTS 10 /* socket options */
100 #define M_SONAME 11 /* socket name */
101 #define M_NAMEI 12 /* namei path name buffer */
102 #define M_GPROF 13 /* kernel profiling buffer */
103 #define M_IOCTLOPS 14 /* ioctl data buffer */
104 #define M_MAPMEM 15 /* mapped memory descriptors */
105 #define M_CRED 16 /* credentials */
106 #define M_PGRP 17 /* process group header */
107 #define M_SESSION 18 /* session header */
108 #define M_IOV32 19 /* large iov's for 32 bit process */
109 #define M_MOUNT 20 /* vfs mount struct */
110 #define M_FHANDLE 21 /* network file handle */
111 #define M_NFSREQ 22 /* NFS request header */
112 #define M_NFSMNT 23 /* NFS mount structure */
113 #define M_NFSNODE 24 /* NFS vnode private part */
114 #define M_VNODE 25 /* Dynamically allocated vnodes */
115 #define M_CACHE 26 /* Dynamically allocated cache entries */
116 #define M_DQUOT 27 /* UFS quota entries */
117 #define M_UFSMNT 28 /* UFS mount structure */
118 #define M_SHM 29 /* SVID compatible shared memory segments */
119 #define M_VMMAP 30 /* VM map structures */
120 #define M_VMMAPENT 31 /* VM map entry structures */
121 #define M_VMOBJ 32 /* VM object structure */
122 #define M_VMOBJHASH 33 /* VM object hash structure */
123 #define M_VMPMAP 34 /* VM pmap */
124 #define M_VMPVENT 35 /* VM phys-virt mapping entry */
125 #define M_VMPAGER 36 /* XXX: VM pager struct */
126 #define M_VMPGDATA 37 /* XXX: VM pager private data */
127 #define M_FILEPROC 38 /* Open file structure */
128 #define M_FILEDESC 39 /* Open file descriptor table */
129 #define M_LOCKF 40 /* Byte-range locking structures */
130 #define M_PROC 41 /* Proc structures */
131 #define M_SUBPROC 42 /* Proc sub-structures */
132 #define M_SEGMENT 43 /* Segment for LFS */
133 #define M_LFSNODE 44 /* LFS vnode private part */
134 #define M_FFSNODE 45 /* FFS vnode private part */
135 #define M_MFSNODE 46 /* MFS vnode private part */
136 #define M_NQLEASE 47 /* XXX: Nqnfs lease */
137 #define M_NQMHOST 48 /* XXX: Nqnfs host address table */
138 #define M_NETADDR 49 /* Export host address structure */
139 #define M_NFSSVC 50 /* Nfs server structure */
140 #define M_NFSUID 51 /* Nfs uid mapping structure */
141 #define M_NFSD 52 /* Nfs server daemon structure */
142 #define M_IPMOPTS 53 /* internet multicast options */
143 #define M_IPMADDR 54 /* internet multicast address */
144 #define M_IFMADDR 55 /* link-level multicast address */
145 #define M_MRTABLE 56 /* multicast routing tables */
146 #define M_ISOFSMNT 57 /* ISOFS mount structure */
147 #define M_ISOFSNODE 58 /* ISOFS vnode private part */
148 #define M_NFSRVDESC 59 /* NFS server socket descriptor */
149 #define M_NFSDIROFF 60 /* NFS directory offset data */
150 #define M_NFSBIGFH 61 /* NFS version 3 file handle */
151 #define M_MSDOSFSMNT 62 /* MSDOS FS mount structure */
152 #define M_MSDOSFSFAT 63 /* MSDOS FS fat table */
153 #define M_MSDOSFSNODE 64 /* MSDOS FS vnode private part */
154 #define M_TTYS 65 /* allocated tty structures */
155 #define M_EXEC 66 /* argument lists & other mem used by exec */
156 #define M_MISCFSMNT 67 /* miscfs mount structures */
157 #define M_MISCFSNODE 68 /* miscfs vnode private part */
158 #define M_ADOSFSMNT 69 /* adosfs mount structures */
159 #define M_ADOSFSNODE 70 /* adosfs vnode private part */
160 #define M_ANODE 71 /* adosfs anode structures and tables. */
161 #define M_BUFHDR 72 /* File buffer cache headers */
162 #define M_OFILETABL 73 /* Open file descriptor table */
163 #define M_MCLUST 74 /* mbuf cluster buffers */
164 #define M_HFSMNT 75 /* HFS mount structure */
165 #define M_HFSNODE 76 /* HFS catalog node */
166 #define M_HFSFORK 77 /* HFS file fork */
167 #define M_VOLFSMNT 78 /* VOLFS mount structure */
168 #define M_VOLFSNODE 79 /* VOLFS private node part */
169 #define M_TEMP 80 /* misc temporary data buffers */
170 #define M_KTRACE M_TEMP /* ktrace buffers */
171 #define M_SECA 81 /* security associations, key management */
172 #define M_DEVFS 82
173 #define M_IPFW 83 /* IP Forwarding/NAT */
174 #define M_UDFNODE 84 /* UDF inodes */
175 #define M_UDFMNT 85 /* UDF mount structures */
176 #define M_IP6NDP 86 /* IPv6 Neighbour Discovery*/
177 #define M_IP6OPT 87 /* IPv6 options management */
178 #define M_IP6MISC 88 /* IPv6 misc. memory */
179 #define M_TSEGQ 89 /* TCP segment queue entry */
180 #define M_IGMP 90
181 #define M_JNL_JNL 91 /* Journaling: "struct journal" */
182 #define M_JNL_TR 92 /* Journaling: "struct transaction" */
183 #define M_SPECINFO 93 /* special file node */
184 #define M_KQUEUE 94 /* kqueue */
185 #define M_HFSDIRHINT 95 /* HFS directory hint */
186 #define M_CLRDAHEAD 96 /* storage for cluster read-ahead state */
187 #define M_CLWRBEHIND 97 /* storage for cluster write-behind state */
188 #define M_IOV64 98 /* large iov's for 64 bit process */
189 #define M_FILEGLOB 99 /* fileglobal */
190 #define M_KAUTH 100 /* kauth subsystem */
191 #define M_DUMMYNET 101 /* dummynet */
192 #define M_UNSAFEFS 102 /* storage for vnode lock state for unsafe FS */
193
194 #else /* BSD_KERNEL_PRIVATE */
195
196 #define M_RTABLE 5 /* routing tables */
197 #define M_IFADDR 9 /* interface address (IOFireWireIP)*/
198 #define M_LOCKF 40 /* Byte-range locking structures (msdos) */
199 #define M_TEMP 80 /* misc temporary data buffers */
200 #define M_HFSMNT 75 /* HFS mount structure (afpfs) */
201 #define M_KAUTH 100 /* kauth subsystem (smb) */
202 #define M_SONAME 11 /* socket name (smb) */
203 #define M_PCB 4 /* protocol control block (smb) */
204 #define M_UDFNODE 84 /* UDF inodes (udf)*/
205 #define M_UDFMNT 85 /* UDF mount structures (udf)*/
206
207 #endif /* BSD_KERNEL_PRIVATE */
208
209 #ifdef BSD_KERNEL_PRIVATE
210
211
212 #define M_LAST 103 /* Must be last type + 1 */
213
214 /* Strings corresponding to types of memory */
215 /* Must be in synch with the #defines above */
216 #define INITKMEMNAMES { \
217 "free", /* 0 M_FREE */ \
218 "mbuf", /* 1 M_MBUF */ \
219 "devbuf", /* 2 M_DEVBUF */ \
220 "socket", /* 3 M_SOCKET */ \
221 "pcb", /* 4 M_PCB */ \
222 "routetbl", /* 5 M_RTABLE */ \
223 "hosttbl", /* 6 M_HTABLE */ \
224 "fragtbl", /* 7 M_FTABLE */ \
225 "zombie", /* 8 M_ZOMBIE */ \
226 "ifaddr", /* 9 M_IFADDR */ \
227 "soopts", /* 10 M_SOOPTS */ \
228 "soname", /* 11 M_SONAME */ \
229 "namei", /* 12 M_NAMEI */ \
230 "gprof", /* 13 M_GPROF */ \
231 "ioctlops", /* 14 M_IOCTLOPS */ \
232 "mapmem", /* 15 M_MAPMEM */ \
233 "cred", /* 16 M_CRED */ \
234 "pgrp", /* 17 M_PGRP */ \
235 "session", /* 18 M_SESSION */ \
236 "iov32", /* 19 M_IOV32 */ \
237 "mount", /* 20 M_MOUNT */ \
238 "fhandle", /* 21 M_FHANDLE */ \
239 "NFS req", /* 22 M_NFSREQ */ \
240 "NFS mount", /* 23 M_NFSMNT */ \
241 "NFS node", /* 24 M_NFSNODE */ \
242 "vnodes", /* 25 M_VNODE */ \
243 "namecache", /* 26 M_CACHE */ \
244 "UFS quota", /* 27 M_DQUOT */ \
245 "UFS mount", /* 28 M_UFSMNT */ \
246 "shm", /* 29 M_SHM */ \
247 "VM map", /* 30 M_VMMAP */ \
248 "VM mapent", /* 31 M_VMMAPENT */ \
249 "VM object", /* 32 M_VMOBJ */ \
250 "VM objhash", /* 33 M_VMOBJHASH */ \
251 "VM pmap", /* 34 M_VMPMAP */ \
252 "VM pvmap", /* 35 M_VMPVENT */ \
253 "VM pager", /* 36 M_VMPAGER */ \
254 "VM pgdata", /* 37 M_VMPGDATA */ \
255 "fileproc", /* 38 M_FILEPROC */ \
256 "file desc", /* 39 M_FILEDESC */ \
257 "lockf", /* 40 M_LOCKF */ \
258 "proc", /* 41 M_PROC */ \
259 "subproc", /* 42 M_SUBPROC */ \
260 "LFS segment", /* 43 M_SEGMENT */ \
261 "LFS node", /* 44 M_LFSNODE */ \
262 "FFS node", /* 45 M_FFSNODE */ \
263 "MFS node", /* 46 M_MFSNODE */ \
264 "NQNFS Lease", /* 47 M_NQLEASE */ \
265 "NQNFS Host", /* 48 M_NQMHOST */ \
266 "Export Host", /* 49 M_NETADDR */ \
267 "NFS srvsock", /* 50 M_NFSSVC */ \
268 "NFS uid", /* 51 M_NFSUID */ \
269 "NFS daemon", /* 52 M_NFSD */ \
270 "ip_moptions", /* 53 M_IPMOPTS */ \
271 "in_multi", /* 54 M_IPMADDR */ \
272 "ether_multi", /* 55 M_IFMADDR */ \
273 "mrt", /* 56 M_MRTABLE */ \
274 "ISOFS mount", /* 57 M_ISOFSMNT */ \
275 "ISOFS node", /* 58 M_ISOFSNODE */ \
276 "NFSV3 srvdesc",/* 59 M_NFSRVDESC */ \
277 "NFSV3 diroff", /* 60 M_NFSDIROFF */ \
278 "NFSV3 bigfh", /* 61 M_NFSBIGFH */ \
279 "MSDOSFS mount",/* 62 M_MSDOSFSMNT */ \
280 "MSDOSFS fat", /* 63 M_MSDOSFSFAT */ \
281 "MSDOSFS node", /* 64 M_MSDOSFSNODE */ \
282 "ttys", /* 65 M_TTYS */ \
283 "exec", /* 66 M_EXEC */ \
284 "miscfs mount", /* 67 M_MISCFSMNT */ \
285 "miscfs node", /* 68 M_MISCFSNODE */ \
286 "adosfs mount", /* 69 M_ADOSFSMNT */ \
287 "adosfs node", /* 70 M_ADOSFSNODE */ \
288 "adosfs anode", /* 71 M_ANODE */ \
289 "buf hdrs", /* 72 M_BUFHDR */ \
290 "ofile tabl", /* 73 M_OFILETABL */ \
291 "mbuf clust", /* 74 M_MCLUST */ \
292 "HFS mount", /* 75 M_HFSMNT */ \
293 "HFS node", /* 76 M_HFSNODE */ \
294 "HFS fork", /* 77 M_HFSFORK */ \
295 "VOLFS mount", /* 78 M_VOLFSMNT */ \
296 "VOLFS node", /* 79 M_VOLFSNODE */ \
297 "temp", /* 80 M_TEMP */ \
298 "key mgmt", /* 81 M_SECA */ \
299 "DEVFS", /* 82 M_DEVFS */ \
300 "IpFw/IpAcct", /* 83 M_IPFW */ \
301 "UDF node", /* 84 M_UDFNODE */ \
302 "UDF mount", /* 85 M_UDFMNT */ \
303 "IPv6 NDP", /* 86 M_IP6NDP */ \
304 "IPv6 options", /* 87 M_IP6OPT */ \
305 "IPv6 Misc", /* 88 M_IP6MISC */\
306 "TCP Segment Q",/* 89 M_TSEGQ */\
307 "IGMP state", /* 90 M_IGMP */\
308 "Journal", /* 91 M_JNL_JNL */\
309 "Transaction", /* 92 M_JNL_TR */\
310 "specinfo", /* 93 M_SPECINFO */\
311 "kqueue", /* 94 M_KQUEUE */\
312 "HFS dirhint", /* 95 M_HFSDIRHINT */ \
313 "cluster_read", /* 96 M_CLRDAHEAD */ \
314 "cluster_write",/* 97 M_CLWRBEHIND */ \
315 "iov64", /* 98 M_IOV64 */ \
316 "fileglob", /* 99 M_FILEGLOB */ \
317 "kauth", /* 100 M_KAUTH */ \
318 "dummynet", /* 101 M_DUMMYNET */ \
319 "unsafe_fsnode" /* 102 M_UNSAFEFS */ \
320 }
321
322 struct kmemstats {
323 long ks_inuse; /* # of packets of this type currently
324 * in use */
325 long ks_calls; /* total packets of this type ever allocated */
326 long ks_memuse; /* total memory held in bytes */
327 u_short ks_limblocks; /* number of times blocked for hitting limit */
328 u_short ks_mapblocks; /* number of times blocked for kernel map */
329 long ks_maxused; /* maximum number ever used */
330 long ks_limit; /* most that are allowed to exist */
331 long ks_size; /* sizes of this thing that are allocated */
332 long ks_spare;
333 };
334
335 extern struct kmemstats kmemstats[];
336
337 #endif /* BSD_KERNEL_PRIVATE */
338
339 /*
340 * The malloc/free primatives used
341 * by the BSD kernel code.
342 */
343 #define MALLOC(space, cast, size, type, flags) \
344 (space) = (cast)_MALLOC(size, type, flags)
345
346 #define FREE(addr, type) \
347 _FREE((void *)addr, type)
348
349 #define MALLOC_ZONE(space, cast, size, type, flags) \
350 (space) = (cast)_MALLOC_ZONE(size, type, flags)
351
352 #define FREE_ZONE(addr, size, type) \
353 _FREE_ZONE((void *)addr, size, type)
354
355 extern void *_MALLOC(
356 size_t size,
357 int type,
358 int flags);
359
360 extern void _FREE(
361 void *addr,
362 int type);
363
364 extern void *_MALLOC_ZONE(
365 size_t size,
366 int type,
367 int flags);
368
369 extern void _FREE_ZONE(
370 void *elem,
371 size_t size,
372 int type);
373
374 #endif /* KERNEL */
375
376 #endif /* _SYS_MALLOC_H_ */