]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/malloc.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / sys / malloc.h
CommitLineData
1c79356b 1/*
39236c6e 2 * Copyright (c) 2000-2013 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 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.
0a7de745 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.
0a7de745 17 *
2d21ac55
A
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.
0a7de745 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_
0a7de745 72#define _SYS_MALLOC_H_
1c79356b 73
9bccf70c
A
74#include <sys/appleapiopts.h>
75
1c79356b 76
91447636 77#ifdef KERNEL
1c79356b
A
78/*
79 * flags to malloc
80 */
0a7de745
A
81#define M_WAITOK 0x0000
82#define M_NOWAIT 0x0001
55e303ae 83#define M_ZERO 0x0004 /* bzero the allocation */
0a7de745 84#define M_NULL 0x0008 /* return NULL if space is unavailable*/
91447636 85
f427ee49
A
86#ifdef XNU_KERNEL_PRIVATE
87
88#include <mach/vm_types.h>
89#include <kern/kalloc.h>
91447636 90
f427ee49 91ZONE_VIEW_DECLARE(ZV_NAMEI);
91447636 92
1c79356b
A
93/*
94 * Types of memory to be allocated (not all are used by us)
95 */
0a7de745 96#define M_DEVBUF 2 /* device driver memory */
0a7de745
A
97#define M_PCB 4 /* protocol control block */
98#define M_RTABLE 5 /* routing tables */
0a7de745 99#define M_IFADDR 9 /* interface address */
0a7de745 100#define M_SONAME 11 /* socket name */
0a7de745 101#define M_PGRP 17 /* process group header */
0a7de745 102#define M_FHANDLE 21 /* network file handle */
0a7de745
A
103#define M_NFSNODE 24 /* NFS vnode private part */
104#define M_VNODE 25 /* Dynamically allocated vnodes */
105#define M_CACHE 26 /* Dynamically allocated cache entries */
106#define M_DQUOT 27 /* UFS quota entries */
107#define M_PROC_UUID_POLICY 28 /* proc UUID policy entries */
108#define M_SHM 29 /* SVID compatible shared memory segments */
0a7de745
A
109#define M_LOCKF 40 /* Byte-range locking structures */
110#define M_PROC 41 /* Proc structures */
0a7de745
A
111#define M_NETADDR 49 /* Export host address structure */
112#define M_NFSSVC 50 /* NFS server structure */
0a7de745
A
113#define M_NFSD 52 /* NFS server daemon structure */
114#define M_IPMOPTS 53 /* internet multicast options */
0a7de745 115#define M_IFMADDR 55 /* link-level multicast address */
f427ee49 116#define M_NFSBIO 58 /* NFS client I/O buffers */
0a7de745 117#define M_NFSBIGFH 61 /* NFS version 3 file handle */
0a7de745 118#define M_TTYS 65 /* allocated tty structures */
0a7de745 119#define M_OFILETABL 73 /* Open file descriptor table */
0a7de745
A
120#define M_TEMP 80 /* misc temporary data buffers */
121#define M_SECA 81 /* security associations, key management */
122#define M_DEVFS 82
0a7de745
A
123#define M_UDFNODE 84 /* UDF inodes */
124#define M_UDFMNT 85 /* UDF mount structures */
0a7de745 125#define M_IP6OPT 87 /* IPv6 options management */
0a7de745 126#define M_KQUEUE 94 /* kqueue system */
0a7de745
A
127#define M_KAUTH 100 /* kauth subsystem */
128#define M_DUMMYNET 101 /* dummynet */
0a7de745
A
129#define M_MACTEMP 104 /* MAC framework */
130#define M_SBUF 105 /* string buffers */
0a7de745 131#define M_SELECT 107 /* per-thread select memory */
0a7de745 132#define M_INMFILTER 110 /* IPv4 multicast PCB-layer source filter */
0a7de745
A
133#define M_IN6MFILTER 112 /* IPv6 multicast PCB-layer source filter */
134#define M_IP6MOPTS 113 /* IPv6 multicast options */
0a7de745 135#define M_IP6CGA 117
f427ee49 136#define M_NECP 118 /* General NECP policy data */
0a7de745
A
137#define M_FD_VN_DATA 122 /* Per fd vnode data */
138#define M_FD_DIRBUF 123 /* Directory entries' buffer */
139#define M_NETAGENT 124 /* Network Agents */
140#define M_EVENTHANDLER 125 /* Eventhandler */
141#define M_LLTABLE 126 /* Link layer table */
142#define M_NWKWQ 127 /* Network work queue */
f427ee49 143#define M_CFIL 128 /* Content Filter */
2d21ac55 144
0a7de745 145#define M_LAST 129 /* Must be last type + 1 */
1c79356b 146
c3c9b80d
A
147/*
148 * If you need accounting consider using
149 * KALLOC_HEAP_DEFINE to define a view.
150 */
151#define KM_SHM KHEAP_DEFAULT
152
f427ee49
A
153#define MALLOC(space, cast, size, type, flags) \
154 ({ VM_ALLOC_SITE_STATIC(0, 0); \
3e170ce0 155 (space) = (cast)__MALLOC(size, type, flags, &site); })
5ba3f43e 156
f427ee49
A
157#define REALLOC(space, cast, addr, size, type, flags) \
158 ({ VM_ALLOC_SITE_STATIC(0, 0); \
3e170ce0
A
159 (space) = (cast)__REALLOC(addr, size, type, flags, &site); })
160
f427ee49
A
161#define _MALLOC(size, type, flags) \
162 ({ VM_ALLOC_SITE_STATIC(0, 0); \
3e170ce0 163 __MALLOC(size, type, flags, &site); })
f427ee49
A
164
165#define _REALLOC(addr, size, type, flags) \
166 ({ VM_ALLOC_SITE_STATIC(0, 0); \
3e170ce0
A
167 __REALLOC(addr, size, type, flags, &site); })
168
f427ee49
A
169#define _FREE(addr, type) \
170 (kheap_free_addr)(KHEAP_DEFAULT, addr)
3e170ce0 171
f427ee49
A
172#define FREE(addr, type) \
173 kheap_free_addr(KHEAP_DEFAULT, addr)
3e170ce0 174
f427ee49 175#pragma GCC visibility push(hidden)
0a7de745
A
176
177extern void *__MALLOC(
178 size_t size,
179 int type,
180 int flags,
181 vm_allocation_site_t *site) __attribute__((alloc_size(1)));
182
0a7de745
A
183extern void *__REALLOC(
184 void *addr,
185 size_t size,
186 int type,
187 int flags,
188 vm_allocation_site_t *site) __attribute__((alloc_size(2)));
189
f427ee49 190#pragma GCC visibility pop
3e170ce0
A
191#else /* XNU_KERNEL_PRIVATE */
192
f427ee49
A
193#define M_PCB 4 /* protocol control block (smb) */
194#define M_RTABLE 5 /* routing tables */
195#define M_IFADDR 9 /* interface address (IOFireWireIP)*/
196#define M_SONAME 11 /* socket name (smb) */
197#define M_LOCKF 40 /* Byte-range locking structures (msdos) */
198#define M_TEMP 80 /* misc temporary data buffers */
199#define M_UDFNODE 84 /* UDF inodes (udf)*/
200#define M_UDFMNT 85 /* UDF mount structures (udf)*/
201#define M_KAUTH 100 /* kauth subsystem (smb) */
202
0a7de745 203#define MALLOC(space, cast, size, type, flags) \
1c79356b
A
204 (space) = (cast)_MALLOC(size, type, flags)
205
206#define FREE(addr, type) \
207 _FREE((void *)addr, type)
208
209#define MALLOC_ZONE(space, cast, size, type, flags) \
210 (space) = (cast)_MALLOC_ZONE(size, type, flags)
211
212#define FREE_ZONE(addr, size, type) \
213 _FREE_ZONE((void *)addr, size, type)
214
0a7de745
A
215extern void *_MALLOC(
216 size_t size,
217 int type,
218 int flags);
1c79356b 219
0a7de745
A
220extern void _FREE(
221 void *addr,
222 int type);
1c79356b 223
0a7de745
A
224extern void *_MALLOC_ZONE(
225 size_t size,
226 int type,
227 int flags);
1c79356b 228
0a7de745
A
229extern void _FREE_ZONE(
230 void *elem,
231 size_t size,
232 int type);
1c79356b 233
3e170ce0
A
234#endif /* !XNU_KERNEL_PRIVATE */
235
0a7de745 236#endif /* KERNEL */
1c79356b 237
0a7de745 238#endif /* _SYS_MALLOC_H_ */