Skip to content
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

ShellParams: Add subshell test #922

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ShellParams: Use open_protocol_exclusive in example
It's safer.

Signed-off-by: Daniel Schaefer <[email protected]>
JohnAZoidberg committed Aug 21, 2023
commit 02e789890e2755646a290ac4b0f3307b26e05910
54 changes: 14 additions & 40 deletions uefi-test-runner/examples/shell_params.rs
Original file line number Diff line number Diff line change
@@ -8,12 +8,7 @@ use log::error;
// ANCHOR: use
//use log::info;
use uefi::CStr16;
use uefi::{
prelude::*,
proto::shell_params::ShellParameters,
table::boot::{OpenProtocolAttributes, OpenProtocolParams, SearchType},
Identify,
};
use uefi::{prelude::*, proto::shell_params::ShellParameters};
use uefi_services::println;

extern crate alloc;
@@ -23,55 +18,34 @@ use alloc::vec::Vec;

// ANCHOR: entry
#[entry]
fn main(_image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
fn main(image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
// ANCHOR_END: entry
// ANCHOR: services
uefi_services::init(&mut system_table).unwrap();
let boot_services = system_table.boot_services();
// ANCHOR_END: services

// ANCHOR: params
let shell_params_h = boot_services
.locate_handle_buffer(SearchType::ByProtocol(&ShellParameters::GUID));
let shell_params_h = match shell_params_h {
let shell_params =
boot_services.open_protocol_exclusive::<ShellParameters>(image_handle);
let shell_params = match shell_params {
Ok(s) => s,
Err(e) => {
error!("Failed to get ShellParameters protocol");
return e.status();
}
};
println!("Found {} ShellParams handles", (*shell_params_h).len());
for handle in &*shell_params_h {
let params_handle = unsafe {
boot_services
.open_protocol::<ShellParameters>(
OpenProtocolParams {
handle: *handle,
agent: boot_services.image_handle(),
controller: None,
},
OpenProtocolAttributes::GetProtocol,
)
.expect("Failed to open ShellParams handle")
};

// TODO: Ehm why are there two and one has no args?
// Maybe one is the shell itself?
if params_handle.argc == 0 {
continue;
}

// Get as Vec of String, only with alloc feature
let args: Vec<String> = params_handle.get_args().collect();
println!("Args: {:?}", args);
// Get as Vec of String, only with alloc feature
let args: Vec<String> = shell_params.get_args().collect();
println!("Args: {:?}", args);

// Or without allocating, get a slice of the pointers
let args = params_handle.get_args_slice();
println!("Num args: {}", args.len());
if args.len() > 1 {
unsafe {
println!("First real arg: '{}'", CStr16::from_ptr(args[1]));
}
// Or without allocating, get a slice of the pointers
let args = shell_params.get_args_slice();
println!("Num args: {}", args.len());
if args.len() > 1 {
unsafe {
println!("First real arg: '{}'", CStr16::from_ptr(args[1]));
}
}
// ANCHOR_END: params