From 0a83cc3e74c047aa6a27a5823ec291c032fa072d Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Sun, 28 Jun 2026 01:50:04 +0200 Subject: [PATCH] add `extern "custom"` --- src/items/external-blocks.md | 5 ++++- src/items/functions.md | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index e547edf8a1..aa3b0072db 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -48,7 +48,7 @@ r[items.extern.fn.param-patterns] Patterns are not allowed in parameters, only [IDENTIFIER] or `_` may be used. r[items.extern.fn.qualifiers] -The `safe` and `unsafe` function qualifiers are allowed, but other function qualifiers (e.g. `const`, `async`, `extern`) are not. +The `safe` and `unsafe` function qualifiers are allowed, but other function qualifiers (e.g. `const`, `async`, `extern`) are not. The `safe` qualifier is rejected in `extern "custom"` blocks. r[items.extern.fn.foreign-abi] Functions within external blocks may be called by Rust code, just like functions defined in Rust. The Rust compiler automatically translates between the Rust ABI and the foreign ABI. @@ -112,6 +112,9 @@ r[items.extern.abi.system] r[items.extern.abi.unwind] * `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. + r[items.extern.abi.platform] There are also some platform-specific ABI strings: diff --git a/src/items/functions.md b/src/items/functions.md index 362b39b573..360f734bd4 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -239,6 +239,15 @@ With `panic=unwind`, when a `panic` is turned into an abort by a non-unwinding A 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]. + +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]. + [forced-unwinding]: https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html#forced-unwinding [panic handler]: ../panic.md#the-panic_handler-attribute [panic-ffi]: ../panic.md#unwinding-across-ffi-boundaries @@ -411,6 +420,7 @@ fn foo_oof(#[some_inert_attribute] arg: u8) { [testing attributes]: ../attributes/testing.md [`cold`]: ../attributes/codegen.md#the-cold-attribute [`inline`]: ../attributes/codegen.md#the-inline-attribute +[naked function]: ../attributes/codegen.md#the-naked-attribute [`deprecated`]: ../attributes/diagnostics.md#the-deprecated-attribute [`doc`]: ../../rustdoc/the-doc-attribute.html [`must_use`]: ../attributes/diagnostics.md#the-must_use-attribute @@ -427,3 +437,4 @@ fn foo_oof(#[some_inert_attribute] arg: u8) { [variadic function]: external-blocks.md#variadic-functions [`extern` block]: external-blocks.md [zero-sized]: glossary.zst +[inline assembly]: ../inline-assembly.md