Skip to content

Commit 9d1f82e

Browse files
committed
kmc-solid: Use abort to abort a program
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 commit changes it to a call to the `abort` libc function, making it possible for a system designer to override its behavior as they see fit.
1 parent 1f7fb64 commit 9d1f82e

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
@@ -38,12 +38,11 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe
3838
abort();
3939

4040
cfg_if::cfg_if! {
41-
if #[cfg(unix)] {
41+
if #[cfg(any(unix, target_os = "solid_asp3"))] {
4242
unsafe fn abort() -> ! {
4343
libc::abort();
4444
}
4545
} else if #[cfg(any(target_os = "hermit",
46-
target_os = "solid_asp3",
4746
all(target_vendor = "fortanix", target_env = "sgx")
4847
))] {
4948
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
@@ -74,20 +74,9 @@ pub fn decode_error_kind(code: i32) -> crate::io::ErrorKind {
7474
error::decode_error_kind(code)
7575
}
7676

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

9382
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)