Skip to content
Snippets Groups Projects
  • Nadav Har'El's avatar
    6924f7db
    Fix mincore() on non-mmap()ed memory · 6924f7db
    Nadav Har'El authored
    Commit 65afd075 fixed mincore() to recognize
    unmapped addresses. However, it used mmu::ismapped() which just checks for
    mmap()'ed addresses, and doesn't know about malloc()ed memory. This causes
    trouble for libunwind (which we use for backtrace()) which tests mincore()
    on an on-stack variable, and for non-pthread threads, this stack might be
    malloc'ed, not mmap'ed.
    
    So this patch adds mmu::isreadable(), which checks that a given memory range
    is all readable (this memory can be mmapped, malloced, stack, whatever).
    mincore() now uses that.
    
    mmu::isreadable() is implemented, following Avi's idea, by trying to read,
    with safe_load(), one byte from every page in the range. This approach is
    faster than page-table-walking especially for one-byte checks (which all
    libunwind uses anyway), and also very simple.
    6924f7db
    History
    Fix mincore() on non-mmap()ed memory
    Nadav Har'El authored
    Commit 65afd075 fixed mincore() to recognize
    unmapped addresses. However, it used mmu::ismapped() which just checks for
    mmap()'ed addresses, and doesn't know about malloc()ed memory. This causes
    trouble for libunwind (which we use for backtrace()) which tests mincore()
    on an on-stack variable, and for non-pthread threads, this stack might be
    malloc'ed, not mmap'ed.
    
    So this patch adds mmu::isreadable(), which checks that a given memory range
    is all readable (this memory can be mmapped, malloced, stack, whatever).
    mincore() now uses that.
    
    mmu::isreadable() is implemented, following Avi's idea, by trying to read,
    with safe_load(), one byte from every page in the range. This approach is
    faster than page-table-walking especially for one-byte checks (which all
    libunwind uses anyway), and also very simple.