[compiler-rt] r225323 - [asan] add a flag soft_rss_limit_mb

Jay Foad jay.foad at gmail.com
Fri Jan 9 01:07:22 PST 2015


Should this be memory_order_acquire ?

  bool RssLimitIsExceeded() {
    return atomic_load(&rss_limit_is_exceeded_, memory_order_release);
  }

On 9 January 2015 at 09:03, Jay Foad <jay.foad at gmail.com> wrote:
> Hi Kostya,
>
> This commit seems to be causing a bunch of failures in check-asan on
> PowerPC64 Linux, using GCC 4.8.3 as the host compiler:
>
> Failing Tests (80):
>     AddressSanitizer64 :: TestCases/Linux/coverage-caller-callee-total-count.cc
>     AddressSanitizer64 :: TestCases/Linux/coverage-caller-callee.cc
>     AddressSanitizer64 :: TestCases/Linux/coverage-direct-activation.cc
>     AddressSanitizer64 :: TestCases/Linux/coverage-direct-large.cc
>     AddressSanitizer64 :: TestCases/Linux/coverage-direct.cc
>     AddressSanitizer64 :: TestCases/Linux/coverage-module-unloaded.cc
>     AddressSanitizer64 :: TestCases/Linux/function-sections-are-bad.cc
>     AddressSanitizer64 :: TestCases/Linux/interception_malloc_test.cc
>     AddressSanitizer64 :: TestCases/Linux/interception_readdir_r_test.cc
>     AddressSanitizer64 :: TestCases/Linux/interception_test.cc
>     AddressSanitizer64 :: TestCases/Linux/malloc_delete_mismatch.cc
>     AddressSanitizer64 :: TestCases/Linux/sized_delete_test.cc
>     AddressSanitizer64 :: TestCases/Linux/stack-trace-dlclose.cc
>     AddressSanitizer64 :: TestCases/Linux/stress_dtls.c
>     AddressSanitizer64 :: TestCases/Linux/uar_signals.cc
>     AddressSanitizer64 :: TestCases/Posix/asan-symbolize-sanity-test.cc
>     AddressSanitizer64 :: TestCases/Posix/asprintf.cc
>     AddressSanitizer64 :: TestCases/Posix/assign_large_valloc_to_global.cc
>     AddressSanitizer64 :: TestCases/Posix/glob.cc
>     AddressSanitizer64 :: TestCases/Posix/init-order-dlopen.cc
>     AddressSanitizer64 :: TestCases/Posix/large_allocator_unpoisons_on_free.cc
>     AddressSanitizer64 :: TestCases/Posix/new_array_cookie_test.cc
>     AddressSanitizer64 :: TestCases/Posix/new_array_cookie_uaf_test.cc
>     AddressSanitizer64 ::
> TestCases/Posix/new_array_cookie_with_new_from_class.cc
>     AddressSanitizer64 :: TestCases/Posix/shared-lib-test.cc
>     AddressSanitizer64 :: TestCases/Posix/start-deactivated.cc
>     AddressSanitizer64 :: TestCases/Posix/tsd_dtor_leak.cc
>     AddressSanitizer64 :: TestCases/allocator_returns_null.cc
>     AddressSanitizer64 :: TestCases/asan_and_llvm_coverage_test.cc
>     AddressSanitizer64 :: TestCases/atexit_stats.cc
>     AddressSanitizer64 :: TestCases/contiguous_container.cc
>     AddressSanitizer64 :: TestCases/current_allocated_bytes.cc
>     AddressSanitizer64 :: TestCases/debug_locate.cc
>     AddressSanitizer64 :: TestCases/debug_report.cc
>     AddressSanitizer64 :: TestCases/debug_stacks.cc
>     AddressSanitizer64 :: TestCases/deep_stack_uaf.cc
>     AddressSanitizer64 :: TestCases/deep_thread_stack.cc
>     AddressSanitizer64 :: TestCases/describe_address.cc
>     AddressSanitizer64 :: TestCases/double-free.cc
>     AddressSanitizer64 :: TestCases/free_hook_realloc.cc
>     AddressSanitizer64 :: TestCases/frexp_interceptor.cc
>     AddressSanitizer64 :: TestCases/gc-test.cc
>     AddressSanitizer64 :: TestCases/heap-overflow-large.cc
>     AddressSanitizer64 :: TestCases/heap-overflow.cc
>     AddressSanitizer64 :: TestCases/huge_negative_hea_oob.cc
>     AddressSanitizer64 :: TestCases/init-order-pthread-create.cc
>     AddressSanitizer64 :: TestCases/inline.cc
>     AddressSanitizer64 :: TestCases/interception_failure_test.cc
>     AddressSanitizer64 :: TestCases/intra-object-overflow.cc
>     AddressSanitizer64 :: TestCases/invalid-free.cc
>     AddressSanitizer64 :: TestCases/large_func_test.cc
>     AddressSanitizer64 :: TestCases/log-path_test.cc
>     AddressSanitizer64 :: TestCases/lsan_annotations.cc
>     AddressSanitizer64 :: TestCases/malloc_context_size.cc
>     AddressSanitizer64 :: TestCases/malloc_fill.cc
>     AddressSanitizer64 :: TestCases/max_redzone.cc
>     AddressSanitizer64 :: TestCases/memset_test.cc
>     AddressSanitizer64 :: TestCases/on_error_callback.cc
>     AddressSanitizer64 :: TestCases/partial_right.cc
>     AddressSanitizer64 :: TestCases/poison_partial.cc
>     AddressSanitizer64 :: TestCases/print_summary.cc
>     AddressSanitizer64 :: TestCases/printf-2.c
>     AddressSanitizer64 :: TestCases/sanity_check_pure_c.c
>     AddressSanitizer64 :: TestCases/stack-overflow.cc
>     AddressSanitizer64 :: TestCases/stack-use-after-return.cc
>     AddressSanitizer64 :: TestCases/strdup_oob_test.cc
>     AddressSanitizer64 :: TestCases/strip_path_prefix.c
>     AddressSanitizer64 :: TestCases/suppressions-function.cc
>     AddressSanitizer64 :: TestCases/suppressions-interceptor.cc
>     AddressSanitizer64 :: TestCases/suppressions-library.cc
>     AddressSanitizer64 :: TestCases/throw_call_test.cc
>     AddressSanitizer64 :: TestCases/throw_catch.cc
>     AddressSanitizer64 :: TestCases/throw_invoke_test.cc
>     AddressSanitizer64 :: TestCases/time_interceptor.cc
>     AddressSanitizer64 :: TestCases/uar_and_exceptions.cc
>     AddressSanitizer64 :: TestCases/unaligned_loads_and_stores.cc
>     AddressSanitizer64 :: TestCases/use-after-delete.cc
>     AddressSanitizer64 :: TestCases/use-after-free-right.cc
>     AddressSanitizer64 :: TestCases/use-after-free.cc
>     AddressSanitizer64 :: TestCases/use-after-poison.cc
>
>   Expected Passes    : 63
>   Expected Failures  : 6
>   Unsupported Tests  : 107
>   Unexpected Failures: 80
>
> Many (all?) of the failing tests print this:
>
> ==58738==AddressSanitizer CHECK failed:
> /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_atomic_clang_other.h:28
> "((mo & (memory_order_relaxed | memory_order_consume |
> memory_order_acquire | memory_order_seq_cst))) != (0)" (0x0, 0x0)
>
> Here's a call stack at the point of failure.
>
> (gdb) bt
> #0  __sanitizer::CheckFailed (
>     file=0x100f8c88
> "/home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_atomic_clang_other.h",
> line=28,
>     cond=0x100f96e8 "((mo & (memory_order_relaxed |
> memory_order_consume | memory_order_acquire | memory_order_seq_cst)))
> != (0)", v1=0, v2=0)
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_common.cc:123
> #1  0x0000000010024b90 in atomic_load<__sanitizer::atomic_uint8_t> (
>     mo=__sanitizer::memory_order_release,
>     a=0x1034a249 <__asan::instance+2097793>)
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_atomic_clang_other.h:27
> #2  RssLimitIsExceeded (this=0x10149fc8 <__asan::instance>)
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator.h:1321
> #3  Allocate (check_rss_limit=true, cleared=false, alignment=8,
>     size=<optimized out>, cache=<optimized out>,
>     this=0x10149fc8 <__asan::instance>)
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator.h:1288
> #4  __asan::Allocator::Allocate (this=0x10149fc8 <__asan::instance>,
>     size=<optimized out>, alignment=<optimized out>, stack=0x3fffffffdfe0,
>     alloc_type=<optimized out>, can_fill=<optimized out>)
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/asan_allocator.cc:368
> #5  0x00000000100f6208 in operator new (size=154)
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:62
> #6  0x00003fffb7ebbf34 in .std::string::_Rep::_S_create(unsigned long,
> unsigned long, std::allocator<char> const&) () from
> /lib64/libstdc++.so.6
> #7  0x00003fffb7ebed10 in .char* std::string::_S_construct<char
> const*>(char const*, char const*, std::allocator<char> const&,
> std::forward_iterator_tag) ()
>    from /lib64/libstdc++.so.6
> #8  0x00003fffb7ebf4e8 in .std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::basic_string(char
> const*, std::allocator<char> const&) ()
>    from /lib64/libstdc++.so.6
> #9  0x00000000100f76ec in .main ()
>     at /home/foad/llvm-project/llvm/projects/compiler-rt/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc:25
>
> Thanks,
> Jay.
>
> On 6 January 2015 at 23:53, Kostya Serebryany <kcc at google.com> wrote:
>> Author: kcc
>> Date: Tue Jan  6 17:53:32 2015
>> New Revision: 225323
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=225323&view=rev
>> Log:
>> [asan] add a flag soft_rss_limit_mb
>>
>> Added:
>>     compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc
>> Modified:
>>     compiler-rt/trunk/lib/asan/asan_allocator.cc
>>     compiler-rt/trunk/lib/asan/asan_allocator.h
>>     compiler-rt/trunk/lib/asan/asan_rtl.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h
>>
>> Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=225323&r1=225322&r2=225323&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
>> +++ compiler-rt/trunk/lib/asan/asan_allocator.cc Tue Jan  6 17:53:32 2015
>> @@ -361,15 +361,21 @@ struct Allocator {
>>
>>      AsanThread *t = GetCurrentThread();
>>      void *allocated;
>> +    bool check_rss_limit = true;
>>      if (t) {
>>        AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
>> -      allocated = allocator.Allocate(cache, needed_size, 8, false);
>> +      allocated =
>> +          allocator.Allocate(cache, needed_size, 8, false, check_rss_limit);
>>      } else {
>>        SpinMutexLock l(&fallback_mutex);
>>        AllocatorCache *cache = &fallback_allocator_cache;
>> -      allocated = allocator.Allocate(cache, needed_size, 8, false);
>> +      allocated =
>> +          allocator.Allocate(cache, needed_size, 8, false, check_rss_limit);
>>      }
>>
>> +    if (!allocated)
>> +      return allocator.ReturnNullOrDie();
>> +
>>      if (*(u8 *)MEM_TO_SHADOW((uptr)allocated) == 0 && CanPoisonMemory()) {
>>        // Heap poisoning is enabled, but the allocator provides an unpoisoned
>>        // chunk. This is possible if CanPoisonMemory() was false for some
>> @@ -771,6 +777,10 @@ void asan_mz_force_unlock() {
>>    instance.ForceUnlock();
>>  }
>>
>> +void AsanSoftRssLimitExceededCallback(bool exceeded) {
>> +  instance.allocator.SetRssLimitIsExceeded(exceeded);
>> +}
>> +
>>  }  // namespace __asan
>>
>>  // --- Implementation of LSan-specific functions --- {{{1
>>
>> Modified: compiler-rt/trunk/lib/asan/asan_allocator.h
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.h?rev=225323&r1=225322&r2=225323&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/asan/asan_allocator.h (original)
>> +++ compiler-rt/trunk/lib/asan/asan_allocator.h Tue Jan  6 17:53:32 2015
>> @@ -173,6 +173,7 @@ void asan_mz_force_lock();
>>  void asan_mz_force_unlock();
>>
>>  void PrintInternalAllocatorStats();
>> +void AsanSoftRssLimitExceededCallback(bool exceeded);
>>
>>  }  // namespace __asan
>>  #endif  // ASAN_ALLOCATOR_H
>>
>> Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=225323&r1=225322&r2=225323&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
>> +++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue Jan  6 17:53:32 2015
>> @@ -396,6 +396,7 @@ static void AsanInitInternal() {
>>    InitializeAllocator(allocator_options);
>>
>>    MaybeStartBackgroudThread();
>> +  SetSoftRssLimitExceededCallback(AsanSoftRssLimitExceededCallback);
>>
>>    // On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited
>>    // should be set to 1 prior to initializing the threads.
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=225323&r1=225322&r2=225323&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Tue Jan  6 17:53:32 2015
>> @@ -1279,12 +1279,14 @@ class CombinedAllocator {
>>    }
>>
>>    void *Allocate(AllocatorCache *cache, uptr size, uptr alignment,
>> -                 bool cleared = false) {
>> +                 bool cleared = false, bool check_rss_limit = false) {
>>      // Returning 0 on malloc(0) may break a lot of code.
>>      if (size == 0)
>>        size = 1;
>>      if (size + alignment < size)
>>        return ReturnNullOrDie();
>> +    if (check_rss_limit && RssLimitIsExceeded())
>> +      return ReturnNullOrDie();
>>      if (alignment > 8)
>>        size = RoundUpTo(size, alignment);
>>      void *res;
>> @@ -1315,6 +1317,15 @@ class CombinedAllocator {
>>      atomic_store(&may_return_null_, may_return_null, memory_order_release);
>>    }
>>
>> +  bool RssLimitIsExceeded() {
>> +    return atomic_load(&rss_limit_is_exceeded_, memory_order_release);
>> +  }
>> +
>> +  void SetRssLimitIsExceeded(bool rss_limit_is_exceeded) {
>> +    atomic_store(&rss_limit_is_exceeded_, rss_limit_is_exceeded,
>> +                 memory_order_release);
>> +  }
>> +
>>    void Deallocate(AllocatorCache *cache, void *p) {
>>      if (!p) return;
>>      if (primary_.PointerIsMine(p))
>> @@ -1428,6 +1439,7 @@ class CombinedAllocator {
>>    SecondaryAllocator secondary_;
>>    AllocatorGlobalStats stats_;
>>    atomic_uint8_t may_return_null_;
>> +  atomic_uint8_t rss_limit_is_exceeded_;
>>  };
>>
>>  // Returns true if calloc(size, n) should return 0 due to overflow in size*n.
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=225323&r1=225322&r2=225323&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Tue Jan  6 17:53:32 2015
>> @@ -254,6 +254,12 @@ typedef void (*CheckFailedCallbackType)(
>>                                         u64, u64);
>>  void SetCheckFailedCallback(CheckFailedCallbackType callback);
>>
>> +// Callback will be called if soft_rss_limit_mb is given and the limit is
>> +// exceeded (exceeded==true) or if rss went down below the limit
>> +// (exceeded==false).
>> +// The callback should be registered once at the tool init time.
>> +void SetSoftRssLimitExceededCallback(void (*Callback)(bool exceeded));
>> +
>>  // Functions related to signal handling.
>>  typedef void (*SignalHandlerType)(int, void *, void *);
>>  bool IsDeadlySignal(int signum);
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=225323&r1=225322&r2=225323&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc Tue Jan  6 17:53:32 2015
>> @@ -60,10 +60,18 @@ void ReportErrorSummary(const char *erro
>>  #endif
>>  }
>>
>> +static void (*SoftRssLimitExceededCallback)(bool exceeded);
>> +void SetSoftRssLimitExceededCallback(void (*Callback)(bool exceeded)) {
>> +  CHECK_EQ(SoftRssLimitExceededCallback, nullptr);
>> +  SoftRssLimitExceededCallback = Callback;
>> +}
>> +
>>  void BackgroundThread(void *arg) {
>>    uptr hard_rss_limit_mb = common_flags()->hard_rss_limit_mb;
>> +  uptr soft_rss_limit_mb = common_flags()->soft_rss_limit_mb;
>>    uptr prev_reported_rss = 0;
>>    uptr prev_reported_stack_depot_size = 0;
>> +  bool reached_soft_rss_limit = false;
>>    while (true) {
>>      SleepForMillis(100);
>>      uptr current_rss_mb = GetRSS() >> 20;
>> @@ -91,13 +99,28 @@ void BackgroundThread(void *arg) {
>>        DumpProcessMap();
>>        Die();
>>      }
>> +    if (soft_rss_limit_mb) {
>> +      if (soft_rss_limit_mb < current_rss_mb && !reached_soft_rss_limit) {
>> +        reached_soft_rss_limit = true;
>> +        Report("%s: soft rss limit exhausted (%zdMb vs %zdMb)\n",
>> +               SanitizerToolName, soft_rss_limit_mb, current_rss_mb);
>> +        if (SoftRssLimitExceededCallback)
>> +          SoftRssLimitExceededCallback(true);
>> +      } else if (soft_rss_limit_mb >= current_rss_mb &&
>> +                 reached_soft_rss_limit) {
>> +        reached_soft_rss_limit = false;
>> +        if (SoftRssLimitExceededCallback)
>> +          SoftRssLimitExceededCallback(false);
>> +      }
>> +    }
>>    }
>>  }
>>
>>  void MaybeStartBackgroudThread() {
>>    if (!SANITIZER_LINUX) return;  // Need to implement/test on other platforms.
>> -  // Currently, only start the background thread if hard_rss_limit_mb is given.
>> -  if (!common_flags()->hard_rss_limit_mb) return;
>> +  // Start the background thread if one of the rss limits is given.
>> +  if (!common_flags()->hard_rss_limit_mb &&
>> +      !common_flags()->soft_rss_limit_mb) return;
>>    if (!real_pthread_create) return;  // Can't spawn the thread anyway.
>>    internal_start_thread(BackgroundThread, nullptr);
>>  }
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=225323&r1=225322&r2=225323&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc Tue Jan  6 17:53:32 2015
>> @@ -91,10 +91,19 @@ COMMON_FLAG(uptr, mmap_limit_mb, 0,
>>              "Limit the amount of mmap-ed memory (excluding shadow) in Mb; "
>>              "not a user-facing flag, used mosly for testing the tools")
>>  COMMON_FLAG(uptr, hard_rss_limit_mb, 0,
>> -            "RSS limit in Mb."
>> +            "Hard RSS limit in Mb."
>>              " If non-zero, a background thread is spawned at startup"
>>              " which periodically reads RSS and aborts the process if the"
>>              " limit is reached")
>> +COMMON_FLAG(uptr, soft_rss_limit_mb, 0,
>> +            "Soft RSS limit in Mb."
>> +            " If non-zero, a background thread is spawned at startup"
>> +            " which periodically reads RSS. If the limit is reached"
>> +            " all subsequent malloc/new calls will fail or return NULL"
>> +            " (depending on the value of allocator_may_return_null)"
>> +            " until the RSS goes below the soft limit."
>> +            " This limit does not affect memory allocations other than"
>> +            " malloc/new.")
>>  COMMON_FLAG(
>>      bool, coverage, false,
>>      "If set, coverage information will be dumped at program shutdown (if the "
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h?rev=225323&r1=225322&r2=225323&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h Tue Jan  6 17:53:32 2015
>> @@ -134,6 +134,7 @@ class QuarantineCache {
>>        size += sizeof(QuarantineBatch);  // Count the batch in Quarantine size.
>>      }
>>      QuarantineBatch *b = list_.back();
>> +    CHECK(b);
>>      b->batch[b->count++] = ptr;
>>      b->size += size;
>>      SizeAdd(size);
>> @@ -172,6 +173,7 @@ class QuarantineCache {
>>
>>    NOINLINE QuarantineBatch* AllocBatch(Callback cb) {
>>      QuarantineBatch *b = (QuarantineBatch *)cb.Allocate(sizeof(*b));
>> +    CHECK(b);
>>      b->count = 0;
>>      b->size = 0;
>>      list_.push_back(b);
>>
>> Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc
>> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc?rev=225323&view=auto
>> ==============================================================================
>> --- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc (added)
>> +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/soft_rss_limit_mb_test.cc Tue Jan  6 17:53:32 2015
>> @@ -0,0 +1,62 @@
>> +// Check soft_rss_limit_mb. Not all sanitizers implement it yet.
>> +// RUN: %clangxx -O2 %s -o %t
>> +//
>> +// Run with limit should fail:
>> +// RUN: %tool_options=soft_rss_limit_mb=400:quarantine_size=1:allocator_may_return_null=1     %run %t 2>&1 | FileCheck %s -check-prefix=CHECK_MAY_RETURN_1
>> +// RUN: %tool_options=soft_rss_limit_mb=400:quarantine_size=1:allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s -check-prefix=CHECK_MAY_RETURN_0
>> +
>> +// FIXME: make it work for other sanitizers.
>> +// XFAIL: lsan
>> +// XFAIL: tsan
>> +// XFAIL: msan
>> +#include <stdlib.h>
>> +#include <stdio.h>
>> +#include <string.h>
>> +#include <unistd.h>
>> +
>> +static const int kMaxNumAllocs = 1 << 10;
>> +static const int kAllocSize = 1 << 20;  // Large enough to go vi mmap.
>> +
>> +static char *allocs[kMaxNumAllocs];
>> +
>> +int main() {
>> +  int num_allocs = kMaxNumAllocs / 4;
>> +  for (int i = 0; i < 3; i++, num_allocs *= 2) {
>> +    fprintf(stderr, "[%d] allocating %d times\n", i, num_allocs);
>> +    int zero_results = 0;
>> +    for (int j = 0; j < num_allocs; j++) {
>> +      if ((j % (num_allocs / 4)) == 0) {
>> +        usleep(100000);
>> +        fprintf(stderr, "  [%d]\n", j);
>> +      }
>> +      allocs[j] = (char*)malloc(kAllocSize);
>> +      if (allocs[j])
>> +        memset(allocs[j], -1, kAllocSize);
>> +      else
>> +        zero_results++;
>> +    }
>> +    if (zero_results)
>> +      fprintf(stderr, "Some of the malloc calls returned null: %d\n",
>> +              zero_results);
>> +    if (zero_results != num_allocs)
>> +      fprintf(stderr, "Some of the malloc calls returned non-null: %d\n",
>> +              num_allocs - zero_results);
>> +    for (int j = 0; j < num_allocs; j++) {
>> +      free(allocs[j]);
>> +    }
>> +  }
>> +}
>> +
>> +// CHECK_MAY_RETURN_1: allocating 256 times
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned non-null: 256
>> +// CHECK_MAY_RETURN_1: allocating 512 times
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned null:
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned non-null:
>> +// CHECK_MAY_RETURN_1: allocating 1024 times
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned null:
>> +// CHECK_MAY_RETURN_1: Some of the malloc calls returned non-null:
>> +
>> +// CHECK_MAY_RETURN_0: allocating 256 times
>> +// CHECK_MAY_RETURN_0: Some of the malloc calls returned non-null: 256
>> +// CHECK_MAY_RETURN_0: allocating 512 times
>> +// CHECK_MAY_RETURN_0: allocator is terminating the process instead of returning
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list