Skip to content

Commit

Permalink
Use origin's errno_location in the __errno_location implementation
Browse files Browse the repository at this point in the history
This will help with integrating the musl dynamic linker until a rust
replacement is written.

cc sunfishcode/origin#110
  • Loading branch information
bjorn3 committed Jun 24, 2024
1 parent 9b8afd4 commit e5f3e96
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion c-scape/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static_assertions = "1.1.0"

[features]
default = ["thread", "std", "coexist-with-libc", "threadsafe-setenv", "use-compiler-builtins"]
thread = []
thread = ["origin/unstable-errno"]
std = ["rustix/std", "printf-compat/std"]

# In "take-charge" mode, this enables code in c-scape to define the
Expand Down
13 changes: 9 additions & 4 deletions c-scape/src/errno_.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloc::borrow::ToOwned;
use alloc::format;
use core::cell::SyncUnsafeCell;
use core::ptr::{addr_of_mut, copy_nonoverlapping, null_mut};
use core::ptr::{copy_nonoverlapping, null_mut};
use libc::{c_char, c_int};

/// Return the address of the thread-local `errno` state.
Expand All @@ -13,9 +13,14 @@ use libc::{c_char, c_int};
unsafe extern "C" fn __errno_location() -> *mut c_int {
libc!(libc::__errno_location());

#[cfg_attr(feature = "thread", thread_local)]
static mut ERRNO: i32 = 0;
addr_of_mut!(ERRNO)
#[cfg(feature = "thread")]
return origin::thread::errno_location();

#[cfg(not(feature = "thread"))]
{
static mut ERRNO: i32 = 0;
return core::ptr::addr_of_mut!(ERRNO);
}
}

#[no_mangle]
Expand Down

0 comments on commit e5f3e96

Please sign in to comment.