Skip to content

Commit ab19c99

Browse files
committed
ShellParams: Add protocol
Useful to get the shell arguments for a commandline application. Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 9d9584c commit ab19c99

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Added `core::error::Error` implementations to all error types.
2020
- `SystemTable::exit_boot_services` now takes one param `memory_type` to ensure
2121
the memory type of memory map.
22+
- Added the `ShellParams` protocol
2223

2324
### Removed
2425
- `BootServices::memmove` and `BootServices::set_mem` have been removed, use

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ pub mod driver;
1212
pub mod loaded_image;
1313
pub mod memory_protection;
1414
pub mod rng;
15+
pub mod shell_params;

uefi-raw/src/protocol/shell_params.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::{guid, Char16, Guid};
2+
use core::ffi::c_void;
3+
4+
pub type ShellFileHandle = *const c_void;
5+
6+
#[derive(Debug)]
7+
#[repr(C)]
8+
pub struct ShellParametersProtocol {
9+
/// Pointer to a list of arguments.
10+
pub argv: *const *const Char16,
11+
/// Number of arguments.
12+
pub argc: usize,
13+
/// Handle of the standard input.
14+
pub std_in: ShellFileHandle,
15+
/// Handle of the standard output.
16+
pub std_out: ShellFileHandle,
17+
/// Handle of the standard error output.
18+
pub std_err: ShellFileHandle,
19+
}
20+
21+
impl ShellParametersProtocol {
22+
pub const GUID: Guid = guid!("752f3136-4e16-4fdc-a22a-e5f46812f4ca");
23+
}

uefi/src/proto/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub mod network;
7676
pub mod pi;
7777
pub mod rng;
7878
pub mod security;
79+
pub mod shell_params;
7980
pub mod shim;
8081
pub mod string;
8182
pub mod tcg;

uefi/src/proto/shell_params.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! `ShellParams` protocol
2+
3+
use crate::proto::unsafe_protocol;
4+
use crate::{data_types, Char16};
5+
use core::slice::from_raw_parts;
6+
use uefi_raw::protocol::shell_params::ShellParametersProtocol;
7+
8+
use crate::CStr16;
9+
10+
/// The ShellParameters protocol.
11+
#[derive(Debug)]
12+
#[repr(transparent)]
13+
#[unsafe_protocol(ShellParametersProtocol::GUID)]
14+
pub struct ShellParameters(ShellParametersProtocol);
15+
16+
impl ShellParameters {
17+
/// Get the number of shell parameter arguments
18+
#[must_use]
19+
pub fn args_len(&self) -> usize {
20+
self.0.argc
21+
}
22+
23+
/// Get an iterator of the shell parameter arguments
24+
pub fn args(&self) -> impl Iterator<Item = &CStr16> {
25+
self.args_slice()
26+
.iter()
27+
.map(|x| unsafe { CStr16::from_ptr(*x) })
28+
}
29+
30+
/// Get a slice of the args, as Char16 pointers
31+
#[must_use]
32+
fn args_slice(&self) -> &[*const Char16] {
33+
unsafe {
34+
from_raw_parts(
35+
self.0.argv.cast::<*const data_types::chars::Char16>(),
36+
self.0.argc,
37+
)
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)