PageAllocatorPageSize
Description
Query the system page size in bytes through a PageAllocator. The result is cached inside the allocator instance after the first call.
Parameters
| Name | Direction | Description |
|---|---|---|
self |
in,out | PageAllocator handle (may be NULL for a one-shot query). |
Success
Returns the OS page size in bytes (typically 4096 on x86_64).
Failure
Returns 4096 when the OS query fails.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Debug.c:384:
// Don't release the page. mprotect it PROT_NONE so any UAF
// read/write traps with SIGSEGV at the moment of the bug.
size page_size = PageAllocatorPageSize(&self->page);
size rounded = (padded + page_size - 1) & ~(page_size - 1);
if (!PageProtect(ptr, rounded, PAGE_PROT_NONE)) {- In
Page.c:119:
}
size PageAllocatorPageSize(PageAllocator *self) {
if (self && self->cached_page_size) {
return self->cached_page_size;- In
Page.c:136:
static size page_effective_alignment(PageAllocator *self) {
size requested = self ? self->base.alignment : 0;
size page_size = PageAllocatorPageSize(self);
if (requested < page_size) {
return page_size;- In
Page.c:148:
static size page_rounded_size(PageAllocator *self, size bytes) {
size align = page_effective_alignment(self);
size page_size = PageAllocatorPageSize(self);
if (align > page_size) {
return ALIGN_UP_POW2(bytes, align);- In
Page.c:186:
// `free_entries`. Returns false on OS-allocation failure or overflow.
static bool page_table_grow_into(PageAllocator *page, PageEntry **arr_p, u32 *len_p, u32 *cap_p, size *bytes_p) {
size page_size = PageAllocatorPageSize(page);
size want_bytes;
if (*bytes_p == 0) {- In
PageProtect.c:10:
Allocator *base = ALLOCATOR_OF(&page);
size page_bytes = PageAllocatorPageSize(&page);
void *region = AllocatorAlloc(base, page_bytes, true);
if (!region) {
static bool test_page_size_query(void) {
size ps = PageAllocatorPageSize(NULL);
bool ok = (ps >= 4096) && ((ps & (ps - 1)) == 0);
if (!ok) { PageAllocator alloc = PageAllocatorInit();
Allocator *alloc_base = ALLOCATOR_OF(&alloc);
size page = PageAllocatorPageSize(&alloc);
u8 *ptr = (u8 *)AllocatorAlloc(alloc_base, 64, true);
bool ok = (ptr != NULL); PageAllocator alloc = PageAllocatorInitAligned(64);
Allocator *alloc_base = ALLOCATOR_OF(&alloc);
size page = PageAllocatorPageSize(&alloc);
void *ptr = AllocatorAlloc(alloc_base, 1024, true);
bool ok = (ptr != NULL) && (((u64)ptr & (page - 1u)) == 0); PageAllocator alloc = PageAllocatorInit();
Allocator *alloc_base = ALLOCATOR_OF(&alloc);
size page = PageAllocatorPageSize(&alloc);
if (PageAllocatorEntryCount(&alloc) != 0) {
Last updated on