Skip to content

Commit e726af8

Browse files
authored
Rollup merge of rust-lang#95916 - solid-rs:feat-kmc-solid-abort, r=Mark-Simulacrum
kmc-solid: Use `libc::abort` to abort a program This PR updates the target-specific abort subroutine for the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. The current implementation uses a `hlt` instruction, which is the most direct way to notify a connected debugger but is not the most flexible way. This PR changes it to call the `abort` libc function, making it possible for a system designer to override its behavior as they see fit.
2 parents 0ecbcbb + 9d1f82e commit e726af8

File tree

4 files changed

+6
-47
lines changed

4 files changed

+6
-47
lines changed

library/panic_abort/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ pub unsafe fn __rust_start_panic(_payload: *mut &mut dyn BoxMeUp) -> u32 {
3737
abort();
3838

3939
cfg_if::cfg_if! {
40-
if #[cfg(unix)] {
40+
if #[cfg(any(unix, target_os = "solid_asp3"))] {
4141
unsafe fn abort() -> ! {
4242
libc::abort();
4343
}
4444
} else if #[cfg(any(target_os = "hermit",
45-
target_os = "solid_asp3",
4645
all(target_vendor = "fortanix", target_env = "sgx")
4746
))] {
4847
unsafe fn abort() -> ! {

library/std/src/sys/solid/abi/mod.rs

-26
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,6 @@ mod fs;
44
pub mod sockets;
55
pub use self::fs::*;
66

7-
#[inline(always)]
8-
pub fn breakpoint_program_exited(tid: usize) {
9-
unsafe {
10-
match () {
11-
// SOLID_BP_PROGRAM_EXITED = 15
12-
#[cfg(target_arch = "arm")]
13-
() => core::arch::asm!("bkpt #15", in("r0") tid),
14-
#[cfg(target_arch = "aarch64")]
15-
() => core::arch::asm!("hlt #15", in("x0") tid),
16-
}
17-
}
18-
}
19-
20-
#[inline(always)]
21-
pub fn breakpoint_abort() {
22-
unsafe {
23-
match () {
24-
// SOLID_BP_CSABORT = 16
25-
#[cfg(target_arch = "arm")]
26-
() => core::arch::asm!("bkpt #16"),
27-
#[cfg(target_arch = "aarch64")]
28-
() => core::arch::asm!("hlt #16"),
29-
}
30-
}
31-
}
32-
337
// `solid_types.h`
348
pub use super::itron::abi::{ER, ER_ID, E_TMOUT, ID};
359

library/std/src/sys/solid/mod.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,9 @@ pub fn decode_error_kind(code: i32) -> crate::io::ErrorKind {
7676
error::decode_error_kind(code)
7777
}
7878

79-
#[inline(always)]
79+
#[inline]
8080
pub fn abort_internal() -> ! {
81-
loop {
82-
abi::breakpoint_abort();
83-
}
84-
}
85-
86-
// This function is needed by the panic runtime. The symbol is named in
87-
// pre-link args for the target specification, so keep that in sync.
88-
#[cfg(not(test))]
89-
#[no_mangle]
90-
// NB. used by both libunwind and libpanic_abort
91-
pub extern "C" fn __rust_abort() {
92-
abort_internal();
81+
unsafe { libc::abort() }
9382
}
9483

9584
pub fn hashmap_random_keys() -> (u64, u64) {

library/std/src/sys/solid/os.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::path::{self, PathBuf};
1111
use crate::sys_common::rwlock::StaticRwLock;
1212
use crate::vec;
1313

14-
use super::{abi, error, itron, memchr};
14+
use super::{error, itron, memchr};
1515

1616
// `solid` directly maps `errno`s to μITRON error codes.
1717
impl itron::error::ItronError {
@@ -184,11 +184,8 @@ pub fn home_dir() -> Option<PathBuf> {
184184
None
185185
}
186186

187-
pub fn exit(_code: i32) -> ! {
188-
let tid = itron::task::try_current_task_id().unwrap_or(0);
189-
loop {
190-
abi::breakpoint_program_exited(tid as usize);
191-
}
187+
pub fn exit(code: i32) -> ! {
188+
rtabort!("exit({}) called", code);
192189
}
193190

194191
pub fn getpid() -> u32 {

0 commit comments

Comments
 (0)