diff --git a/src/table/boot.rs b/src/table/boot.rs
index 2307d9551..be2b6244d 100644
--- a/src/table/boot.rs
+++ b/src/table/boot.rs
@@ -14,6 +14,7 @@ use core::cell::UnsafeCell;
use core::ffi::c_void;
use core::fmt::{Debug, Formatter};
use core::mem::{self, MaybeUninit};
+use core::ops::{Deref, DerefMut};
use core::ptr::NonNull;
use core::{ptr, slice};
@@ -884,6 +885,8 @@ impl BootServices {
)
.into_with_val(|| unsafe {
let interface = P::mut_ptr_from_ffi(interface) as *const UnsafeCell
;
+
+ #[allow(deprecated)]
ScopedProtocol {
interface: &*interface,
open_params: params,
@@ -1030,21 +1033,17 @@ impl BootServices {
},
OpenProtocolAttributes::Exclusive,
)?;
- let loaded_image = unsafe { &*loaded_image.interface.get() };
-
- let device_handle = loaded_image.device();
let device_path = self.open_protocol::(
OpenProtocolParams {
- handle: device_handle,
+ handle: loaded_image.device(),
agent: image_handle,
controller: None,
},
OpenProtocolAttributes::Exclusive,
)?;
- let mut device_path = unsafe { &*device_path.interface.get() };
- let device_handle = self.locate_device_path::(&mut device_path)?;
+ let device_handle = self.locate_device_path::(&mut &*device_path)?;
self.open_protocol::(
OpenProtocolParams {
@@ -1330,6 +1329,7 @@ pub struct OpenProtocolParams {
/// protocol and why [`UnsafeCell`] is used.
pub struct ScopedProtocol<'a, P: Protocol + ?Sized> {
/// The protocol interface.
+ #[deprecated(since = "0.16.0", note = "use Deref and DerefMut instead")]
pub interface: &'a UnsafeCell,
open_params: OpenProtocolParams,
@@ -1353,6 +1353,26 @@ impl<'a, P: Protocol + ?Sized> Drop for ScopedProtocol<'a, P> {
}
}
+impl<'a, P: Protocol + ?Sized> Deref for ScopedProtocol<'a, P> {
+ type Target = P;
+
+ fn deref(&self) -> &Self::Target {
+ #[allow(deprecated)]
+ unsafe {
+ &*self.interface.get()
+ }
+ }
+}
+
+impl<'a, P: Protocol + ?Sized> DerefMut for ScopedProtocol<'a, P> {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ #[allow(deprecated)]
+ unsafe {
+ &mut *self.interface.get()
+ }
+ }
+}
+
/// Type of allocation to perform.
#[derive(Debug, Copy, Clone)]
pub enum AllocateType {
diff --git a/uefi-test-runner/src/main.rs b/uefi-test-runner/src/main.rs
index 28a02dd30..4abe960e4 100644
--- a/uefi-test-runner/src/main.rs
+++ b/uefi-test-runner/src/main.rs
@@ -86,7 +86,7 @@ fn check_screenshot(image: Handle, bt: &BootServices, name: &str) {
.get(1)
.expect("Second serial device is missing");
- let serial = bt
+ let mut serial = bt
.open_protocol::(
OpenProtocolParams {
handle: serial_handle,
@@ -96,7 +96,6 @@ fn check_screenshot(image: Handle, bt: &BootServices, name: &str) {
OpenProtocolAttributes::Exclusive,
)
.expect("Could not open serial protocol");
- let serial = unsafe { &mut *serial.interface.get() };
// Set a large timeout to avoid problems with Travis
let mut io_mode = *serial.io_mode();
diff --git a/uefi-test-runner/src/proto/debug.rs b/uefi-test-runner/src/proto/debug.rs
index 9b174f0a1..eb6eee103 100644
--- a/uefi-test-runner/src/proto/debug.rs
+++ b/uefi-test-runner/src/proto/debug.rs
@@ -7,7 +7,7 @@ pub fn test(image: Handle, bt: &BootServices) {
info!("Running UEFI debug connection protocol test");
if let Ok(handles) = bt.find_handles::() {
for handle in handles {
- if let Ok(debug_support) = bt.open_protocol::(
+ if let Ok(mut debug_support) = bt.open_protocol::(
OpenProtocolParams {
handle,
agent: image,
@@ -15,8 +15,6 @@ pub fn test(image: Handle, bt: &BootServices) {
},
OpenProtocolAttributes::Exclusive,
) {
- let debug_support = unsafe { &mut *debug_support.interface.get() };
-
// make sure that the max processor index is a sane value, i.e. it works
let maximum_processor_index = debug_support.get_maximum_processor_index();
assert_ne!(
@@ -94,7 +92,7 @@ pub fn test(image: Handle, bt: &BootServices) {
_ => unreachable!(),
}
- test_invalidate_instruction_cache(debug_support);
+ test_invalidate_instruction_cache(&mut *debug_support);
}
}
} else {
diff --git a/uefi-test-runner/src/proto/device_path.rs b/uefi-test-runner/src/proto/device_path.rs
index 3c783e141..6cc7a8410 100644
--- a/uefi-test-runner/src/proto/device_path.rs
+++ b/uefi-test-runner/src/proto/device_path.rs
@@ -16,7 +16,6 @@ pub fn test(image: Handle, bt: &BootServices) {
OpenProtocolAttributes::Exclusive,
)
.expect("Failed to open LoadedImage protocol");
- let loaded_image = unsafe { &*loaded_image.interface.get() };
let device_path = bt
.open_protocol::(
@@ -28,7 +27,6 @@ pub fn test(image: Handle, bt: &BootServices) {
OpenProtocolAttributes::Exclusive,
)
.expect("Failed to open DevicePath protocol");
- let device_path = unsafe { &*device_path.interface.get() };
let device_path_to_text = bt
.locate_protocol::()
diff --git a/uefi-test-runner/src/proto/loaded_image.rs b/uefi-test-runner/src/proto/loaded_image.rs
index 0382006f6..e21580d91 100644
--- a/uefi-test-runner/src/proto/loaded_image.rs
+++ b/uefi-test-runner/src/proto/loaded_image.rs
@@ -15,7 +15,6 @@ pub fn test(image: Handle, bt: &BootServices) {
OpenProtocolAttributes::Exclusive,
)
.expect("Failed to open LoadedImage protocol");
- let loaded_image = unsafe { &*loaded_image.interface.get() };
let load_options = loaded_image.load_options_as_bytes();
info!("LoadedImage options: {:?}", load_options);
diff --git a/uefi-test-runner/src/proto/media/known_disk.rs b/uefi-test-runner/src/proto/media/known_disk.rs
index 1ac6f0f99..f1d6744ee 100644
--- a/uefi-test-runner/src/proto/media/known_disk.rs
+++ b/uefi-test-runner/src/proto/media/known_disk.rs
@@ -154,7 +154,7 @@ pub fn test_known_disk(image: Handle, bt: &BootServices) {
let mut found_test_disk = false;
for handle in handles {
- let sfs = bt
+ let mut sfs = bt
.open_protocol::(
OpenProtocolParams {
handle,
@@ -164,7 +164,6 @@ pub fn test_known_disk(image: Handle, bt: &BootServices) {
OpenProtocolAttributes::Exclusive,
)
.expect("Failed to get simple file system");
- let sfs = unsafe { &mut *sfs.interface.get() };
let mut directory = sfs.open_volume().unwrap();
let mut fs_info_buf = vec![0; 128];
diff --git a/uefi-test-runner/src/proto/media/mod.rs b/uefi-test-runner/src/proto/media/mod.rs
index 1a6db9497..da4bf5729 100644
--- a/uefi-test-runner/src/proto/media/mod.rs
+++ b/uefi-test-runner/src/proto/media/mod.rs
@@ -72,7 +72,6 @@ pub fn test(image: Handle, bt: &BootServices) {
OpenProtocolAttributes::Exclusive,
)
.expect("Failed to get partition info");
- let pi = unsafe { &*pi.interface.get() };
if let Some(mbr) = pi.mbr_partition_record() {
info!("MBR partition: {:?}", mbr);
diff --git a/uefi-test-runner/src/proto/network.rs b/uefi-test-runner/src/proto/network.rs
index e0002382f..a1dc49e31 100644
--- a/uefi-test-runner/src/proto/network.rs
+++ b/uefi-test-runner/src/proto/network.rs
@@ -13,7 +13,7 @@ pub fn test(image: Handle, bt: &BootServices) {
if let Ok(handles) = bt.find_handles::() {
for handle in handles {
- let base_code = bt
+ let mut base_code = bt
.open_protocol::(
OpenProtocolParams {
handle,
@@ -24,8 +24,6 @@ pub fn test(image: Handle, bt: &BootServices) {
)
.unwrap();
- let base_code = unsafe { &mut *base_code.interface.get() };
-
info!("Starting PXE Base Code");
base_code
.start(false)
diff --git a/uefi-test-runner/src/proto/rng.rs b/uefi-test-runner/src/proto/rng.rs
index 7fc556bc9..5b612b695 100644
--- a/uefi-test-runner/src/proto/rng.rs
+++ b/uefi-test-runner/src/proto/rng.rs
@@ -11,7 +11,7 @@ pub fn test(image: Handle, bt: &BootServices) {
.first()
.expect("No Rng handles");
- let rng = bt
+ let mut rng = bt
.open_protocol::(
OpenProtocolParams {
handle,
@@ -21,7 +21,6 @@ pub fn test(image: Handle, bt: &BootServices) {
OpenProtocolAttributes::Exclusive,
)
.expect("Failed to open Rng protocol");
- let rng = unsafe { &mut *rng.interface.get() };
let mut list = [RngAlgorithmType::EMPTY_ALGORITHM; 4];