Skip to content

Commit

Permalink
Use EFIAPI ABI introduced in latest nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Oct 30, 2019
1 parent 5d1f121 commit 6fbc3ad
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 67 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions src/proto/console/gop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/proto/console/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
12 changes: 6 additions & 6 deletions src/proto/console/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}

Expand Down
4 changes: 2 additions & 2 deletions src/proto/console/text/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
18 changes: 9 additions & 9 deletions src/proto/console/text/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
20 changes: 10 additions & 10 deletions src/proto/media/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down
2 changes: 1 addition & 1 deletion src/proto/media/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions src/proto/pi/mp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand Down
38 changes: 19 additions & 19 deletions src/table/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ 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,
desc_size: &mut usize,
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<EventNotifyFn>,
notify_ctx: *mut c_void,
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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -272,7 +272,7 @@ impl BootServices {
let mut event = MaybeUninit::<Event>::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
}
Expand Down Expand Up @@ -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);
6 changes: 3 additions & 3 deletions src/table/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions uefi-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::table::Boot>) -> uefi::Status = #entry_fn_ident;
static _UEFI_ENTRY_POINT_TYPE_CHECK: extern "efiapi" fn(uefi::Handle, uefi::table::SystemTable<uefi::table::Boot>) -> uefi::Status = #entry_fn_ident;
#[no_mangle]
pub extern "win64" #f
pub extern "efiapi" #f
);
result.into()
}
4 changes: 2 additions & 2 deletions uefi-test-runner/src/proto/pi/mp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 6fbc3ad

Please sign in to comment.