u64 Offset : 20; // Offset from the beginning of the backend
// allocation to the beginning chunk itself, in
// multiples of MinAlignment. See comment about its
- // maximum value and test in Initialize.
+ // maximum value and test in init().
u64 Unused_1_ : 28;
u16 Salt : 16;
};
#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_flag_parser.h"
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
+const char* __scudo_default_options();
+
namespace __scudo {
-Flags scudo_flags_dont_use_directly; // use via flags().
+Flags ScudoFlags; // Use via getFlags().
void Flags::setDefaults() {
#define SCUDO_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
#undef SCUDO_FLAG
}
+static const char *callGetScudoDefaultOptions() {
+ return (&__scudo_default_options) ? __scudo_default_options() : "";
+}
+
void initFlags() {
SetCommonFlagsDefaults();
{
Flags *f = getFlags();
f->setDefaults();
- FlagParser scudo_parser;
- RegisterScudoFlags(&scudo_parser, f);
- RegisterCommonFlags(&scudo_parser);
+ FlagParser ScudoParser;
+ RegisterScudoFlags(&ScudoParser, f);
+ RegisterCommonFlags(&ScudoParser);
+
+ // Override from user-specified string.
+ const char *ScudoDefaultOptions = callGetScudoDefaultOptions();
+ ScudoParser.ParseString(ScudoDefaultOptions);
- scudo_parser.ParseString(GetEnv("SCUDO_OPTIONS"));
+ // Override from environment.
+ ScudoParser.ParseString(GetEnv("SCUDO_OPTIONS"));
InitializeCommonFlags();
}
Flags *getFlags() {
- return &scudo_flags_dont_use_directly;
+ return &ScudoFlags;
}
}
///
//===----------------------------------------------------------------------===//
+#include "scudo_utils.h"
+
#include "sanitizer_common/sanitizer_common.h"
namespace __sanitizer {
-bool AddDieCallback(DieCallbackType callback) { return true; }
+bool AddDieCallback(DieCallbackType Callback) { return true; }
-bool RemoveDieCallback(DieCallbackType callback) { return true; }
+bool RemoveDieCallback(DieCallbackType Callback) { return true; }
-void SetUserDieCallback(DieCallbackType callback) {}
+void SetUserDieCallback(DieCallbackType Callback) {}
void NORETURN Die() {
if (common_flags()->abort_on_error)
void SetCheckFailedCallback(CheckFailedCallbackType callback) {}
-void NORETURN CheckFailed(const char *file, int line, const char *cond,
- u64 v1, u64 v2) {
- Report("Sanitizer CHECK failed: %s:%d %s (%lld, %lld)\n", file, line, cond,
- v1, v2);
- Die();
+void NORETURN CheckFailed(const char *File, int Line, const char *Condition,
+ u64 Value1, u64 Value2) {
+ __scudo::dieWithMessage("Scudo CHECK failed: %s:%d %s (%lld, %lld)\n",
+ File, Line, Condition, Value1, Value2);
}
} // namespace __sanitizer
namespace __scudo {
FORMAT(1, 2)
-void dieWithMessage(const char *Format, ...) {
+void NORETURN dieWithMessage(const char *Format, ...) {
// Our messages are tiny, 128 characters is more than enough.
char Message[128];
va_list Args;
--- /dev/null
+// RUN: %clang_scudo %s -o %t
+// RUN: %run %t 2>&1
+// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t 2>&1
+// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t 2>&1 | FileCheck %s
+
+// Tests that the options can be passed using getScudoDefaultOptions, and that
+// the environment ones take precedence over them.
+
+#include <stdlib.h>
+#include <malloc.h>
+
+extern "C" const char* __scudo_default_options() {
+ return "DeallocationTypeMismatch=0"; // Defaults to true in scudo_flags.inc.
+}
+
+int main(int argc, char **argv)
+{
+ int *p = (int *)malloc(16);
+ if (!p)
+ return 1;
+ delete p;
+ return 0;
+}
+
+// CHECK: ERROR: allocation type mismatch on address
Options
-------
-Several aspects of the allocator can be configured through environment options,
-following the usual ASan options syntax, through the variable SCUDO_OPTIONS.
+Several aspects of the allocator can be configured through the following ways:
+
+- by defining a __scudo_default_options function in one's program that returns
+ the options string to be parsed. Said function must have the following
+ prototype: ``extern "C" const char* __scudo_default_options()``.
+
+- through the environment variable SCUDO_OPTIONS, containing the options string
+ to be parsed. Options defined this way will override any definition made
+ through __scudo_default_options;
+
+The options string follows a syntax similar to ASan, where distinct options
+can be assigned in the same string, separated by colons.
+
+For example, using the environment variable:
+
+.. code::
+
+ SCUDO_OPTIONS="DeleteSizeMismatch=1:QuarantineSizeMb=16" ./a.out
+
+Or using the function:
+
+.. code::
+
+ extern "C" const char *__scudo_default_options() {
+ return "DeleteSizeMismatch=1:QuarantineSizeMb=16";
+ }
-For example: SCUDO_OPTIONS="DeleteSizeMismatch=1:QuarantineSizeMb=16".
The following options are available: