diff options
| author | Kostya Kortchinsky <kostyak@google.com> | 2017-12-13 20:41:35 +0000 |
|---|---|---|
| committer | Kostya Kortchinsky <kostyak@google.com> | 2017-12-13 20:41:35 +0000 |
| commit | f22f5fe9103be03cb93ba4587cec3e6af71ef784 (patch) | |
| tree | 0d9a21b3327b5cc35840c725d88ee3af18b7f494 /compiler-rt/lib | |
| parent | 51d7798237ba9ecbb4596f8399506485e548290f (diff) | |
| download | bcm5719-llvm-f22f5fe9103be03cb93ba4587cec3e6af71ef784.tar.gz bcm5719-llvm-f22f5fe9103be03cb93ba4587cec3e6af71ef784.zip | |
[scudo] Adding a public Scudo interface
Summary:
The first and only function to start with allows to set the soft or hard RSS
limit at runtime. Add associated tests.
Reviewers: alekseyshl
Reviewed By: alekseyshl
Subscribers: mgorny, #sanitizers, llvm-commits
Differential Revision: https://reviews.llvm.org/D41128
llvm-svn: 320611
Diffstat (limited to 'compiler-rt/lib')
| -rw-r--r-- | compiler-rt/lib/scudo/scudo_allocator.cpp | 18 | ||||
| -rw-r--r-- | compiler-rt/lib/scudo/scudo_interface_internal.h | 22 | ||||
| -rw-r--r-- | compiler-rt/lib/scudo/scudo_platform.h | 6 |
3 files changed, 46 insertions, 0 deletions
diff --git a/compiler-rt/lib/scudo/scudo_allocator.cpp b/compiler-rt/lib/scudo/scudo_allocator.cpp index 47804c44c4f..19c89810a3e 100644 --- a/compiler-rt/lib/scudo/scudo_allocator.cpp +++ b/compiler-rt/lib/scudo/scudo_allocator.cpp @@ -597,6 +597,14 @@ struct ScudoAllocator { initThreadMaybe(); return FailureHandler::OnBadRequest(); } + + void setRssLimit(uptr LimitMb, bool HardLimit) { + if (HardLimit) + HardRssLimitMb = LimitMb; + else + SoftRssLimitMb = LimitMb; + CheckRssLimit = HardRssLimitMb || SoftRssLimitMb; + } }; static ScudoAllocator Instance(LINKER_INITIALIZED); @@ -726,3 +734,13 @@ int __sanitizer_get_ownership(const void *Ptr) { uptr __sanitizer_get_allocated_size(const void *Ptr) { return Instance.getUsableSize(Ptr); } + +// Interface functions + +extern "C" { +void __scudo_set_rss_limit(unsigned long LimitMb, int HardLimit) { // NOLINT + if (!SCUDO_CAN_USE_PUBLIC_INTERFACE) + return; + Instance.setRssLimit(LimitMb, !!HardLimit); +} +} // extern "C" diff --git a/compiler-rt/lib/scudo/scudo_interface_internal.h b/compiler-rt/lib/scudo/scudo_interface_internal.h new file mode 100644 index 00000000000..3f39e0c4ee0 --- /dev/null +++ b/compiler-rt/lib/scudo/scudo_interface_internal.h @@ -0,0 +1,22 @@ +//===-- scudo_interface_internal.h ------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// Private Scudo interface header. +/// +//===----------------------------------------------------------------------===// + +#ifndef SCUDO_INTERFACE_INTERNAL_H_ +#define SCUDO_INTERFACE_INTERNAL_H_ + +extern "C" { +SANITIZER_INTERFACE_ATTRIBUTE +void __scudo_set_rss_limit(unsigned long LimitMb, int HardLimit); // NOLINT +} // extern "C" + +#endif // SCUDO_INTERFACE_INTERNAL_H_ diff --git a/compiler-rt/lib/scudo/scudo_platform.h b/compiler-rt/lib/scudo/scudo_platform.h index a915c9843a5..e1c9c32e9a6 100644 --- a/compiler-rt/lib/scudo/scudo_platform.h +++ b/compiler-rt/lib/scudo/scudo_platform.h @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// /// /// Scudo platform specific definitions. +/// TODO(kostyak): add tests for the compile time defines. /// //===----------------------------------------------------------------------===// @@ -45,6 +46,11 @@ # define SCUDO_SHARED_TSD_POOL_SIZE 32U #endif // SCUDO_SHARED_TSD_POOL_SIZE +// The following allows the public interface functions to be disabled. +#ifndef SCUDO_CAN_USE_PUBLIC_INTERFACE +# define SCUDO_CAN_USE_PUBLIC_INTERFACE 1 +#endif + namespace __scudo { #if SANITIZER_CAN_USE_ALLOCATOR64 |

