You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, generated interface implementation (including callback consumption) does not catch unwinding panics. By default, when a panic occurs in user code, the thread starts unwinding all the way down to system dlls. Since unwinding across FFI boundary is undefined behavior, user code invocations should be wrapped in catch_unwind.
Yeah, I'm still trying to figure out how best to handle this. On Windows, we generally have an abort/terminate function that immediately terminates the process (e.g. TerminateProcess) without unwinding in order to collect reliable crash dumps. This is distinct from "exceptions" that may unwind the stack, and we certainly don't want to allow exceptions to unwind as that is not reliable across ABI boundaries in C++ either. So ideally, we could ensure that panic does not unwind but if I don't know whether that is practical.
And if catch_unwind is used, the question is what to do with the resulting error. I don't want it to propagate but neither do I want to simply swallow the error and lose that context.
Because the ABI semantics don't allow for it. Errors must be reported via return codes. Unwinding is also not compatible across compilers and languages.
Just looking again at this old issue. I think I'm going to leave this up to the implementor. I don't see what the implement macro can do beyond simply aborting in such cases, in which case it would be more efficient to do that declaratively:
Activity
kennykerr commentedon Aug 18, 2021
Yeah, I'm still trying to figure out how best to handle this. On Windows, we generally have an abort/terminate function that immediately terminates the process (e.g. TerminateProcess) without unwinding in order to collect reliable crash dumps. This is distinct from "exceptions" that may unwind the stack, and we certainly don't want to allow exceptions to unwind as that is not reliable across ABI boundaries in C++ either. So ideally, we could ensure that
panicdoes not unwind but if I don't know whether that is practical.And if
catch_unwindis used, the question is what to do with the resulting error. I don't want it to propagate but neither do I want to simply swallow the error and lose that context.bdbai commentedon Aug 18, 2021
May I know the reason not to do so?
kennykerr commentedon Aug 18, 2021
Because the ABI semantics don't allow for it. Errors must be reported via return codes. Unwinding is also not compatible across compilers and languages.
bdbai commentedon Aug 18, 2021
Can we mimic the behavior when an exception is thrown in cppwinrt, like reporting the error via
RoOriginateLanguageException?RobJellinghaus commentedon Oct 11, 2021
FWIW there is an RFC to reduce undefined behavior when unwinding across FFI boundaries, but it looks to be fairly static in the last year or so: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
kennykerr commentedon Mar 6, 2023
Just looking again at this old issue. I think I'm going to leave this up to the implementor. I don't see what the
implementmacro can do beyond simply aborting in such cases, in which case it would be more efficient to do that declaratively:https://doc.rust-lang.org/book/ch09-01-unrecoverable-errors-with-panic.html