ubsan_parser.ParseString(ubsan_default_options);
#endif
- // Override from command line.
- asan_parser.ParseString(GetEnv("ASAN_OPTIONS"));
+ // 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;
+ }
+
+ asan_parser.ParseString(options);
#if CAN_SANITIZE_LEAKS
lsan_parser.ParseString(GetEnv("LSAN_OPTIONS"));
#endif
(ASAN_LOW_MEMORY) ? 1UL << 6 : 1UL << 8;
f->quarantine_size_mb = kDefaultQuarantineSizeMb;
}
+
+ if (getFlagsFromFile)
+ UnmapOrDie(asanFlags, len);
+
}
} // namespace __asan
#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_libc.h"
#include "sanitizer_common/sanitizer_symbolizer.h"
+#include "sanitizer_common/sanitizer_posix.h"
#include "lsan/lsan_common.h"
#include "ubsan/ubsan_init.h"
#include "ubsan/ubsan_platform.h"
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() {
+ uptr tmp = OpenFile("/proc/self/maps", RdOnly);
+ if(!internal_iserror(tmp)) {
+ internal_close(tmp);
+ 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();
+ MaybeDisableUlimit();
SanitizerToolName = "AddressSanitizer";
CHECK(!asan_init_is_running && "ASan init calls itself!");
asan_init_is_running = true;
class AsanInitializer {
public: // NOLINT
AsanInitializer() {
+ MaybeMountProcFS();
AsanInitFromRtl();
}
};
// Initialize as requested from instrumented application code.
// We use this call as a trigger to wake up ASan from deactivated state.
void __asan_init() {
+ MaybeMountProcFS();
AsanActivate();
AsanInitInternal();
}
// Override from user-specified string.
parser.ParseString(MaybeCallUbsanDefaultOptions());
- // Override from environment variable.
- parser.ParseString(GetEnv("UBSAN_OPTIONS"));
+
+ // 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;
+ }
+ parser.ParseString(options);
+ UnmapOrDie(ubsanFlags, len);
SetVerbosity(common_flags()->verbosity);
if (Verbosity()) ReportUnrecognizedFlags();