]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/vm_param.h
xnu-792.6.76.tar.gz
[apple/xnu.git] / osfmk / mach / vm_param.h
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 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52 /*
53 * File: mach/vm_param.h
54 * Author: Avadis Tevanian, Jr., Michael Wayne Young
55 * Date: 1985
56 *
57 * Machine independent virtual memory parameters.
58 *
59 */
60
61 #ifndef _MACH_VM_PARAM_H_
62 #define _MACH_VM_PARAM_H_
63
64 #include <mach/machine/vm_param.h>
65
66 #ifdef KERNEL
67
68 #ifndef ASSEMBLER
69 #include <mach/vm_types.h>
70 #endif /* ASSEMBLER */
71
72 /*
73 * The machine independent pages are refered to as PAGES. A page
74 * is some number of hardware pages, depending on the target machine.
75 */
76
77 #ifndef ASSEMBLER
78
79 #define PAGE_SIZE_64 (unsigned long long)PAGE_SIZE /* pagesize in addr units */
80 #define PAGE_MASK_64 (unsigned long long)PAGE_MASK /* mask for off in page */
81
82 /*
83 * Convert addresses to pages and vice versa. No rounding is used.
84 * The atop_32 and ptoa_32 macros should not be use on 64 bit types.
85 * The round_page_64 and trunc_page_64 macros should be used instead.
86 */
87
88 #define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT)
89 #define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT)
90 #define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT)
91 #define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT)
92
93 /*
94 * While the following block is enabled, the legacy atop and ptoa
95 * macros will behave correctly. If not, they will generate
96 * invalid lvalue errors.
97 */
98
99 #if 1
100 #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
101 #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
102 #else
103 #define atop(x) (0UL = 0)
104 #define ptoa(x) (0UL = 0)
105 #endif
106
107 /*
108 * Page-size rounding macros for the Public fixed-width VM types.
109 */
110 #define mach_vm_round_page(x) (((mach_vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
111 #define mach_vm_trunc_page(x) ((mach_vm_offset_t)(x) & ~((signed)PAGE_MASK))
112
113 #define memory_object_round_page(x) (((memory_object_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
114 #define memory_object_trunc_page(x) ((memory_object_offset_t)(x) & ~((signed)PAGE_MASK))
115
116 /*
117 * Rounding macros for the legacy (scalable with the current task's
118 * address space size) VM types.
119 */
120
121 #define round_page(x) (((vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
122 #define trunc_page(x) ((vm_offset_t)(x) & ~((signed)PAGE_MASK))
123
124 /*
125 * Round off or truncate to the nearest page. These will work
126 * for either addresses or counts. (i.e. 1 byte rounds to 1 page
127 * bytes. The round_page_32 and trunc_page_32 macros should not be
128 * use on 64 bit types. The round_page_64 and trunc_page_64 macros
129 * should be used instead.
130 *
131 * These should only be used in the rare case the size of the address
132 * or length is hard-coded as 32 or 64 bit. Otherwise, the macros
133 * associated with the specific VM type should be used.
134 */
135
136 #define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
137 #define trunc_page_32(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
138 #define round_page_64(x) (((uint64_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
139 #define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK))
140
141
142 /*
143 * Enable the following block to find uses of xxx_32 macros that should
144 * be xxx_64. These macros only work in C code, not C++. The resulting
145 * binaries are not functional. Look for invalid lvalue errors in
146 * the compiler output.
147 *
148 * Enabling the following block will also find use of the xxx_64 macros
149 * that have been passed pointers. The parameters should be case to an
150 * unsigned long type first. Look for invalid operands to binary + error
151 * in the compiler output.
152 */
153
154 #if 0
155 #undef atop_32
156 #undef ptoa_32
157 #undef round_page_32
158 #undef trunc_page_32
159 #undef atop_64
160 #undef ptoa_64
161 #undef round_page_64
162 #undef trunc_page_64
163
164 #ifndef __cplusplus
165
166 #define atop_32(x) \
167 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
168 (*(long *)0), \
169 (0UL)) = 0)
170
171 #define ptoa_32(x) \
172 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
173 (*(long *)0), \
174 (0UL)) = 0)
175
176 #define round_page_32(x) \
177 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
178 (*(long *)0), \
179 (0UL)) = 0)
180
181 #define trunc_page_32(x) \
182 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
183 (*(long *)0), \
184 (0UL)) = 0)
185 #else
186
187 #define atop_32(x) (0)
188 #define ptoa_32(x) (0)
189 #define round_page_32(x) (0)
190 #define trunc_page_32(x) (0)
191
192 #endif /* ! __cplusplus */
193
194 #define atop_64(x) ((uint64_t)((x) + (uint8_t *)0))
195 #define ptoa_64(x) ((uint64_t)((x) + (uint8_t *)0))
196 #define round_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
197 #define trunc_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
198
199 #endif
200
201 /*
202 * Determine whether an address is page-aligned, or a count is
203 * an exact page multiple.
204 */
205
206 #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
207
208 extern vm_size_t mem_size; /* 32-bit size of memory - limited by maxmem - deprecated */
209 extern uint64_t max_mem; /* 64-bit size of memory - limited by maxmem */
210
211 #ifdef XNU_KERNEL_PRIVATE
212
213 extern uint64_t mem_actual; /* 64-bit size of memory - not limited by maxmem */
214 extern uint64_t sane_size; /* Memory size to use for defaults calculations */
215 extern addr64_t vm_last_addr; /* Highest kernel virtual address known to the VM system */
216
217 #endif /* XNU_KERNEL_PRIVATE */
218
219 extern vm_size_t page_size;
220 extern vm_size_t page_mask;
221 extern int page_shift;
222
223 /* We need a way to get rid of compiler warnings when we cast from */
224 /* a 64 bit value to an address that is 32 bits. */
225 /* We know at this point the cast is harmless but sometime in */
226 /* the future it may not be. */
227 /* When size of an int is no longer equal to size of uintptr_t then */
228 /* the compile will fail and we know we need to fix our cast. */
229 #include <stdint.h>
230 #ifndef __CAST_DOWN_CHECK
231 #define __CAST_DOWN_CHECK
232 typedef char __NEED_TO_CHANGE_CAST_DOWN[ sizeof(uintptr_t) == sizeof(int) ? 0 : -1 ];
233 #define CAST_DOWN( type, addr ) ( ((type)((uintptr_t) (addr))) )
234 #endif /* __CAST_DOWN_CHECK */
235
236 #endif /* ASSEMBLER */
237
238 #endif /* KERNEL */
239
240 #endif /* _MACH_VM_PARAM_H_ */