@@ -34,8 +34,8 @@ namespace {
3434class Decorator : public __sanitizer ::SanitizerCommonDecorator {
3535public:
3636 Decorator () : SanitizerCommonDecorator() {}
37- const char *FunctionName () { return Green (); }
38- const char *Reason () { return Blue (); }
37+ const char *FunctionName () const { return Green (); }
38+ const char *Reason () const { return Blue (); }
3939};
4040} // namespace
4141
@@ -46,18 +46,50 @@ static void PrintStackTrace(uptr pc, uptr bp) {
4646 stack.Print ();
4747}
4848
49- void __rtsan::PrintDiagnostics (const char *intercepted_function_name, uptr pc,
50- uptr bp) {
49+ template <class ... Ts> struct Overloaded : Ts... {
50+ using Ts::operator ()...;
51+ };
52+ // TODO: Remove below when c++20
53+ template <class ... Ts> Overloaded (Ts...) -> Overloaded<Ts...>;
54+
55+ void PrintError (Decorator &decorator, const DiagnosticsCallerInfo &info) {
56+ const char *violation_type = std::visit (
57+ Overloaded{
58+ [](const InterceptedCallInfo &) { return " unsafe-library-call" ; },
59+ [](const BlockingCallInfo &) { return " blocking-call" ; }},
60+ info);
61+
62+ Printf (" %s" , decorator.Error ());
63+ Report (" ERROR: RealtimeSanitizer: %s\n " , violation_type);
64+ }
65+
66+ void PrintReason (Decorator &decorator, const DiagnosticsCallerInfo &info) {
67+ Printf (" %s" , decorator.Reason ());
68+
69+ std::visit (
70+ Overloaded{[decorator](const InterceptedCallInfo &call) {
71+ Printf (" Intercepted call to real-time unsafe function "
72+ " `%s%s%s` in real-time context!" ,
73+ decorator.FunctionName (),
74+ call.intercepted_function_name_ , decorator.Reason ());
75+ },
76+ [decorator](const BlockingCallInfo &arg) {
77+ Printf (" Call to blocking function "
78+ " `%s%s%s` in real-time context!" ,
79+ decorator.FunctionName (), arg.blocking_function_name_ ,
80+ decorator.Reason ());
81+ }},
82+ info);
83+
84+ Printf (" \n " );
85+ }
86+
87+ void __rtsan::PrintDiagnostics (const DiagnosticsInfo &info) {
5188 ScopedErrorReportLock l;
5289
5390 Decorator d;
54- Printf (" %s" , d.Error ());
55- Report (" ERROR: RealtimeSanitizer: unsafe-library-call\n " );
56- Printf (" %s" , d.Reason ());
57- Printf (" Intercepted call to real-time unsafe function "
58- " `%s%s%s` in real-time context!\n " ,
59- d.FunctionName (), intercepted_function_name, d.Reason ());
60-
91+ PrintError (d, info.call_info );
92+ PrintReason (d, info.call_info );
6193 Printf (" %s" , d.Default ());
62- PrintStackTrace (pc, bp);
94+ PrintStackTrace (info. pc , info. bp );
6395}
0 commit comments