]>
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) 1995, 1997 Apple Computer, Inc. All Rights Reserved */ | |
29 | /* | |
30 | * Copyright (c) 1987, 1991, 1993 | |
31 | * The Regents of the University of California. All rights reserved. | |
32 | * | |
33 | * Redistribution and use in source and binary forms, with or without | |
34 | * modification, are permitted provided that the following conditions | |
35 | * are met: | |
36 | * 1. Redistributions of source code must retain the above copyright | |
37 | * notice, this list of conditions and the following disclaimer. | |
38 | * 2. Redistributions in binary form must reproduce the above copyright | |
39 | * notice, this list of conditions and the following disclaimer in the | |
40 | * documentation and/or other materials provided with the distribution. | |
41 | * 3. All advertising materials mentioning features or use of this software | |
42 | * must display the following acknowledgement: | |
43 | * This product includes software developed by the University of | |
44 | * California, Berkeley and its contributors. | |
45 | * 4. Neither the name of the University nor the names of its contributors | |
46 | * may be used to endorse or promote products derived from this software | |
47 | * without specific prior written permission. | |
48 | * | |
49 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
50 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
51 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | |
60 | * | |
61 | * @(#)kern_malloc.c 8.4 (Berkeley) 5/20/95 | |
62 | */ | |
2d21ac55 A |
63 | /* |
64 | * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce | |
65 | * support for mandatory and extensible security protections. This notice | |
66 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
67 | * Version 2.0. | |
68 | */ | |
1c79356b A |
69 | |
70 | #include <sys/param.h> | |
71 | #include <sys/malloc.h> | |
72 | ||
73 | #include <sys/socket.h> | |
74 | #include <sys/socketvar.h> | |
75 | ||
76 | #include <net/route.h> | |
fe8ab488 | 77 | #include <net/necp.h> |
1c79356b A |
78 | |
79 | #include <netinet/in.h> | |
80 | #include <netinet/in_systm.h> | |
81 | #include <netinet/ip.h> | |
82 | #include <netinet/in_pcb.h> | |
39236c6e | 83 | #include <netinet/flow_divert.h> |
1c79356b | 84 | |
55e303ae A |
85 | #include <sys/event.h> |
86 | #include <sys/eventvar.h> | |
87 | ||
91447636 A |
88 | #include <sys/proc_internal.h> |
89 | #include <sys/mount_internal.h> | |
90 | #include <sys/vnode_internal.h> | |
91 | #include <sys/ubc_internal.h> | |
1c79356b | 92 | #include <sys/namei.h> |
91447636 | 93 | #include <sys/file_internal.h> |
1c79356b A |
94 | #include <sys/filedesc.h> |
95 | #include <sys/tty.h> | |
9bccf70c | 96 | #include <sys/quota.h> |
91447636 | 97 | #include <sys/uio_internal.h> |
0c530ab8 | 98 | #include <sys/resourcevar.h> |
2d21ac55 | 99 | #include <sys/signalvar.h> |
39037602 | 100 | #include <sys/decmpfs.h> |
1c79356b | 101 | |
55e303ae | 102 | #include <miscfs/specfs/specdev.h> |
1c79356b A |
103 | |
104 | #include <nfs/rpcv2.h> | |
105 | #include <nfs/nfsproto.h> | |
106 | #include <nfs/nfsnode.h> | |
107 | #include <nfs/nfsmount.h> | |
1c79356b A |
108 | |
109 | #include <mach/mach_types.h> | |
110 | ||
111 | #include <kern/zalloc.h> | |
112 | #include <kern/kalloc.h> | |
113 | ||
39236c6e | 114 | void kmeminit(void); |
1c79356b | 115 | |
2d21ac55 A |
116 | /* Strings corresponding to types of memory. |
117 | * Must be in synch with the #defines is sys/malloc.h | |
118 | * NOTE - the reason we pass null strings in some cases is to reduce of foot | |
119 | * print as much as possible for systems where a tiny kernel is needed. | |
39037602 | 120 | * todo - We should probably redesign this and use enums for our types and only |
2d21ac55 A |
121 | * include types needed for that configuration of the kernel. This can't be |
122 | * done without some kind of kpi since several types are hardwired and exported | |
39037602 | 123 | * (for example see types M_UDFMNT, M_TEMP, etc in sys/malloc.h) |
2d21ac55 A |
124 | */ |
125 | const char *memname[] = { | |
126 | "free", /* 0 M_FREE */ | |
127 | "mbuf", /* 1 M_MBUF */ | |
128 | "devbuf", /* 2 M_DEVBUF */ | |
129 | "socket", /* 3 M_SOCKET */ | |
130 | "pcb", /* 4 M_PCB */ | |
131 | "routetbl", /* 5 M_RTABLE */ | |
132 | "hosttbl", /* 6 M_HTABLE */ | |
133 | "fragtbl", /* 7 M_FTABLE */ | |
134 | "zombie", /* 8 M_ZOMBIE */ | |
135 | "ifaddr", /* 9 M_IFADDR */ | |
136 | "soopts", /* 10 M_SOOPTS */ | |
137 | "soname", /* 11 M_SONAME */ | |
138 | "namei", /* 12 M_NAMEI */ | |
139 | "gprof", /* 13 M_GPROF */ | |
140 | "ioctlops", /* 14 M_IOCTLOPS */ | |
141 | "mapmem", /* 15 M_MAPMEM */ | |
142 | "cred", /* 16 M_CRED */ | |
143 | "pgrp", /* 17 M_PGRP */ | |
144 | "session", /* 18 M_SESSION */ | |
145 | "iov32", /* 19 M_IOV32 */ | |
146 | "mount", /* 20 M_MOUNT */ | |
147 | "fhandle", /* 21 M_FHANDLE */ | |
148 | #if (NFSCLIENT || NFSSERVER) | |
149 | "NFS req", /* 22 M_NFSREQ */ | |
150 | "NFS mount", /* 23 M_NFSMNT */ | |
151 | "NFS node", /* 24 M_NFSNODE */ | |
152 | #else | |
153 | "", /* 22 M_NFSREQ */ | |
154 | "", /* 23 M_NFSMNT */ | |
155 | "", /* 24 M_NFSNODE */ | |
156 | #endif | |
157 | "vnodes", /* 25 M_VNODE */ | |
158 | "namecache", /* 26 M_CACHE */ | |
159 | #if QUOTA | |
160 | "UFS quota", /* 27 M_DQUOT */ | |
161 | #else | |
162 | "", /* 27 M_DQUOT */ | |
163 | #endif | |
39236c6e | 164 | "proc uuid policy", /* 28 M_PROC_UUID_POLICY */ |
2d21ac55 A |
165 | #if (SYSV_SEM || SYSV_MSG || SYSV_SHM) |
166 | "shm", /* 29 M_SHM */ | |
167 | #else | |
168 | "", /* 29 M_SHM */ | |
169 | #endif | |
170 | "plimit", /* 30 M_VMMAP */ | |
171 | "sigacts", /* 31 M_VMMAPENT */ | |
172 | "VM object", /* 32 M_VMOBJ */ | |
173 | "VM objhash", /* 33 M_VMOBJHASH */ | |
174 | "VM pmap", /* 34 M_VMPMAP */ | |
175 | "VM pvmap", /* 35 M_VMPVENT */ | |
176 | "VM pager", /* 36 M_VMPAGER */ | |
177 | "VM pgdata", /* 37 M_VMPGDATA */ | |
178 | "fileproc", /* 38 M_FILEPROC */ | |
179 | "file desc", /* 39 M_FILEDESC */ | |
180 | "lockf", /* 40 M_LOCKF */ | |
181 | "proc", /* 41 M_PROC */ | |
182 | "pstats", /* 42 M_SUBPROC */ | |
183 | "LFS segment", /* 43 M_SEGMENT */ | |
184 | "LFS node", /* 44 M_LFSNODE */ | |
2d21ac55 | 185 | "", /* 45 M_FFSNODE */ |
2d21ac55 A |
186 | "MFS node", /* 46 M_MFSNODE */ |
187 | "NQNFS Lease", /* 47 M_NQLEASE */ | |
188 | "NQNFS Host", /* 48 M_NQMHOST */ | |
189 | "Export Host", /* 49 M_NETADDR */ | |
190 | #if (NFSCLIENT || NFSSERVER) | |
191 | "NFS srvsock", /* 50 M_NFSSVC */ | |
192 | "NFS uid", /* 51 M_NFSUID */ | |
193 | "NFS daemon", /* 52 M_NFSD */ | |
194 | #else | |
195 | "", /* 50 M_NFSSVC */ | |
196 | "", /* 51 M_NFSUID */ | |
197 | "", /* 52 M_NFSD */ | |
198 | #endif | |
199 | "ip_moptions", /* 53 M_IPMOPTS */ | |
200 | "in_multi", /* 54 M_IPMADDR */ | |
201 | "ether_multi", /* 55 M_IFMADDR */ | |
202 | "mrt", /* 56 M_MRTABLE */ | |
b0d623f7 A |
203 | "", /* 57 unused entry */ |
204 | "", /* 58 unused entry */ | |
2d21ac55 A |
205 | #if (NFSCLIENT || NFSSERVER) |
206 | "NFSV3 srvdesc",/* 59 M_NFSRVDESC */ | |
207 | "NFSV3 diroff", /* 60 M_NFSDIROFF */ | |
208 | "NFSV3 bigfh", /* 61 M_NFSBIGFH */ | |
209 | #else | |
210 | "", /* 59 M_NFSRVDESC */ | |
211 | "", /* 60 M_NFSDIROFF */ | |
212 | "", /* 61 M_NFSBIGFH */ | |
213 | #endif | |
214 | "MSDOSFS mount",/* 62 M_MSDOSFSMNT */ | |
215 | "MSDOSFS fat", /* 63 M_MSDOSFSFAT */ | |
216 | "MSDOSFS node", /* 64 M_MSDOSFSNODE */ | |
217 | "ttys", /* 65 M_TTYS */ | |
218 | "exec", /* 66 M_EXEC */ | |
219 | "miscfs mount", /* 67 M_MISCFSMNT */ | |
220 | "miscfs node", /* 68 M_MISCFSNODE */ | |
221 | "adosfs mount", /* 69 M_ADOSFSMNT */ | |
222 | "adosfs node", /* 70 M_ADOSFSNODE */ | |
223 | "adosfs anode", /* 71 M_ANODE */ | |
224 | "buf hdrs", /* 72 M_BUFHDR */ | |
225 | "ofile tabl", /* 73 M_OFILETABL */ | |
226 | "mbuf clust", /* 74 M_MCLUST */ | |
39037602 A |
227 | "", /* 75 unused */ |
228 | "", /* 76 unused */ | |
229 | "", /* 77 unused */ | |
230 | "", /* 78 unused */ | |
231 | "", /* 79 unused */ | |
2d21ac55 A |
232 | "temp", /* 80 M_TEMP */ |
233 | "key mgmt", /* 81 M_SECA */ | |
234 | "DEVFS", /* 82 M_DEVFS */ | |
235 | "IpFw/IpAcct", /* 83 M_IPFW */ | |
236 | "UDF node", /* 84 M_UDFNODE */ | |
237 | "UDF mount", /* 85 M_UDFMNT */ | |
238 | #if INET6 | |
239 | "IPv6 NDP", /* 86 M_IP6NDP */ | |
240 | "IPv6 options", /* 87 M_IP6OPT */ | |
241 | "IPv6 Misc", /* 88 M_IP6MISC */ | |
242 | #else | |
243 | "", /* 86 M_IP6NDP */ | |
244 | "", /* 87 M_IP6OPT */ | |
245 | "", /* 88 M_IP6MISC */ | |
246 | #endif | |
247 | "TCP Segment Q",/* 89 M_TSEGQ */ | |
248 | "IGMP state", /* 90 M_IGMP */ | |
39037602 A |
249 | "", /* 91 unused */ |
250 | "", /* 92 unused */ | |
2d21ac55 A |
251 | "specinfo", /* 93 M_SPECINFO */ |
252 | "kqueue", /* 94 M_KQUEUE */ | |
39037602 A |
253 | "", /* 95 unused */ |
254 | "cluster_read", /* 96 M_CLRDAHEAD */ | |
2d21ac55 A |
255 | "cluster_write",/* 97 M_CLWRBEHIND */ |
256 | "iov64", /* 98 M_IOV64 */ | |
257 | "fileglob", /* 99 M_FILEGLOB */ | |
258 | "kauth", /* 100 M_KAUTH */ | |
259 | "dummynet", /* 101 M_DUMMYNET */ | |
b0d623f7 | 260 | "", /* 102 M_UNSAFEFS */ |
2d21ac55 A |
261 | "macpipelabel", /* 103 M_MACPIPELABEL */ |
262 | "mactemp", /* 104 M_MACTEMP */ | |
263 | "sbuf", /* 105 M_SBUF */ | |
264 | "extattr", /* 106 M_EXTATTR */ | |
3e170ce0 | 265 | "select", /* 107 M_SELECT */ |
2d21ac55 A |
266 | #if TRAFFIC_MGT |
267 | "traffic_mgt", /* 108 M_TRAFFIC_MGT */ | |
268 | #else | |
269 | "", /* 108 M_TRAFFIC_MGT */ | |
270 | #endif | |
39037602 | 271 | #if FS_COMPRESSION |
b0d623f7 A |
272 | "decmpfs_cnode",/* 109 M_DECMPFS_CNODE */ |
273 | #else | |
274 | "", /* 109 M_DECMPFS_CNODE */ | |
39037602 | 275 | #endif /* FS_COMPRESSION */ |
6d2010ae A |
276 | "ipmfilter", /* 110 M_INMFILTER */ |
277 | "ipmsource", /* 111 M_IPMSOURCE */ | |
278 | "in6mfilter", /* 112 M_IN6MFILTER */ | |
279 | "ip6mopts", /* 113 M_IP6MOPTS */ | |
280 | "ip6msource", /* 114 M_IP6MSOURCE */ | |
39236c6e A |
281 | #if FLOW_DIVERT |
282 | "flow_divert_pcb", /* 115 M_FLOW_DIVERT_PCB */ | |
283 | "flow_divert_group", /* 116 M_FLOW_DIVERT_GROUP */ | |
284 | #else | |
285 | "", /* 115 M_FLOW_DIVERT_PCB */ | |
286 | "", /* 116 M_FLOW_DIVERT_GROUP */ | |
287 | #endif | |
288 | "ip6cga", /* 117 M_IP6CGA */ | |
fe8ab488 A |
289 | #if NECP |
290 | "necp", /* 118 M_NECP */ | |
291 | "necp_session_policy", /* 119 M_NECP_SESSION_POLICY */ | |
292 | "necp_socket_policy", /* 120 M_NECP_SOCKET_POLICY */ | |
293 | "necp_ip_policy", /* 121 M_NECP_IP_POLICY */ | |
294 | #else | |
295 | "", /* 118 M_NECP */ | |
296 | "", /* 119 M_NECP_SESSION_POLICY */ | |
297 | "", /* 120 M_NECP_SOCKET_POLICY */ | |
298 | "", /* 121 M_NECP_IP_POLICY */ | |
299 | #endif | |
300 | "fdvnodedata" /* 122 M_FD_VN_DATA */ | |
301 | "fddirbuf", /* 123 M_FD_DIRBUF */ | |
3e170ce0 | 302 | "netagent", /* 124 M_NETAGENT */ |
fe8ab488 | 303 | "" |
2d21ac55 A |
304 | }; |
305 | ||
306 | /* for use with kmzones.kz_zalloczone */ | |
6d2010ae | 307 | #define KMZ_CREATEZONE_ACCT ((void *)-3) |
1c79356b A |
308 | #define KMZ_CREATEZONE ((void *)-2) |
309 | #define KMZ_LOOKUPZONE ((void *)-1) | |
2d21ac55 | 310 | #define KMZ_MALLOC ((void *)0) |
1c79356b | 311 | #define KMZ_SHAREZONE ((void *)1) |
2d21ac55 A |
312 | |
313 | struct kmzones { | |
314 | size_t kz_elemsize; | |
315 | void *kz_zalloczone; | |
0b4c1975 | 316 | boolean_t kz_noencrypt; |
1c79356b A |
317 | } kmzones[M_LAST] = { |
318 | #define SOS(sname) sizeof (struct sname) | |
319 | #define SOX(sname) -1 | |
0b4c1975 A |
320 | { -1, 0, FALSE }, /* 0 M_FREE */ |
321 | { MSIZE, KMZ_CREATEZONE, FALSE }, /* 1 M_MBUF */ | |
322 | { 0, KMZ_MALLOC, FALSE }, /* 2 M_DEVBUF */ | |
323 | { SOS(socket), KMZ_CREATEZONE, TRUE }, /* 3 M_SOCKET */ | |
324 | { SOS(inpcb), KMZ_LOOKUPZONE, TRUE }, /* 4 M_PCB */ | |
325 | { M_MBUF, KMZ_SHAREZONE, FALSE }, /* 5 M_RTABLE */ | |
326 | { M_MBUF, KMZ_SHAREZONE, FALSE }, /* 6 M_HTABLE */ | |
327 | { M_MBUF, KMZ_SHAREZONE, FALSE }, /* 7 M_FTABLE */ | |
328 | { SOS(rusage), KMZ_CREATEZONE, TRUE }, /* 8 M_ZOMBIE */ | |
329 | { 0, KMZ_MALLOC, FALSE }, /* 9 M_IFADDR */ | |
330 | { M_MBUF, KMZ_SHAREZONE, FALSE }, /* 10 M_SOOPTS */ | |
331 | { 0, KMZ_MALLOC, FALSE }, /* 11 M_SONAME */ | |
332 | { MAXPATHLEN, KMZ_CREATEZONE, FALSE }, /* 12 M_NAMEI */ | |
333 | { 0, KMZ_MALLOC, FALSE }, /* 13 M_GPROF */ | |
334 | { 0, KMZ_MALLOC, FALSE }, /* 14 M_IOCTLOPS */ | |
335 | { 0, KMZ_MALLOC, FALSE }, /* 15 M_MAPMEM */ | |
336 | { SOS(ucred), KMZ_CREATEZONE, FALSE }, /* 16 M_CRED */ | |
337 | { SOS(pgrp), KMZ_CREATEZONE, FALSE }, /* 17 M_PGRP */ | |
338 | { SOS(session), KMZ_CREATEZONE, FALSE }, /* 18 M_SESSION */ | |
339 | { SOS(user32_iovec), KMZ_LOOKUPZONE, FALSE },/* 19 M_IOV32 */ | |
340 | { SOS(mount), KMZ_CREATEZONE, FALSE }, /* 20 M_MOUNT */ | |
341 | { 0, KMZ_MALLOC, FALSE }, /* 21 M_FHANDLE */ | |
2d21ac55 | 342 | #if (NFSCLIENT || NFSSERVER) |
0b4c1975 | 343 | { SOS(nfsreq), KMZ_CREATEZONE, FALSE }, /* 22 M_NFSREQ */ |
6d2010ae | 344 | { SOS(nfsmount),KMZ_CREATEZONE, FALSE }, /* 23 M_NFSMNT */ |
0b4c1975 | 345 | { SOS(nfsnode), KMZ_CREATEZONE, FALSE }, /* 24 M_NFSNODE */ |
2d21ac55 | 346 | #else |
0b4c1975 A |
347 | { 0, KMZ_MALLOC, FALSE }, /* 22 M_NFSREQ */ |
348 | { 0, KMZ_MALLOC, FALSE }, /* 23 M_NFSMNT */ | |
349 | { 0, KMZ_MALLOC, FALSE }, /* 24 M_NFSNODE */ | |
2d21ac55 | 350 | #endif |
0b4c1975 | 351 | { SOS(vnode), KMZ_CREATEZONE, TRUE }, /* 25 M_VNODE */ |
6d2010ae | 352 | { SOS(namecache), KMZ_CREATEZONE, FALSE }, /* 26 M_CACHE */ |
2d21ac55 | 353 | #if QUOTA |
0b4c1975 | 354 | { SOX(dquot), KMZ_LOOKUPZONE, FALSE }, /* 27 M_DQUOT */ |
2d21ac55 | 355 | #else |
0b4c1975 | 356 | { 0, KMZ_MALLOC, FALSE }, /* 27 M_DQUOT */ |
2d21ac55 | 357 | #endif |
39236c6e | 358 | { 0, KMZ_MALLOC, FALSE }, /* 28 M_PROC_UUID_POLICY */ |
6d2010ae | 359 | { 0, KMZ_MALLOC, FALSE }, /* 29 M_SHM */ |
0b4c1975 | 360 | { SOS(plimit), KMZ_CREATEZONE, TRUE }, /* 30 M_PLIMIT */ |
6d2010ae | 361 | { SOS(sigacts), KMZ_CREATEZONE_ACCT, TRUE }, /* 31 M_SIGACTS */ |
0b4c1975 A |
362 | { 0, KMZ_MALLOC, FALSE }, /* 32 M_VMOBJ */ |
363 | { 0, KMZ_MALLOC, FALSE }, /* 33 M_VMOBJHASH */ | |
364 | { 0, KMZ_MALLOC, FALSE }, /* 34 M_VMPMAP */ | |
365 | { 0, KMZ_MALLOC, FALSE }, /* 35 M_VMPVENT */ | |
366 | { 0, KMZ_MALLOC, FALSE }, /* 36 M_VMPAGER */ | |
367 | { 0, KMZ_MALLOC, FALSE }, /* 37 M_VMPGDATA */ | |
6d2010ae A |
368 | { SOS(fileproc),KMZ_CREATEZONE_ACCT, TRUE }, /* 38 M_FILEPROC */ |
369 | { SOS(filedesc),KMZ_CREATEZONE_ACCT, TRUE }, /* 39 M_FILEDESC */ | |
370 | { SOX(lockf), KMZ_CREATEZONE_ACCT, TRUE }, /* 40 M_LOCKF */ | |
0b4c1975 A |
371 | { SOS(proc), KMZ_CREATEZONE, FALSE }, /* 41 M_PROC */ |
372 | { SOS(pstats), KMZ_CREATEZONE, TRUE }, /* 42 M_PSTATS */ | |
373 | { 0, KMZ_MALLOC, FALSE }, /* 43 M_SEGMENT */ | |
374 | { M_FFSNODE, KMZ_SHAREZONE, FALSE }, /* 44 M_LFSNODE */ | |
375 | { 0, KMZ_MALLOC, FALSE }, /* 45 M_FFSNODE */ | |
376 | { M_FFSNODE, KMZ_SHAREZONE, FALSE }, /* 46 M_MFSNODE */ | |
377 | { 0, KMZ_MALLOC, FALSE }, /* 47 M_NQLEASE */ | |
378 | { 0, KMZ_MALLOC, FALSE }, /* 48 M_NQMHOST */ | |
379 | { 0, KMZ_MALLOC, FALSE }, /* 49 M_NETADDR */ | |
2d21ac55 A |
380 | #if (NFSCLIENT || NFSSERVER) |
381 | { SOX(nfsrv_sock), | |
6d2010ae | 382 | KMZ_CREATEZONE_ACCT, FALSE }, /* 50 M_NFSSVC */ |
0b4c1975 | 383 | { 0, KMZ_MALLOC, FALSE }, /* 51 M_NFSUID */ |
2d21ac55 | 384 | { SOX(nfsrvcache), |
6d2010ae | 385 | KMZ_CREATEZONE_ACCT, FALSE }, /* 52 M_NFSD */ |
2d21ac55 | 386 | #else |
0b4c1975 A |
387 | { 0, KMZ_MALLOC, FALSE }, /* 50 M_NFSSVC */ |
388 | { 0, KMZ_MALLOC, FALSE }, /* 51 M_NFSUID */ | |
389 | { 0, KMZ_MALLOC, FALSE }, /* 52 M_NFSD */ | |
2d21ac55 A |
390 | #endif |
391 | { SOX(ip_moptions), | |
0b4c1975 A |
392 | KMZ_LOOKUPZONE, FALSE }, /* 53 M_IPMOPTS */ |
393 | { SOX(in_multi),KMZ_LOOKUPZONE, FALSE }, /* 54 M_IPMADDR */ | |
2d21ac55 | 394 | { SOX(ether_multi), |
0b4c1975 A |
395 | KMZ_LOOKUPZONE, FALSE }, /* 55 M_IFMADDR */ |
396 | { SOX(mrt), KMZ_CREATEZONE, TRUE }, /* 56 M_MRTABLE */ | |
397 | { 0, KMZ_MALLOC, FALSE }, /* 57 unused entry */ | |
398 | { 0, KMZ_MALLOC, FALSE }, /* 58 unused entry */ | |
2d21ac55 A |
399 | #if (NFSCLIENT || NFSSERVER) |
400 | { SOS(nfsrv_descript), | |
6d2010ae | 401 | KMZ_CREATEZONE_ACCT, FALSE }, /* 59 M_NFSRVDESC */ |
0b4c1975 A |
402 | { SOS(nfsdmap), KMZ_CREATEZONE, FALSE }, /* 60 M_NFSDIROFF */ |
403 | { SOS(fhandle), KMZ_LOOKUPZONE, FALSE }, /* 61 M_NFSBIGFH */ | |
2d21ac55 | 404 | #else |
0b4c1975 A |
405 | { 0, KMZ_MALLOC, FALSE }, /* 59 M_NFSRVDESC */ |
406 | { 0, KMZ_MALLOC, FALSE }, /* 60 M_NFSDIROFF */ | |
407 | { 0, KMZ_MALLOC, FALSE }, /* 61 M_NFSBIGFH */ | |
2d21ac55 | 408 | #endif |
0b4c1975 A |
409 | { 0, KMZ_MALLOC, FALSE }, /* 62 M_MSDOSFSMNT */ |
410 | { 0, KMZ_MALLOC, FALSE }, /* 63 M_MSDOSFSFAT */ | |
411 | { 0, KMZ_MALLOC, FALSE }, /* 64 M_MSDOSFSNODE */ | |
412 | { SOS(tty), KMZ_CREATEZONE, FALSE }, /* 65 M_TTYS */ | |
413 | { 0, KMZ_MALLOC, FALSE }, /* 66 M_EXEC */ | |
414 | { 0, KMZ_MALLOC, FALSE }, /* 67 M_MISCFSMNT */ | |
415 | { 0, KMZ_MALLOC, FALSE }, /* 68 M_MISCFSNODE */ | |
416 | { 0, KMZ_MALLOC, FALSE }, /* 69 M_ADOSFSMNT */ | |
417 | { 0, KMZ_MALLOC, FALSE }, /* 70 M_ADOSFSNODE */ | |
418 | { 0, KMZ_MALLOC, FALSE }, /* 71 M_ANODE */ | |
6d2010ae | 419 | { 0, KMZ_MALLOC, TRUE }, /* 72 M_BUFHDR */ |
2d21ac55 | 420 | { (NDFILE * OFILESIZE), |
6d2010ae | 421 | KMZ_CREATEZONE_ACCT, FALSE }, /* 73 M_OFILETABL */ |
0b4c1975 | 422 | { MCLBYTES, KMZ_CREATEZONE, FALSE }, /* 74 M_MCLUST */ |
39037602 A |
423 | { 0, KMZ_MALLOC, FALSE }, /* 75 unused */ |
424 | { 0, KMZ_MALLOC, FALSE }, /* 76 unused */ | |
425 | { 0, KMZ_MALLOC, FALSE }, /* 77 unused */ | |
39236c6e A |
426 | { 0, KMZ_MALLOC, FALSE }, /* 78 unused */ |
427 | { 0, KMZ_MALLOC, FALSE }, /* 79 unused */ | |
0b4c1975 A |
428 | { 0, KMZ_MALLOC, FALSE }, /* 80 M_TEMP */ |
429 | { 0, KMZ_MALLOC, FALSE }, /* 81 M_SECA */ | |
430 | { 0, KMZ_MALLOC, FALSE }, /* 82 M_DEVFS */ | |
431 | { 0, KMZ_MALLOC, FALSE }, /* 83 M_IPFW */ | |
432 | { 0, KMZ_MALLOC, FALSE }, /* 84 M_UDFNODE */ | |
433 | { 0, KMZ_MALLOC, FALSE }, /* 85 M_UDFMOUNT */ | |
434 | { 0, KMZ_MALLOC, FALSE }, /* 86 M_IP6NDP */ | |
435 | { 0, KMZ_MALLOC, FALSE }, /* 87 M_IP6OPT */ | |
436 | { 0, KMZ_MALLOC, FALSE }, /* 88 M_IP6MISC */ | |
437 | { 0, KMZ_MALLOC, FALSE }, /* 89 M_TSEGQ */ | |
438 | { 0, KMZ_MALLOC, FALSE }, /* 90 M_IGMP */ | |
39037602 A |
439 | { 0, KMZ_MALLOC, FALSE }, /* 91 unused */ |
440 | { 0, KMZ_MALLOC, FALSE }, /* 92 unused */ | |
6d2010ae A |
441 | { SOS(specinfo),KMZ_CREATEZONE, TRUE }, /* 93 M_SPECINFO */ |
442 | { SOS(kqueue), KMZ_CREATEZONE, FALSE }, /* 94 M_KQUEUE */ | |
39037602 | 443 | { 0, KMZ_MALLOC, FALSE }, /* 95 unused */ |
0b4c1975 A |
444 | { SOS(cl_readahead), KMZ_CREATEZONE, TRUE }, /* 96 M_CLRDAHEAD */ |
445 | { SOS(cl_writebehind),KMZ_CREATEZONE, TRUE }, /* 97 M_CLWRBEHIND */ | |
446 | { SOS(user64_iovec), KMZ_LOOKUPZONE, FALSE },/* 98 M_IOV64 */ | |
447 | { SOS(fileglob), KMZ_CREATEZONE, TRUE }, /* 99 M_FILEGLOB */ | |
448 | { 0, KMZ_MALLOC, FALSE }, /* 100 M_KAUTH */ | |
449 | { 0, KMZ_MALLOC, FALSE }, /* 101 M_DUMMYNET */ | |
0b4c1975 | 450 | { 0, KMZ_MALLOC, FALSE }, /* 102 M_UNSAFEFS */ |
0b4c1975 A |
451 | { 0, KMZ_MALLOC, FALSE }, /* 103 M_MACPIPELABEL */ |
452 | { 0, KMZ_MALLOC, FALSE }, /* 104 M_MACTEMP */ | |
453 | { 0, KMZ_MALLOC, FALSE }, /* 105 M_SBUF */ | |
454 | { 0, KMZ_MALLOC, FALSE }, /* 106 M_HFS_EXTATTR */ | |
3e170ce0 | 455 | { 0, KMZ_MALLOC, FALSE }, /* 107 M_SELECT */ |
0b4c1975 | 456 | { 0, KMZ_MALLOC, FALSE }, /* 108 M_TRAFFIC_MGT */ |
39037602 | 457 | #if FS_COMPRESSION |
6d2010ae | 458 | { SOS(decmpfs_cnode),KMZ_CREATEZONE , FALSE}, /* 109 M_DECMPFS_CNODE */ |
b0d623f7 | 459 | #else |
0b4c1975 | 460 | { 0, KMZ_MALLOC, FALSE }, /* 109 M_DECMPFS_CNODE */ |
39037602 | 461 | #endif /* FS_COMPRESSION */ |
6d2010ae A |
462 | { 0, KMZ_MALLOC, FALSE }, /* 110 M_INMFILTER */ |
463 | { 0, KMZ_MALLOC, FALSE }, /* 111 M_IPMSOURCE */ | |
464 | { 0, KMZ_MALLOC, FALSE }, /* 112 M_IN6MFILTER */ | |
465 | { 0, KMZ_MALLOC, FALSE }, /* 113 M_IP6MOPTS */ | |
466 | { 0, KMZ_MALLOC, FALSE }, /* 114 M_IP6MSOURCE */ | |
39236c6e A |
467 | #if FLOW_DIVERT |
468 | { SOS(flow_divert_pcb), KMZ_CREATEZONE, TRUE }, /* 115 M_FLOW_DIVERT_PCB */ | |
469 | { SOS(flow_divert_group), KMZ_CREATEZONE, TRUE }, /* 116 M_FLOW_DIVERT_GROUP */ | |
470 | #else | |
471 | { 0, KMZ_MALLOC, FALSE }, /* 115 M_FLOW_DIVERT_PCB */ | |
472 | { 0, KMZ_MALLOC, FALSE }, /* 116 M_FLOW_DIVERT_GROUP */ | |
473 | #endif /* FLOW_DIVERT */ | |
474 | { 0, KMZ_MALLOC, FALSE }, /* 117 M_IP6CGA */ | |
fe8ab488 A |
475 | { 0, KMZ_MALLOC, FALSE }, /* 118 M_NECP */ |
476 | #if NECP | |
477 | { SOS(necp_session_policy), KMZ_CREATEZONE, TRUE }, /* 119 M_NECP_SESSION_POLICY */ | |
478 | { SOS(necp_kernel_socket_policy), KMZ_CREATEZONE, TRUE }, /* 120 M_NECP_SOCKET_POLICY */ | |
479 | { SOS(necp_kernel_ip_output_policy), KMZ_CREATEZONE, TRUE }, /* 121 M_NECP_IP_POLICY */ | |
480 | #else | |
481 | { 0, KMZ_MALLOC, FALSE }, /* 119 M_NECP_SESSION_POLICY */ | |
482 | { 0, KMZ_MALLOC, FALSE }, /* 120 M_NECP_SOCKET_POLICY */ | |
483 | { 0, KMZ_MALLOC, FALSE }, /* 121 M_NECP_IP_POLICY */ | |
484 | #endif /* NECP */ | |
3e170ce0 A |
485 | { 0, KMZ_MALLOC, FALSE }, /* 122 M_FD_VN_DATA */ |
486 | { 0, KMZ_MALLOC, FALSE }, /* 123 M_FD_DIRBUF */ | |
487 | { 0, KMZ_MALLOC, FALSE }, /* 124 M_NETAGENT */ | |
1c79356b A |
488 | #undef SOS |
489 | #undef SOX | |
490 | }; | |
491 | ||
55e303ae | 492 | extern zone_t kalloc_zone(vm_size_t); /* XXX */ |
1c79356b A |
493 | |
494 | /* | |
495 | * Initialize the kernel memory allocator | |
496 | */ | |
497 | void | |
498 | kmeminit(void) | |
499 | { | |
500 | struct kmzones *kmz; | |
501 | ||
d7e50217 | 502 | if ((sizeof(kmzones)/sizeof(kmzones[0])) != (sizeof(memname)/sizeof(memname[0]))) { |
2d21ac55 | 503 | panic("kmeminit: kmzones has %lu elements but memname has %lu\n", |
d7e50217 A |
504 | (sizeof(kmzones)/sizeof(kmzones[0])), (sizeof(memname)/sizeof(memname[0]))); |
505 | } | |
506 | ||
1c79356b A |
507 | kmz = kmzones; |
508 | while (kmz < &kmzones[M_LAST]) { | |
509 | /* XXX */ | |
2d21ac55 | 510 | if (kmz->kz_elemsize == (size_t)(-1)) |
1c79356b A |
511 | ; |
512 | else | |
513 | /* XXX */ | |
6d2010ae A |
514 | if (kmz->kz_zalloczone == KMZ_CREATEZONE || |
515 | kmz->kz_zalloczone == KMZ_CREATEZONE_ACCT) { | |
1c79356b A |
516 | kmz->kz_zalloczone = zinit(kmz->kz_elemsize, |
517 | 1024 * 1024, PAGE_SIZE, | |
518 | memname[kmz - kmzones]); | |
6d2010ae A |
519 | zone_change(kmz->kz_zalloczone, Z_CALLERACCT, |
520 | (kmz->kz_zalloczone == KMZ_CREATEZONE_ACCT)); | |
521 | ||
0b4c1975 A |
522 | if (kmz->kz_noencrypt == TRUE) |
523 | zone_change(kmz->kz_zalloczone, Z_NOENCRYPT, TRUE); | |
1c79356b A |
524 | } |
525 | else if (kmz->kz_zalloczone == KMZ_LOOKUPZONE) | |
526 | kmz->kz_zalloczone = kalloc_zone(kmz->kz_elemsize); | |
527 | ||
528 | kmz++; | |
529 | } | |
530 | ||
531 | kmz = kmzones; | |
532 | while (kmz < &kmzones[M_LAST]) { | |
533 | /* XXX */ | |
2d21ac55 | 534 | if (kmz->kz_elemsize == (size_t)(-1)) |
1c79356b A |
535 | ; |
536 | else | |
537 | /* XXX */ | |
538 | if (kmz->kz_zalloczone == KMZ_SHAREZONE) { | |
539 | kmz->kz_zalloczone = | |
540 | kmzones[kmz->kz_elemsize].kz_zalloczone; | |
541 | kmz->kz_elemsize = | |
542 | kmzones[kmz->kz_elemsize].kz_elemsize; | |
543 | } | |
544 | ||
545 | kmz++; | |
546 | } | |
547 | } | |
548 | ||
91447636 | 549 | void * |
3e170ce0 A |
550 | _MALLOC_external( |
551 | size_t size, | |
552 | int type, | |
553 | int flags); | |
554 | void * | |
555 | _MALLOC_external( | |
1c79356b A |
556 | size_t size, |
557 | int type, | |
558 | int flags) | |
3e170ce0 A |
559 | { |
560 | static vm_allocation_site_t site = { VM_KERN_MEMORY_KALLOC, VM_TAG_BT }; | |
561 | return (__MALLOC(size, type, flags, &site)); | |
562 | } | |
563 | ||
564 | void * | |
565 | __MALLOC( | |
566 | size_t size, | |
567 | int type, | |
568 | int flags, | |
569 | vm_allocation_site_t *site) | |
1c79356b | 570 | { |
39037602 A |
571 | void *addr = NULL; |
572 | vm_size_t msize = size; | |
1c79356b A |
573 | |
574 | if (type >= M_LAST) | |
575 | panic("_malloc TYPE"); | |
576 | ||
577 | if (size == 0) | |
2d21ac55 | 578 | return (NULL); |
1c79356b | 579 | |
39037602 A |
580 | if (msize != size) { |
581 | panic("Requested size to __MALLOC is too large (%llx)!\n", (uint64_t)size); | |
582 | } | |
583 | ||
1c79356b | 584 | if (flags & M_NOWAIT) { |
39037602 | 585 | addr = (void *)kalloc_canblock(&msize, FALSE, site); |
1c79356b | 586 | } else { |
39037602 A |
587 | addr = (void *)kalloc_canblock(&msize, TRUE, site); |
588 | if (addr == NULL) { | |
b0d623f7 A |
589 | /* |
590 | * We get here when the caller told us to block waiting for memory, but | |
591 | * kalloc said there's no memory left to get. Generally, this means there's a | |
592 | * leak or the caller asked for an impossibly large amount of memory. Since there's | |
593 | * nothing left to wait for and the caller isn't expecting a NULL return code, we | |
594 | * just panic. This is less than ideal, but returning NULL doesn't help since the | |
595 | * majority of callers don't check the return value and will just dereference the pointer and | |
596 | * trap anyway. We may as well get a more descriptive message out while we can. | |
597 | */ | |
598 | ||
599 | panic("_MALLOC: kalloc returned NULL (potential leak), size %llu", (uint64_t) size); | |
600 | } | |
1c79356b | 601 | } |
39037602 | 602 | if (!addr) |
1c79356b A |
603 | return (0); |
604 | ||
55e303ae | 605 | if (flags & M_ZERO) |
39037602 | 606 | bzero(addr, size); |
55e303ae | 607 | |
39037602 | 608 | return (addr); |
1c79356b A |
609 | } |
610 | ||
91447636 A |
611 | void |
612 | _FREE( | |
1c79356b A |
613 | void *addr, |
614 | int type) | |
615 | { | |
1c79356b A |
616 | if (type >= M_LAST) |
617 | panic("_free TYPE"); | |
618 | ||
9bccf70c A |
619 | if (!addr) |
620 | return; /* correct (convenient bsd kernel legacy) */ | |
1c79356b | 621 | |
39037602 | 622 | kfree_addr(addr); |
1c79356b A |
623 | } |
624 | ||
6d2010ae | 625 | void * |
3e170ce0 | 626 | __REALLOC( |
6d2010ae A |
627 | void *addr, |
628 | size_t size, | |
629 | int type, | |
3e170ce0 A |
630 | int flags, |
631 | vm_allocation_site_t *site) | |
6d2010ae | 632 | { |
6d2010ae A |
633 | void *newaddr; |
634 | size_t alloc; | |
635 | ||
636 | /* realloc(NULL, ...) is equivalent to malloc(...) */ | |
637 | if (addr == NULL) | |
3e170ce0 | 638 | return (__MALLOC(size, type, flags, site)); |
6d2010ae | 639 | |
39037602 A |
640 | alloc = kalloc_size(addr); |
641 | /* | |
642 | * Find out the size of the bucket in which the new sized allocation | |
643 | * would land. If it matches the bucket of the original allocation, | |
644 | * simply return the address. | |
645 | */ | |
646 | if (kalloc_bucket_size(size) == alloc) | |
647 | return addr; | |
648 | ||
6d2010ae | 649 | /* Allocate a new, bigger (or smaller) block */ |
3e170ce0 | 650 | if ((newaddr = __MALLOC(size, type, flags, site)) == NULL) |
6d2010ae A |
651 | return (NULL); |
652 | ||
6d2010ae A |
653 | /* Copy over original contents */ |
654 | bcopy(addr, newaddr, MIN(size, alloc)); | |
655 | _FREE(addr, type); | |
656 | ||
657 | return (newaddr); | |
658 | } | |
659 | ||
91447636 | 660 | void * |
3e170ce0 A |
661 | _MALLOC_ZONE_external( |
662 | size_t size, | |
663 | int type, | |
664 | int flags); | |
665 | void * | |
666 | _MALLOC_ZONE_external( | |
1c79356b A |
667 | size_t size, |
668 | int type, | |
669 | int flags) | |
3e170ce0 A |
670 | { |
671 | return (__MALLOC_ZONE(size, type, flags, NULL)); | |
672 | } | |
673 | ||
674 | void * | |
675 | __MALLOC_ZONE( | |
676 | size_t size, | |
677 | int type, | |
678 | int flags, | |
679 | vm_allocation_site_t *site) | |
1c79356b A |
680 | { |
681 | struct kmzones *kmz; | |
682 | void *elem; | |
683 | ||
684 | if (type >= M_LAST) | |
685 | panic("_malloc_zone TYPE"); | |
686 | ||
687 | kmz = &kmzones[type]; | |
688 | if (kmz->kz_zalloczone == KMZ_MALLOC) | |
91447636 | 689 | panic("_malloc_zone ZONE: type = %d", type); |
1c79356b A |
690 | |
691 | /* XXX */ | |
2d21ac55 | 692 | if (kmz->kz_elemsize == (size_t)(-1)) |
1c79356b A |
693 | panic("_malloc_zone XXX"); |
694 | /* XXX */ | |
695 | if (size == kmz->kz_elemsize) | |
696 | if (flags & M_NOWAIT) { | |
697 | elem = (void *)zalloc_noblock(kmz->kz_zalloczone); | |
698 | } else { | |
699 | elem = (void *)zalloc(kmz->kz_zalloczone); | |
700 | } | |
39037602 A |
701 | else { |
702 | vm_size_t kalloc_size = size; | |
703 | if (size > kalloc_size) { | |
704 | elem = NULL; | |
705 | } else if (flags & M_NOWAIT) { | |
706 | elem = (void *)kalloc_canblock(&kalloc_size, FALSE, site); | |
1c79356b | 707 | } else { |
39037602 | 708 | elem = (void *)kalloc_canblock(&kalloc_size, TRUE, site); |
1c79356b | 709 | } |
39037602 | 710 | } |
1c79356b A |
711 | |
712 | return (elem); | |
713 | } | |
714 | ||
91447636 A |
715 | void |
716 | _FREE_ZONE( | |
1c79356b A |
717 | void *elem, |
718 | size_t size, | |
719 | int type) | |
720 | { | |
721 | struct kmzones *kmz; | |
722 | ||
723 | if (type >= M_LAST) | |
724 | panic("FREE_SIZE"); | |
725 | ||
726 | kmz = &kmzones[type]; | |
727 | if (kmz->kz_zalloczone == KMZ_MALLOC) | |
728 | panic("free_zone ZONE"); | |
729 | ||
730 | /* XXX */ | |
2d21ac55 | 731 | if (kmz->kz_elemsize == (size_t)(-1)) |
1c79356b A |
732 | panic("FREE_SIZE XXX"); |
733 | /* XXX */ | |
734 | if (size == kmz->kz_elemsize) | |
91447636 | 735 | zfree(kmz->kz_zalloczone, elem); |
1c79356b | 736 | else |
91447636 | 737 | kfree(elem, size); |
1c79356b | 738 | } |
6d2010ae A |
739 | |
740 | #if CONFIG_ZLEAKS | |
741 | ||
742 | SYSCTL_DECL(_kern_zleak); | |
743 | SYSCTL_NODE(_kern, OID_AUTO, zleak, CTLFLAG_RW | CTLFLAG_LOCKED, 0, "zleak"); | |
744 | ||
745 | /* | |
746 | * kern.zleak.active | |
747 | * | |
748 | * Show the status of the zleak subsystem (0 = enabled, 1 = active, | |
749 | * and -1 = failed), and if enabled, allow it to be activated immediately. | |
750 | */ | |
751 | static int | |
752 | sysctl_zleak_active SYSCTL_HANDLER_ARGS | |
753 | { | |
754 | #pragma unused(arg1, arg2) | |
755 | int oldval, val, error; | |
756 | ||
757 | val = oldval = get_zleak_state(); | |
758 | error = sysctl_handle_int(oidp, &val, 0, req); | |
759 | if (error || !req->newptr) | |
760 | return (error); | |
761 | /* | |
762 | * Can only be activated if it's off (and not failed.) | |
763 | * Cannot be deactivated once it's on. | |
764 | */ | |
765 | if (val == 1 && oldval == 0) { | |
766 | kern_return_t kr = zleak_activate(); | |
767 | ||
768 | if (KERN_SUCCESS != kr) | |
769 | printf("zleak_active: failed to activate " | |
770 | "live zone leak debugging (%d).\n", kr); | |
771 | } if (val == 0 && oldval == 1) { | |
772 | printf("zleak_active: active, cannot be disabled.\n"); | |
773 | return (EINVAL); | |
774 | } | |
775 | return (0); | |
776 | } | |
777 | ||
778 | SYSCTL_PROC(_kern_zleak, OID_AUTO, active, | |
779 | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED, | |
780 | 0, 0, sysctl_zleak_active, "I", "zleak activity"); | |
781 | ||
782 | /* | |
783 | * kern.zleak.max_zonemap_size | |
784 | * | |
785 | * Read the value of the maximum zonemap size in bytes; useful | |
786 | * as the maximum size that zleak.global_threshold and | |
787 | * zleak.zone_threshold should be set to. | |
788 | */ | |
789 | static int | |
790 | sysctl_zleak_max_zonemap_size SYSCTL_HANDLER_ARGS | |
791 | { | |
792 | uint64_t zmap_max_size = *(vm_size_t *)arg1; | |
793 | ||
794 | return sysctl_handle_quad(oidp, &zmap_max_size, arg2, req); | |
795 | } | |
796 | ||
797 | SYSCTL_PROC(_kern_zleak, OID_AUTO, max_zonemap_size, | |
798 | CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_LOCKED, | |
799 | &zleak_max_zonemap_size, 0, | |
800 | sysctl_zleak_max_zonemap_size, "Q", "zleak max zonemap size"); | |
801 | ||
802 | ||
803 | static int | |
804 | sysctl_zleak_threshold SYSCTL_HANDLER_ARGS | |
805 | { | |
806 | #pragma unused(oidp, arg2) | |
807 | int error; | |
808 | uint64_t value = *(vm_size_t *)arg1; | |
809 | ||
810 | error = sysctl_io_number(req, value, sizeof (value), &value, NULL); | |
811 | ||
812 | if (error || !req->newptr) | |
813 | return (error); | |
814 | ||
815 | if (value > (uint64_t)zleak_max_zonemap_size) | |
816 | return (ERANGE); | |
817 | ||
818 | *(vm_size_t *)arg1 = value; | |
819 | return (0); | |
820 | } | |
821 | ||
822 | /* | |
823 | * kern.zleak.global_threshold | |
824 | * | |
825 | * Set the global zleak threshold size (in bytes). If the zone map | |
826 | * grows larger than this value, zleaks are automatically activated. | |
827 | * | |
828 | * The default value is set in zleak_init(). | |
829 | */ | |
830 | SYSCTL_PROC(_kern_zleak, OID_AUTO, global_threshold, | |
831 | CTLTYPE_QUAD | CTLFLAG_RW | CTLFLAG_LOCKED, | |
832 | &zleak_global_tracking_threshold, 0, | |
833 | sysctl_zleak_threshold, "Q", "zleak global threshold"); | |
834 | ||
835 | /* | |
836 | * kern.zleak.zone_threshold | |
837 | * | |
838 | * Set the per-zone threshold size (in bytes) above which any | |
839 | * zone will automatically start zleak tracking. | |
840 | * | |
841 | * The default value is set in zleak_init(). | |
842 | * | |
843 | * Setting this variable will have no effect until zleak tracking is | |
844 | * activated (See above.) | |
845 | */ | |
846 | SYSCTL_PROC(_kern_zleak, OID_AUTO, zone_threshold, | |
847 | CTLTYPE_QUAD | CTLFLAG_RW | CTLFLAG_LOCKED, | |
848 | &zleak_per_zone_tracking_threshold, 0, | |
849 | sysctl_zleak_threshold, "Q", "zleak per-zone threshold"); | |
850 | ||
851 | #endif /* CONFIG_ZLEAKS */ |