Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FFI-Safe Polymorphism article] unwind safety #36

Open
Mart-Bogdan opened this issue Dec 20, 2020 · 2 comments · May be fixed by #37
Open

[FFI-Safe Polymorphism article] unwind safety #36

Mart-Bogdan opened this issue Dec 20, 2020 · 2 comments · May be fixed by #37

Comments

@Mart-Bogdan
Copy link

Mart-Bogdan commented Dec 20, 2020

Hello, really nice article, but there is one important point!

According to Nomicon https://doc.rust-lang.org/nomicon/ffi.html#ffi-and-panics

A panic! across an FFI boundary is undefined behavior.

I don't say that article should dig so deep, but please add Note/warning that in real use all functions that are called from FFI should use catch_unwind and report errors to native code in other way.

Taking into account that it could be used with any user-provided impls of Write, that is fairly possible to encounter panics.

P.S. Rust's catch unwind is fairly cheap and creates small overhead in case no panic actually happen,

@Michael-F-Bryan
Copy link
Owner

Taking into account that it could be used with any user-provided impls of Write, that is fairly possible to encounter panics.

Hehe, I was kinda lazy and didn't make the functions inside the ffi module exception safe. Thanks for keeping me honest!

@Michael-F-Bryan
Copy link
Owner

Michael-F-Bryan commented Dec 20, 2020

Looking at the resolution in Michael-F-Bryan/thin-trait-objects#2, @Mart-Bogdan what do you think the best way to address exception safety (and my solution, poisoning) would be?

Should I update the original article, or maybe make a follow-up, or maybe even quietly sweep it under the rug and pretend it never happened? The code and concepts required are non-trivial and more relevant to designing a sound foreign function interface than the concept of Thin Trait Objects, so I'd like to do it justice if I can.

@Michael-F-Bryan Michael-F-Bryan linked a pull request Dec 20, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants