From ee652e5cf110e657e30a1b6bb2cae4b1103697f7 Mon Sep 17 00:00:00 2001 From: Byeongkeun Ahn <7p54ks3@naver.com> Date: Wed, 4 Sep 2024 22:32:21 +0900 Subject: [PATCH] Call exit syscall properly in linux aarch64 --- basm-std/src/platform/malloc/mod.rs | 2 +- basm-std/src/platform/mod.rs | 25 +++++++++++++++---------- basm-std/src/platform/os/mod.rs | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/basm-std/src/platform/malloc/mod.rs b/basm-std/src/platform/malloc/mod.rs index 617e7ecf..51f1d5db 100644 --- a/basm-std/src/platform/malloc/mod.rs +++ b/basm-std/src/platform/malloc/mod.rs @@ -1,6 +1,6 @@ pub mod dlmalloc; pub mod dlmalloc_interface; -#[cfg(not(any(target_arch = "wasm32", target_arch = "aarch64")))] +#[cfg(not(target_arch = "wasm32"))] pub mod dlmalloc_linux; #[cfg(target_arch = "aarch64")] pub mod dlmalloc_macos; diff --git a/basm-std/src/platform/mod.rs b/basm-std/src/platform/mod.rs index 44c99c94..994179fe 100644 --- a/basm-std/src/platform/mod.rs +++ b/basm-std/src/platform/mod.rs @@ -25,12 +25,12 @@ pub fn init(platform_data_by_loader: usize) { /* use OS APIs directly */ os::windows::init(); } - #[cfg(not(any(target_arch = "wasm32", target_arch = "aarch64")))] + #[cfg(not(any(target_arch = "wasm32")))] services::ENV_ID_LINUX => { /* use syscalls directly */ os::linux::init(); } - #[cfg(target_arch = "aarch64")] + #[cfg(all(target_os = "macos", target_arch = "aarch64"))] services::ENV_ID_MACOS => { os::macos::init(); } @@ -51,17 +51,22 @@ pub fn init(platform_data_by_loader: usize) { } #[cfg(not(test))] pub fn try_exit() { - let pd = services::platform_data(); - if (pd.env_id == services::ENV_ID_LINUX || pd.env_id == services::ENV_ID_MACOS) - && (pd.env_flags & services::ENV_FLAGS_NO_EXIT) == 0 + #[cfg(not(target_arch = "wasm32"))] { - #[cfg(not(any(target_arch = "wasm32", target_arch = "aarch64")))] - unsafe { - os::linux::syscall::exit_group(services::get_exit_status() as usize); + let pd = services::platform_data(); + if (pd.env_flags & services::ENV_FLAGS_NO_EXIT) != 0 { + return; + } + if pd.env_id == services::ENV_ID_LINUX { + unsafe { + os::linux::syscall::exit_group(services::get_exit_status() as usize); + } } #[cfg(target_arch = "aarch64")] - unsafe { - os::macos::syscall::exit_group(services::get_exit_status() as usize); + if pd.env_id == services::ENV_ID_MACOS { + unsafe { + os::macos::syscall::exit_group(services::get_exit_status() as usize); + } } } } diff --git a/basm-std/src/platform/os/mod.rs b/basm-std/src/platform/os/mod.rs index fd07a007..94de96c9 100644 --- a/basm-std/src/platform/os/mod.rs +++ b/basm-std/src/platform/os/mod.rs @@ -1,4 +1,4 @@ -#[cfg(not(any(target_arch = "wasm32", target_arch = "aarch64")))] +#[cfg(not(any(target_arch = "wasm32")))] pub mod linux; #[cfg(target_arch = "aarch64")] pub mod macos;