code queries
Ákos Uzonyi
uzonyi.akos at gmail.com
Wed Jul 15 18:21:06 UTC 2020
On Wed, 15 Jul 2020 at 19:27, Bran S <archsbran at gmail.com> wrote:
> Could you please elaborate on this magic calculation that is going on here.
> Link: https://github.com/strace/strace/blob/master/tests/tail_alloc.c#L16
>
> const size_t len = (size + page_size - 1) & -page_size;
>
> I have tried running it in several variations, but I fail to see the
> pattern by which value of the variable `len` changes.
> Why is doing this required?
If you are unsure why something is done differently than you would
think, just try your version and see what happens. If you remove this
"magic" calculation, munmap fails with EINVAL. Looking up the man
page, you quickly realize that EINVAL means "addr" (in this case
"tail_guard") is not aligned to a page boundary. So this magic
calculation just rounds up "size" to be a multiple of page_size.
More information about the Strace-devel
mailing list