Skip to content

Commit e472f0c

Browse files
author
Kyle Strand
committed
PR comments from Niko
1 parent f2ecfa3 commit e472f0c

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

rfcs/0000-c-unwind-abi.md

+19-10
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ how well the current design satisfies these constraints.
7474
frames "as if" they were Rust panics (i.e., running destrutors or,
7575
in the case of `unwind=abort`, aborting the program).
7676
* **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.
8286
* **Do not change the ABI of functions in the `libc` crate:** Some `libc`
8387
functions may invoke `pthread_exit`, which uses [a form of
8488
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
191195
unwind"` ABI boundary, but the Rust code is compiled with `panic=abort`, the
192196
unwind will be caught and the process aborted.
193197

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
196200
undefined behavior, and is not guaranteed to cause the program to abort under
197201
`panic=abort`.
198202

@@ -212,9 +216,14 @@ behavior. `"C"`-like ABIs are `"C"` itself but also related ABIs such as
212216
| `panic=abort` | `"C"`-like | `panic!` aborts (no unwinding occurs) | UB |
213217

214218
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].
218227

219228
No subtype relationship is defined between functions or function pointers using
220229
different ABIs. This RFC also does not define coercions between `"C"` and

rfcs/0000-longjmp-pof-annotation.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fn foo<D: Drop>(c: bool, d: D) {
3636
}
3737

3838
/// Calls `longjmp` if `c` is true; otherwise returns normally.
39+
#[cancelable]
3940
extern "C" fn longjmp_if_true(c: bool);
4041
```
4142

0 commit comments

Comments
 (0)