add extern "custom" - #2300
Conversation
There was a problem hiding this comment.
Maybe it would be good to have an example at src/inline-assembly.md alongside naked functions?
| For other considerations and limitations regarding unwinding across FFI boundaries, see the [relevant section in the Panic documentation][panic-ffi]. | ||
|
|
||
| r[items.fn.extern.custom] | ||
| An `extern "custom"` function has an unknown, custom ABI. The only way to call such a function is via [inline assembly]. |
There was a problem hiding this comment.
Maybe a usage hint:
... unknown, custom ABI. This can be used to implement calling conventions unsupported by
rustc. The only way to call such a function is via [inline assembly].
There was a problem hiding this comment.
Somewhere in the reference it would probably be good to clarify the purpose of parameters and return types in extern "custom" definitions, since they don't directly serve any purpose. I feel like we discussed this somewhere but can't seem to find it.
There was a problem hiding this comment.
We actually disallow them entirely
error: invalid signature for `extern "custom"` function
--> <source>:6:31
|
6 | unsafe extern "custom" fn foo(a: i32) -> i32 {
| ^^^^^^ ^^^
|
= note: functions with the "custom" ABI cannot have any parameters or return type
help: remove the parameters and return type
|
6 - unsafe extern "custom" fn foo(a: i32) -> i32 {
6 + unsafe extern "custom" fn foo() {
|
| * `extern "C-unwind"` and `extern "system-unwind"` --- Identical to `"C"` and `"system"`, respectively, but with [different behavior][unwind-behavior] when the callee unwinds (by panicking or throwing a C++ style exception). | ||
|
|
||
| r[items.extern.abi.custom] | ||
| * `unsafe extern "custom"` --- A custom ABI that is not known to the rust compiler. |
There was a problem hiding this comment.
| * `unsafe extern "custom"` --- A custom ABI that is not known to the rust compiler. | |
| * `unsafe extern "custom"` --- A custom ABI that is not known to the compiler. |
| r[items.fn.extern.custom] | ||
| An `extern "custom"` function has an unknown, custom ABI. The only way to call such a function is via [inline assembly]. | ||
|
|
||
| r[items.fn.extern.custom.safety] | ||
| An `extern "custom"` function must be `unsafe`. | ||
|
|
||
| r[items.fn.extern.custom.naked] | ||
| An `extern "custom"` function definition must be a [naked function]. | ||
|
|
There was a problem hiding this comment.
We need to add the rules here about what's allowed or not allowed in terms of parameters and return types.
There was a problem hiding this comment.
And we need to add text about the function pointer restrictions as well.
|
Reminder, once the PR becomes ready for a review, use |
stabilization PR: rust-lang/rust#158504
This is a tricky one that is an exception to some rules. I've tried to put the raw information in, but this'll probably require some refinement.