uefi: process: Add stderr support · model-checking/verify-rust-std@36a0e1e (original) (raw)
`@@ -92,10 +92,15 @@ impl Command {
`
92
92
``
93
93
`pub fn output(&mut self) -> io::Result<(ExitStatus, Vec, Vec)> {
`
94
94
`let mut cmd = uefi_command_internal::Command::load_image(&self.prog)?;
`
``
95
+
95
96
` cmd.stdout_init()?;
`
``
97
`+
cmd.stderr_init()?;
`
``
98
+
96
99
`let stat = cmd.start_image()?;
`
97
100
`let stdout = cmd.stdout()?;
`
98
``
`-
Ok((ExitStatus(stat), stdout, Vec::new()))
`
``
101
`+
let stderr = cmd.stderr()?;
`
``
102
+
``
103
`+
Ok((ExitStatus(stat), stdout, stderr))
`
99
104
`}
`
100
105
`}
`
101
106
``
`@@ -263,6 +268,7 @@ mod uefi_command_internal {
`
263
268
`pub struct Command {
`
264
269
`handle: NonNullcrate::ffi::c_void,
`
265
270
`stdout: Option<helpers::Protocol>,
`
``
271
`+
stderr: Option<helpers::Protocol>,
`
266
272
`st: Box<r_efi::efi::SystemTable>,
`
267
273
`}
`
268
274
``
`@@ -271,7 +277,7 @@ mod uefi_command_internal {
`
271
277
`handle: NonNullcrate::ffi::c_void,
`
272
278
`st: Box<r_efi::efi::SystemTable>,
`
273
279
`) -> Self {
`
274
``
`-
Self { handle, stdout: None, st }
`
``
280
`+
Self { handle, stdout: None, stderr: None, st }
`
275
281
`}
`
276
282
``
277
283
`pub fn load_image(p: &OsStr) -> io::Result {
`
`@@ -349,6 +355,19 @@ mod uefi_command_internal {
`
349
355
`Ok(())
`
350
356
`}
`
351
357
``
``
358
`+
pub fn stderr_init(&mut self) -> io::Result<()> {
`
``
359
`+
let mut protocol =
`
``
360
`+
helpers::Protocol::create(PipeProtocol::new(), simple_text_output::PROTOCOL_GUID)?;
`
``
361
+
``
362
`+
self.st.standard_error_handle = protocol.handle().as_ptr();
`
``
363
`+
self.st.std_err =
`
``
364
`+
protocol.as_mut() as *mut PipeProtocol as *mut simple_text_output::Protocol;
`
``
365
+
``
366
`+
self.stderr = Some(protocol);
`
``
367
+
``
368
`+
Ok(())
`
``
369
`+
}
`
``
370
+
352
371
`pub fn stdout(&self) -> io::Result<Vec> {
`
353
372
`if let Some(stdout) = &self.stdout {
`
354
373
` stdout
`
`@@ -361,6 +380,19 @@ mod uefi_command_internal {
`
361
380
`Err(const_io_error!(io::ErrorKind::NotFound, "stdout not found"))
`
362
381
`}
`
363
382
`}
`
``
383
+
``
384
`+
pub fn stderr(&self) -> io::Result<Vec> {
`
``
385
`+
if let Some(stderr) = &self.stderr {
`
``
386
`+
stderr
`
``
387
`+
.as_ref()
`
``
388
`+
.utf8()
`
``
389
`+
.into_string()
`
``
390
`+
.map_err(|_| const_io_error!(io::ErrorKind::Other, "utf8 conversion failed"))
`
``
391
`+
.map(Into::into)
`
``
392
`+
} else {
`
``
393
`+
Err(const_io_error!(io::ErrorKind::NotFound, "stdout not found"))
`
``
394
`+
}
`
``
395
`+
}
`
364
396
`}
`
365
397
``
366
398
`impl Drop for Command {
`