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