Skip to content

Rollup of 7 pull requests #127954

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

Closed
wants to merge 28 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
395ea03
uefi: Add process
Ayush1325 Mar 26, 2024
ed2dca2
uefi: process: Add support to capture stdout
Ayush1325 Mar 29, 2024
3c47880
uefi: process: Add stderr support
Ayush1325 Mar 29, 2024
8ee24d3
uefi: process: Add null protocol
Ayush1325 Mar 29, 2024
588881b
uefi: process Implement inherit
Ayush1325 Mar 29, 2024
6ce936a
uefi: process: Add support for args
Ayush1325 Mar 29, 2024
c05a9b1
uefi: process: Add CommandArgs support
Ayush1325 Mar 29, 2024
a1e344f
uefi: process: Final Touchups
Ayush1325 Mar 29, 2024
4a868f4
uefi: process: Fixes from PR
Ayush1325 Mar 30, 2024
5834772
Update Tests
veera-sivarajan Jul 4, 2024
cf09cba
When finding item gated behind a `cfg` flat, point at it
estebank Jul 12, 2024
5483945
rewrite dump-ice-to-disk to rmake
Oneirical Jul 9, 2024
f54fa62
rewrite panic-abort-eh_frame to rmake
Oneirical Jul 9, 2024
2e1e627
rustdoc: fix `current` class on sidebar modnav
notriddle Jul 18, 2024
4cad705
Parser: Suggest Placing the Return Type After Function Parameters
veera-sivarajan Jul 4, 2024
2f5a84e
Don't allow unsafe statics outside of extern blocks
compiler-errors Jul 18, 2024
e69ff1c
Remove an unnecessary `ForceCollect::Yes`.
nnethercote Jul 16, 2024
7d7e2a1
Don't always force collect tokens in `recover_stmt_local_after_let`.
nnethercote Jul 16, 2024
9d908a2
Use `ForceCollect` in `parse_attr_item`.
nnethercote Jul 17, 2024
4158a1c
Only check `force_collect` in `collect_tokens_trailing_token`.
nnethercote Jul 17, 2024
0c932b7
Rearrange sidebar modnav builder to more logical order
notriddle Jul 19, 2024
0db8c6d
Rollup merge of #123196 - Ayush1325:uefi-process, r=joboet
tgross35 Jul 19, 2024
d649d08
Rollup merge of #127350 - veera-sivarajan:bugfix-126311, r=lcnr
tgross35 Jul 19, 2024
279a895
Rollup merge of #127523 - Oneirical:treasure-test, r=jieyouxu
tgross35 Jul 19, 2024
27b0ee3
Rollup merge of #127662 - estebank:gate-span, r=TaKO8Ki
tgross35 Jul 19, 2024
9d98e59
Rollup merge of #127903 - nnethercote:force_collect-improvements, r=p…
tgross35 Jul 19, 2024
21b179e
Rollup merge of #127932 - notriddle:notriddle/current, r=GuillaumeGomez
tgross35 Jul 19, 2024
35ec8ee
Rollup merge of #127943 - compiler-errors:no-unsafe, r=spastorino
tgross35 Jul 19, 2024
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
uefi: process: Add null protocol
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
  • Loading branch information
Ayush1325 committed May 29, 2024
commit 8ee24d371424c098ce82a918f9ed8227ebbcb521
138 changes: 100 additions & 38 deletions library/std/src/sys/pal/uefi/process.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use r_efi::protocols::simple_text_output;

use crate::ffi::OsStr;
use crate::ffi::OsString;
use crate::fmt;
Expand All @@ -13,12 +15,16 @@ use crate::sys_common::process::{CommandEnv, CommandEnvs};

pub use crate::ffi::OsString as EnvKey;

use super::helpers;

////////////////////////////////////////////////////////////////////////////////
// Command
////////////////////////////////////////////////////////////////////////////////

pub struct Command {
prog: OsString,
stdout: Option<uefi_command_internal::PipeProtocol>,
stderr: Option<uefi_command_internal::PipeProtocol>,
}

// passed back to std::process with the pipes connected to the child, if any
Expand All @@ -39,7 +45,7 @@ pub enum Stdio {

impl Command {
pub fn new(program: &OsStr) -> Command {
Command { prog: program.to_os_string() }
Command { prog: program.to_os_string(), stdout: None, stderr: None }
}

pub fn arg(&mut self, _arg: &OsStr) {
Expand All @@ -58,12 +64,20 @@ impl Command {
panic!("unsupported")
}

pub fn stdout(&mut self, _stdout: Stdio) {
panic!("unsupported")
pub fn stdout(&mut self, stdout: Stdio) {
self.stdout = match stdout {
Stdio::MakePipe => Some(uefi_command_internal::PipeProtocol::new()),
Stdio::Null => Some(uefi_command_internal::PipeProtocol::null()),
_ => None,
};
}

pub fn stderr(&mut self, _stderr: Stdio) {
panic!("unsupported")
pub fn stderr(&mut self, stderr: Stdio) {
self.stderr = match stderr {
Stdio::MakePipe => Some(uefi_command_internal::PipeProtocol::new()),
Stdio::Null => Some(uefi_command_internal::PipeProtocol::null()),
_ => None,
};
}

pub fn get_program(&self) -> &OsStr {
Expand Down Expand Up @@ -93,8 +107,26 @@ impl Command {
pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
let mut cmd = uefi_command_internal::Command::load_image(&self.prog)?;

cmd.stdout_init()?;
cmd.stderr_init()?;
let stdout: helpers::Protocol<uefi_command_internal::PipeProtocol> =
match self.stdout.take() {
Some(s) => helpers::Protocol::create(s, simple_text_output::PROTOCOL_GUID),
None => helpers::Protocol::create(
uefi_command_internal::PipeProtocol::new(),
simple_text_output::PROTOCOL_GUID,
),
}?;

let stderr: helpers::Protocol<uefi_command_internal::PipeProtocol> =
match self.stderr.take() {
Some(s) => helpers::Protocol::create(s, simple_text_output::PROTOCOL_GUID),
None => helpers::Protocol::create(
uefi_command_internal::PipeProtocol::new(),
simple_text_output::PROTOCOL_GUID,
),
}?;

cmd.stdout_init(stdout)?;
cmd.stderr_init(stderr)?;

let stat = cmd.start_image()?;
let stdout = cmd.stdout()?;
Expand Down Expand Up @@ -342,10 +374,10 @@ mod uefi_command_internal {
Ok(r)
}

pub fn stdout_init(&mut self) -> io::Result<()> {
let mut protocol =
helpers::Protocol::create(PipeProtocol::new(), simple_text_output::PROTOCOL_GUID)?;

pub fn stdout_init(
&mut self,
mut protocol: helpers::Protocol<PipeProtocol>,
) -> io::Result<()> {
self.st.console_out_handle = protocol.handle().as_ptr();
self.st.con_out =
protocol.as_mut() as *mut PipeProtocol as *mut simple_text_output::Protocol;
Expand All @@ -355,10 +387,10 @@ mod uefi_command_internal {
Ok(())
}

pub fn stderr_init(&mut self) -> io::Result<()> {
let mut protocol =
helpers::Protocol::create(PipeProtocol::new(), simple_text_output::PROTOCOL_GUID)?;

pub fn stderr_init(
&mut self,
mut protocol: helpers::Protocol<PipeProtocol>,
) -> io::Result<()> {
self.st.standard_error_handle = protocol.handle().as_ptr();
self.st.std_err =
protocol.as_mut() as *mut PipeProtocol as *mut simple_text_output::Protocol;
Expand All @@ -368,29 +400,17 @@ mod uefi_command_internal {
Ok(())
}

pub fn stdout(&self) -> io::Result<Vec<u8>> {
if let Some(stdout) = &self.stdout {
stdout
.as_ref()
.utf8()
.into_string()
.map_err(|_| const_io_error!(io::ErrorKind::Other, "utf8 conversion failed"))
.map(Into::into)
} else {
Err(const_io_error!(io::ErrorKind::NotFound, "stdout not found"))
pub fn stderr(&self) -> io::Result<Vec<u8>> {
match &self.stderr {
Some(stderr) => stderr.as_ref().utf8(),
None => Ok(Vec::new()),
}
}

pub fn stderr(&self) -> io::Result<Vec<u8>> {
if let Some(stderr) = &self.stderr {
stderr
.as_ref()
.utf8()
.into_string()
.map_err(|_| const_io_error!(io::ErrorKind::Other, "utf8 conversion failed"))
.map(Into::into)
} else {
Err(const_io_error!(io::ErrorKind::NotFound, "stdout not found"))
pub fn stdout(&self) -> io::Result<Vec<u8>> {
match &self.stdout {
Some(stdout) => stdout.as_ref().utf8(),
None => Ok(Vec::new()),
}
}
}
Expand All @@ -407,7 +427,7 @@ mod uefi_command_internal {
}

#[repr(C)]
struct PipeProtocol {
pub struct PipeProtocol {
reset: simple_text_output::ProtocolReset,
output_string: simple_text_output::ProtocolOutputString,
test_string: simple_text_output::ProtocolTestString,
Expand All @@ -423,7 +443,7 @@ mod uefi_command_internal {
}

impl PipeProtocol {
fn new() -> Self {
pub fn new() -> Self {
let mut mode = Box::new(simple_text_output::Mode {
max_mode: 0,
mode: 0,
Expand All @@ -448,8 +468,36 @@ mod uefi_command_internal {
}
}

fn utf8(&self) -> OsString {
pub fn null() -> Self {
let mut mode = Box::new(simple_text_output::Mode {
max_mode: 0,
mode: 0,
attribute: 0,
cursor_column: 0,
cursor_row: 0,
cursor_visible: r_efi::efi::Boolean::FALSE,
});
Self {
reset: Self::reset_null,
output_string: Self::output_string_null,
test_string: Self::test_string,
query_mode: Self::query_mode,
set_mode: Self::set_mode,
set_attribute: Self::set_attribute,
clear_screen: Self::clear_screen,
set_cursor_position: Self::set_cursor_position,
enable_cursor: Self::enable_cursor,
mode: mode.as_mut(),
_mode: mode,
_buffer: Vec::new(),
}
}

pub fn utf8(&self) -> io::Result<Vec<u8>> {
OsString::from_wide(&self._buffer)
.into_string()
.map(Into::into)
.map_err(|_| const_io_error!(io::ErrorKind::Other, "utf8 conversion failed"))
}

extern "efiapi" fn reset(
Expand All @@ -463,6 +511,13 @@ mod uefi_command_internal {
r_efi::efi::Status::SUCCESS
}

extern "efiapi" fn reset_null(
_: *mut simple_text_output::Protocol,
_: r_efi::efi::Boolean,
) -> r_efi::efi::Status {
r_efi::efi::Status::SUCCESS
}

extern "efiapi" fn output_string(
proto: *mut simple_text_output::Protocol,
buf: *mut r_efi::efi::Char16,
Expand All @@ -484,6 +539,13 @@ mod uefi_command_internal {
r_efi::efi::Status::SUCCESS
}

extern "efiapi" fn output_string_null(
_: *mut simple_text_output::Protocol,
_: *mut r_efi::efi::Char16,
) -> r_efi::efi::Status {
r_efi::efi::Status::SUCCESS
}

extern "efiapi" fn test_string(
_: *mut simple_text_output::Protocol,
_: *mut r_efi::efi::Char16,
Expand Down