ndk icon indicating copy to clipboard operation
ndk copied to clipboard

aaudio callbacks are unsound

Open nicbn opened this issue 3 years ago • 1 comments

https://github.com/rust-windowing/android-ndk-rs/blob/f24606cc840af2f97f0daebe1e2e7cd3aca52287/ndk/src/aaudio.rs#L545-L565

If callback panics and unwinds, ffi_callback unwinds, which is undefined behaviour.

Rust's unwinding strategy is not specified to be fundamentally compatible with any other language's unwinding. As such, unwinding into Rust from another language, or unwinding into another language from Rust is Undefined Behavior. You must absolutely catch any panics at the FFI boundary! What you do at that point is up to you, but something must be done. If you fail to do this, at best, your application will crash and burn. At worst, your application won't crash and burn, and will proceed with completely clobbered state.

nicbn avatar May 01 '22 01:05 nicbn

Feel free to submit a PR to address this.

CC @JasperDeSutter.

MarijnS95 avatar May 03 '22 13:05 MarijnS95