[PATCH] D56621: [hwasan] Madvise away thread aux data

Evgenii Stepanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 11 16:19:44 PST 2019


eugenis created this revision.
eugenis added reviewers: kcc, pcc.
Herald added a subscriber: kubamracek.

Release memory pages for thread data (allocator cache, stack allocations
ring buffer, etc) when a thread exits. We can not simply munmap them
because this memory is custom allocated within a limited address range,
and it needs to stay "reserved".


https://reviews.llvm.org/D56621

Files:
  compiler-rt/lib/hwasan/hwasan_thread_list.h


Index: compiler-rt/lib/hwasan/hwasan_thread_list.h
===================================================================
--- compiler-rt/lib/hwasan/hwasan_thread_list.h
+++ compiler-rt/lib/hwasan/hwasan_thread_list.h
@@ -129,6 +129,12 @@
     return t;
   }
 
+  void DontNeedThread(Thread *t) {
+    uptr start = (uptr)t;
+    uptr end = start + sizeof(Thread) + ring_buffer_size_;
+    ReleaseMemoryPagesToOS(start, end);
+  }
+
   void ReleaseThread(Thread *t) {
     // FIXME: madvise away the ring buffer?
     RemoveThreadStats(t);
@@ -136,6 +142,7 @@
     SpinMutexLock l(&list_mutex_);
     live_list_.Remove(t);
     free_list_.Push(t);
+    DontNeedThread(t);
   }
 
   Thread *GetThreadByBufferAddress(uptr p) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56621.181389.patch
Type: text/x-patch
Size: 721 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190112/2c712ef3/attachment.bin>


More information about the llvm-commits mailing list