2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
54 * File: mach/vm_param.h
55 * Author: Avadis Tevanian, Jr., Michael Wayne Young
58 * Machine independent virtual memory parameters.
62 #ifndef _MACH_VM_PARAM_H_
63 #define _MACH_VM_PARAM_H_
65 #include <mach/machine/vm_param.h>
70 #include <mach/vm_types.h>
71 #endif /* ASSEMBLER */
74 * The machine independent pages are refered to as PAGES. A page
75 * is some number of hardware pages, depending on the target machine.
80 #define PAGE_SIZE_64 (unsigned long long)PAGE_SIZE /* pagesize in addr units */
81 #define PAGE_MASK_64 (unsigned long long)PAGE_MASK /* mask for off in page */
84 * Convert addresses to pages and vice versa. No rounding is used.
85 * The atop_32 and ptoa_32 macros should not be use on 64 bit types.
86 * The round_page_64 and trunc_page_64 macros should be used instead.
89 #define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT)
90 #define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT)
91 #define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT)
92 #define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT)
95 * While the following block is enabled, the legacy atop and ptoa
96 * macros will behave correctly. If not, they will generate
97 * invalid lvalue errors.
101 #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
102 #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
104 #define atop(x) (0UL = 0)
105 #define ptoa(x) (0UL = 0)
109 * Page-size rounding macros for the Public fixed-width VM types.
111 #define mach_vm_round_page(x) (((mach_vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
112 #define mach_vm_trunc_page(x) ((mach_vm_offset_t)(x) & ~((signed)PAGE_MASK))
114 #define memory_object_round_page(x) (((memory_object_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
115 #define memory_object_trunc_page(x) ((memory_object_offset_t)(x) & ~((signed)PAGE_MASK))
118 * Rounding macros for the legacy (scalable with the current task's
119 * address space size) VM types.
122 #define round_page(x) (((vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
123 #define trunc_page(x) ((vm_offset_t)(x) & ~((signed)PAGE_MASK))
126 * Round off or truncate to the nearest page. These will work
127 * for either addresses or counts. (i.e. 1 byte rounds to 1 page
128 * bytes. The round_page_32 and trunc_page_32 macros should not be
129 * use on 64 bit types. The round_page_64 and trunc_page_64 macros
130 * should be used instead.
132 * These should only be used in the rare case the size of the address
133 * or length is hard-coded as 32 or 64 bit. Otherwise, the macros
134 * associated with the specific VM type should be used.
137 #define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
138 #define trunc_page_32(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
139 #define round_page_64(x) (((uint64_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
140 #define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK))
144 * Enable the following block to find uses of xxx_32 macros that should
145 * be xxx_64. These macros only work in C code, not C++. The resulting
146 * binaries are not functional. Look for invalid lvalue errors in
147 * the compiler output.
149 * Enabling the following block will also find use of the xxx_64 macros
150 * that have been passed pointers. The parameters should be case to an
151 * unsigned long type first. Look for invalid operands to binary + error
152 * in the compiler output.
168 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
173 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
177 #define round_page_32(x) \
178 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
182 #define trunc_page_32(x) \
183 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
188 #define atop_32(x) (0)
189 #define ptoa_32(x) (0)
190 #define round_page_32(x) (0)
191 #define trunc_page_32(x) (0)
193 #endif /* ! __cplusplus */
195 #define atop_64(x) ((uint64_t)((x) + (uint8_t *)0))
196 #define ptoa_64(x) ((uint64_t)((x) + (uint8_t *)0))
197 #define round_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
198 #define trunc_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
203 * Determine whether an address is page-aligned, or a count is
204 * an exact page multiple.
207 #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
209 extern vm_size_t mem_size
; /* 32-bit size of memory - limited by maxmem - deprecated */
210 extern uint64_t max_mem
; /* 64-bit size of memory - limited by maxmem */
212 #ifdef XNU_KERNEL_PRIVATE
214 extern uint64_t mem_actual
; /* 64-bit size of memory - not limited by maxmem */
215 extern uint64_t sane_size
; /* Memory size to use for defaults calculations */
216 extern addr64_t vm_last_addr
; /* Highest kernel virtual address known to the VM system */
218 #endif /* XNU_KERNEL_PRIVATE */
220 extern vm_size_t page_size
;
221 extern vm_size_t page_mask
;
222 extern int page_shift
;
224 /* We need a way to get rid of compiler warnings when we cast from */
225 /* a 64 bit value to an address that is 32 bits. */
226 /* We know at this point the cast is harmless but sometime in */
227 /* the future it may not be. */
228 /* When size of an int is no longer equal to size of uintptr_t then */
229 /* the compile will fail and we know we need to fix our cast. */
231 #ifndef __CAST_DOWN_CHECK
232 #define __CAST_DOWN_CHECK
233 typedef char __NEED_TO_CHANGE_CAST_DOWN
[ sizeof(uintptr_t) == sizeof(int) ? 0 : -1 ];
234 #define CAST_DOWN( type, addr ) ( ((type)((uintptr_t) (addr))) )
235 #endif /* __CAST_DOWN_CHECK */
237 #endif /* ASSEMBLER */
241 #endif /* _MACH_VM_PARAM_H_ */