@@ -24,6 +24,8 @@ This feature allows for use of one of following sanitizers:
2424    AddressSanitizer, but based on partial hardware assistance.
2525  *  [ LeakSanitizer] ( #leaksanitizer )  a run-time memory leak detector.
2626  *  [ MemorySanitizer] ( #memorysanitizer )  a detector of uninitialized reads.
27+   *  [ RealtimeSanitizer] ( #realtimesanitizer )  a detector of calls to function with
28+     non-deterministic execution time in realtime contexts.
2729  *  [ ThreadSanitizer] ( #threadsanitizer )  a fast data race detector.
2830
2931*  Those that apart from testing, may be used in production:
@@ -43,11 +45,11 @@ This feature allows for use of one of following sanitizers:
4345
4446To enable a sanitizer compile with ` -Zsanitizer=address ` , ` -Zsanitizer=cfi ` ,
4547` -Zsanitizer=dataflow ` ,` -Zsanitizer=hwaddress ` , ` -Zsanitizer=leak ` ,
46- ` -Zsanitizer=memory ` , ` -Zsanitizer=memtag ` , ` -Zsanitizer=shadow-call-stack  ` , or 
47- ` -Zsanitizer=thread ` . You might also need the  ` --target `  and  ` build-std `  flags. 
48- If you're working with other languages that are also instrumented with sanitizers, 
49- you might need the ` external-clangrt `  flag. See the section on 
50- [ working with other languages] ( #working-with-other-languages ) .
48+ ` -Zsanitizer=memory ` , ` -Zsanitizer=memtag ` , ` -Zsanitizer=realtime  ` , 
49+ ` -Zsanitizer=shadow-call-stack  `  or  ` -Zsanitizer= thread` . You might also need the
50+ ` --target `  and  ` build-std `  flags.  If you're working with other languages that are also
51+ instrumented with sanitizers,  you might need the ` external-clangrt `  flag. See
52+ the section on  [ working with other languages] ( #working-with-other-languages ) .
5153
5254Example:
5355``` shell 
@@ -865,6 +867,69 @@ WARNING: ThreadSanitizer: data race (pid=10574)
865867  Location is global ' example::A::h43ac149ddf992709'  
866868` ` ` 
867869
870+ #  RealtimeSanitizer
871+ RealtimeSanitizer detects non-deterministic execution time  calls in  real-time contexts. 
872+ Functions marked with the `  # [sanitize(realtime = "nonblocking")]` attribute are considered real-time functions.
873+ When RTSan detects a call to a function  with  a non-deterministic execution time, like ` malloc` ` free`  
874+ while  in  a real-time context, it reports an error.
875+ 
876+ Besides " nonblocking" " blocking" " caller"  
877+ - " blocking"  
878+ When reaching such a function  while  in  a real-time context a violation will be reported. A typical use 
879+ case  is a userland spinlock.
880+ - functions marked with " caller" if  they were called from a real-time context. 
881+ If no attribute is set, this is the default. Between entering a " nonblocking" function  and  exiting that 
882+ function  again  the program will get sanitized.
883+ 
884+ The santizer checks can be disabled using the external functions `__rtsan_disable ()`  and ` ` . 
885+ Each call to `  __rtsan_disable()`  must be paired with one following call to ` ` , otherwise the behaviour is undefined.
886+ 
887+ ` ` ` 
888+ unsafe extern " C"  
889+   fn __rtsan_disable (); 
890+   fn __rtsan_enable (); 
891+ } 
892+ ` ` ` 
893+ 
894+ ` ` ` 
895+ // in  a real-time context 
896+ # [cfg(debug_assertions)]
897+ { 
898+     unsafe { __rtsan_disable () }; 
899+     log! (" logging xyz" ;  
900+     unsafe { __rtsan_enable () }; 
901+ } 
902+ ` ` ` 
903+ 
904+ See the [Clang RealtimeSanitizer documentation][clang-rtsan] for  more details. 
905+ 
906+ # # Example
907+ 
908+ ` ` ` 
909+ # [sanitize(realtime = "nonblocking")]
910+ fn real_time () { 
911+   let  vec = vec! [0, 1, 2];  // call to malloc is detected and reported as an error 
912+ } 
913+ ` ` ` 
914+ 
915+ ` ` ` 
916+ ==8670==ERROR: RealtimeSanitizer: unsafe-library-call 
917+ Intercepted call to real-time unsafe function  `malloc`  in  real-time context!  
918+     # 0 0x00010107b0d8 in malloc rtsan_interceptors_posix.cpp:792 
919+     # 1 0x000100d94e70 in alloc::alloc::Global::alloc_impl::h9e1fc3206c868eea+0xa0 (realtime_vec:arm64+0x100000e70) 
920+     # 2 0x000100d94d90 in alloc::alloc::exchange_malloc::hd45b5788339eb5c8+0x48 (realtime_vec:arm64+0x100000d90) 
921+     # 3 0x000100d95020 in realtime_vec::main::hea6bd69b03eb9ca1+0x24 (realtime_vec:arm64+0x100001020) 
922+     # 4 0x000100d94a28 in core::ops::function::FnOnce::call_once::h493b6cb9dd87d87c+0xc (realtime_vec:arm64+0x100000a28) 
923+     # 5 0x000100d949b8 in std::sys::backtrace::__rust_begin_short_backtrace::hfcddb06c73c19eea+0x8 (realtime_vec:arm64+0x1000009b8) 
924+     # 6 0x000100d9499c in std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h202288c05a2064f0+0xc (realtime_vec:arm64+0x10000099c) 
925+     # 7 0x000100d9fa34 in std::rt::lang_start_internal::h6c763158a05ac05f+0x6c (realtime_vec:arm64+0x10000ba34) 
926+     # 8 0x000100d94980 in std::rt::lang_start::h1c29cc56df0598b4+0x38 (realtime_vec:arm64+0x100000980) 
927+     # 9 0x000100d95118 in main+0x20 (realtime_vec:arm64+0x100001118) 
928+     # 10 0x000183a46b94 in start+0x17b8 (dyld:arm64+0xfffffffffff3ab94) 
929+ 
930+ SUMMARY: RealtimeSanitizer: unsafe-library-call rtsan_interceptors_posix.cpp:792 in  malloc 
931+ ` ` ` 
932+ 
868933#  Instrumentation of external dependencies and std
869934
870935The sanitizers to varying degrees work correctly with partially instrumented 
@@ -918,6 +983,7 @@ Sanitizers produce symbolized stacktraces when llvm-symbolizer binary is in `PAT
918983*  [MemorySanitizer in  Clang][clang-msan]
919984*  [MemTagSanitizer in  LLVM][llvm-memtag]
920985*  [ThreadSanitizer in  Clang][clang-tsan]
986+ *  [RealtimeSanitizer in  Clang][clang-rtsan]
921987
922988[clang-asan]: https://clang.llvm.org/docs/AddressSanitizer.html 
923989[clang-cfi]: https://clang.llvm.org/docs/ControlFlowIntegrity.html 
@@ -926,6 +992,7 @@ Sanitizers produce symbolized stacktraces when llvm-symbolizer binary is in `PAT
926992[clang-kcfi]: https://clang.llvm.org/docs/ControlFlowIntegrity.html#fsanitize-kcfi 
927993[clang-lsan]: https://clang.llvm.org/docs/LeakSanitizer.html 
928994[clang-msan]: https://clang.llvm.org/docs/MemorySanitizer.html 
995+ [clan-rtsan]: https://clang.llvm.org/docs/RealtimeSanitizer.html 
929996[clang-safestack]: https://clang.llvm.org/docs/SafeStack.html 
930997[clang-scs]: https://clang.llvm.org/docs/ShadowCallStack.html 
931998[clang-tsan]: https://clang.llvm.org/docs/ThreadSanitizer.html 
0 commit comments