File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,14 @@ macro_rules! argument_new {
7272 // a `fn(&T, ...)`, so the invariant is maintained.
7373 ty: ArgumentType :: Placeholder {
7474 value: NonNull :: <$t>:: from_ref( $x) . cast( ) ,
75+ // The Rust ABI considers all pointers to be equivalent, so transmuting a fn(&T) to
76+ // fn(NonNull<()>) and calling it with a NonNull<()> that points at a T is allowed.
77+ // However, the CFI sanitizer does not allow this, and triggers a crash when it
78+ // happens.
79+ //
80+ // To avoid this crash, we use a helper function when CFI is enabled. To avoid the
81+ // cost of this helper function (mainly code-size) when it is not needed, we
82+ // transmute the function pointer otherwise.
7583 #[ cfg( not( any( sanitize = "cfi" , sanitize = "kcfi" ) ) ) ]
7684 formatter: {
7785 let f: fn ( & $t, & mut Formatter <' _>) -> Result = $f;
You can’t perform that action at this time.
0 commit comments