Skip to content

Commit d94e1b1

Browse files
committed
[Fixed] nits and only readonly hook called.
1 parent 04be50f commit d94e1b1

File tree

5 files changed

+71
-53
lines changed

5 files changed

+71
-53
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# uefi-raw - [Unreleased]
22

33
## Added
4-
- Added `ResetNotification`.
4+
- Added `ResetNotificationProtocol`.
55

66
## Added
77
- Added `TimestampProtocol`.

uefi-raw/src/protocol/misc.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::{guid, Guid, Status};
21
use crate::table::runtime;
2+
use crate::{guid, Guid, Status};
33

44
#[derive(Debug)]
55
#[repr(C)]
@@ -28,15 +28,20 @@ pub struct TimestampProperties {
2828
#[derive(Debug)]
2929
#[repr(C)]
3030
pub struct ResetNotificationProtocol {
31-
pub register_reset_notify: unsafe extern "efiapi" fn(this: *const Self, reset_function: Option<ResetSystemFn>) -> Status,
32-
pub unregister_reset_notify: unsafe extern "efiapi" fn(this: *const Self, reset_function: Option<ResetSystemFn>) -> Status,
31+
pub register_reset_notify: unsafe extern "efiapi" fn(
32+
this: *const Self,
33+
reset_function: Option<ResetSystemFn>,
34+
) -> Status,
35+
pub unregister_reset_notify: unsafe extern "efiapi" fn(
36+
this: *const Self,
37+
reset_function: Option<ResetSystemFn>,
38+
) -> Status,
3339
}
3440

3541
impl ResetNotificationProtocol {
3642
pub const GUID: Guid = guid!("9da34ae0-eaf9-4bbf-8ec3-fd60226c44be");
3743
}
3844

39-
4045
/// Raw reset notification function, to be called if you register it when a RestSystem() is executed.
4146
// copy from uefi-raw/src/table/runtime.rs:53 at commit@6093205c3eb27b2e78be4c003c04d46679bff420
4247
pub type ResetSystemFn = unsafe extern "efiapi" fn(

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

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,66 @@ use uefi::proto::misc::{ResetNotification, Timestamp};
33
use uefi::table::runtime;
44

55
///
6-
/// you may see those log, it's nothing just for your computer firmware does not support the new UEFI feature.
6+
/// you may see those log, it's nothing just for your computer firmware does not support the new UEFI feature of Timestamp Protocol.
77
///
88
/// ```sh
9-
/// [ INFO]: uefi-test-runner\src\proto\misc.rs@012: Running loaded Timestamp Protocol test
10-
/// [ WARN]: uefi-test-runner\src\proto\misc.rs@026: Failed to open Timestamp Protocol: Error { status: UNSUPPORTED, data: () }
11-
/// [ INFO]: uefi-test-runner\src\proto\misc.rs@033: Running loaded ResetNotification protocol test
12-
/// [ WARN]: uefi-test-runner\src\proto\misc.rs@068: Failed to open ResetNotification Protocol: Error { status: UNSUPPORTED, data: () }
9+
/// [ INFO]: uefi-test-runner\src\proto\misc.rs@020: Running loaded Timestamp Protocol test
10+
/// [ WARN]: uefi-test-runner\src\proto\misc.rs@037: Failed to found Timestamp Protocol: Error { status: NOT_FOUND, data: () }
11+
/// [ INFO]: uefi-test-runner\src\proto\misc.rs@043: Running loaded ResetNotification protocol test
12+
/// [ INFO]: uefi-test-runner\src\proto\misc.rs@053: ResetNotification Protocol register null test: Err(Error { status: INVALID_PARAMETER, data: () })
13+
/// [ INFO]: uefi-test-runner\src\proto\misc.rs@059: ResetNotification Protocol unregister null test: Err(Error { status: INVALID_PARAMETER, data: () })
14+
/// [ INFO]: uefi-test-runner\src\proto\misc.rs@078: ResetNotification Protocol register efi_reset_fn test: Ok(())
15+
/// [ INFO]: uefi-test-runner\src\proto\misc.rs@084: ResetNotification Protocol unregister efi_reset_fn test: Ok(())
1316
/// ```
14-
pub fn test(image: Handle, bt: &BootServices) {
15-
test_timestamp(image, bt);
16-
test_reset_notification(image, bt);
17+
pub fn test(bt: &BootServices) {
18+
test_timestamp(bt);
19+
test_reset_notification(bt);
1720
}
1821

19-
pub fn test_timestamp(image: Handle, bt: &BootServices) {
22+
pub fn test_timestamp(bt: &BootServices) {
2023
info!("Running loaded Timestamp Protocol test");
2124

22-
let result = bt
23-
.open_protocol_exclusive::<Timestamp>(image);
25+
let handle = bt.get_handle_for_protocol::<Timestamp>();
26+
27+
match handle {
28+
Ok(handle) => {
29+
let timestamp_proto = bt
30+
.open_protocol_exclusive::<Timestamp>(handle)
31+
.expect("Founded Timestamp Protocol but open failed");
2432

25-
match result {
26-
Ok(timestamp_proto) => {
2733
let timestamp = timestamp_proto.get_timestamp();
2834
info!("Timestamp Protocol's timestamp: {:?}", timestamp);
2935

3036
let properties = timestamp_proto.get_properties();
3137
info!("Timestamp Protocol's properties: {:?}", properties);
3238
}
3339
Err(err) => {
34-
warn!("Failed to open Timestamp Protocol: {:?}", err);
40+
warn!("Failed to found Timestamp Protocol: {:?}", err);
3541
}
3642
}
3743
}
3844

39-
40-
pub fn test_reset_notification(image: Handle, bt: &BootServices) {
45+
pub fn test_reset_notification(bt: &BootServices) {
4146
info!("Running loaded ResetNotification protocol test");
4247

43-
let result = bt
44-
.open_protocol_exclusive::<ResetNotification>(image);
48+
let handle = bt.get_handle_for_protocol::<ResetNotification>();
4549

46-
match result {
47-
Ok(mut reset_notif_proto) => {
50+
match handle {
51+
Ok(handle) => {
52+
let mut reset_notif_proto = bt
53+
.open_protocol_exclusive::<ResetNotification>(handle)
54+
.expect("Founded ResetNotification Protocol but open failed");
4855
let result = reset_notif_proto.register_reset_notify(None);
49-
info!("ResetNotification Protocol register null test: {:?}", result);
56+
info!(
57+
"ResetNotification Protocol register null test: {:?}",
58+
result
59+
);
5060

5161
let result = reset_notif_proto.unregister_reset_notify(None);
52-
info!("ResetNotification Protocol unregister null test: {:?}", result);
53-
54-
62+
info!(
63+
"ResetNotification Protocol unregister null test: {:?}",
64+
result
65+
);
5566

5667
// value efi_reset_fn is the type of ResetSystemFn, a function pointer
5768
unsafe extern "efiapi" fn efi_reset_fn(
@@ -67,14 +78,19 @@ pub fn test_reset_notification(image: Handle, bt: &BootServices) {
6778
}
6879

6980
let result = reset_notif_proto.register_reset_notify(Some(efi_reset_fn));
70-
info!("ResetNotification Protocol register efi_reset_fn test: {:?}", result);
81+
info!(
82+
"ResetNotification Protocol register efi_reset_fn test: {:?}",
83+
result
84+
);
7185

7286
let result = reset_notif_proto.unregister_reset_notify(Some(efi_reset_fn));
73-
info!("ResetNotification Protocol unregister efi_reset_fn test: {:?}", result);
87+
info!(
88+
"ResetNotification Protocol unregister efi_reset_fn test: {:?}",
89+
result
90+
);
7491
}
7592
Err(err) => {
76-
warn!("Failed to open ResetNotification Protocol: {:?}", err);
93+
warn!("Failed to found ResetNotification Protocol: {:?}", err);
7794
}
7895
}
7996
}
80-

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use uefi::{Identify, proto};
21
use uefi::prelude::*;
32
use uefi::proto::loaded_image::LoadedImage;
3+
use uefi::{proto, Identify};
44

55
pub fn test(image: Handle, st: &mut SystemTable<Boot>) {
66
info!("Testing various protocols");
@@ -21,13 +21,13 @@ pub fn test(image: Handle, st: &mut SystemTable<Boot>) {
2121
rng::test(bt);
2222
shell_params::test(bt);
2323
string::test(bt);
24-
misc::test(image, bt);
24+
misc::test(bt);
2525

2626
#[cfg(any(
27-
target_arch = "x86",
28-
target_arch = "x86_64",
29-
target_arch = "arm",
30-
target_arch = "aarch64"
27+
target_arch = "x86",
28+
target_arch = "x86_64",
29+
target_arch = "arm",
30+
target_arch = "aarch64"
3131
))]
3232
shim::test(bt);
3333
tcg::test(bt);
@@ -61,17 +61,17 @@ mod device_path;
6161
mod driver;
6262
mod loaded_image;
6363
mod media;
64+
mod misc;
6465
mod network;
6566
mod pi;
6667
mod rng;
6768
mod shell_params;
6869
#[cfg(any(
69-
target_arch = "x86",
70-
target_arch = "x86_64",
71-
target_arch = "arm",
72-
target_arch = "aarch64"
70+
target_arch = "x86",
71+
target_arch = "x86_64",
72+
target_arch = "arm",
73+
target_arch = "aarch64"
7374
))]
7475
mod shim;
7576
mod string;
7677
mod tcg;
77-
mod misc;

uefi/src/proto/misc.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Miscellaneous protocols.
22
3-
use uefi_raw::protocol::misc::{ResetNotificationProtocol, ResetSystemFn, TimestampProperties, TimestampProtocol};
3+
use uefi_raw::protocol::misc::{
4+
ResetNotificationProtocol, ResetSystemFn, TimestampProperties, TimestampProtocol,
5+
};
46

5-
use crate::{Result, StatusExt};
67
use crate::proto::unsafe_protocol;
8+
use crate::{Result, StatusExt};
79

810
/// Protocol for retrieving a high-resolution timestamp counter.
911
#[derive(Debug)]
@@ -65,21 +67,16 @@ impl ResetNotification {
6567
/// }
6668
/// ```
6769
pub fn register_reset_notify(&mut self, reset_function: Option<ResetSystemFn>) -> Result {
68-
unsafe {
69-
(self.0.register_reset_notify)(&mut self.0, reset_function)
70-
}.to_result()
70+
unsafe { (self.0.register_reset_notify)(&mut self.0, reset_function) }.to_result()
7171
}
7272

7373
/// Removes a reset notification function that has been previously registered with RegisterResetNotify().
7474
/// Tips: RegisterResetNotify() has named as `register_reset_notify()` in uefi-rs.
7575
pub fn unregister_reset_notify(&mut self, reset_function: Option<ResetSystemFn>) -> Result {
76-
unsafe {
77-
(self.0.unregister_reset_notify)(&mut self.0, reset_function)
78-
}.to_result()
76+
unsafe { (self.0.unregister_reset_notify)(&mut self.0, reset_function) }.to_result()
7977
}
8078
}
8179

82-
8380
// !TODO: make a safe FFI for raw function 'ResetSystemFn'
8481
// copy and edit from uefi-raw/src/table/runtime.rs:84 at commit@6093205c3eb27b2e78be4c003c04d46679bff420
8582
// pub fn new(&self, rt: ResetType, status: Status, data: Option<&[u8]>) -> Option<ResetSystemFn>

0 commit comments

Comments
 (0)