[PATCH] D47642: [asan, myriad] Implement aligned local pool allocation

Walter Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 1 14:33:10 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL333788: [asan, myriad] Implement aligned local pool allocation (authored by waltl, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D47642?vs=149552&id=149553#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47642

Files:
  compiler-rt/trunk/lib/asan/asan_malloc_linux.cc


Index: compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
===================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
+++ compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
@@ -18,6 +18,8 @@
 #if SANITIZER_FREEBSD || SANITIZER_FUCHSIA || SANITIZER_LINUX || \
     SANITIZER_NETBSD || SANITIZER_RTEMS || SANITIZER_SOLARIS
 
+#include "sanitizer_common/sanitizer_allocator_checks.h"
+#include "sanitizer_common/sanitizer_errno.h"
 #include "sanitizer_common/sanitizer_tls_get_addr.h"
 #include "asan_allocator.h"
 #include "asan_interceptors.h"
@@ -44,6 +46,27 @@
   return mem;
 }
 
+static int PosixMemalignFromLocalPool(void **memptr, uptr alignment,
+                                      uptr size_in_bytes) {
+  if (UNLIKELY(!CheckPosixMemalignAlignment(alignment)))
+    return errno_EINVAL;
+
+  CHECK(alignment >= kWordSize);
+
+  uptr addr = (uptr)&alloc_memory_for_dlsym[allocated_for_dlsym];
+  uptr aligned_addr = RoundUpTo(addr, alignment);
+  uptr aligned_size = RoundUpTo(size_in_bytes, kWordSize);
+
+  uptr *end_mem = (uptr*)(aligned_addr + aligned_size);
+  uptr allocated = end_mem - alloc_memory_for_dlsym;
+  if (allocated >= kDlsymAllocPoolSize)
+    return errno_ENOMEM;
+
+  allocated_for_dlsym = allocated;
+  *memptr = (void*)aligned_addr;
+  return 0;
+}
+
 // On RTEMS, we use the local pool to handle memory allocation before
 // the ASan run-time has been initialized.
 static INLINE bool EarlyMalloc() {
@@ -166,8 +189,9 @@
 #endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
 
 INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
+  if (UNLIKELY(UseLocalPool()))
+    return PosixMemalignFromLocalPool(memptr, alignment, size);
   GET_STACK_TRACE_MALLOC;
-  // Printf("posix_memalign: %zx %zu\n", alignment, size);
   return asan_posix_memalign(memptr, alignment, size, &stack);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47642.149553.patch
Type: text/x-patch
Size: 1894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180601/880276cc/attachment.bin>


More information about the llvm-commits mailing list