Can someone explain what is this piece of code do?
pa_offset = offset & ~(sysconf(_SC_PAGE_SIZE) - 1);
/* offset for mmap() must be page aligned */
I understand that here sysconf
returns the page size, which lets assume that it is 4096, but after that I am not able to understand the logic. Thanks in advance.
If sysconf
returns the page size, which is a power of two or 00..00100..00
in binary, - 1
makes a mask of that number (that is, it makes a number of the form 00..0011..11
, then ~
computes the reverse of this mask (11..1100..00
). Lastly, the bitwise and &
operation between the newly created mask and offset
rounds offset
down to the nearest multiple of the page size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With