@@ -34,9 +34,15 @@ 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};
40+
41+ template <class ... Ts> struct Overloaded : Ts... {
42+ using Ts::operator ()...;
43+ };
44+ // TODO: Remove below when c++20
45+ template <class ... Ts> Overloaded (Ts...) -> Overloaded<Ts...>;
4046} // namespace
4147
4248static void PrintStackTrace (uptr pc, uptr bp) {
@@ -46,18 +52,46 @@ static void PrintStackTrace(uptr pc, uptr bp) {
4652 stack.Print ();
4753}
4854
49- void __rtsan::PrintDiagnostics (const char *intercepted_function_name, uptr pc,
50- uptr bp) {
55+ static void PrintError (const Decorator &decorator,
56+ const DiagnosticsCallerInfo &info) {
57+ const char *violation_type = std::visit (
58+ Overloaded{
59+ [](const InterceptedCallInfo &) { return " unsafe-library-call" ; },
60+ [](const BlockingCallInfo &) { return " blocking-call" ; }},
61+ info);
62+
63+ Printf (" %s" , decorator.Error ());
64+ Report (" ERROR: RealtimeSanitizer: %s\n " , violation_type);
65+ }
66+
67+ static void PrintReason (const Decorator &decorator,
68+ const DiagnosticsCallerInfo &info) {
69+ Printf (" %s" , decorator.Reason ());
70+
71+ std::visit (
72+ Overloaded{[decorator](const InterceptedCallInfo &call) {
73+ Printf (" Intercepted call to real-time unsafe function "
74+ " `%s%s%s` in real-time context!" ,
75+ decorator.FunctionName (),
76+ call.intercepted_function_name_ , decorator.Reason ());
77+ },
78+ [decorator](const BlockingCallInfo &arg) {
79+ Printf (" Call to blocking function "
80+ " `%s%s%s` in real-time context!" ,
81+ decorator.FunctionName (), arg.blocking_function_name_ ,
82+ decorator.Reason ());
83+ }},
84+ info);
85+
86+ Printf (" \n " );
87+ }
88+
89+ void __rtsan::PrintDiagnostics (const DiagnosticsInfo &info) {
5190 ScopedErrorReportLock l;
5291
5392 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-
93+ PrintError (d, info.call_info );
94+ PrintReason (d, info.call_info );
6195 Printf (" %s" , d.Default ());
62- PrintStackTrace (pc, bp);
96+ PrintStackTrace (info. pc , info. bp );
6397}
0 commit comments