The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
page.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * page size and alignment helpers: the one definition of PAGE_SIZE.
5 * the hardware page is 4 KiB on both i686 and x86_64.
6 */
7
8#include "common/stdint.h"
9
10// bytes in a page, and log2 of that
11#define PAGE_SHIFT 12u
12#define PAGE_SIZE (1u << PAGE_SHIFT)
13
14// mask of the offset-within-page bits
15#define PAGE_OFFSET_MASK (PAGE_SIZE - 1u)
16
17// round an address or size down / up to a page boundary
18#define PAGE_ALIGN_DOWN(x) ((x) & ~(uintptr_t)PAGE_OFFSET_MASK)
19#define PAGE_ALIGN_UP(x) (((x) + PAGE_OFFSET_MASK) & ~(uintptr_t)PAGE_OFFSET_MASK)
20
21// true if an address or size is a whole number of pages
22#define PAGE_IS_ALIGNED(x) (((x) & PAGE_OFFSET_MASK) == 0)
23
24// number of pages needed to hold a byte count
25#define PAGE_COUNT(bytes) (((bytes) + PAGE_OFFSET_MASK) >> PAGE_SHIFT)