@@ -24,6 +24,8 @@ This feature allows for use of one of following sanitizers:
24
24
AddressSanitizer, but based on partial hardware assistance.
25
25
* [ LeakSanitizer] ( #leaksanitizer ) a run-time memory leak detector.
26
26
* [ MemorySanitizer] ( #memorysanitizer ) a detector of uninitialized reads.
27
+ * [ RealtimeSanitizer] ( #realtimesanitizer ) a detector of functions with
28
+ non-deterministic execution time in realtime contexts.
27
29
* [ ThreadSanitizer] ( #threadsanitizer ) a fast data race detector.
28
30
29
31
* Those that apart from testing, may be used in production:
@@ -43,11 +45,11 @@ This feature allows for use of one of following sanitizers:
43
45
44
46
To enable a sanitizer compile with ` -Zsanitizer=address ` , ` -Zsanitizer=cfi ` ,
45
47
` -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 ) .
51
53
52
54
Example:
53
55
``` shell
@@ -865,6 +867,51 @@ WARNING: ThreadSanitizer: data race (pid=10574)
865
867
Location is global ' example::A::h43ac149ddf992709' of size 8 at 0x5632dfe3d030 (example+0x000000bd9030)
866
868
` ` `
867
869
870
+ # RealtimeSanitizer
871
+ RealtimeSanitizer detects non-deterministic execution time calls in realtime contexts.
872
+ Usafe of RTSan is on a function-by-function basis. The sanitizer only inspects code that
873
+ is marked as being real-time sensitive. This is done with the ` sanitize` attribute.
874
+ Any function that is subject to real-time contraints should be marked with ` # [sanitize(realtime = "on")]` .
875
+
876
+ Besides " on" the attribute can also be used with " off" , " blocking" and " caller" .
877
+ - " off" disables the sanitizer for this function. Not real-time sensitive operations in this
878
+ function aren't detected anymore.
879
+ - " blocking" marks the function as having a non-deterministic execution time. When reaching such
880
+ a function while in a real-time context a violation will be reported.
881
+ - " caller" is the default if no attribute is present, but can also be set explicitly. These functions
882
+ will be sanitized if called from a function that was being sanitized and will not be sanitized if called
883
+ from a function not sanitized. So any given function could be both sanitized and not sanitized in one program execution.
884
+
885
+ See the [Clang RealtimeSanitizer documentation][clang-rtsan] for more details.
886
+
887
+ # # Example
888
+
889
+ ` ` ` rust
890
+ # [sanitize(realtime = "on")]
891
+ fn main () {
892
+ let vec = vec! [0, 1, 2];
893
+ println! (" alloc not detected" )
894
+ }
895
+ ` ` `
896
+
897
+ ` ` ` shell
898
+ ==8670==ERROR: RealtimeSanitizer: unsafe-library-call
899
+ Intercepted call to real-time unsafe function `malloc` in real-time context!
900
+ # 0 0x00010107b0d8 in malloc rtsan_interceptors_posix.cpp:792
901
+ # 1 0x000100d94e70 in alloc::alloc::Global::alloc_impl::h9e1fc3206c868eea+0xa0 (realtime_vec:arm64+0x100000e70)
902
+ # 2 0x000100d94d90 in alloc::alloc::exchange_malloc::hd45b5788339eb5c8+0x48 (realtime_vec:arm64+0x100000d90)
903
+ # 3 0x000100d95020 in realtime_vec::main::hea6bd69b03eb9ca1+0x24 (realtime_vec:arm64+0x100001020)
904
+ # 4 0x000100d94a28 in core::ops::function::FnOnce::call_once::h493b6cb9dd87d87c+0xc (realtime_vec:arm64+0x100000a28)
905
+ # 5 0x000100d949b8 in std::sys::backtrace::__rust_begin_short_backtrace::hfcddb06c73c19eea+0x8 (realtime_vec:arm64+0x1000009b8)
906
+ # 6 0x000100d9499c in std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h202288c05a2064f0+0xc (realtime_vec:arm64+0x10000099c)
907
+ # 7 0x000100d9fa34 in std::rt::lang_start_internal::h6c763158a05ac05f+0x6c (realtime_vec:arm64+0x10000ba34)
908
+ # 8 0x000100d94980 in std::rt::lang_start::h1c29cc56df0598b4+0x38 (realtime_vec:arm64+0x100000980)
909
+ # 9 0x000100d95118 in main+0x20 (realtime_vec:arm64+0x100001118)
910
+ # 10 0x000183a46b94 in start+0x17b8 (dyld:arm64+0xfffffffffff3ab94)
911
+
912
+ SUMMARY: RealtimeSanitizer: unsafe-library-call rtsan_interceptors_posix.cpp:792 in malloc
913
+ ` ` `
914
+
868
915
# Instrumentation of external dependencies and std
869
916
870
917
The sanitizers to varying degrees work correctly with partially instrumented
@@ -918,6 +965,7 @@ Sanitizers produce symbolized stacktraces when llvm-symbolizer binary is in `PAT
918
965
* [MemorySanitizer in Clang][clang-msan]
919
966
* [MemTagSanitizer in LLVM][llvm-memtag]
920
967
* [ThreadSanitizer in Clang][clang-tsan]
968
+ * [RealtimeSanitizer in Clang][clang-rtsan]
921
969
922
970
[clang-asan]: https://clang.llvm.org/docs/AddressSanitizer.html
923
971
[clang-cfi]: https://clang.llvm.org/docs/ControlFlowIntegrity.html
@@ -926,6 +974,7 @@ Sanitizers produce symbolized stacktraces when llvm-symbolizer binary is in `PAT
926
974
[clang-kcfi]: https://clang.llvm.org/docs/ControlFlowIntegrity.html#fsanitize-kcfi
927
975
[clang-lsan]: https://clang.llvm.org/docs/LeakSanitizer.html
928
976
[clang-msan]: https://clang.llvm.org/docs/MemorySanitizer.html
977
+ [clan-rtsan]: https://clang.llvm.org/docs/RealtimeSanitizer.html
929
978
[clang-safestack]: https://clang.llvm.org/docs/SafeStack.html
930
979
[clang-scs]: https://clang.llvm.org/docs/ShadowCallStack.html
931
980
[clang-tsan]: https://clang.llvm.org/docs/ThreadSanitizer.html
0 commit comments