Skip to content

Commit a42d2b9

Browse files
committed
Replaces Image::current with current_image
1 parent 1c027ea commit a42d2b9

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ Keep in mind that you need to put everything your test needed in the same functi
202202
- `File::info()` now return `Box<FileInfo>` instead of `Owned<FileInfo>` when success.
203203
- The second parameter of `Owned::new()` is changed to `Dtor`.
204204
- `SystemTable::current()` was replaced with `zfi::system_table()`.
205+
- `Image::current()` was replaced with `zfi::current_image()`.
205206

206207
## License
207208

src/boot.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::event::Event;
2-
use crate::{Device, Guid, Image, Pages, Path, Status, TableHeader, IMAGE, PAGE_SIZE};
2+
use crate::{
3+
current_image, Device, Guid, Image, Pages, Path, Status, TableHeader, IMAGE, PAGE_SIZE,
4+
};
35
use alloc::vec::Vec;
46
use bitflags::bitflags;
57
use core::mem::size_of;
@@ -181,7 +183,7 @@ impl BootServices {
181183
/// functions that are automatically called by Rust (e.g. when the value is dropped)! Usually
182184
/// this method will be called right before transfering the control to the OS kernel.
183185
pub unsafe fn exit_boot_services(&self, map_key: usize) -> Result<(), Status> {
184-
let status = (self.exit_boot_services)(Image::current(), map_key);
186+
let status = (self.exit_boot_services)(current_image(), map_key);
185187

186188
if status != Status::SUCCESS {
187189
Err(status)

src/debug.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
EfiChar, EfiString, File, FileAttributes, FileCreateError, Image, Owned, Path, PathNode,
3-
Status, DEBUG_WRITER,
2+
current_image, EfiChar, EfiString, File, FileAttributes, FileCreateError, Owned, Path,
3+
PathNode, Status, DEBUG_WRITER,
44
};
55
use alloc::borrow::ToOwned;
66
use alloc::boxed::Box;
@@ -44,7 +44,7 @@ impl DebugFile {
4444
/// `ext` is a file extension without leading dot.
4545
pub fn next_to_image(ext: &str) -> Result<Self, DebugFileError> {
4646
// Get FS on the device where the image is located.
47-
let im = Image::current().proto();
47+
let im = current_image().proto();
4848
let fs = match im.device().file_system() {
4949
Some(v) => v,
5050
None => return Err(DebugFileError::UnsupportedImageLocation),

src/image.rs

-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ use core::ptr::null;
55
pub struct Image(());
66

77
impl Image {
8-
pub fn current() -> &'static Self {
9-
// SAFETY: This is safe because the only place that write IMAGE is our init function.
10-
unsafe { &*IMAGE }
11-
}
12-
138
/// Gets the `EFI_LOADED_IMAGE_PROTOCOL` from this image.
149
pub fn proto(&self) -> &LoadedImage {
1510
static ID: Guid = Guid::new(

src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ pub unsafe fn init(
8181
}
8282
}
8383

84+
/// Returns `im` that was passed to [`init()`].
85+
pub fn current_image() -> &'static Image {
86+
// SAFETY: This is safe because the only place that write IMAGE is our init function.
87+
unsafe { &*IMAGE }
88+
}
89+
8490
/// Returns `st` that was passed to [`init()`].
8591
pub fn system_table() -> &'static SystemTable {
8692
// SAFETY: This is safe because the only place that write ST is our init function.

0 commit comments

Comments
 (0)