@@ -74,11 +74,15 @@ how well the current design satisfies these constraints.
74
74
frames "as if" they were Rust panics (i.e., running destrutors or,
75
75
in the case of ` unwind=abort ` , aborting the program).
76
76
* ** Enable error handling with ` longjmp ` :**
77
- As mentioned above, some existing Rust libraries use ` longjmp ` . Despite the
78
- fact that ` longjmp ` on Windows is [ technically a form of
79
- unwinding] [ forced-unwinding ] , using ` longjmp ` across Rust
80
- [ POFs] [ POF-definition ] [ is safe] [ longjmp-pr ] with the current implementation
81
- of ` rustc ` , and we would like this to remain safe.
77
+ As mentioned above, some existing Rust libraries rely on the ability to
78
+ ` longjmp ` across Rust frames to interoperate with Ruby, Lua, and other C
79
+ APIs. The behavior of ` longjmp ` traversing Rust frames is not specified or
80
+ guaranteed to be safe; in the current implementation of ` rustc ` ,
81
+ however, it [ is safe] [ longjmp-pr ] . On Windows, ` longjmp ` is implemented as a
82
+ form of unwinding called [ "forced unwinding"] [ forced-unwinding ] , so any
83
+ specification of the behavior of forced unwinding across FFI boundaries
84
+ should be forward-compatible with a [ future RFC] [ unresolved-questions ] that
85
+ will provide a well-defined way to interoperate with longjmp-based APIs.
82
86
* ** Do not change the ABI of functions in the ` libc ` crate:** Some ` libc `
83
87
functions may invoke ` pthread_exit ` , which uses [ a form of
84
88
unwinding] [ forced-unwinding ] in the GNU libc implementation. Such functions
@@ -191,8 +195,8 @@ If a non-forced foreign unwind would enter a Rust frame via an `extern "C
191
195
unwind"` ABI boundary, but the Rust code is compiled with ` panic=abort`, the
192
196
unwind will be caught and the process aborted.
193
197
194
- However, unwinding from another language into Rust through an FFI entrypoint
195
- declared with ` extern "C" ` (contrary to the guidelines above) is always
198
+ With the exception of the above case, however, unwinding from another language
199
+ into Rust through an FFI entrypoint declared with ` extern "C" ` is always
196
200
undefined behavior, and is not guaranteed to cause the program to abort under
197
201
` panic=abort ` .
198
202
@@ -212,9 +216,14 @@ behavior. `"C"`-like ABIs are `"C"` itself but also related ABIs such as
212
216
| ` panic=abort ` | ` "C" ` -like | ` panic! ` aborts (no unwinding occurs) | UB |
213
217
214
218
The interaction of Rust frames with C functions that deallocate frames (i.e.
215
- functions that may use forced unwinding on specific platforms) is not specified
216
- in this RFC. However, we do specify that deallocating
217
- non-[ POFs] [ POF-definition ] s in this way is undefined behavior.
219
+ functions that may use forced unwinding on specific platforms) is independent
220
+ of the panic runtime, ABI, or platform.
221
+
222
+ * ** When deallocating Rust non-POFs:** this is explicitly undefined behavior.
223
+ * ** When deallocating Rust [ POFs] [ POF-definition ] :** for now, this is not
224
+ specified, and must be considered undefined behavior. However, we do plan to
225
+ specify a safe way to deallocate POFs with ` longjmp ` or ` pthread_exit ` in [ a
226
+ future RFC] [ unresolved-questions ] .
218
227
219
228
No subtype relationship is defined between functions or function pointers using
220
229
different ABIs. This RFC also does not define coercions between ` "C" ` and
0 commit comments