[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
//===-- harness.h -----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef GWP_ASAN_TESTS_HARNESS_H_
|
|
|
|
#define GWP_ASAN_TESTS_HARNESS_H_
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
// Include sanitizer_common first as gwp_asan/guarded_pool_allocator.h
|
|
|
|
// transiently includes definitions.h, which overwrites some of the definitions
|
|
|
|
// in sanitizer_common.
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
|
|
|
|
#include "gwp_asan/guarded_pool_allocator.h"
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
#include "gwp_asan/optional/backtrace.h"
|
|
|
|
#include "gwp_asan/optional/options_parser.h"
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
#include "gwp_asan/options.h"
|
|
|
|
|
|
|
|
class DefaultGuardedPoolAllocator : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
DefaultGuardedPoolAllocator() {
|
|
|
|
gwp_asan::options::Options Opts;
|
|
|
|
Opts.setDefaults();
|
|
|
|
MaxSimultaneousAllocations = Opts.MaxSimultaneousAllocations;
|
|
|
|
|
|
|
|
Opts.Printf = __sanitizer::Printf;
|
|
|
|
GPA.init(Opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
gwp_asan::GuardedPoolAllocator GPA;
|
|
|
|
decltype(gwp_asan::options::Options::MaxSimultaneousAllocations)
|
|
|
|
MaxSimultaneousAllocations;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CustomGuardedPoolAllocator : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
void
|
|
|
|
InitNumSlots(decltype(gwp_asan::options::Options::MaxSimultaneousAllocations)
|
|
|
|
MaxSimultaneousAllocationsArg) {
|
|
|
|
gwp_asan::options::Options Opts;
|
|
|
|
Opts.setDefaults();
|
|
|
|
|
|
|
|
Opts.MaxSimultaneousAllocations = MaxSimultaneousAllocationsArg;
|
|
|
|
MaxSimultaneousAllocations = MaxSimultaneousAllocationsArg;
|
|
|
|
|
|
|
|
Opts.Printf = __sanitizer::Printf;
|
|
|
|
GPA.init(Opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
gwp_asan::GuardedPoolAllocator GPA;
|
|
|
|
decltype(gwp_asan::options::Options::MaxSimultaneousAllocations)
|
|
|
|
MaxSimultaneousAllocations;
|
|
|
|
};
|
|
|
|
|
[GWP-ASan] Add generic unwinders and structure backtrace output.
Summary:
Adds two flavours of generic unwinder and all the supporting cruft. If the
supporting allocator is okay with bringing in sanitizer_common, they can use
the fast frame-pointer based unwinder from sanitizer_common. Otherwise, we also
provide the backtrace() libc-based unwinder as well. Of course, the allocator
can always specify its own unwinder and unwinder-symbolizer.
The slightly changed output format is exemplified in the first comment on this
patch. It now better incorporates backtrace information, and displays
allocation details on the second line.
Reviewers: eugenis, vlad.tsyrklevich
Reviewed By: eugenis, vlad.tsyrklevich
Subscribers: srhines, kubamracek, mgorny, cryptoad, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D63841
llvm-svn: 364941
2019-07-03 00:04:52 +08:00
|
|
|
class BacktraceGuardedPoolAllocator : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
BacktraceGuardedPoolAllocator() {
|
|
|
|
// Call initOptions to initialise the internal sanitizer_common flags. These
|
|
|
|
// flags are referenced by the sanitizer_common unwinder, and if left
|
|
|
|
// uninitialised, they'll unintentionally crash the program.
|
|
|
|
gwp_asan::options::initOptions();
|
|
|
|
|
|
|
|
gwp_asan::options::Options Opts;
|
|
|
|
Opts.setDefaults();
|
|
|
|
|
|
|
|
Opts.Printf = __sanitizer::Printf;
|
|
|
|
Opts.Backtrace = gwp_asan::options::getBacktraceFunction();
|
|
|
|
Opts.PrintBacktrace = gwp_asan::options::getPrintBacktraceFunction();
|
|
|
|
GPA.init(Opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
gwp_asan::GuardedPoolAllocator GPA;
|
|
|
|
};
|
|
|
|
|
[GWP-ASan] Core Guarded Pool Allocator [4].
Summary:
See D60593 for further information.
This patch introduces the core of GWP-ASan, being the guarded pool allocator. This class contains the logic for creating and maintaining allocations in the guarded pool. Its public interface is to be utilised by supporting allocators in order to provide sampled guarded allocation behaviour.
This patch also contains basic functionality tests of the allocator as unittests. The error-catching behaviour will be tested in upcoming patches that use Scudo as an implementing allocator.
Reviewers: vlad.tsyrklevich, eugenis, jfb
Reviewed By: vlad.tsyrklevich
Subscribers: dexonsmith, kubamracek, mgorny, cryptoad, jfb, #sanitizers, llvm-commits, morehouse
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D62872
llvm-svn: 362636
2019-06-06 03:42:48 +08:00
|
|
|
#endif // GWP_ASAN_TESTS_HARNESS_H_
|