From e48d698dc9f9532fb51a8eff9558176c60da4300 Mon Sep 17 00:00:00 2001 From: Kostya Kortchinsky Date: Wed, 13 Dec 2017 20:41:35 +0000 Subject: [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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320611 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/scudo/scudo_allocator.cpp | 18 ++++++++++++++++++ lib/scudo/scudo_interface_internal.h | 22 ++++++++++++++++++++++ lib/scudo/scudo_platform.h | 6 ++++++ 3 files changed, 46 insertions(+) create mode 100644 lib/scudo/scudo_interface_internal.h (limited to 'lib') diff --git a/lib/scudo/scudo_allocator.cpp b/lib/scudo/scudo_allocator.cpp index 47804c44c..19c89810a 100644 --- a/lib/scudo/scudo_allocator.cpp +++ b/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/lib/scudo/scudo_interface_internal.h b/lib/scudo/scudo_interface_internal.h new file mode 100644 index 000000000..3f39e0c4e --- /dev/null +++ b/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/lib/scudo/scudo_platform.h b/lib/scudo/scudo_platform.h index a915c9843..e1c9c32e9 100644 --- a/lib/scudo/scudo_platform.h +++ b/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 -- cgit v1.2.3