Skip to content

Commit 6cc4182

Browse files
roblablaGabrielMajeri
authored andcommitted
Use EFIAPI ABI introduced in latest nightly (#104)
- Use `efiapi` ABI introduced in latest nightly - Document the requirement of `#![feature(abi_efiapi)]`
1 parent 37039fd commit 6cc4182

File tree

15 files changed

+70
-67
lines changed

15 files changed

+70
-67
lines changed

BUILDING.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The following steps allow you to build a simple UEFI app.
1818
and make sure you have an entry point function which matches the one below:
1919

2020
```rust
21+
#![feature(abi_efiapi)]
2122
use uefi::prelude::*;
2223

2324
#[entry]

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#![cfg_attr(feature = "exts", feature(allocator_api, alloc_layout_extra))]
2727
#![feature(optin_builtin_traits)]
2828
#![feature(try_trait)]
29+
#![feature(abi_efiapi)]
2930
#![no_std]
3031
// Enable some additional warnings and lints.
3132
#![warn(missing_docs, unused)]

src/proto/console/gop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ use core::ptr;
3737
#[unsafe_guid("9042a9de-23dc-4a38-96fb-7aded080516a")]
3838
#[derive(Protocol)]
3939
pub struct GraphicsOutput<'boot> {
40-
query_mode: extern "win64" fn(
40+
query_mode: extern "efiapi" fn(
4141
&GraphicsOutput,
4242
mode: u32,
4343
info_sz: &mut usize,
4444
&mut *const ModeInfo,
4545
) -> Status,
46-
set_mode: extern "win64" fn(&mut GraphicsOutput, mode: u32) -> Status,
46+
set_mode: extern "efiapi" fn(&mut GraphicsOutput, mode: u32) -> Status,
4747
// Clippy correctly complains that this is too complicated, but we can't change the spec.
4848
#[allow(clippy::type_complexity)]
49-
blt: unsafe extern "win64" fn(
49+
blt: unsafe extern "efiapi" fn(
5050
this: &mut GraphicsOutput,
5151
buffer: *mut BltPixel,
5252
op: u32,

src/proto/console/pointer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use core::mem::MaybeUninit;
99
#[unsafe_guid("31878c87-0b75-11d5-9a4f-0090273fc14d")]
1010
#[derive(Protocol)]
1111
pub struct Pointer<'boot> {
12-
reset: extern "win64" fn(this: &mut Pointer, ext_verif: bool) -> Status,
13-
get_state: extern "win64" fn(this: &Pointer, state: *mut PointerState) -> Status,
12+
reset: extern "efiapi" fn(this: &mut Pointer, ext_verif: bool) -> Status,
13+
get_state: extern "efiapi" fn(this: &Pointer, state: *mut PointerState) -> Status,
1414
wait_for_input: Event,
1515
mode: &'boot PointerMode,
1616
}

src/proto/console/serial.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub struct Serial<'boot> {
1818
// Revision of this protocol, only 1.0 is currently defined.
1919
// Future versions will be backwards compatible.
2020
revision: u32,
21-
reset: extern "win64" fn(&mut Serial) -> Status,
22-
set_attributes: extern "win64" fn(
21+
reset: extern "efiapi" fn(&mut Serial) -> Status,
22+
set_attributes: extern "efiapi" fn(
2323
&Serial,
2424
baud_rate: u64,
2525
receive_fifo_depth: u32,
@@ -28,10 +28,10 @@ pub struct Serial<'boot> {
2828
data_bits: u8,
2929
stop_bits_type: StopBits,
3030
) -> Status,
31-
set_control_bits: extern "win64" fn(&mut Serial, ControlBits) -> Status,
32-
get_control_bits: extern "win64" fn(&Serial, &mut ControlBits) -> Status,
33-
write: unsafe extern "win64" fn(&mut Serial, &mut usize, *const u8) -> Status,
34-
read: unsafe extern "win64" fn(&mut Serial, &mut usize, *mut u8) -> Status,
31+
set_control_bits: extern "efiapi" fn(&mut Serial, ControlBits) -> Status,
32+
get_control_bits: extern "efiapi" fn(&Serial, &mut ControlBits) -> Status,
33+
write: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *const u8) -> Status,
34+
read: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *mut u8) -> Status,
3535
io_mode: &'boot IoMode,
3636
}
3737

src/proto/console/text/input.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use core::mem::MaybeUninit;
77
#[unsafe_guid("387477c1-69c7-11d2-8e39-00a0c969723b")]
88
#[derive(Protocol)]
99
pub struct Input {
10-
reset: extern "win64" fn(this: &mut Input, extended: bool) -> Status,
11-
read_key_stroke: extern "win64" fn(this: &mut Input, key: *mut RawKey) -> Status,
10+
reset: extern "efiapi" fn(this: &mut Input, extended: bool) -> Status,
11+
read_key_stroke: extern "efiapi" fn(this: &mut Input, key: *mut RawKey) -> Status,
1212
wait_for_key: Event,
1313
}
1414

src/proto/console/text/output.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ use core::fmt;
1111
#[unsafe_guid("387477c2-69c7-11d2-8e39-00a0c969723b")]
1212
#[derive(Protocol)]
1313
pub struct Output<'boot> {
14-
reset: extern "win64" fn(this: &Output, extended: bool) -> Status,
15-
output_string: unsafe extern "win64" fn(this: &Output, string: *const Char16) -> Status,
16-
test_string: unsafe extern "win64" fn(this: &Output, string: *const Char16) -> Status,
17-
query_mode: extern "win64" fn(
14+
reset: extern "efiapi" fn(this: &Output, extended: bool) -> Status,
15+
output_string: unsafe extern "efiapi" fn(this: &Output, string: *const Char16) -> Status,
16+
test_string: unsafe extern "efiapi" fn(this: &Output, string: *const Char16) -> Status,
17+
query_mode: extern "efiapi" fn(
1818
this: &Output,
1919
mode: usize,
2020
columns: &mut usize,
2121
rows: &mut usize,
2222
) -> Status,
23-
set_mode: extern "win64" fn(this: &mut Output, mode: usize) -> Status,
24-
set_attribute: extern "win64" fn(this: &mut Output, attribute: usize) -> Status,
25-
clear_screen: extern "win64" fn(this: &mut Output) -> Status,
26-
set_cursor_position: extern "win64" fn(this: &mut Output, column: usize, row: usize) -> Status,
27-
enable_cursor: extern "win64" fn(this: &mut Output, visible: bool) -> Status,
23+
set_mode: extern "efiapi" fn(this: &mut Output, mode: usize) -> Status,
24+
set_attribute: extern "efiapi" fn(this: &mut Output, attribute: usize) -> Status,
25+
clear_screen: extern "efiapi" fn(this: &mut Output) -> Status,
26+
set_cursor_position: extern "efiapi" fn(this: &mut Output, column: usize, row: usize) -> Status,
27+
enable_cursor: extern "efiapi" fn(this: &mut Output, visible: bool) -> Status,
2828
data: &'boot OutputData,
2929
}
3030

src/proto/media/file/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -271,40 +271,40 @@ impl Drop for FileHandle {
271271
#[repr(C)]
272272
pub(super) struct FileImpl {
273273
revision: u64,
274-
open: unsafe extern "win64" fn(
274+
open: unsafe extern "efiapi" fn(
275275
this: &mut FileImpl,
276276
new_handle: &mut *mut FileImpl,
277277
filename: *const Char16,
278278
open_mode: FileMode,
279279
attributes: FileAttribute,
280280
) -> Status,
281-
close: extern "win64" fn(this: &mut FileImpl) -> Status,
282-
delete: extern "win64" fn(this: &mut FileImpl) -> Status,
283-
read: unsafe extern "win64" fn(
281+
close: extern "efiapi" fn(this: &mut FileImpl) -> Status,
282+
delete: extern "efiapi" fn(this: &mut FileImpl) -> Status,
283+
read: unsafe extern "efiapi" fn(
284284
this: &mut FileImpl,
285285
buffer_size: &mut usize,
286286
buffer: *mut u8,
287287
) -> Status,
288-
write: unsafe extern "win64" fn(
288+
write: unsafe extern "efiapi" fn(
289289
this: &mut FileImpl,
290290
buffer_size: &mut usize,
291291
buffer: *const u8,
292292
) -> Status,
293-
get_position: extern "win64" fn(this: &mut FileImpl, position: &mut u64) -> Status,
294-
set_position: extern "win64" fn(this: &mut FileImpl, position: u64) -> Status,
295-
get_info: unsafe extern "win64" fn(
293+
get_position: extern "efiapi" fn(this: &mut FileImpl, position: &mut u64) -> Status,
294+
set_position: extern "efiapi" fn(this: &mut FileImpl, position: u64) -> Status,
295+
get_info: unsafe extern "efiapi" fn(
296296
this: &mut FileImpl,
297297
information_type: &Guid,
298298
buffer_size: &mut usize,
299299
buffer: *mut u8,
300300
) -> Status,
301-
set_info: unsafe extern "win64" fn(
301+
set_info: unsafe extern "efiapi" fn(
302302
this: &mut FileImpl,
303303
information_type: &Guid,
304304
buffer_size: usize,
305305
buffer: *const c_void,
306306
) -> Status,
307-
flush: extern "win64" fn(this: &mut FileImpl) -> Status,
307+
flush: extern "efiapi" fn(this: &mut FileImpl) -> Status,
308308
}
309309

310310
/// Disambiguates the file type. Returned by `File::into_type()`.

src/proto/media/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::ptr;
1414
#[derive(Protocol)]
1515
pub struct SimpleFileSystem {
1616
revision: u64,
17-
open_volume: extern "win64" fn(this: &mut SimpleFileSystem, root: &mut *mut FileImpl) -> Status,
17+
open_volume: extern "efiapi" fn(this: &mut SimpleFileSystem, root: &mut *mut FileImpl) -> Status,
1818
}
1919

2020
impl SimpleFileSystem {

src/proto/pi/mp.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use core::ptr;
2020
use core::time::Duration;
2121

2222
/// Callback to be called on the AP.
23-
pub type Procedure = extern "win64" fn(*mut c_void);
23+
pub type Procedure = extern "efiapi" fn(*mut c_void);
2424

2525
bitflags! {
2626
/// Flags indicating if the processor is BSP or AP,
@@ -94,17 +94,17 @@ pub struct CPUPhysicalLocation {
9494
#[unsafe_guid("3fdda605-a76e-4f46-ad29-12f4531b3d08")]
9595
#[derive(Protocol)]
9696
pub struct MPServices {
97-
get_number_of_processors: extern "win64" fn(
97+
get_number_of_processors: extern "efiapi" fn(
9898
this: *const MPServices,
9999
number_of_processors: *mut usize,
100100
number_of_enabled_processors: *mut usize,
101101
) -> Status,
102-
get_processor_info: extern "win64" fn(
102+
get_processor_info: extern "efiapi" fn(
103103
this: *const MPServices,
104104
processor_number: usize,
105105
processor_info_buffer: *mut ProcessorInformation,
106106
) -> Status,
107-
startup_all_aps: extern "win64" fn(
107+
startup_all_aps: extern "efiapi" fn(
108108
this: *const MPServices,
109109
procedure: Procedure,
110110
single_thread: bool,
@@ -113,7 +113,7 @@ pub struct MPServices {
113113
procedure_argument: *mut c_void,
114114
failed_cpu_list: *mut *mut usize,
115115
) -> Status,
116-
startup_this_ap: extern "win64" fn(
116+
startup_this_ap: extern "efiapi" fn(
117117
this: *const MPServices,
118118
procedure: Procedure,
119119
processor_number: usize,
@@ -122,18 +122,18 @@ pub struct MPServices {
122122
procedure_argument: *mut c_void,
123123
finished: *mut bool,
124124
) -> Status,
125-
switch_bsp: extern "win64" fn(
125+
switch_bsp: extern "efiapi" fn(
126126
this: *const MPServices,
127127
processor_number: usize,
128128
enable_old_bsp: bool,
129129
) -> Status,
130-
enable_disable_ap: extern "win64" fn(
130+
enable_disable_ap: extern "efiapi" fn(
131131
this: *const MPServices,
132132
processor_number: usize,
133133
enable_ap: bool,
134134
health_flag: *const u32,
135135
) -> Status,
136-
who_am_i: extern "win64" fn(this: *const MPServices, processor_number: *mut usize) -> Status,
136+
who_am_i: extern "efiapi" fn(this: *const MPServices, processor_number: *mut usize) -> Status,
137137
}
138138

139139
impl MPServices {

src/table/boot.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,38 @@ pub struct BootServices {
1818
header: Header,
1919

2020
// Task Priority services
21-
raise_tpl: unsafe extern "win64" fn(new_tpl: Tpl) -> Tpl,
22-
restore_tpl: unsafe extern "win64" fn(old_tpl: Tpl),
21+
raise_tpl: unsafe extern "efiapi" fn(new_tpl: Tpl) -> Tpl,
22+
restore_tpl: unsafe extern "efiapi" fn(old_tpl: Tpl),
2323

2424
// Memory allocation functions
25-
allocate_pages: extern "win64" fn(
25+
allocate_pages: extern "efiapi" fn(
2626
alloc_ty: u32,
2727
mem_ty: MemoryType,
2828
count: usize,
2929
addr: &mut u64,
3030
) -> Status,
31-
free_pages: extern "win64" fn(addr: u64, pages: usize) -> Status,
32-
get_memory_map: unsafe extern "win64" fn(
31+
free_pages: extern "efiapi" fn(addr: u64, pages: usize) -> Status,
32+
get_memory_map: unsafe extern "efiapi" fn(
3333
size: &mut usize,
3434
map: *mut MemoryDescriptor,
3535
key: &mut MemoryMapKey,
3636
desc_size: &mut usize,
3737
desc_version: &mut u32,
3838
) -> Status,
3939
allocate_pool:
40-
extern "win64" fn(pool_type: MemoryType, size: usize, buffer: &mut *mut u8) -> Status,
41-
free_pool: extern "win64" fn(buffer: *mut u8) -> Status,
40+
extern "efiapi" fn(pool_type: MemoryType, size: usize, buffer: &mut *mut u8) -> Status,
41+
free_pool: extern "efiapi" fn(buffer: *mut u8) -> Status,
4242

4343
// Event & timer functions
44-
create_event: unsafe extern "win64" fn(
44+
create_event: unsafe extern "efiapi" fn(
4545
ty: EventType,
4646
notify_tpl: Tpl,
4747
notify_func: Option<EventNotifyFn>,
4848
notify_ctx: *mut c_void,
4949
event: *mut Event,
5050
) -> Status,
5151
set_timer: usize,
52-
wait_for_event: unsafe extern "win64" fn(
52+
wait_for_event: unsafe extern "efiapi" fn(
5353
number_of_events: usize,
5454
events: *mut Event,
5555
out_index: *mut usize,
@@ -63,10 +63,10 @@ pub struct BootServices {
6363
reinstall_protocol_interface: usize,
6464
uninstall_protocol_interface: usize,
6565
handle_protocol:
66-
extern "win64" fn(handle: Handle, proto: &Guid, out_proto: &mut *mut c_void) -> Status,
66+
extern "efiapi" fn(handle: Handle, proto: &Guid, out_proto: &mut *mut c_void) -> Status,
6767
_reserved: usize,
6868
register_protocol_notify: usize,
69-
locate_handle: unsafe extern "win64" fn(
69+
locate_handle: unsafe extern "efiapi" fn(
7070
search_ty: i32,
7171
proto: *const Guid,
7272
key: *mut c_void,
@@ -82,12 +82,12 @@ pub struct BootServices {
8282
exit: usize,
8383
unload_image: usize,
8484
exit_boot_services:
85-
unsafe extern "win64" fn(image_handle: Handle, map_key: MemoryMapKey) -> Status,
85+
unsafe extern "efiapi" fn(image_handle: Handle, map_key: MemoryMapKey) -> Status,
8686

8787
// Misc services
8888
get_next_monotonic_count: usize,
89-
stall: extern "win64" fn(microseconds: usize) -> Status,
90-
set_watchdog_timer: unsafe extern "win64" fn(
89+
stall: extern "efiapi" fn(microseconds: usize) -> Status,
90+
set_watchdog_timer: unsafe extern "efiapi" fn(
9191
timeout: usize,
9292
watchdog_code: u64,
9393
data_size: usize,
@@ -106,7 +106,7 @@ pub struct BootServices {
106106
// Library services
107107
protocols_per_handle: usize,
108108
locate_handle_buffer: usize,
109-
locate_protocol: extern "win64" fn(
109+
locate_protocol: extern "efiapi" fn(
110110
proto: &Guid,
111111
registration: *mut c_void,
112112
out_proto: &mut *mut c_void,
@@ -118,8 +118,8 @@ pub struct BootServices {
118118
calculate_crc32: usize,
119119

120120
// Misc services
121-
copy_mem: unsafe extern "win64" fn(dest: *mut u8, src: *const u8, len: usize),
122-
set_mem: unsafe extern "win64" fn(buffer: *mut u8, len: usize, value: u8),
121+
copy_mem: unsafe extern "efiapi" fn(dest: *mut u8, src: *const u8, len: usize),
122+
set_mem: unsafe extern "efiapi" fn(buffer: *mut u8, len: usize, value: u8),
123123

124124
// New event functions (UEFI 2.0 or newer)
125125
create_event_ex: usize,
@@ -280,7 +280,7 @@ impl BootServices {
280280
let mut event = MaybeUninit::<Event>::uninit();
281281

282282
// Use a trampoline to handle the impedance mismatch between Rust & C
283-
unsafe extern "win64" fn notify_trampoline(e: Event, ctx: *mut c_void) {
283+
unsafe extern "efiapi" fn notify_trampoline(e: Event, ctx: *mut c_void) {
284284
let notify_fn: fn(Event) = mem::transmute(ctx);
285285
notify_fn(e); // SAFETY: Aborting panics are assumed here
286286
}
@@ -801,4 +801,4 @@ bitflags! {
801801
}
802802

803803
/// Raw event notification function
804-
type EventNotifyFn = unsafe extern "win64" fn(event: Event, context: *mut c_void);
804+
type EventNotifyFn = unsafe extern "efiapi" fn(event: Event, context: *mut c_void);

src/table/runtime.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ use core::ptr;
1414
pub struct RuntimeServices {
1515
header: Header,
1616
get_time:
17-
unsafe extern "win64" fn(time: *mut Time, capabilities: *mut TimeCapabilities) -> Status,
18-
set_time: unsafe extern "win64" fn(time: &Time) -> Status,
17+
unsafe extern "efiapi" fn(time: *mut Time, capabilities: *mut TimeCapabilities) -> Status,
18+
set_time: unsafe extern "efiapi" fn(time: &Time) -> Status,
1919
// Skip some useless functions.
2020
_pad: [usize; 8],
21-
reset: unsafe extern "win64" fn(
21+
reset: unsafe extern "efiapi" fn(
2222
rt: ResetType,
2323
status: Status,
2424
data_size: usize,

uefi-macros/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
139139
let entry_fn_ident = &f.sig.ident;
140140

141141
let result = quote!(
142-
static _UEFI_ENTRY_POINT_TYPE_CHECK: extern "win64" fn(uefi::Handle, uefi::table::SystemTable<uefi::table::Boot>) -> uefi::Status = #entry_fn_ident;
142+
static _UEFI_ENTRY_POINT_TYPE_CHECK: extern "efiapi" fn(uefi::Handle, uefi::table::SystemTable<uefi::table::Boot>) -> uefi::Status = #entry_fn_ident;
143143
#[no_mangle]
144-
pub extern "win64" #f
144+
pub extern "efiapi" #f
145145
);
146146
result.into()
147147
}

uefi-test-runner/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![no_main]
33
#![feature(asm)]
44
#![feature(slice_patterns)]
5+
#![feature(abi_efiapi)]
56

67
#[macro_use]
78
extern crate log;

uefi-test-runner/src/proto/pi/mp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ fn test_get_processor_info(mps: &MPServices) {
6161
mps.enable_disable_ap(1, true, None).unwrap().unwrap();
6262
}
6363

64-
extern "win64" fn proc_increment_atomic(arg: *mut c_void) {
64+
extern "efiapi" fn proc_increment_atomic(arg: *mut c_void) {
6565
let counter: &AtomicUsize = unsafe { &*(arg as *const _) };
6666
counter.fetch_add(1, Ordering::Relaxed);
6767
}
6868

69-
extern "win64" fn proc_wait_100ms(arg: *mut c_void) {
69+
extern "efiapi" fn proc_wait_100ms(arg: *mut c_void) {
7070
let bt: &BootServices = unsafe { &*(arg as *const _) };
7171
bt.stall(100_000);
7272
}

0 commit comments

Comments
 (0)