Skip to content

Commit 9122563

Browse files
committed
Remove the extern "custom" calling convention
This feature likely needs more design and constrained naked functions are useful without it. I have also added a brief discussion of this feature to the future possibilities section. If people feel strongly that we should keep the custom calling convention, we can revert this commit.
1 parent a580606 commit 9122563

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

text/0000-constrained-naked.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)
55

66
# Summary
7-
This document attempts to increase the utility of [naked functions](https://github.com/rust-lang/rfcs/blob/master/text/1201-naked-fns.md) by constraining their use and increasing their defined invariants. This document also defines a new calling convention: `extern "custom"`.
7+
This document attempts to increase the utility of [naked functions](https://github.com/rust-lang/rfcs/blob/master/text/1201-naked-fns.md) by constraining their use and increasing their defined invariants.
88

99
# Motivation
1010

@@ -37,19 +37,6 @@ In exchange for the above constraints, the compiler commits to:
3737

3838
As a (weaker) correlary to the last compiler commitment, the initial state of all registers in the `asm!()` statement conform to the specified calling convention.
3939

40-
# Custom Calling Convention
41-
42-
In order to expand the usefulness of naked functions, this document also define a new calling convention, `extern "custom"`, that can be used only with naked functions. Functions with `extern "custom"` are not callable from Rust and must be marked as`unsafe`. The function definition must contain no arguments or return type. For example:
43-
44-
```rust
45-
#[naked]
46-
unsafe extern "custom" fn callback() {
47-
asm!("mov rbx, rsi")
48-
}
49-
```
50-
51-
An `extern "custom"` function can be passed as a function pointer argument or passed to an `asm!()` block via `sym`.
52-
5340
# Explanation
5441

5542
Since a naked function has no prologue, any naive attempt to use the stack can produce invalid code. This certainly includes local variables. But this can also include attempts to reference function arguments which may be placed on the stack. This is why a naked function may only contain a single `asm!()` statement.
@@ -64,8 +51,6 @@ Because naked functions depend upon the calling convention so heavily, inlining
6451

6552
Since the `const` and `sym` operands modify neither the stack nor the registers, their use is permitted.
6653

67-
Because the compiler guarantees that no instructions not in the `asm!()` block of a naked function will be emitted to the function body, an `extern "custom"` function can implement whatever custom calling convention it wants. This is useful in a variety of scenarios where the calling convention is custom, such as in interrupt handlers or callbacks from assembly code.
68-
6954
## Examples
7055

7156
This function adds three to a number and returns the result:
@@ -140,4 +125,6 @@ Due to the definition of naked functions, the arguments will always be flagged a
140125

141126
It would be possible to define new calling conventions that can be used with naked functions.
142127

128+
A previous version of this document defined an `extern "custom"` calling convention. It was observed in conversation that calling conventions are really a *type* and that it could be useful to have calling conventions as part of the type system. In the interest of moving forward with constrained naked functions, it is best to limit the scope of this RFC and defer this (very good) conversation to a future RFC.
129+
143130
It may also be possible to loosen the definition of a naked function in a future RFC. For example, it might be possible to allow the use of some additional, possibly new, operands to the `asm!()` block.

0 commit comments

Comments
 (0)