Skip to content

Commit

Permalink
Merge pull request #2054 from yingcong-wu/yc-0903-handle-option-excep…
Browse files Browse the repository at this point in the history
…tion

[DeviceSanitizer] refine option parsing
  • Loading branch information
pbalcer authored Sep 13, 2024
2 parents 35b83de + fcdc6a7 commit ab5eb82
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions source/loader/layers/sanitizer/asan_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ struct AsanOptions {

private:
AsanOptions(logger::Logger &logger) {
auto OptionsEnvMap = getenv_to_map("UR_LAYER_ASAN_OPTIONS");
std::optional<EnvVarMap> OptionsEnvMap;
try {
OptionsEnvMap = getenv_to_map("UR_LAYER_ASAN_OPTIONS");
} catch (const std::invalid_argument &e) {
std::stringstream SS;
SS << "<SANITIZER>[ERROR]: ";
SS << e.what();
logger.always(SS.str().c_str());
die("Sanitizer failed to parse options.\n");
}

if (!OptionsEnvMap.has_value()) {
return;
}
Expand Down Expand Up @@ -74,8 +84,8 @@ struct AsanOptions {
Opt = false;
} else {
std::stringstream SS;
SS << "<SANITIZER>[ERROR]: \"" << Name << "\" is set to \""
<< Value << "\", which is not an valid setting. ";
SS << "\"" << Name << "\" is set to \"" << Value
<< "\", which is not an valid setting. ";
SS << "Acceptable input are: for enable, use:";
for (auto &S : TrueStrings) {
SS << " \"" << S << "\"";
Expand All @@ -86,7 +96,8 @@ struct AsanOptions {
SS << " \"" << S << "\"";
}
SS << ".";
die(SS.str().c_str());
logger.error(SS.str().c_str());
die("Sanitizer failed to parse options.\n");
}
}
};
Expand All @@ -106,9 +117,10 @@ struct AsanOptions {
}
MaxQuarantineSizeMB = temp_long;
} catch (...) {
die("<SANITIZER>[ERROR]: \"quarantine_size_mb\" should be "
"an positive integer that smaller than or equal to "
"4294967295.");
logger.error("\"quarantine_size_mb\" should be "
"an integer in range[0, {}].",
UINT32_MAX);
die("Sanitizer failed to parse options.\n");
}
}

Expand All @@ -120,10 +132,12 @@ struct AsanOptions {
if (MinRZSize < 16) {
MinRZSize = 16;
logger.warning("Trying to set redzone size to a "
"value less than 16 is ignored");
"value less than 16 is ignored.");
}
} catch (...) {
die("<SANITIZER>[ERROR]: \"redzone\" should be an integer");
logger.error(
"\"redzone\" should be an integer in range[0, 16].");
die("Sanitizer failed to parse options.\n");
}
}

Expand All @@ -135,10 +149,12 @@ struct AsanOptions {
if (MaxRZSize > 2048) {
MaxRZSize = 2048;
logger.warning("Trying to set max redzone size to a "
"value greater than 2048 is ignored");
"value greater than 2048 is ignored.");
}
} catch (...) {
die("<SANITIZER>[ERROR]: \"max_redzone\" should be an integer");
logger.error(
"\"max_redzone\" should be an integer in range[0, 2048].");
die("Sanitizer failed to parse options.\n");
}
}
}
Expand Down

0 comments on commit ab5eb82

Please sign in to comment.