Is it possible to get the page size for the target platform programmatically? Ideally this would be as a compile-time constant, but a runtime variable would be good too.
This is definitely a runtime rather than compile time constraint. On most *nix systems you’d call http://man7.org/linux/man-pages/man3/sysconf.3.html
Ah, oh well. Thanks!
Note that some platforms have multiple page sizes (4KB, 2MB and 1GB on x86).
PAGE_SIZE is always 4096 on x86 Linux – huge pages are a different beast.
Still, there definitely are other arches that have (statically) configurable sizes. Just grep for
define PAGE_SHIFT in the kernel sources for a taste, or
PAGE_SHIFT definitions in lxr. And there are other OSes that can have more dynamic per-process page sizes.
Here’s a taste of what can go wrong if you statically compile the page size: