Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9353463

Browse files
committed
Add ExitStatusExt::aborted_code for Fuchsia platform
1 parent 70ebedb commit 9353463

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

‎library/std/src/os/fuchsia/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
#![stable(feature = "raw_ext", since = "1.1.0")]
44

55
pub mod fs;
6+
#[unstable(feature = "fuchsia_exit_status_aborted", issue = "none")]
7+
pub mod process;
68
pub mod raw;

‎library/std/src/os/fuchsia/process.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! Fuchsia-specific extensions to primitives in the [`std::process`] module.
2+
//!
3+
//! [`std::process`]: crate::process
4+
5+
use crate::process;
6+
use crate::sealed::Sealed;
7+
8+
#[unstable(feature = "fuchsia_exit_status_aborted", issue = "none")]
9+
pub trait ExitStatusExt: Sealed {
10+
/// If the process was aborted, returns the status code.
11+
#[must_use]
12+
fn aborted_code(&self) -> Option<i32>;
13+
}
14+
15+
#[unstable(feature = "fuchsia_exit_status_aborted", issue = "none")]
16+
impl ExitStatusExt for process::ExitStatus {
17+
/// If the process was aborted, returns the status code.
18+
fn aborted_code(&self) -> Option<i32> {
19+
match self.code() {
20+
// Upon an abort, Fuchsia returns the status code ZX_TASK_RETCODE_EXCEPTION_KILL.
21+
code @ Some(-1028) => code,
22+
Some(_) | None => None,
23+
}
24+
}
25+
}

‎library/test/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#![feature(panic_can_unwind)]
2525
#![feature(test)]
2626
#![feature(inline_const_pat)]
27+
#![cfg_attr(target_os = "fuchsia", feature(fuchsia_exit_status_aborted))]
2728
#![allow(internal_features)]
2829

2930
// Public reexports

‎library/test/src/test_result.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::any::Any;
22
use std::process::ExitStatus;
33

4+
#[cfg(target_os = "fuchsia")]
5+
use std::os::fuchsia::process::ExitStatusExt as _;
46
#[cfg(unix)]
5-
use std::os::unix::process::ExitStatusExt;
7+
use std::os::unix::process::ExitStatusExtas _;
68

79
use super::bench::BenchSamples;
810
use super::options::ShouldPanic;
@@ -88,12 +90,21 @@ pub fn get_result_from_exit_code(
8890
time_opts: &Option<time::TestTimeOptions>,
8991
exec_time: &Option<time::TestExecTime>,
9092
) -> TestResult {
91-
let result = match status.code() {
93+
#[cfg(target_os = "fuchsia")]
94+
let result = status.aborted_code().map(|_| TestResult::TrFailed);
95+
#[cfg(not(target_os = "fuchsia"))]
96+
let result: Option<TestResult> = None;
97+
98+
let result = result.unwrap_or_else(|| match status.code() {
9299
Some(TR_OK) => TestResult::TrOk,
93100
// On Windows we use __fastfail to abort, which is documented to use this
94101
// exception code.
95102
#[cfg(windows)]
96103
Some(const {0xC0000409u32 as i32}) => TestResult::TrFailed,
104+
#[cfg(any(windows, unix))]
105+
Some(code) => TestResult::TrFailedMsg(format!("got unexpected return code {code}")),
106+
#[cfg(not(any(windows, unix)))]
107+
Some(_) => TestResult::TrFailed,
97108
#[cfg(unix)]
98109
None => match status.signal() {
99110
Some(libc::SIGABRT) => TestResult::TrFailed,
@@ -102,16 +113,9 @@ pub fn get_result_from_exit_code(
102113
}
103114
None => unreachable!("status.code() returned None but status.signal() was None"),
104115
},
105-
// Upon an abort, Fuchsia returns the status code ZX_TASK_RETCODE_EXCEPTION_KILL.
106-
#[cfg(target_os = "fuchsia")]
107-
Some(-1028) => TestResult::TrFailed,
108116
#[cfg(not(unix))]
109117
None => TestResult::TrFailedMsg(format!("unknown return code")),
110-
#[cfg(any(windows, unix))]
111-
Some(code) => TestResult::TrFailedMsg(format!("got unexpected return code {code}")),
112-
#[cfg(not(any(windows, unix)))]
113-
Some(_) => TestResult::TrFailed,
114-
};
118+
});
115119

116120
// If test is already failed (or allowed to fail), do not change the result.
117121
if result != TestResult::TrOk {

‎tests/ui/process/signal-exit-status.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,28 @@
22
//@ ignore-wasm32 no processes
33
//@ ignore-sgx no processes
44
//@ ignore-windows
5-
//@ ignore-fuchsia code returned as ZX_TASK_RETCODE_EXCEPTION_KILL, FIXME (#58590)
65

76
#![feature(core_intrinsics)]
7+
#![cfg_attr(target_os = "fuchsia", feature(fuchsia_exit_status_aborted))]
88

99
use std::env;
1010
use std::process::Command;
1111

12+
#[cfg(target_os = "fuchsia")]
13+
use std::os::fuchsia::process::ExitStatusExt;
14+
1215
pub fn main() {
1316
let args: Vec<String> = env::args().collect();
1417
if args.len() >= 2 && args[1] == "signal" {
1518
// Raise an aborting signal without UB
1619
core::intrinsics::abort();
1720
} else {
21+
// Spawn a child process that will raise an aborting signal
1822
let status = Command::new(&args[0]).arg("signal").status().unwrap();
23+
24+
#[cfg(not(target_os = "fuchsia"))]
1925
assert!(status.code().is_none());
26+
#[cfg(target_os = "fuchsia")]
27+
assert!(status.aborted_code().is_some());
2028
}
2129
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /