Skip to content

Commit 3ad386d

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 3ce9ed4 commit 3ad386d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- `From<&CStr16>` for `CString16`
2020
- `From<&CStr16>` for `String`
2121
- `From<&CString16>` for `String`
22+
- Added the `ShellParams` protocol
2223

2324
### Changed
2425

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

0 commit comments

Comments
 (0)