From 6fbc3ad52e55833ca43393c68f6db902b1852b8c Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 25 Oct 2019 15:43:50 +0000 Subject: [PATCH 1/2] Use EFIAPI ABI introduced in latest nightly --- src/lib.rs | 1 + src/proto/console/gop.rs | 6 ++--- src/proto/console/pointer/mod.rs | 4 +-- src/proto/console/serial.rs | 12 ++++----- src/proto/console/text/input.rs | 4 +-- src/proto/console/text/output.rs | 18 +++++++------- src/proto/media/file/mod.rs | 20 +++++++-------- src/proto/media/fs.rs | 2 +- src/proto/pi/mp.rs | 16 ++++++------ src/table/boot.rs | 38 ++++++++++++++--------------- src/table/runtime.rs | 6 ++--- uefi-macros/src/lib.rs | 4 +-- uefi-test-runner/src/proto/pi/mp.rs | 4 +-- 13 files changed, 68 insertions(+), 67 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5402b24f7..c88ed73ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ #![cfg_attr(feature = "exts", feature(allocator_api, alloc_layout_extra))] #![feature(optin_builtin_traits)] #![feature(try_trait)] +#![feature(abi_efiapi)] #![no_std] // Enable some additional warnings and lints. #![warn(missing_docs, unused)] diff --git a/src/proto/console/gop.rs b/src/proto/console/gop.rs index 946714f78..62fd14bf2 100644 --- a/src/proto/console/gop.rs +++ b/src/proto/console/gop.rs @@ -37,16 +37,16 @@ use core::ptr; #[unsafe_guid("9042a9de-23dc-4a38-96fb-7aded080516a")] #[derive(Protocol)] pub struct GraphicsOutput<'boot> { - query_mode: extern "win64" fn( + query_mode: extern "efiapi" fn( &GraphicsOutput, mode: u32, info_sz: &mut usize, &mut *const ModeInfo, ) -> Status, - set_mode: extern "win64" fn(&mut GraphicsOutput, mode: u32) -> Status, + set_mode: extern "efiapi" fn(&mut GraphicsOutput, mode: u32) -> Status, // Clippy correctly complains that this is too complicated, but we can't change the spec. #[allow(clippy::type_complexity)] - blt: unsafe extern "win64" fn( + blt: unsafe extern "efiapi" fn( this: &mut GraphicsOutput, buffer: *mut BltPixel, op: u32, diff --git a/src/proto/console/pointer/mod.rs b/src/proto/console/pointer/mod.rs index be40ca1d7..9380d3157 100644 --- a/src/proto/console/pointer/mod.rs +++ b/src/proto/console/pointer/mod.rs @@ -9,8 +9,8 @@ use core::mem::MaybeUninit; #[unsafe_guid("31878c87-0b75-11d5-9a4f-0090273fc14d")] #[derive(Protocol)] pub struct Pointer<'boot> { - reset: extern "win64" fn(this: &mut Pointer, ext_verif: bool) -> Status, - get_state: extern "win64" fn(this: &Pointer, state: *mut PointerState) -> Status, + reset: extern "efiapi" fn(this: &mut Pointer, ext_verif: bool) -> Status, + get_state: extern "efiapi" fn(this: &Pointer, state: *mut PointerState) -> Status, wait_for_input: Event, mode: &'boot PointerMode, } diff --git a/src/proto/console/serial.rs b/src/proto/console/serial.rs index 460033a6d..c56e6fd8d 100644 --- a/src/proto/console/serial.rs +++ b/src/proto/console/serial.rs @@ -18,8 +18,8 @@ pub struct Serial<'boot> { // Revision of this protocol, only 1.0 is currently defined. // Future versions will be backwards compatible. revision: u32, - reset: extern "win64" fn(&mut Serial) -> Status, - set_attributes: extern "win64" fn( + reset: extern "efiapi" fn(&mut Serial) -> Status, + set_attributes: extern "efiapi" fn( &Serial, baud_rate: u64, receive_fifo_depth: u32, @@ -28,10 +28,10 @@ pub struct Serial<'boot> { data_bits: u8, stop_bits_type: StopBits, ) -> Status, - set_control_bits: extern "win64" fn(&mut Serial, ControlBits) -> Status, - get_control_bits: extern "win64" fn(&Serial, &mut ControlBits) -> Status, - write: unsafe extern "win64" fn(&mut Serial, &mut usize, *const u8) -> Status, - read: unsafe extern "win64" fn(&mut Serial, &mut usize, *mut u8) -> Status, + set_control_bits: extern "efiapi" fn(&mut Serial, ControlBits) -> Status, + get_control_bits: extern "efiapi" fn(&Serial, &mut ControlBits) -> Status, + write: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *const u8) -> Status, + read: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *mut u8) -> Status, io_mode: &'boot IoMode, } diff --git a/src/proto/console/text/input.rs b/src/proto/console/text/input.rs index fbfcd5a96..e2d28f54a 100644 --- a/src/proto/console/text/input.rs +++ b/src/proto/console/text/input.rs @@ -7,8 +7,8 @@ use core::mem::MaybeUninit; #[unsafe_guid("387477c1-69c7-11d2-8e39-00a0c969723b")] #[derive(Protocol)] pub struct Input { - reset: extern "win64" fn(this: &mut Input, extended: bool) -> Status, - read_key_stroke: extern "win64" fn(this: &mut Input, key: *mut RawKey) -> Status, + reset: extern "efiapi" fn(this: &mut Input, extended: bool) -> Status, + read_key_stroke: extern "efiapi" fn(this: &mut Input, key: *mut RawKey) -> Status, wait_for_key: Event, } diff --git a/src/proto/console/text/output.rs b/src/proto/console/text/output.rs index be5663ccf..c99646748 100644 --- a/src/proto/console/text/output.rs +++ b/src/proto/console/text/output.rs @@ -11,20 +11,20 @@ use core::fmt; #[unsafe_guid("387477c2-69c7-11d2-8e39-00a0c969723b")] #[derive(Protocol)] pub struct Output<'boot> { - reset: extern "win64" fn(this: &Output, extended: bool) -> Status, - output_string: unsafe extern "win64" fn(this: &Output, string: *const Char16) -> Status, - test_string: unsafe extern "win64" fn(this: &Output, string: *const Char16) -> Status, - query_mode: extern "win64" fn( + reset: extern "efiapi" fn(this: &Output, extended: bool) -> Status, + output_string: unsafe extern "efiapi" fn(this: &Output, string: *const Char16) -> Status, + test_string: unsafe extern "efiapi" fn(this: &Output, string: *const Char16) -> Status, + query_mode: extern "efiapi" fn( this: &Output, mode: usize, columns: &mut usize, rows: &mut usize, ) -> Status, - set_mode: extern "win64" fn(this: &mut Output, mode: usize) -> Status, - set_attribute: extern "win64" fn(this: &mut Output, attribute: usize) -> Status, - clear_screen: extern "win64" fn(this: &mut Output) -> Status, - set_cursor_position: extern "win64" fn(this: &mut Output, column: usize, row: usize) -> Status, - enable_cursor: extern "win64" fn(this: &mut Output, visible: bool) -> Status, + set_mode: extern "efiapi" fn(this: &mut Output, mode: usize) -> Status, + set_attribute: extern "efiapi" fn(this: &mut Output, attribute: usize) -> Status, + clear_screen: extern "efiapi" fn(this: &mut Output) -> Status, + set_cursor_position: extern "efiapi" fn(this: &mut Output, column: usize, row: usize) -> Status, + enable_cursor: extern "efiapi" fn(this: &mut Output, visible: bool) -> Status, data: &'boot OutputData, } diff --git a/src/proto/media/file/mod.rs b/src/proto/media/file/mod.rs index 26d5199c2..364b7d231 100644 --- a/src/proto/media/file/mod.rs +++ b/src/proto/media/file/mod.rs @@ -271,40 +271,40 @@ impl Drop for FileHandle { #[repr(C)] pub(super) struct FileImpl { revision: u64, - open: unsafe extern "win64" fn( + open: unsafe extern "efiapi" fn( this: &mut FileImpl, new_handle: &mut *mut FileImpl, filename: *const Char16, open_mode: FileMode, attributes: FileAttribute, ) -> Status, - close: extern "win64" fn(this: &mut FileImpl) -> Status, - delete: extern "win64" fn(this: &mut FileImpl) -> Status, - read: unsafe extern "win64" fn( + close: extern "efiapi" fn(this: &mut FileImpl) -> Status, + delete: extern "efiapi" fn(this: &mut FileImpl) -> Status, + read: unsafe extern "efiapi" fn( this: &mut FileImpl, buffer_size: &mut usize, buffer: *mut u8, ) -> Status, - write: unsafe extern "win64" fn( + write: unsafe extern "efiapi" fn( this: &mut FileImpl, buffer_size: &mut usize, buffer: *const u8, ) -> Status, - get_position: extern "win64" fn(this: &mut FileImpl, position: &mut u64) -> Status, - set_position: extern "win64" fn(this: &mut FileImpl, position: u64) -> Status, - get_info: unsafe extern "win64" fn( + get_position: extern "efiapi" fn(this: &mut FileImpl, position: &mut u64) -> Status, + set_position: extern "efiapi" fn(this: &mut FileImpl, position: u64) -> Status, + get_info: unsafe extern "efiapi" fn( this: &mut FileImpl, information_type: &Guid, buffer_size: &mut usize, buffer: *mut u8, ) -> Status, - set_info: unsafe extern "win64" fn( + set_info: unsafe extern "efiapi" fn( this: &mut FileImpl, information_type: &Guid, buffer_size: usize, buffer: *const c_void, ) -> Status, - flush: extern "win64" fn(this: &mut FileImpl) -> Status, + flush: extern "efiapi" fn(this: &mut FileImpl) -> Status, } /// Disambiguates the file type. Returned by `File::into_type()`. diff --git a/src/proto/media/fs.rs b/src/proto/media/fs.rs index 083104910..afb60e2bd 100644 --- a/src/proto/media/fs.rs +++ b/src/proto/media/fs.rs @@ -14,7 +14,7 @@ use core::ptr; #[derive(Protocol)] pub struct SimpleFileSystem { revision: u64, - open_volume: extern "win64" fn(this: &mut SimpleFileSystem, root: &mut *mut FileImpl) -> Status, + open_volume: extern "efiapi" fn(this: &mut SimpleFileSystem, root: &mut *mut FileImpl) -> Status, } impl SimpleFileSystem { diff --git a/src/proto/pi/mp.rs b/src/proto/pi/mp.rs index 53528ed5a..27e4fbc76 100644 --- a/src/proto/pi/mp.rs +++ b/src/proto/pi/mp.rs @@ -20,7 +20,7 @@ use core::ptr; use core::time::Duration; /// Callback to be called on the AP. -pub type Procedure = extern "win64" fn(*mut c_void); +pub type Procedure = extern "efiapi" fn(*mut c_void); bitflags! { /// Flags indicating if the processor is BSP or AP, @@ -94,17 +94,17 @@ pub struct CPUPhysicalLocation { #[unsafe_guid("3fdda605-a76e-4f46-ad29-12f4531b3d08")] #[derive(Protocol)] pub struct MPServices { - get_number_of_processors: extern "win64" fn( + get_number_of_processors: extern "efiapi" fn( this: *const MPServices, number_of_processors: *mut usize, number_of_enabled_processors: *mut usize, ) -> Status, - get_processor_info: extern "win64" fn( + get_processor_info: extern "efiapi" fn( this: *const MPServices, processor_number: usize, processor_info_buffer: *mut ProcessorInformation, ) -> Status, - startup_all_aps: extern "win64" fn( + startup_all_aps: extern "efiapi" fn( this: *const MPServices, procedure: Procedure, single_thread: bool, @@ -113,7 +113,7 @@ pub struct MPServices { procedure_argument: *mut c_void, failed_cpu_list: *mut *mut usize, ) -> Status, - startup_this_ap: extern "win64" fn( + startup_this_ap: extern "efiapi" fn( this: *const MPServices, procedure: Procedure, processor_number: usize, @@ -122,18 +122,18 @@ pub struct MPServices { procedure_argument: *mut c_void, finished: *mut bool, ) -> Status, - switch_bsp: extern "win64" fn( + switch_bsp: extern "efiapi" fn( this: *const MPServices, processor_number: usize, enable_old_bsp: bool, ) -> Status, - enable_disable_ap: extern "win64" fn( + enable_disable_ap: extern "efiapi" fn( this: *const MPServices, processor_number: usize, enable_ap: bool, health_flag: *const u32, ) -> Status, - who_am_i: extern "win64" fn(this: *const MPServices, processor_number: *mut usize) -> Status, + who_am_i: extern "efiapi" fn(this: *const MPServices, processor_number: *mut usize) -> Status, } impl MPServices { diff --git a/src/table/boot.rs b/src/table/boot.rs index c8f270ea2..9b2203902 100644 --- a/src/table/boot.rs +++ b/src/table/boot.rs @@ -18,18 +18,18 @@ pub struct BootServices { header: Header, // Task Priority services - raise_tpl: unsafe extern "win64" fn(new_tpl: Tpl) -> Tpl, - restore_tpl: unsafe extern "win64" fn(old_tpl: Tpl), + raise_tpl: unsafe extern "efiapi" fn(new_tpl: Tpl) -> Tpl, + restore_tpl: unsafe extern "efiapi" fn(old_tpl: Tpl), // Memory allocation functions - allocate_pages: extern "win64" fn( + allocate_pages: extern "efiapi" fn( alloc_ty: u32, mem_ty: MemoryType, count: usize, addr: &mut u64, ) -> Status, - free_pages: extern "win64" fn(addr: u64, pages: usize) -> Status, - get_memory_map: unsafe extern "win64" fn( + free_pages: extern "efiapi" fn(addr: u64, pages: usize) -> Status, + get_memory_map: unsafe extern "efiapi" fn( size: &mut usize, map: *mut MemoryDescriptor, key: &mut MemoryMapKey, @@ -37,11 +37,11 @@ pub struct BootServices { desc_version: &mut u32, ) -> Status, allocate_pool: - extern "win64" fn(pool_type: MemoryType, size: usize, buffer: &mut *mut u8) -> Status, - free_pool: extern "win64" fn(buffer: *mut u8) -> Status, + extern "efiapi" fn(pool_type: MemoryType, size: usize, buffer: &mut *mut u8) -> Status, + free_pool: extern "efiapi" fn(buffer: *mut u8) -> Status, // Event & timer functions - create_event: unsafe extern "win64" fn( + create_event: unsafe extern "efiapi" fn( ty: EventType, notify_tpl: Tpl, notify_func: Option, @@ -49,7 +49,7 @@ pub struct BootServices { event: *mut Event, ) -> Status, set_timer: usize, - wait_for_event: unsafe extern "win64" fn( + wait_for_event: unsafe extern "efiapi" fn( number_of_events: usize, events: *mut Event, out_index: *mut usize, @@ -63,10 +63,10 @@ pub struct BootServices { reinstall_protocol_interface: usize, uninstall_protocol_interface: usize, handle_protocol: - extern "win64" fn(handle: Handle, proto: &Guid, out_proto: &mut *mut c_void) -> Status, + extern "efiapi" fn(handle: Handle, proto: &Guid, out_proto: &mut *mut c_void) -> Status, _reserved: usize, register_protocol_notify: usize, - locate_handle: unsafe extern "win64" fn( + locate_handle: unsafe extern "efiapi" fn( search_ty: i32, proto: *const Guid, key: *mut c_void, @@ -82,12 +82,12 @@ pub struct BootServices { exit: usize, unload_image: usize, exit_boot_services: - unsafe extern "win64" fn(image_handle: Handle, map_key: MemoryMapKey) -> Status, + unsafe extern "efiapi" fn(image_handle: Handle, map_key: MemoryMapKey) -> Status, // Misc services get_next_monotonic_count: usize, - stall: extern "win64" fn(microseconds: usize) -> Status, - set_watchdog_timer: unsafe extern "win64" fn( + stall: extern "efiapi" fn(microseconds: usize) -> Status, + set_watchdog_timer: unsafe extern "efiapi" fn( timeout: usize, watchdog_code: u64, data_size: usize, @@ -106,7 +106,7 @@ pub struct BootServices { // Library services protocols_per_handle: usize, locate_handle_buffer: usize, - locate_protocol: extern "win64" fn( + locate_protocol: extern "efiapi" fn( proto: &Guid, registration: *mut c_void, out_proto: &mut *mut c_void, @@ -118,8 +118,8 @@ pub struct BootServices { calculate_crc32: usize, // Misc services - copy_mem: unsafe extern "win64" fn(dest: *mut u8, src: *const u8, len: usize), - set_mem: unsafe extern "win64" fn(buffer: *mut u8, len: usize, value: u8), + copy_mem: unsafe extern "efiapi" fn(dest: *mut u8, src: *const u8, len: usize), + set_mem: unsafe extern "efiapi" fn(buffer: *mut u8, len: usize, value: u8), // New event functions (UEFI 2.0 or newer) create_event_ex: usize, @@ -272,7 +272,7 @@ impl BootServices { let mut event = MaybeUninit::::uninit(); // Use a trampoline to handle the impedance mismatch between Rust & C - unsafe extern "win64" fn notify_trampoline(e: Event, ctx: *mut c_void) { + unsafe extern "efiapi" fn notify_trampoline(e: Event, ctx: *mut c_void) { let notify_fn: fn(Event) = mem::transmute(ctx); notify_fn(e); // SAFETY: Aborting panics are assumed here } @@ -789,4 +789,4 @@ bitflags! { } /// Raw event notification function -type EventNotifyFn = unsafe extern "win64" fn(event: Event, context: *mut c_void); +type EventNotifyFn = unsafe extern "efiapi" fn(event: Event, context: *mut c_void); diff --git a/src/table/runtime.rs b/src/table/runtime.rs index 09d7cfeb8..b4aecb685 100644 --- a/src/table/runtime.rs +++ b/src/table/runtime.rs @@ -14,11 +14,11 @@ use core::ptr; pub struct RuntimeServices { header: Header, get_time: - unsafe extern "win64" fn(time: *mut Time, capabilities: *mut TimeCapabilities) -> Status, - set_time: unsafe extern "win64" fn(time: &Time) -> Status, + unsafe extern "efiapi" fn(time: *mut Time, capabilities: *mut TimeCapabilities) -> Status, + set_time: unsafe extern "efiapi" fn(time: &Time) -> Status, // Skip some useless functions. _pad: [usize; 8], - reset: unsafe extern "win64" fn( + reset: unsafe extern "efiapi" fn( rt: ResetType, status: Status, data_size: usize, diff --git a/uefi-macros/src/lib.rs b/uefi-macros/src/lib.rs index 909b54255..d3d8d910e 100644 --- a/uefi-macros/src/lib.rs +++ b/uefi-macros/src/lib.rs @@ -139,9 +139,9 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { let entry_fn_ident = &f.sig.ident; let result = quote!( - static _UEFI_ENTRY_POINT_TYPE_CHECK: extern "win64" fn(uefi::Handle, uefi::table::SystemTable) -> uefi::Status = #entry_fn_ident; + static _UEFI_ENTRY_POINT_TYPE_CHECK: extern "efiapi" fn(uefi::Handle, uefi::table::SystemTable) -> uefi::Status = #entry_fn_ident; #[no_mangle] - pub extern "win64" #f + pub extern "efiapi" #f ); result.into() } diff --git a/uefi-test-runner/src/proto/pi/mp.rs b/uefi-test-runner/src/proto/pi/mp.rs index 4d74ef4ce..34d8c4572 100644 --- a/uefi-test-runner/src/proto/pi/mp.rs +++ b/uefi-test-runner/src/proto/pi/mp.rs @@ -61,12 +61,12 @@ fn test_get_processor_info(mps: &MPServices) { mps.enable_disable_ap(1, true, None).unwrap().unwrap(); } -extern "win64" fn proc_increment_atomic(arg: *mut c_void) { +extern "efiapi" fn proc_increment_atomic(arg: *mut c_void) { let counter: &AtomicUsize = unsafe { &*(arg as *const _) }; counter.fetch_add(1, Ordering::Relaxed); } -extern "win64" fn proc_wait_100ms(arg: *mut c_void) { +extern "efiapi" fn proc_wait_100ms(arg: *mut c_void) { let bt: &BootServices = unsafe { &*(arg as *const _) }; bt.stall(100_000); } From ced057b32c2145947adfedd56aa4d2148e0cbe1e Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 1 Nov 2019 13:47:21 +0000 Subject: [PATCH 2/2] DOc the requirement of feature(abi_efiapi) --- BUILDING.md | 1 + uefi-test-runner/src/main.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/BUILDING.md b/BUILDING.md index cbfa0f5ee..d4a320faa 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -18,6 +18,7 @@ The following steps allow you to build a simple UEFI app. and make sure you have an entry point function which matches the one below: ```rust +#![feature(abi_efiapi)] use uefi::prelude::*; #[entry] diff --git a/uefi-test-runner/src/main.rs b/uefi-test-runner/src/main.rs index f36ff46d8..6468a21bc 100644 --- a/uefi-test-runner/src/main.rs +++ b/uefi-test-runner/src/main.rs @@ -2,6 +2,7 @@ #![no_main] #![feature(asm)] #![feature(slice_patterns)] +#![feature(abi_efiapi)] #[macro_use] extern crate log;