Skip to content

Commit 8a54e4d

Browse files
committed
Fix the shim protocol on non-x86 platforms
1 parent 80d0d28 commit 8a54e4d

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/proto/shim/mod.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
//! Shim lock protocol.
22
3+
#![cfg(any(
4+
target_arch = "i386",
5+
target_arch = "x86_64",
6+
target_arch = "arm",
7+
target_arch = "aarch64"
8+
))]
9+
310
use crate::proto::Protocol;
411
use crate::result::Error;
512
use crate::{unsafe_guid, Result, Status};
@@ -36,6 +43,18 @@ pub struct Hashes {
3643
pub sha1: [u8; SHA1_DIGEST_SIZE],
3744
}
3845

46+
// These macros set the correct calling convention for the Shim protocol methods.
47+
48+
#[cfg(any(target_arch = "i386", target_arch = "x86_64"))]
49+
macro_rules! shim_function {
50+
(fn $args:tt -> $return_type:ty) => (extern "sysv64" fn $args -> $return_type)
51+
}
52+
53+
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
54+
macro_rules! shim_function {
55+
(fn $args:tt -> $return_type:ty) => (extern "C" fn $args -> $return_type)
56+
}
57+
3958
/// The Shim lock protocol.
4059
///
4160
/// This protocol is not part of the UEFI specification, but is
@@ -50,15 +69,17 @@ pub struct Hashes {
5069
#[unsafe_guid("605dab50-e046-4300-abb6-3dd810dd8b23")]
5170
#[derive(Protocol)]
5271
pub struct ShimLock {
53-
verify: extern "sysv64" fn(buffer: *const u8, size: u32) -> Status,
54-
hash: extern "sysv64" fn(
55-
buffer: *const u8,
56-
size: u32,
57-
context: *mut Context,
58-
sha256: *mut [u8; SHA256_DIGEST_SIZE],
59-
sha1: *mut [u8; SHA1_DIGEST_SIZE],
60-
) -> Status,
61-
context: extern "sysv64" fn(buffer: *const u8, size: u32, context: *mut Context) -> Status,
72+
verify: shim_function! { fn(buffer: *const u8, size: u32) -> Status },
73+
hash: shim_function! {
74+
fn(
75+
buffer: *const u8,
76+
size: u32,
77+
context: *mut Context,
78+
sha256: *mut [u8; SHA256_DIGEST_SIZE],
79+
sha1: *mut [u8; SHA1_DIGEST_SIZE]
80+
) -> Status
81+
},
82+
context: shim_function! { fn(buffer: *const u8, size: u32, context: *mut Context) -> Status },
6283
}
6384

6485
impl ShimLock {

uefi-test-runner/src/proto/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ pub fn test(st: &mut SystemTable<Boot>) {
1313
debug::test(bt);
1414
media::test(bt);
1515
pi::test(bt);
16+
17+
#[cfg(any(
18+
target_arch = "i386",
19+
target_arch = "x86_64",
20+
target_arch = "arm",
21+
target_arch = "aarch64"
22+
))]
1623
shim::test(bt);
1724
}
1825

@@ -33,4 +40,10 @@ mod console;
3340
mod debug;
3441
mod media;
3542
mod pi;
43+
#[cfg(any(
44+
target_arch = "i386",
45+
target_arch = "x86_64",
46+
target_arch = "arm",
47+
target_arch = "aarch64"
48+
))]
3649
mod shim;

0 commit comments

Comments
 (0)