-
-
Notifications
You must be signed in to change notification settings - Fork 170
Updating Uefi Raw for EFI Shell Protocol #1680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicholasbishop
merged 4 commits into
rust-osdev:main
from
RenTrieu:enhancement/efi_shell_protocol_uefi_raw
Jun 2, 2025
+212
−1
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
//! EFI Shell Protocol v2.2 | ||
|
||
use core::ffi::c_void; | ||
|
||
use crate::{Char8, Char16, Event, Guid, Handle, Status, guid}; | ||
|
||
use super::device_path::DevicePathProtocol; | ||
use super::file_system::FileInfo; | ||
use super::shell_params::ShellFileHandle; | ||
|
||
use bitflags::bitflags; | ||
|
||
/// List Entry for File Lists | ||
#[derive(Debug)] | ||
#[repr(C)] | ||
pub struct ListEntry { | ||
pub f_link: *mut ListEntry, | ||
pub b_link: *mut ListEntry, | ||
} | ||
|
||
/// ShellFileInfo for File Lists | ||
#[derive(Debug)] | ||
#[repr(C)] | ||
pub struct ShellFileInfo { | ||
pub link: ListEntry, | ||
pub status: Status, | ||
pub full_name: *mut Char16, | ||
pub file_name: *mut Char16, | ||
pub handle: ShellFileHandle, | ||
pub info: FileInfo, | ||
} | ||
|
||
bitflags! { | ||
/// Specifies the source of the component name | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct ShellDeviceNameFlags: u32 { | ||
/// Use Component Name | ||
const USE_COMPONENT_NAME = 0x0000001; | ||
/// Use Device Path | ||
const USE_DEVICE_PATH = 0x0000002; | ||
} | ||
} | ||
|
||
/// Shell Protocol | ||
#[derive(Debug)] | ||
#[repr(C)] | ||
pub struct ShellProtocol { | ||
pub execute: unsafe extern "efiapi" fn( | ||
parent_image_handle: *const Handle, | ||
command_line: *const Char16, | ||
environment: *const *const Char16, | ||
status_code: *mut Status, | ||
) -> Status, | ||
pub get_env: unsafe extern "efiapi" fn(name: *const Char16) -> *const Char16, | ||
pub set_env: unsafe extern "efiapi" fn( | ||
name: *const Char16, | ||
value: *const Char16, | ||
volatile: bool, | ||
) -> Status, | ||
pub get_alias: unsafe extern "efiapi" fn(alias: *const Char16, volatile: bool) -> *const Char16, | ||
pub set_alias: unsafe extern "efiapi" fn( | ||
command: *const Char16, | ||
alias: *const Char16, | ||
replace: bool, | ||
volatile: bool, | ||
) -> Status, | ||
pub get_help_text: unsafe extern "efiapi" fn( | ||
command: *const Char16, | ||
sections: *const Char16, | ||
help_text: *mut *mut Char16, | ||
) -> Status, | ||
pub get_device_path_from_map: | ||
unsafe extern "efiapi" fn(mapping: *const Char16) -> *const DevicePathProtocol, | ||
pub get_map_from_device_path: | ||
unsafe extern "efiapi" fn(device_path: *mut *mut DevicePathProtocol) -> *const Char16, | ||
pub get_device_path_from_file_path: | ||
unsafe extern "efiapi" fn(path: *const Char16) -> *const DevicePathProtocol, | ||
pub get_file_path_from_device_path: | ||
unsafe extern "efiapi" fn(path: *const DevicePathProtocol) -> *const Char16, | ||
pub set_map: unsafe extern "efiapi" fn( | ||
device_path: *const DevicePathProtocol, | ||
mapping: *const Char16, | ||
) -> Status, | ||
|
||
pub get_cur_dir: unsafe extern "efiapi" fn(file_system_mapping: *const Char16) -> *const Char16, | ||
pub set_cur_dir: | ||
unsafe extern "efiapi" fn(file_system: *const Char16, dir: *const Char16) -> Status, | ||
pub open_file_list: unsafe extern "efiapi" fn( | ||
path: *const Char16, | ||
open_mode: u64, | ||
file_list: *mut *mut ShellFileInfo, | ||
) -> Status, | ||
pub free_file_list: unsafe extern "efiapi" fn(file_list: *const *const ShellFileInfo) -> Status, | ||
pub remove_dup_in_file_list: | ||
unsafe extern "efiapi" fn(file_list: *const *const ShellFileInfo) -> Status, | ||
|
||
pub batch_is_active: unsafe extern "efiapi" fn() -> bool, | ||
pub is_root_shell: unsafe extern "efiapi" fn() -> bool, | ||
pub enable_page_break: unsafe extern "efiapi" fn(), | ||
pub disable_page_break: unsafe extern "efiapi" fn(), | ||
pub get_page_break: unsafe extern "efiapi" fn() -> bool, | ||
pub get_device_name: unsafe extern "efiapi" fn( | ||
device_handle: Handle, | ||
flags: ShellDeviceNameFlags, | ||
language: *const Char8, | ||
best_device_name: *mut *mut Char16, | ||
) -> Status, | ||
|
||
pub get_file_info: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> *const FileInfo, | ||
pub set_file_info: unsafe extern "efiapi" fn( | ||
file_handle: ShellFileHandle, | ||
file_info: *const FileInfo, | ||
) -> Status, | ||
pub open_file_by_name: unsafe extern "efiapi" fn( | ||
file_name: *const Char16, | ||
file_handle: *mut ShellFileHandle, | ||
open_mode: u64, | ||
) -> Status, | ||
pub close_file: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> Status, | ||
pub create_file: unsafe extern "efiapi" fn( | ||
file_name: *const Char16, | ||
file_attribs: u64, | ||
file_handle: *mut ShellFileHandle, | ||
) -> Status, | ||
pub read_file: unsafe extern "efiapi" fn( | ||
file_handle: ShellFileHandle, | ||
read_size: *mut usize, | ||
buffer: *mut c_void, | ||
) -> Status, | ||
pub write_file: unsafe extern "efiapi" fn( | ||
file_handle: ShellFileHandle, | ||
buffer_size: *mut usize, | ||
buffer: *mut c_void, | ||
) -> Status, | ||
pub delete_file: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> Status, | ||
pub delete_file_by_name: unsafe extern "efiapi" fn(file_name: *const Char16) -> Status, | ||
pub get_file_position: | ||
unsafe extern "efiapi" fn(file_handle: ShellFileHandle, position: *mut u64) -> Status, | ||
pub set_file_position: | ||
unsafe extern "efiapi" fn(file_handle: ShellFileHandle, position: u64) -> Status, | ||
pub flush_file: unsafe extern "efiapi" fn(file_handle: ShellFileHandle) -> Status, | ||
pub find_files: unsafe extern "efiapi" fn( | ||
file_pattern: *const Char16, | ||
file_list: *mut *mut ShellFileInfo, | ||
) -> Status, | ||
pub find_files_in_dir: unsafe extern "efiapi" fn( | ||
file_dir_handle: ShellFileHandle, | ||
file_list: *mut *mut ShellFileInfo, | ||
) -> Status, | ||
pub get_file_size: | ||
unsafe extern "efiapi" fn(file_handle: ShellFileHandle, size: *mut u64) -> Status, | ||
|
||
pub open_root: unsafe extern "efiapi" fn( | ||
device_path: *const DevicePathProtocol, | ||
file_handle: *mut ShellFileHandle, | ||
) -> Status, | ||
pub open_root_by_handle: unsafe extern "efiapi" fn( | ||
device_handle: Handle, | ||
file_handle: *mut ShellFileHandle, | ||
) -> Status, | ||
|
||
pub execution_break: Event, | ||
|
||
pub major_version: u32, | ||
pub minor_version: u32, | ||
pub register_guid_name: | ||
unsafe extern "efiapi" fn(guid: *const Guid, guid_name: *const Char16) -> Status, | ||
pub get_guid_name: | ||
unsafe extern "efiapi" fn(guid: *const Guid, guid_name: *mut *mut Char16) -> Status, | ||
pub get_guid_from_name: | ||
unsafe extern "efiapi" fn(guid_name: *const Char16, guid: *mut Guid) -> Status, | ||
pub get_env_ex: | ||
unsafe extern "efiapi" fn(name: *const Char16, attributes: *mut u32) -> *const Char16, | ||
} | ||
|
||
impl ShellProtocol { | ||
pub const GUID: Guid = guid!("6302d008-7f9b-4f30-87ac-60c9fef5da4e"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use uefi::boot; | ||
use uefi::proto::shell::Shell; | ||
|
||
pub fn test() { | ||
info!("Running shell protocol tests"); | ||
|
||
let handle = boot::get_handle_for_protocol::<Shell>().expect("No Shell handles"); | ||
|
||
let mut _shell = | ||
boot::open_protocol_exclusive::<Shell>(handle).expect("Failed to open Shell protocol"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
//! EFI Shell Protocol v2.2 | ||
|
||
use crate::proto::unsafe_protocol; | ||
|
||
pub use uefi_raw::protocol::shell::ShellProtocol; | ||
|
||
/// Shell Protocol | ||
#[derive(Debug)] | ||
#[repr(transparent)] | ||
#[unsafe_protocol(uefi_raw::protocol::shell::ShellProtocol::GUID)] | ||
pub struct Shell(uefi_raw::protocol::shell::ShellProtocol); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicholasbishop, I think we should use
here and other optional parameters, right? I know that this is not streamlined across the code base for all
OPTIONAL
parameters. What do you say?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uefi-raw should stick close to the C API, so it should not use
Option
. (Personally I think the UEFI spec should just remove theOPTIONAL
annotation, as they use it quite inconsistently and it doesn't have a clear purpose.)(Also, it wouldn't be compatible with the C ABI unless we also switched from a raw pointer to NonNull.
Option<NonNull>
is ABI compatible with a raw pointer, butOption<const*>
is not, because it can't use the niche optimization.)