Skip to content
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

kmc-solid: Use libc::abort to abort a program #95916

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions library/panic_abort/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe
abort();

cfg_if::cfg_if! {
if #[cfg(unix)] {
if #[cfg(any(unix, target_os = "solid_asp3"))] {
unsafe fn abort() -> ! {
libc::abort();
}
} else if #[cfg(any(target_os = "hermit",
target_os = "solid_asp3",
all(target_vendor = "fortanix", target_env = "sgx")
))] {
unsafe fn abort() -> ! {
Expand Down
26 changes: 0 additions & 26 deletions library/std/src/sys/solid/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,6 @@ mod fs;
pub mod sockets;
pub use self::fs::*;

#[inline(always)]
pub fn breakpoint_program_exited(tid: usize) {
unsafe {
match () {
// SOLID_BP_PROGRAM_EXITED = 15
#[cfg(target_arch = "arm")]
() => core::arch::asm!("bkpt #15", in("r0") tid),
#[cfg(target_arch = "aarch64")]
() => core::arch::asm!("hlt #15", in("x0") tid),
}
}
}

#[inline(always)]
pub fn breakpoint_abort() {
unsafe {
match () {
// SOLID_BP_CSABORT = 16
#[cfg(target_arch = "arm")]
() => core::arch::asm!("bkpt #16"),
#[cfg(target_arch = "aarch64")]
() => core::arch::asm!("hlt #16"),
}
}
}

// `solid_types.h`
pub use super::itron::abi::{ER, ER_ID, E_TMOUT, ID};

Expand Down
15 changes: 2 additions & 13 deletions library/std/src/sys/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,9 @@ pub fn decode_error_kind(code: i32) -> crate::io::ErrorKind {
error::decode_error_kind(code)
}

#[inline(always)]
#[inline]
pub fn abort_internal() -> ! {
loop {
abi::breakpoint_abort();
}
}

// This function is needed by the panic runtime. The symbol is named in
// pre-link args for the target specification, so keep that in sync.
#[cfg(not(test))]
#[no_mangle]
// NB. used by both libunwind and libpanic_abort
pub extern "C" fn __rust_abort() {
abort_internal();
unsafe { libc::abort() }
}

pub fn hashmap_random_keys() -> (u64, u64) {
Expand Down
9 changes: 3 additions & 6 deletions library/std/src/sys/solid/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::path::{self, PathBuf};
use crate::sys_common::rwlock::StaticRwLock;
use crate::vec;

use super::{abi, error, itron, memchr};
use super::{error, itron, memchr};

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

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

pub fn getpid() -> u32 {
Expand Down