@@ -246,9 +246,13 @@ impl Prev {
246246 fn execute ( & self , sig : c_int ) {
247247 let fptr = self . info ;
248248 if fptr != 0 && fptr != SIG_DFL && fptr != SIG_IGN {
249+ // `sighandler_t` is an integer type. Transmuting it directly from an integer to a
250+ // function pointer seems dubious w.r.t. pointer provenance -- at least Miri complains
251+ // about it. Casting to a raw pointer first side-steps the issue.
252+ let fptr = fptr as * mut ( ) ;
249253 // FFI ‒ calling the original signal handler.
250254 unsafe {
251- let action = mem:: transmute :: < usize , extern "C" fn ( c_int ) > ( fptr) ;
255+ let action = mem:: transmute :: < * mut ( ) , extern "C" fn ( c_int ) > ( fptr) ;
252256 action ( sig) ;
253257 }
254258 }
@@ -258,6 +262,10 @@ impl Prev {
258262 unsafe fn execute ( & self , sig : c_int , info : * mut siginfo_t , data : * mut c_void ) {
259263 let fptr = self . info . sa_sigaction ;
260264 if fptr != 0 && fptr != libc:: SIG_DFL && fptr != libc:: SIG_IGN {
265+ // `sa_sigaction` is usually stored as integer type. Transmuting it directly from an
266+ // integer to a function pointer seems dubious w.r.t. pointer provenance -- at least
267+ // Miri complains about it. Casting to a raw pointer first side-steps the issue.
268+ let fptr = fptr as * mut ( ) ;
261269 // Android is broken and uses different int types than the rest (and different
262270 // depending on the pointer width). This converts the flags to the proper type no
263271 // matter what it is on the given platform.
@@ -269,11 +277,11 @@ impl Prev {
269277 let mut siginfo = self . info . sa_flags ;
270278 siginfo = libc:: SA_SIGINFO as _ ;
271279 if self . info . sa_flags & siginfo == 0 {
272- let action = mem:: transmute :: < usize , extern "C" fn ( c_int ) > ( fptr) ;
280+ let action = mem:: transmute :: < * mut ( ) , extern "C" fn ( c_int ) > ( fptr) ;
273281 action ( sig) ;
274282 } else {
275283 type SigAction = extern "C" fn ( c_int , * mut siginfo_t , * mut c_void ) ;
276- let action = mem:: transmute :: < usize , SigAction > ( fptr) ;
284+ let action = mem:: transmute :: < * mut ( ) , SigAction > ( fptr) ;
277285 action ( sig, info, data) ;
278286 }
279287 }
0 commit comments