const EILSEQ: c_int = 84;
const EINVAL: c_int = 22;
const EACCES: c_int = 13;
const ENODEV: c_int = 19;
const EMSGSIZE: c_int = 90;
const EFAULT: c_int = 14;
const E2BIG: c_int = 7;
const EIO: c_int = 5;
const ENXIO: c_int = 6;
const EBADF: c_int = 9;
const ERANGE: c_int = 34;
const ENOSYS: c_int = 38;
const EOPNOTSUPP: c_int = 95;
const ENOENT: c_int = 2;
const EEXIST: c_int = 17;
const ENOTDIR: c_int = 20;
const EMFILE: c_int = 24;
const ENOSPC: c_int = 28;
const ENAMETOOLONG: c_int = 36;
const ELOOP: c_int = 40;
const EIDRM: c_int = 43;
const ENOTSUP: c_int = 95;
const EAFNOSUPPORT: c_int = 97;
const LC_CTYPE: c_int = 0;
const LC_NUMERIC: c_int = 1;
const LC_TIME: c_int = 2;
const LC_COLLATE: c_int = 3;
const LC_MONETARY: c_int = 4;
const LC_MESSAGES: c_int = 5;
const LC_ALL: c_int = 6;
const ENOMEM: c_int = 12;
const EINTR: c_int = 4;
const EPERM: c_int = 1;
const EAGAIN: c_int = 11;
const EBUSY: c_int = 16;
const EDEADLK: c_int = 35;
const ETIMEDOUT: c_int = 110;
const ECANCELED: c_int = 125;
const EOVERFLOW: c_int = 75;
const EOWNERDEAD: c_int = 130;
const ENOTRECOVERABLE: c_int = 131;
static mut ERRNO_FALLBACK: c_int = 0;
static ERRNO_TLS_ACTIVE: AtomicUsize = AtomicUsize::new(0);
const ERRNO_TCB_OFFSET: usize = 0x30;
#[inline]
unsafe fn errno_ptr() -> *mut c_int {
if ERRNO_TLS_ACTIVE.load(Ordering::Relaxed) == 0 {
return core::ptr::addr_of_mut!(ERRNO_FALLBACK);
}
let slot = tcb_slot(ERRNO_TCB_OFFSET);
if slot.is_null() {
core::ptr::addr_of_mut!(ERRNO_FALLBACK)
} else {
slot as *mut c_int
}
}
unsafe fn errno_init() {
let tp = arch_get_tp();
#[cfg(target_arch = "x86_64")]
let tcb = tp;
#[cfg(target_arch = "powerpc64")]
let tcb = tp.wrapping_sub(256 + 0x7000);
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64", target_arch = "loongarch64"))]
let tcb = tp.wrapping_sub(256);
if tp != 0 && core::ptr::read(tcb as *const usize) == tcb {
ERRNO_TLS_ACTIVE.store(1, Ordering::Relaxed);
}
}
#[inline]
unsafe fn syscall_ret(r: i64) -> i64 {
if r < 0 {
*errno_ptr() = (-r) as c_int;
-1
} else {
r
}
}
#[no_mangle]
pub unsafe extern "C" fn __errno_location() -> *mut c_int {
errno_ptr()
}
unsafe fn h_errno_ptr() -> *mut c_int {
if ERRNO_TLS_ACTIVE.load(Ordering::Relaxed) == 0 {
return core::ptr::addr_of_mut!(h_errno);
}
errno_ptr().add(1)
}
#[cfg(not(test))]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
unsafe { abort() }
}
#[cfg(not(test))]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}