Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 828
cforfun Avatar asked Dec 30 '25 19:12

cforfun


1 Answers

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

like image 137
Giuseppe Guerrini Avatar answered Jan 01 '26 10:01

Giuseppe Guerrini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!