You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
10
10
11
-
# Motivation
11
+
##Motivation
12
12
[motivation]: #motivation
13
13
14
14
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
36
36
37
37
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.
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)
45
45
46
-
## Usage
46
+
###Usage
47
47
48
48
You can specify the ordinality of an exported function using the `export_ordinal` attribute on it. The attribute must be marked as unsafe.
49
49
@@ -56,13 +56,13 @@ pub extern "C" fn hello() {
56
56
57
57
This example will export `hello` as ordinal 1, and when a program tries to call ordinal 1 in your DLL, it will be executed.
58
58
59
-
## Behaviour
59
+
###Behaviour
60
60
61
61
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).
62
62
63
63
If `export_ordinal` isn't provided, an unused ordinal will be assigned during compilation.
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:
118
118
119
119
This proposal should make the workflow of specifying ordinals much easier, while staying consistent with the syntax of the existing `link_ordinal`.
120
120
121
-
# Prior art
121
+
##Prior art
122
122
[prior-art]: #prior-art
123
123
124
124
I am not currently aware of any programming languages that currently implement an equivalent feature.
125
125
126
-
# Unresolved questions
126
+
##Unresolved questions
127
127
[unresolved-questions]: #unresolved-questions
128
128
129
129
Some unresolved questions are:
130
130
1. Can ordinals be skipped? If you specify ordinals `1, 3, 4`, should this throw an error as `2` is skipped?
131
131
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)?
132
132
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?
133
133
134
-
# Future possibilities
134
+
##Future possibilities
135
135
[future-possibilities]: #future-possibilities
136
136
137
137
I cannot currently think of any future possibilities.
0 commit comments