Overlapping pages with mmap (MAP_FIXED)

前端 未结 3 638
慢半拍i
慢半拍i 2021-02-04 07:08

Due to some obscure reasons which are not relevant for this question, I need to resort to use MAP_FIXED in order to obtain a page close to where the text section of libc lives i

3条回答
  •  粉色の甜心
    2021-02-04 07:33

    It seems that posix_mem_offset() is what I was looking for.

    Not only it tells you if an address is mapped but also, in case it happens to be mapped, it implicitly gives you the boundaries of the mapped area to which it belongs (by providing SIZE_MAX in the len argument).

    So, before enforcing MAP_FIXED, I can use posix_mem_offset() to verify that the address I am using is not mapped yet.

    I could use msync() or mincore() too (checking for an ENOMEM error tells you that an address is already mapped), but then I would be blinder (no information about the area where the address is mapped). Also, msync() has side effects which may have a performance impact and mincore() is BSD-only (not POSIX).

提交回复
热议问题