/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ *
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* Please see the License for the specific language governing rights and
* limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
* @OSF_COPYRIGHT@
#ifndef _MACH_VM_PARAM_H_
#define _MACH_VM_PARAM_H_
-#ifndef KERNEL_PRIVATE
-
-#error YOU HAVE MADE A MISTAKE BY INCLUDING THIS FILE;
-#error
-#error THIS FILE SHOULD NOT BE VISIBLE TO USER PROGRAMS.
-#error
-#error USE <mach/machine/vm_param.h> TO GET MACHINE-DEPENDENT ADDRESS
-#error SPACE AND PAGE SIZE ITEMS.
-#error
-#error USE <mach/machine/vm_types.h> TO GET TYPE DECLARATIONS USED IN
-#error THE MACH KERNEL INTERFACE.
-#error
-#error IN ALL PROBABILITY, YOU SHOULD GET ALL OF THE TYPES USED IN THE
-#error INTERFACE FROM <mach/mach_types.h>
-
-#endif /* KERNEL_PRIVATE */
-
#include <mach/machine/vm_param.h>
+#ifdef KERNEL
+
#ifndef ASSEMBLER
#include <mach/vm_types.h>
#endif /* ASSEMBLER */
* is some number of hardware pages, depending on the target machine.
*/
-/*
- * All references to the size of a page should be done with PAGE_SIZE
- * or PAGE_SHIFT. The fact they are variables is hidden here so that
- * we can easily make them constant if we so desire.
- */
-
-/*
- * Regardless whether it is implemented with a constant or a variable,
- * the PAGE_SIZE is assumed to be a power of two throughout the
- * virtual memory system implementation.
- */
-
-#ifdef PAGE_SIZE_FIXED
-#define PAGE_SIZE 4096
-#define PAGE_SHIFT 12
-#define PAGE_MASK (PAGE_SIZE-1)
-#endif /* PAGE_SIZE_FIXED */
-
#ifndef ASSEMBLER
-extern vm_size_t page_size;
-extern vm_size_t page_mask;
-extern int page_shift;
-
-#ifndef PAGE_SIZE_FIXED
-#define PAGE_SIZE page_size /* pagesize in addr units */
-#define PAGE_SHIFT page_shift /* number of bits to shift for pages */
-#define PAGE_MASK page_mask /* mask for off in page */
-
-#define PAGE_SIZE_64 (unsigned long long)page_size /* pagesize in addr units */
-#define PAGE_MASK_64 (unsigned long long)page_mask /* mask for off in page */
-#else /* PAGE_SIZE_FIXED */
-
-#define PAGE_SIZE_64 (unsigned long long)4096
-#define PAGE_MASK_64 (PAGE_SIZE_64-1)
-#endif /* PAGE_SIZE_FIXED */
+#define PAGE_SIZE_64 (unsigned long long)PAGE_SIZE /* pagesize in addr units */
+#define PAGE_MASK_64 (unsigned long long)PAGE_MASK /* mask for off in page */
/*
* Convert addresses to pages and vice versa. No rounding is used.
#define ptoa(x) (0UL = 0)
#endif
+/*
+ * Page-size rounding macros for the Public fixed-width VM types.
+ */
+#define mach_vm_round_page(x) (((mach_vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
+#define mach_vm_trunc_page(x) ((mach_vm_offset_t)(x) & ~((signed)PAGE_MASK))
+
+#define memory_object_round_page(x) (((memory_object_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
+#define memory_object_trunc_page(x) ((memory_object_offset_t)(x) & ~((signed)PAGE_MASK))
+
+/*
+ * Rounding macros for the legacy (scalable with the current task's
+ * address space size) VM types.
+ */
+
+#define round_page(x) (((vm_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
+#define trunc_page(x) ((vm_offset_t)(x) & ~((signed)PAGE_MASK))
/*
* Round off or truncate to the nearest page. These will work
* bytes. The round_page_32 and trunc_page_32 macros should not be
* use on 64 bit types. The round_page_64 and trunc_page_64 macros
* should be used instead.
+ *
+ * These should only be used in the rare case the size of the address
+ * or length is hard-coded as 32 or 64 bit. Otherwise, the macros
+ * associated with the specific VM type should be used.
*/
#define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
#define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK))
-/*
- * While the following block is enabled, the legacy round_page
- * and trunc_page macros will behave correctly. If not, they will
- * generate invalid lvalue errors.
- */
-
-#if 1
-#define round_page(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
-#define trunc_page(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
-#else
-#define round_page(x) (0UL = 0)
-#define trunc_page(x) (0UL = 0)
-#endif
-
/*
* Enable the following block to find uses of xxx_32 macros that should
* be xxx_64. These macros only work in C code, not C++. The resulting
#define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
extern vm_size_t mem_size; /* 32-bit size of memory - limited by maxmem - deprecated */
-extern uint64_t max_mem; /* 64-bit size of memory - limited by maxmem */
-extern uint64_t mem_actual; /* 64-bit size of memory - not limited by maxmem */
-extern uint64_t sane_size; /* Memory size to use for defaults calculations */
+extern uint64_t max_mem; /* 64-bit size of memory - limited by maxmem */
+
+#ifdef XNU_KERNEL_PRIVATE
+
+extern uint64_t mem_actual; /* 64-bit size of memory - not limited by maxmem */
+extern uint64_t sane_size; /* Memory size to use for defaults calculations */
extern addr64_t vm_last_addr; /* Highest kernel virtual address known to the VM system */
+extern const vm_offset_t vm_min_kernel_address;
+extern const vm_offset_t vm_max_kernel_address;
+
+#endif /* XNU_KERNEL_PRIVATE */
+
+extern vm_size_t page_size;
+extern vm_size_t page_mask;
+extern int page_shift;
+
/* We need a way to get rid of compiler warnings when we cast from */
/* a 64 bit value to an address that is 32 bits. */
/* We know at this point the cast is harmless but sometime in */
#endif /* __CAST_DOWN_CHECK */
#endif /* ASSEMBLER */
+
+#endif /* KERNEL */
+
#endif /* _MACH_VM_PARAM_H_ */