Search code examples
csizemallocprocessor

how to find out the page size of a processor using C program and malloc?


is it possible to find out the page size of a processor using C program and malloc? and not by using sysconf() call?


Solution

  • If you can #include some linux kernel header, you can find the macro PAGE_SIZE in

    <asm/page.h>
    

    On cygwin (and perhaps windows' ddk) i's in

    <w32api/ddk/winddk.h>
    

    There are "dirty tricks" (very, very dirty!) to calculat the page size at runtime. All unportable and totally system-dependent.

    Let's have some fun!

    A possible trick on may systems is to create a shared memory object only 1 byte long. The system call usually rounds the size up to the system page size. Bleach!

    Another one, if you are running on unix-like systems and you dare to intercept the SIGSEGV signal, you could try to explore the memory by looking for valid areas and see which power of 2 they are rounded. Uhm...

    So, why sysctl is not good for you?

    Regards