Skip to content

Commit 1c1c032

Browse files
committed
Fix header levels of 3641
The RFC template was updated after this RFC was created to not use level-1 headers.
1 parent 0616201 commit 1c1c032

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

text/3641-export-function-ordinals.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
- RFC PR: [rust-lang/rfcs#3641](https://github.com/rust-lang/rfcs/pull/3641)
44
- Rust Issue: [rust-lang/rust#154022](https://github.com/rust-lang/rust/issues/154022)
55

6-
# Summary
6+
## Summary
77
[summary]: #summary
88

99
Adding an unsafe attribute, `#[unsafe(export_ordinal(n))]`, that marks the ordinal position of an exported function in a cdylib on windows targets without creating a `lib.def` file.
1010

11-
# Motivation
11+
## Motivation
1212
[motivation]: #motivation
1313

1414
Sometimes when creating DLLs, the ordinal position of an exported function is very important. For example, when creating a DLL for use in [Microsoft Detours](https://github.com/microsoft/Detours/), the [`DetourFinishHelperProcess`](https://github.com/microsoft/Detours/wiki/DetourFinishHelperProcess) function must be Ordinal 1.
@@ -36,14 +36,14 @@ The biggest downside of the current method is that once you specify a `.def` fil
3636

3737
By creating an attribute for specifying function ordinals, we can choose the ordinal position for the functions where it matters, and let Rust choose the ordinal for any other functions where ordinal position is not important.
3838

39-
# Guide-level explanation
39+
## Guide-level explanation
4040
[guide-level-explanation]: #guide-level-explanation
4141

42-
## Ordinals
42+
### Ordinals
4343

4444
Function Ordinals refer to the position of an exported function in a Dynamically Linked Library (DLL). When accessing functions by name, this is not important. However some applications access functions based on their position (ordinal), rather than their name. The Microsoft documentation for this concept is available [here.](https://learn.microsoft.com/en-us/cpp/build/exporting-functions-from-a-dll-by-ordinal-rather-than-by-name)
4545

46-
## Usage
46+
### Usage
4747

4848
You can specify the ordinality of an exported function using the `export_ordinal` attribute on it. The attribute must be marked as unsafe.
4949

@@ -56,13 +56,13 @@ pub extern "C" fn hello() {
5656

5757
This example will export `hello` as ordinal 1, and when a program tries to call ordinal 1 in your DLL, it will be executed.
5858

59-
## Behaviour
59+
### Behaviour
6060

6161
If other software expects your function to be a specific ordinal, you should be very careful when changing the ordinal or removing the `export_ordinal` attribute, as it could lead to the wrong function being called (or not found at all).
6262

6363
If `export_ordinal` isn't provided, an unused ordinal will be assigned during compilation.
6464

65-
# Reference-level explanation
65+
## Reference-level explanation
6666
[reference-level-explanation]: #reference-level-explanation
6767

6868
`export_ordinal` is a new attribute for functions which has a signature similar to the following:
@@ -95,12 +95,12 @@ pub fn hello() {}
9595
pub unsafe extern "C" fn world() {}
9696
```
9797

98-
# Drawbacks
98+
## Drawbacks
9999
[drawbacks]: #drawbacks
100100

101101
1. Specifying ordinals in code could add a lot of additional complexity with linking.
102102

103-
# Rationale and alternatives
103+
## Rationale and alternatives
104104
[rationale-and-alternatives]: #rationale-and-alternatives
105105

106106
This design is consistent with the [`link_ordinal`](https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute) attribute already in use.
@@ -118,20 +118,20 @@ Some considered alternatives are:
118118

119119
This proposal should make the workflow of specifying ordinals much easier, while staying consistent with the syntax of the existing `link_ordinal`.
120120

121-
# Prior art
121+
## Prior art
122122
[prior-art]: #prior-art
123123

124124
I am not currently aware of any programming languages that currently implement an equivalent feature.
125125

126-
# Unresolved questions
126+
## Unresolved questions
127127
[unresolved-questions]: #unresolved-questions
128128

129129
Some unresolved questions are:
130130
1. Can ordinals be skipped? If you specify ordinals `1, 3, 4`, should this throw an error as `2` is skipped?
131131
2. If ordinals `1, 3` are specified, and you have another exported function, should it use `2` (the next unused ordinal) or `4` (the next in the sequence)?
132132
3. Instead of implementing this proposal, Could the usage of the `.def` file be changed to allow other functions to stay exported, even if they aren't included in the `.def` file?
133133

134-
# Future possibilities
134+
## Future possibilities
135135
[future-possibilities]: #future-possibilities
136136

137137
I cannot currently think of any future possibilities.

0 commit comments

Comments
 (0)