When in linux kernel space one can always use the kernel's own PAGE_SIZE and PAGE_SHIFT macros, but when I want to write user space code that will work regardless from the size of the size of these variables in the current machine, I have to use sysconf. For example to get the size of a page one could run sysconf(_SC_PAGESIZE). However I am looking for the PAGE_SHIFT value. Is there a similar proper way to get it or do I have to calculate it from the size of the page?
PAGE_SHIFT
should be in <sys/user.h>
$ printf '#include <sys/user.h>\nPAGE_SHIFT' | gcc -xc -E -P - | tail -n1
12