[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 08:56:32 PDT 2018


waltl created this revision.
waltl added reviewers: vitalybuka, eugenis, alekseyshl.
Herald added a subscriber: kubamracek.

Extend the local pool allocation support to posix_memalign.


Repository:
  rL LLVM

https://reviews.llvm.org/D47642

Files:
  compiler-rt/lib/asan/asan_malloc_linux.cc
  compiler-rt/lib/asan/asan_malloc_rtems.inc


Index: compiler-rt/lib/asan/asan_malloc_rtems.inc
===================================================================
--- /dev/null
+++ compiler-rt/lib/asan/asan_malloc_rtems.inc
@@ -0,0 +1,44 @@
+//===-- asan_malloc_rtems.inc ---------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is to be included by asan_malloc_linux.cc.  It implements
+// aligned local pool allocation for RTEMS.
+//
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_common/sanitizer_allocator_checks.h"
+#include "sanitizer_common/sanitizer_errno.h"
+
+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;
+}
+
+INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
+  if (UNLIKELY(UseLocalPool()))
+    return PosixMemalignFromLocalPool(memptr, alignment, size);
+  GET_STACK_TRACE_MALLOC;
+  return asan_posix_memalign(memptr, alignment, size, &stack);
+}
Index: compiler-rt/lib/asan/asan_malloc_linux.cc
===================================================================
--- compiler-rt/lib/asan/asan_malloc_linux.cc
+++ compiler-rt/lib/asan/asan_malloc_linux.cc
@@ -165,11 +165,15 @@
 }
 #endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
 
+#if !SANITIZER_RTEMS
 INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
   GET_STACK_TRACE_MALLOC;
   // Printf("posix_memalign: %zx %zu\n", alignment, size);
   return asan_posix_memalign(memptr, alignment, size, &stack);
 }
+#else
+#include "asan_malloc_rtems.inc"
+#endif // !SANITIZER_RTEMS
 
 INTERCEPTOR(void*, valloc, uptr size) {
   GET_STACK_TRACE_MALLOC;


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


More information about the llvm-commits mailing list