code from {A, UB}San to sanitizer_common code.
Add -fno-omit-frame-pointer -U_FORTIFY_SOURCE to lsan-force-options because
LSan heavily relies on frame pointers. Disable LSan in QEMU builds through
LSAN_OPTIONS file. Refactor Tizen specific patches in ASan and UBSan.
ubsan_parser.ParseString(ubsan_default_options);
#endif
- // Read from command line.
- const char *options = GetEnv("ASAN_OPTIONS");
- // If environment variable ASAN_OPTIONS is not set use predefined file to
- // init options.
- bool getFlagsFromFile = options == 0;
- char *asanFlags = 0;
- uptr len = GetPageSizeCached();
- uptr read_len = 0;
- if (getFlagsFromFile) {
- ReadFileToBuffer("/ASAN_OPTIONS", &asanFlags, &len, &read_len,
- GetPageSizeCached());
- options = asanFlags;
- }
-
+ int mmaped = 0;
+ const char *options =
+ GetRuntimeOptions("ASAN_OPTIONS", "/ASAN_OPTIONS", &mmaped);
asan_parser.ParseString(options);
+
#if CAN_SANITIZE_LEAKS
lsan_parser.ParseString(GetEnv("LSAN_OPTIONS"));
#endif
f->quarantine_size_mb = kDefaultQuarantineSizeMb;
}
- if (getFlagsFromFile)
- UnmapOrDie(asanFlags, len);
-
+ if (mmaped)
+ UnmapOrDie((void *)options, GetPageSizeCached());
}
} // namespace __asan
kHighShadowBeg > kMidMemEnd);
}
-extern "C"
-int mount(const char *source, const char *target, const char *filesystemtype,
- unsigned long mountflags, const void *data);
-
static void MaybeDisableUlimit() {
if (!AddressSpaceIsUnlimited())
SetAddressSpaceUnlimited();
}
-bool MaybeMountProcFS() {
- if (FileExists("/proc/self/maps")) return true;
-
- if(0 != mount("proc", "/proc", "proc", 0, 0)) {
- Report("Failed to mount /proc, Asan is likely to fail\n");
- return false;
- }
- return true;
-}
-
static void AsanInitInternal() {
if (LIKELY(asan_inited)) return;
MaybeMountProcFS();
#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_flag_parser.h"
#include "sanitizer_common/sanitizer_stacktrace.h"
+#include "sanitizer_common/sanitizer_libc.h"
#include "lsan_allocator.h"
#include "lsan_common.h"
#include "lsan_thread.h"
RegisterLsanFlags(&parser, f);
RegisterCommonFlags(&parser);
- parser.ParseString(GetEnv("LSAN_OPTIONS"));
+ int mmaped = 0;
+ const char *options =
+ GetRuntimeOptions("LSAN_OPTIONS", "/LSAN_OPTIONS", &mmaped);
+ parser.ParseString(options);
SetVerbosity(common_flags()->verbosity);
if (Verbosity()) ReportUnrecognizedFlags();
if (common_flags()->help) parser.PrintFlagDescriptions();
+ __sanitizer_set_report_path(common_flags()->log_path);
+
+ if (mmaped)
+ UnmapOrDie((void *)options, GetPageSizeCached());
}
extern "C" void __lsan_init() {
Printf("\n\n");
}
+const char *GetRuntimeOptions(const char *env_option, const char *filename,
+ int *mmaped) {
+ // Read from command line.
+ const char *options = GetEnv(env_option);
+ // If environment variable {A, L, UB}SAN_OPTIONS is not set use predefined
+ // file to init options.
+ bool getFlagsFromFile = options == 0;
+ char *flags = 0;
+ uptr len = GetPageSizeCached();
+ uptr read_len = 0;
+ if (getFlagsFromFile) {
+ ReadFileToBuffer(filename, &flags, &len, &read_len, GetPageSizeCached());
+ *mmaped = 1;
+ options = flags;
+ }
+ return options;
+}
+
} // namespace __sanitizer
using namespace __sanitizer; // NOLINT
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
+const char *GetRuntimeOptions(const char *env_option, const char *filename,
+ int *mmaped);
+
} // namespace __sanitizer
inline void *operator new(__sanitizer::operator_new_size_type size,
return all == 0;
}
+bool MaybeMountProcFS() {
+ if (FileExists("/proc/self/maps"))
+ return true;
+
+ if (0 != mount("proc", "/proc", "proc", 0, 0)) {
+ Report("Failed to mount /proc, %s is likely to fail\n", SanitizerToolName);
+ return false;
+ }
+ return true;
+}
+
} // namespace __sanitizer
// Error handling
bool internal_iserror(uptr retval, int *rverrno = nullptr);
+extern "C" int mount(const char *source, const char *target,
+ const char *filesystemtype, unsigned long mountflags,
+ const void *data);
+
+bool MaybeMountProcFS();
+
} // namespace __sanitizer
#endif // SANITIZER_LIBC_H
// Override from user-specified string.
parser.ParseString(MaybeCallUbsanDefaultOptions());
- // Read from command line.
- const char *options = GetEnv("UBSAN_OPTIONS");
- char *ubsanFlags = 0;
- uptr len = GetPageSizeCached();
- uptr read_len = 0;
- bool getFlagsFromFile = ubsanFlags == 0;
- // Override from predefined file if exists.
- if (getFlagsFromFile) {
- ReadFileToBuffer("/UBSAN_OPTIONS", &ubsanFlags, &len, &read_len,
- GetPageSizeCached());
- options = ubsanFlags;
- }
+ int mmaped = 0;
+ const char *options =
+ GetRuntimeOptions("UBSAN_OPTIONS", "/UBSAN_OPTIONS", &mmaped);
parser.ParseString(options);
- UnmapOrDie(ubsanFlags, len);
+
+ if (mmaped)
+ UnmapOrDie((void *)options, GetPageSizeCached());
SetVerbosity(common_flags()->verbosity);
if (Verbosity()) ReportUnrecognizedFlags();