Skip to content

Commit ee9dbc4

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

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-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/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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! `ShellParams` protocol
2+
3+
use crate::proto::unsafe_protocol;
4+
use crate::Char16;
5+
use core::ffi::c_void;
6+
use core::slice::from_raw_parts;
7+
8+
#[cfg(feature = "alloc")]
9+
use crate::CStr16;
10+
#[cfg(feature = "alloc")]
11+
use alloc::string::String;
12+
#[cfg(feature = "alloc")]
13+
use alloc::string::ToString;
14+
15+
type ShellFileHandle = *const c_void;
16+
17+
/// The ShellParameters protocol.
18+
#[derive(Debug)]
19+
#[repr(transparent)]
20+
#[unsafe_protocol("752f3136-4e16-4fdc-a22a-e5f46812f4ca")]
21+
pub struct ShellParameters {
22+
/// Pointer to a list of arguments
23+
pub argv: *const *const Char16,
24+
/// Number of arguments
25+
pub argc: usize,
26+
/// Handle of the standard input
27+
std_in: ShellFileHandle,
28+
/// Handle of the standard output
29+
std_out: ShellFileHandle,
30+
/// Handle of the standard error output
31+
std_err: ShellFileHandle,
32+
}
33+
34+
impl ShellParameters {
35+
/// Get an iterator of the shell parameter arguments
36+
#[cfg(feature = "alloc")]
37+
pub fn get_args(&self) -> impl Iterator<Item = String> {
38+
unsafe {
39+
from_raw_parts(self.argv, self.argc)
40+
.iter()
41+
.map(|x| CStr16::from_ptr(*x).to_string())
42+
}
43+
}
44+
45+
/// Get a slice of the args, as Char16 pointers
46+
#[must_use]
47+
pub fn get_args_slice(&self) -> &[*const Char16] {
48+
unsafe { from_raw_parts(self.argv, self.argc) }
49+
}
50+
}

0 commit comments

Comments
 (0)