#include <mach/vm_param.h>
mach/vm_param.h
macroatop_32
#define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT)
macroptoa_32
#define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT)
macroatop_64
#define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT)
macroptoa_64
#define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT)
macroatop_kernel
#define atop_kernel(x) ((vm_address_t)(x) >> PAGE_SHIFT)
macroptoa_kernel
#define ptoa_kernel(x) ((vm_address_t)(x) << PAGE_SHIFT)
macroatop
#define atop(x) ((vm_address_t)(x) >> PAGE_SHIFT)
macroptoa
#define ptoa(x) ((vm_address_t)(x) << PAGE_SHIFT)
macromach_vm_round_page
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))
macromach_vm_trunc_page
#define mach_vm_trunc_page(x) ((mach_vm_offset_t)(x) & ~((signed)PAGE_MASK))
macroround_page_overflow
#define round_page_overflow(in, out) __os_warn_unused(({ bool __ovr = os_add_overflow(in, (__typeof__(*out))PAGE_MASK, out); *out &= ~((__typeof__(*out))PAGE_MASK); __ovr; }))
functionmach_vm_round_page_overflow
static inline int OS_WARN_RESULT mach_vm_round_page_overflow( mach_vm_offset_t in, mach_vm_offset_t *out )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/mach/vm_param.h
Rounds in up to the next page boundary and stores the result in *out, returning nonzero if the addition of PAGE_MASK overflowed (in which case *out is not meaningful) and zero on success. Inline wrapper around the round_page_overflow macro; the result must not be ignored.
macromemory_object_round_page
#define memory_object_round_page(x) (((memory_object_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
macromemory_object_trunc_page
#define memory_object_trunc_page(x) ((memory_object_offset_t)(x) & ~((signed)PAGE_MASK))
macroround_page
#define round_page(x) (((vm_offset_t)(x) + PAGE_MASK) & ~((vm_offset_t)PAGE_MASK))
macrotrunc_page
#define trunc_page(x) ((vm_offset_t)(x) & ~((vm_offset_t)PAGE_MASK))
macroround_page_32
#define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((uint32_t)PAGE_MASK))
macrotrunc_page_32
#define trunc_page_32(x) ((uint32_t)(x) & ~((uint32_t)PAGE_MASK))
macroround_page_64
#define round_page_64(x) (((uint64_t)(x) + PAGE_MASK_64) & ~((uint64_t)PAGE_MASK_64))
macrotrunc_page_64
#define trunc_page_64(x) ((uint64_t)(x) & ~((uint64_t)PAGE_MASK_64))
macroround_page_mask_32
#define round_page_mask_32(x, mask) (((uint32_t)(x) + (mask)) & ~((uint32_t)(mask)))
macrotrunc_page_mask_32
#define trunc_page_mask_32(x, mask) ((uint32_t)(x) & ~((uint32_t)(mask)))
macroround_page_mask_64
#define round_page_mask_64(x, mask) (((uint64_t)(x) + (mask)) & ~((uint64_t)(mask)))
macrotrunc_page_mask_64
#define trunc_page_mask_64(x, mask) ((uint64_t)(x) & ~((uint64_t)(mask)))
macropage_aligned
#define page_aligned(x) (((x) & PAGE_MASK) == 0)
macroANON_MAX_PAGES
The VM compressor pager uses 32-bit page numbers, so this limits the size
of anonymous memory objects to 0xffffffff pages.
When we need to allocate a chunk of anonymous memory over that size,
we have to allocate more than one chunk.
#define ANON_MAX_PAGES 0xFFFFFFFFULL
macroANON_MAX_SIZE
#define ANON_MAX_SIZE (ANON_MAX_PAGES << PAGE_SHIFT)
macroANON_CHUNK_SIZE
Work-around for <rdar://problem/6626493>
Break large anonymous memory areas into 128MB chunks to alleviate
the cost of copying when copy-on-write is not possible because a small
portion of it being wired.
#define ANON_CHUNK_SIZE (128ULL * 1024 * 1024)
128MB
macroMALLOC_MEDIUM_CHUNK_SIZE
The 'medium' malloc allocator would like its regions
to be chunked up into MALLOC_MEDIUM_CHUNK_SIZE chunks
and backed by different objects. This avoids contention
on a single large object and showed solid improvements on high
core machines with workloads involving video and graphics processing.
#define MALLOC_MEDIUM_CHUNK_SIZE (8ULL * 1024 * 1024)
8 MB
variablepage_shift
extern int page_shift
macroCAST_DOWN
#define CAST_DOWN(type, addr) ( ((type)((uintptr_t) (addr)/(sizeof(type) < sizeof(uintptr_t) ? 0 : 1))) )
macroCAST_DOWN_EXPLICIT
#define CAST_DOWN_EXPLICIT(type, addr) ( ((type)((uintptr_t) (addr))) )