[all-commits] [llvm/llvm-project] db00fa: [compiler-rt][asan] decommit shadow memory for unm...

Marco Vanotti via All-commits all-commits at lists.llvm.org
Tue Jul 21 11:08:25 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: db00fac2a2b8641c20acd69b549943409145e8cb
      https://github.com/llvm/llvm-project/commit/db00fac2a2b8641c20acd69b549943409145e8cb
  Author: Marco Vanotti <mvanotti at google.com>
  Date:   2020-07-21 (Tue, 21 Jul 2020)

  Changed paths:
    M compiler-rt/lib/asan/asan_fuchsia.cpp
    M compiler-rt/lib/asan/asan_linux.cpp
    M compiler-rt/lib/asan/asan_mac.cpp
    M compiler-rt/lib/asan/asan_poisoning.cpp
    M compiler-rt/lib/asan/asan_rtems.cpp
    M compiler-rt/lib/asan/asan_win.cpp

  Log Message:
  -----------
  [compiler-rt][asan] decommit shadow memory for unmaps in fuchsia.

This CL allows asan allocator in fuchsia to decommit shadow memory
for memory allocated using mmap.

Big allocations in asan end up being allocated via `mmap` and freed with
`munmap`. However, when that memory is freed, asan returns the
corresponding shadow memory back to the OS via a call to
`ReleaseMemoryPagesToOs`.

In fuchsia, `ReleaseMemoryPagesToOs` is a no-op: to be able to free
memory back to the OS, you have to hold a handle to the vmo you want to
modify, which is tricky at the ReleaseMemoryPagesToOs level as that
function is not exclusively used for shadow memory.

The function `__sanitizer_fill_shadow` fills a given shadow memory range
with a specific value, and if that value is 0 (unpoison) and the memory
range is bigger than a threshold parameter, it will decommit that memory
if it is all zeroes.

This CL modifies the `FlushUnneededASanShadowMemory` function in
`asan_poisoning.cpp` to add a call to `__sanitizer_fill_shadow` with
value and threshold = 0. This way, all the unneeded shadow memory gets
returned back to the OS.

A test for this behavior can be found in fxrev.dev/391974

Differential Revision: https://reviews.llvm.org/D80355

Change-Id: Id6dd85693e78a222f0329d5b2201e0da753e01c0




More information about the All-commits mailing list