Merge branch 'nightly-2025-10-03' into 'master'
Support nightly-2025-10-03 See merge request redox-os/relibc!730
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
name = "relibc"
|
||||
version = "0.2.5"
|
||||
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "relibc"
|
||||
|
||||
@@ -236,7 +236,7 @@ $(BUILD)/release/libc.a: $(BUILD)/release/librelibc.a $(BUILD)/openlibm/libopenl
|
||||
$(BUILD)/release/librelibc.a: $(SRC)
|
||||
$(CARGO) rustc --release $(CARGOFLAGS) -- --emit link=$@ $(RUSTCFLAGS)
|
||||
# TODO: Better to only allow a certain whitelisted set of symbols? Perhaps
|
||||
# use some cbindgen hook, specify them manually, or grep for #[no_mangle].
|
||||
# use some cbindgen hook, specify them manually, or grep for #[unsafe(no_mangle)].
|
||||
./renamesyms.sh "$@" "$(BUILD)/release/deps/"
|
||||
touch $@
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
sed -i 's/::std::os::raw:://g' $1
|
||||
perl -i -p0e 's/extern "C" \{\n pub fn/#[no_mangle]\npub extern "C" fn/g' $1
|
||||
perl -i -p0e 's/extern "C" \{\n pub fn/#[unsafe(no_mangle)]\npub extern "C" fn/g' $1
|
||||
perl -i -p0e 's/;\n\}/ {\n unimplemented!();\n\}\n/g' $1
|
||||
rustfmt $1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "generic-rt"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
name = "ld_so"
|
||||
version = "0.1.0"
|
||||
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "ld_so"
|
||||
|
||||
@@ -250,7 +250,7 @@ SECTIONS
|
||||
*
|
||||
* .init_array also depends on TLS and is discarded as we don't need it.
|
||||
*/
|
||||
*(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.init_array)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ SECTIONS
|
||||
*
|
||||
* .init_array also depends on TLS and is discarded as we don't need it.
|
||||
*/
|
||||
*(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.init_array)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ SECTIONS
|
||||
*
|
||||
* .init_array also depends on TLS and is discarded as we don't need it.
|
||||
*/
|
||||
*(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.init_array)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ SECTIONS
|
||||
*
|
||||
* .init_array also depends on TLS and is discarded as we don't need it.
|
||||
*/
|
||||
*(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.init_array)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ SECTIONS
|
||||
*
|
||||
* .init_array also depends on TLS and is discarded as we don't need it.
|
||||
*/
|
||||
*(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.gnu.linkonce.tb.*) *(.tcommon)
|
||||
*(.init_array)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -73,21 +73,20 @@ _start:
|
||||
"
|
||||
);
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn main(_argc: isize, _argv: *const *const i8) -> usize {
|
||||
// LD
|
||||
0x1D
|
||||
}
|
||||
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
|
||||
relibc_panic(pi)
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
name = "redox-rt"
|
||||
authors = ["4lDO2 <4lDO2@protonmail.com>"]
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
description = "Libc-independent runtime for Redox"
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ use core::{cell::SyncUnsafeCell, mem::offset_of, ptr::NonNull};
|
||||
use syscall::{data::*, error::*};
|
||||
|
||||
use crate::{
|
||||
proc::{fork_inner, FdGuard, ForkArgs},
|
||||
protocol::{ProcCall, RtSigInfo},
|
||||
signal::{inner_c, PosixStackt, RtSigarea, SigStack, PROC_CONTROL_STRUCT},
|
||||
RtTcb, Tcb,
|
||||
proc::{FdGuard, ForkArgs, fork_inner},
|
||||
protocol::{ProcCall, RtSigInfo},
|
||||
signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, inner_c},
|
||||
};
|
||||
|
||||
// Setup a stack starting from the very end of the address space, and then growing downwards.
|
||||
|
||||
@@ -3,10 +3,10 @@ use core::{cell::SyncUnsafeCell, mem::offset_of, ptr::NonNull, sync::atomic::Ord
|
||||
use syscall::*;
|
||||
|
||||
use crate::{
|
||||
proc::{fork_inner, FdGuard, ForkArgs},
|
||||
protocol::{ProcCall, RtSigInfo},
|
||||
signal::{inner_fastcall, PosixStackt, RtSigarea, SigStack, PROC_CONTROL_STRUCT},
|
||||
RtTcb,
|
||||
proc::{FdGuard, ForkArgs, fork_inner},
|
||||
protocol::{ProcCall, RtSigInfo},
|
||||
signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, inner_fastcall},
|
||||
};
|
||||
|
||||
// Setup a stack starting from the very end of the address space, and then growing downwards.
|
||||
@@ -363,7 +363,7 @@ asmfunction!(__relibc_internal_rlct_clone_ret -> usize: ["
|
||||
|
||||
ret
|
||||
"] <= []);
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
fn __relibc_internal_sigentry_crit_first();
|
||||
fn __relibc_internal_sigentry_crit_second();
|
||||
fn __relibc_internal_sigentry_crit_third();
|
||||
@@ -384,7 +384,7 @@ pub unsafe fn arch_pre(stack: &mut SigStack, area: &mut SigArea) -> PosixStackt
|
||||
flags: 0, // TODO
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe fn manually_enter_trampoline() {
|
||||
let c = &crate::Tcb::current().unwrap().os_specific.control;
|
||||
c.control_flags.store(
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use core::cell::SyncUnsafeCell;
|
||||
|
||||
use crate::{
|
||||
proc::{fork_inner, FdGuard, ForkArgs},
|
||||
protocol::{ProcCall, RtSigInfo},
|
||||
signal::{get_sigaltstack, inner_c, PosixStackt, RtSigarea, SigStack},
|
||||
RtTcb, Tcb,
|
||||
proc::{FdGuard, ForkArgs, fork_inner},
|
||||
protocol::{ProcCall, RtSigInfo},
|
||||
signal::{PosixStackt, RtSigarea, SigStack, get_sigaltstack, inner_c},
|
||||
};
|
||||
use core::{mem::offset_of, ptr::NonNull, sync::atomic::Ordering};
|
||||
use syscall::{data::*, error::*};
|
||||
@@ -614,7 +614,7 @@ pub unsafe fn manually_enter_trampoline() {
|
||||
", inout("t0") ip_location => _, out("ra") _);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
fn __relibc_internal_sigentry_crit_first();
|
||||
fn __relibc_internal_sigentry_crit_second();
|
||||
fn __relibc_internal_sigentry_crit_third();
|
||||
|
||||
@@ -11,10 +11,10 @@ use syscall::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
proc::{fork_inner, FdGuard, ForkArgs},
|
||||
protocol::{ProcCall, RtSigInfo},
|
||||
signal::{get_sigaltstack, inner_c, PosixStackt, RtSigarea, SigStack, PROC_CONTROL_STRUCT},
|
||||
Tcb,
|
||||
proc::{FdGuard, ForkArgs, fork_inner},
|
||||
protocol::{ProcCall, RtSigInfo},
|
||||
signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, get_sigaltstack, inner_c},
|
||||
};
|
||||
|
||||
// Setup a stack starting from the very end of the address space, and then growing downwards.
|
||||
@@ -465,7 +465,7 @@ __relibc_internal_sigentry_crit_third:
|
||||
proc_fd = sym PROC_FD,
|
||||
]);
|
||||
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
fn __relibc_internal_sigentry_crit_first();
|
||||
fn __relibc_internal_sigentry_crit_second();
|
||||
fn __relibc_internal_sigentry_crit_third();
|
||||
@@ -499,7 +499,7 @@ pub unsafe fn arch_pre(stack: &mut SigStack, area: &mut SigArea) -> PosixStackt
|
||||
pub(crate) static SUPPORTS_AVX: AtomicU8 = AtomicU8::new(0);
|
||||
|
||||
// __relibc will be prepended to the name, so no_mangle is fine
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe fn manually_enter_trampoline() {
|
||||
let c = &Tcb::current().unwrap().os_specific.control;
|
||||
c.control_flags.store(
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@
|
||||
|
||||
use core::{
|
||||
cell::UnsafeCell,
|
||||
mem::{size_of, MaybeUninit},
|
||||
mem::{MaybeUninit, size_of},
|
||||
};
|
||||
|
||||
use generic_rt::{ExpectTlsFree, GenericTcb};
|
||||
@@ -38,7 +38,7 @@ macro_rules! asmfunction(
|
||||
.size ", stringify!($name), ", . - ", stringify!($name), "
|
||||
"), $($decl = $(sym $symname)?$(const $constval)?),*);
|
||||
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
pub fn $name($($(_: $arg),*)?) $(-> $ret)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
use core::{
|
||||
cell::SyncUnsafeCell,
|
||||
fmt::Debug,
|
||||
mem::{size_of, MaybeUninit},
|
||||
mem::{MaybeUninit, size_of},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
DYNAMIC_PROC_INFO, RtTcb, StaticProcInfo,
|
||||
arch::*,
|
||||
auxv_defs::*,
|
||||
protocol::{ProcCall, ThreadCall},
|
||||
read_proc_meta,
|
||||
sys::{proc_call, thread_call},
|
||||
RtTcb, StaticProcInfo, DYNAMIC_PROC_INFO,
|
||||
};
|
||||
|
||||
use alloc::{boxed::Box, collections::BTreeMap, vec};
|
||||
@@ -19,19 +19,19 @@ use alloc::{boxed::Box, collections::BTreeMap, vec};
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
use goblin::elf32::{
|
||||
header::Header,
|
||||
program_header::program_header32::{ProgramHeader, PF_R, PF_W, PF_X, PT_INTERP, PT_LOAD},
|
||||
program_header::program_header32::{PF_R, PF_W, PF_X, PT_INTERP, PT_LOAD, ProgramHeader},
|
||||
};
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
use goblin::elf64::{
|
||||
header::Header,
|
||||
program_header::program_header64::{ProgramHeader, PF_R, PF_W, PF_X, PT_INTERP, PT_LOAD},
|
||||
program_header::program_header64::{PF_R, PF_W, PF_X, PT_INTERP, PT_LOAD, ProgramHeader},
|
||||
};
|
||||
|
||||
use syscall::{
|
||||
CallFlags, GrantDesc, GrantFlags, MAP_FIXED_NOREPLACE, MAP_SHARED, Map, PAGE_SIZE, PROT_EXEC,
|
||||
PROT_READ, PROT_WRITE, SetSighandlerData,
|
||||
error::*,
|
||||
flag::{MapFlags, SEEK_SET},
|
||||
CallFlags, GrantDesc, GrantFlags, Map, SetSighandlerData, MAP_FIXED_NOREPLACE, MAP_SHARED,
|
||||
PAGE_SIZE, PROT_EXEC, PROT_READ, PROT_WRITE,
|
||||
};
|
||||
|
||||
pub enum FexecResult {
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
use core::{ffi::c_int, ptr::NonNull, sync::atomic::Ordering};
|
||||
|
||||
use syscall::{
|
||||
data::AtomicU64, CallFlags, Error, RawAction, Result, SenderInfo, SetSighandlerData,
|
||||
SigProcControl, Sigcontrol, SigcontrolFlags, TimeSpec, EAGAIN, EINTR, EINVAL, ENOMEM, EPERM,
|
||||
CallFlags, EAGAIN, EINTR, EINVAL, ENOMEM, EPERM, Error, RawAction, Result, SenderInfo,
|
||||
SetSighandlerData, SigProcControl, Sigcontrol, SigcontrolFlags, TimeSpec, data::AtomicU64,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
RtTcb, Tcb,
|
||||
arch::*,
|
||||
current_proc_fd,
|
||||
proc::FdGuard,
|
||||
protocol::{
|
||||
ProcCall, RtSigInfo, ThreadCall, SIGCHLD, SIGCONT, SIGKILL, SIGSTOP, SIGTSTP, SIGTTIN,
|
||||
SIGTTOU, SIGURG, SIGWINCH,
|
||||
ProcCall, RtSigInfo, SIGCHLD, SIGCONT, SIGKILL, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG,
|
||||
SIGWINCH, ThreadCall,
|
||||
},
|
||||
static_proc_info,
|
||||
sync::Mutex,
|
||||
sys::{proc_call, this_thread_call},
|
||||
RtTcb, Tcb,
|
||||
};
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
@@ -133,7 +133,7 @@ unsafe fn inner(stack: &mut SigStack) {
|
||||
(area.tmp_rt_inf.pid, area.tmp_rt_inf.uid)
|
||||
} else {
|
||||
stack.sig_code = 0; // TODO: SI_USER constant?
|
||||
// TODO: Handle SIGCHLD. Maybe that should always be queued though?
|
||||
// TODO: Handle SIGCHLD. Maybe that should always be queued though?
|
||||
let inf = SenderInfo::from_raw(area.tmp_id_inf);
|
||||
(inf.pid, inf.ruid)
|
||||
}
|
||||
@@ -778,7 +778,7 @@ pub fn await_signal_async(inner_allowset: u64) -> Result<Unreachable> {
|
||||
res?;
|
||||
unreachable!()
|
||||
}
|
||||
/*#[no_mangle]
|
||||
/*#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __redox_rt_debug_sigctl() {
|
||||
let tcb = &RtTcb::current().control;
|
||||
let _ = syscall::write(1, alloc::format!("SIGCTL: {tcb:#x?}\n").as_bytes());
|
||||
|
||||
+3
-3
@@ -5,16 +5,16 @@ use core::{
|
||||
};
|
||||
|
||||
use syscall::{
|
||||
error::{self, Error, Result, EINTR},
|
||||
CallFlags, TimeSpec, EINVAL, ERESTART,
|
||||
CallFlags, EINVAL, ERESTART, TimeSpec,
|
||||
error::{self, EINTR, Error, Result},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
DYNAMIC_PROC_INFO, DynamicProcInfo, RtTcb, Tcb,
|
||||
arch::manually_enter_trampoline,
|
||||
protocol::{ProcCall, ProcKillTarget, RtSigInfo, ThreadCall, WaitFlags},
|
||||
read_proc_meta,
|
||||
signal::tmp_disable_signals,
|
||||
DynamicProcInfo, RtTcb, Tcb, DYNAMIC_PROC_INFO,
|
||||
};
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -2,7 +2,7 @@ use core::mem::size_of;
|
||||
|
||||
use syscall::Result;
|
||||
|
||||
use crate::{arch::*, proc::*, signal::tmp_disable_signals, static_proc_info, RtTcb};
|
||||
use crate::{RtTcb, arch::*, proc::*, signal::tmp_disable_signals, static_proc_info};
|
||||
|
||||
/// Spawns a new context sharing the same address space as the current one (i.e. a new thread).
|
||||
pub unsafe fn rlct_clone_impl(stack: *mut usize) -> Result<FdGuard> {
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2025-01-12"
|
||||
channel = "nightly-2025-10-03"
|
||||
components = ["rust-src"]
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ blank_lines_lower_bound = 0
|
||||
blank_lines_upper_bound = 1
|
||||
brace_style = "SameLineWhere"
|
||||
disable_all_formatting = false
|
||||
edition = "2018"
|
||||
edition = "2024"
|
||||
empty_item_single_line = true
|
||||
fn_single_line = false
|
||||
force_explicit_abi = true
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::{
|
||||
io::{self, Write},
|
||||
platform::{self, types::*, WriteByte},
|
||||
platform::{self, WriteByte, types::*},
|
||||
};
|
||||
use core::{
|
||||
cmp, fmt,
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
name = "crt0"
|
||||
version = "0.1.0"
|
||||
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "crt0"
|
||||
|
||||
+3
-4
@@ -74,11 +74,11 @@ _start:
|
||||
"
|
||||
);
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn relibc_crt0(sp: usize) -> ! {
|
||||
// This wrapper ensures a dynamic libc.so can access a hidden main function
|
||||
//TODO: common definition of types
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
fn main(argc: isize, argv: *mut *mut c_char, envp: *mut *mut c_char) -> c_int;
|
||||
fn relibc_start_v1(
|
||||
sp: usize,
|
||||
@@ -93,14 +93,13 @@ pub unsafe extern "C" fn relibc_crt0(sp: usize) -> ! {
|
||||
}
|
||||
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
|
||||
relibc_panic(pi)
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
name = "crti"
|
||||
version = "0.1.0"
|
||||
authors = ["jD91mZM2 <me@krake.one>"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "crti"
|
||||
|
||||
+1
-2
@@ -75,14 +75,13 @@ global_asm!(
|
||||
// risc-v has no _init / _fini functions; it exclusively uses init/fini arrays
|
||||
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
|
||||
relibc_panic(pi)
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
name = "crtn"
|
||||
version = "0.1.0"
|
||||
authors = ["jD91mZM2 <me@krake.one>"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "crtn"
|
||||
|
||||
+1
-2
@@ -61,14 +61,13 @@ global_asm!(
|
||||
// risc-v has no _init / _fini functions; it exclusively uses init/fini arrays
|
||||
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
|
||||
relibc_panic(pi)
|
||||
}
|
||||
|
||||
+7
-6
@@ -1,4 +1,4 @@
|
||||
use crate::platform::types::*;
|
||||
use crate::{platform::types::*, raw_cell::RawCell};
|
||||
|
||||
// TODO: Implement cxa_finalize and uncomment this
|
||||
|
||||
@@ -9,17 +9,18 @@ struct CxaAtExitFunc {
|
||||
//dso: *mut c_void,
|
||||
}
|
||||
|
||||
static mut CXA_ATEXIT_FUNCS: [Option<CxaAtExitFunc>; 32] = [None; 32];
|
||||
static CXA_ATEXIT_FUNCS: RawCell<[Option<CxaAtExitFunc>; 32]> = RawCell::new([None; 32]);
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __cxa_atexit(
|
||||
func_opt: Option<extern "C" fn(*mut c_void)>,
|
||||
arg: *mut c_void,
|
||||
dso: *mut c_void,
|
||||
) -> c_int {
|
||||
for item in &mut CXA_ATEXIT_FUNCS {
|
||||
if item.is_none() {
|
||||
*item = func_opt.map(|func| CxaAtExitFunc {} /*{ func, arg, dso }*/);
|
||||
for i in 0..CXA_ATEXIT_FUNCS.unsafe_ref().len() {
|
||||
if CXA_ATEXIT_FUNCS.unsafe_ref()[i].is_none() {
|
||||
CXA_ATEXIT_FUNCS.unsafe_mut()[i] =
|
||||
func_opt.map(|func| CxaAtExitFunc {} /*{ func, arg, dso }*/);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
unistd::{SEEK_CUR, SEEK_END, SEEK_SET},
|
||||
},
|
||||
io,
|
||||
platform::{types::*, Pal, Sys},
|
||||
platform::{Pal, Sys, types::*},
|
||||
};
|
||||
use core::ops::Deref;
|
||||
|
||||
|
||||
@@ -12,17 +12,17 @@ pub struct aiocb {
|
||||
pub aio_sigevent: sigevent,
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn aio_read(aiocbp: *mut aiocb) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn aio_write(aiocbp: *mut aiocb) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn lio_listio(
|
||||
mode: c_int,
|
||||
list: *const *const aiocb,
|
||||
@@ -32,22 +32,22 @@ pub extern "C" fn lio_listio(
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn aio_error(aiocbp: *const aiocb) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn aio_return(aiocbp: *mut aiocb) -> usize {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn aio_cancel(fildes: c_int, aiocbp: *mut aiocb) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn aio_suspend(
|
||||
list: *const *const aiocb,
|
||||
nent: c_int,
|
||||
@@ -56,7 +56,7 @@ pub extern "C" fn aio_suspend(
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn aio_fsync(operation: c_int, aiocbp: *mut aiocb) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
+11
-11
@@ -13,57 +13,57 @@ pub struct fenv_t {
|
||||
pub cw: u64,
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn feclearexcept(excepts: c_int) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fegenenv(envp: *mut fenv_t) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fegetexceptflag(flagp: *mut fexcept_t, excepts: c_int) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fegetround() -> c_int {
|
||||
FE_TONEAREST
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn feholdexcept(envp: *mut fenv_t) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn feraiseexcept(except: c_int) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fesetenv(envp: *const fenv_t) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fesetexceptflag(flagp: *const fexcept_t, excepts: c_int) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fesetround(round: c_int) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fetestexcept(excepts: c_int) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn feupdateenv(envp: *const fenv_t) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use platform::types::*;
|
||||
|
||||
/*
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn func(args) -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub type elf_greg_t = c_ulong;
|
||||
pub type elf_gregset_t = [c_ulong; 34];
|
||||
pub type elf_fpregset_t = user_fpsimd_struct;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn _cbindgen_export_aarch64_user(
|
||||
a: user_regs_struct,
|
||||
b: user_fpsimd_struct,
|
||||
|
||||
@@ -28,7 +28,7 @@ pub type elf_greg_t = c_ulong;
|
||||
pub type elf_gregset_t = user_regs_struct;
|
||||
pub type elf_fpregset_t = user_fpregs_struct;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn _cbindgen_only_generates_structs_if_they_are_mentioned_which_is_dumb_riscv64_user(
|
||||
a: user_regs_struct,
|
||||
b: user_fpregs_struct,
|
||||
|
||||
@@ -71,7 +71,7 @@ pub struct user {
|
||||
pub u_debugreg: [c_ulong; 8],
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn _cbindgen_export_x86_user(
|
||||
a: user_fpregs_struct,
|
||||
b: user_regs_struct,
|
||||
|
||||
+14
-13
@@ -14,10 +14,11 @@ use crate::{
|
||||
c_str::CStr,
|
||||
header::{
|
||||
errno::*,
|
||||
netinet_in::{in_addr, in_addr_t, ntohl, INADDR_NONE},
|
||||
netinet_in::{INADDR_NONE, in_addr, in_addr_t, ntohl},
|
||||
sys_socket::{constants::*, socklen_t},
|
||||
},
|
||||
platform::{self, types::*},
|
||||
raw_cell::RawCell,
|
||||
};
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_addr.html>.
|
||||
@@ -26,7 +27,7 @@ use crate::{
|
||||
/// The `inet_addr()` function was marked obsolescent in the Open Group Base
|
||||
/// Specifications Issue 8.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn inet_addr(cp: *const c_char) -> in_addr_t {
|
||||
let mut val: in_addr = in_addr { s_addr: 0 };
|
||||
|
||||
@@ -38,7 +39,7 @@ pub unsafe extern "C" fn inet_addr(cp: *const c_char) -> in_addr_t {
|
||||
}
|
||||
|
||||
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/inet_aton.3.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_int {
|
||||
// TODO: octal/hex
|
||||
unsafe { inet_pton(AF_INET, cp, inp as *mut c_void) }
|
||||
@@ -50,7 +51,7 @@ pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_in
|
||||
/// The `inet_lnaof()` function was specified in Networking Services Issue 5,
|
||||
/// but not in the Open Group Base Specifications Issue 6 and later.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn inet_lnaof(r#in: in_addr) -> in_addr_t {
|
||||
if r#in.s_addr >> 24 < 128 {
|
||||
r#in.s_addr & 0xff_ffff
|
||||
@@ -67,7 +68,7 @@ pub extern "C" fn inet_lnaof(r#in: in_addr) -> in_addr_t {
|
||||
/// The `inet_makeaddr()` function was specified in Networking Services Issue
|
||||
/// 5, but not in the Open Group Base Specifications Issue 6 and later.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn inet_makeaddr(net: in_addr_t, lna: in_addr_t) -> in_addr {
|
||||
let mut output: in_addr = in_addr { s_addr: 0 };
|
||||
|
||||
@@ -88,7 +89,7 @@ pub extern "C" fn inet_makeaddr(net: in_addr_t, lna: in_addr_t) -> in_addr {
|
||||
/// The `inet_netof()` function was specified in Networking Services Issue 5,
|
||||
/// but not in the Open Group Base Specifications Issue 6 and later.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn inet_netof(r#in: in_addr) -> in_addr_t {
|
||||
if r#in.s_addr >> 24 < 128 {
|
||||
r#in.s_addr & 0xff_ffff
|
||||
@@ -105,7 +106,7 @@ pub extern "C" fn inet_netof(r#in: in_addr) -> in_addr_t {
|
||||
/// The `inet_network()` function was specified in Networking Services Issue 5,
|
||||
/// but not in the Open Group Base Specifications Issue 6 and later.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn inet_network(cp: *const c_char) -> in_addr_t {
|
||||
ntohl(unsafe { inet_addr(cp) })
|
||||
}
|
||||
@@ -116,22 +117,22 @@ pub unsafe extern "C" fn inet_network(cp: *const c_char) -> in_addr_t {
|
||||
/// The `inet_ntoa()` function was marked obsolescent in the Open Group Base
|
||||
/// Specifications Issue 8.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn inet_ntoa(r#in: in_addr) -> *const c_char {
|
||||
static mut NTOA_ADDR: [c_char; 16] = [0; 16];
|
||||
static NTOA_ADDR: RawCell<[c_char; 16]> = RawCell::new([0; 16]);
|
||||
|
||||
unsafe {
|
||||
inet_ntop(
|
||||
AF_INET,
|
||||
&r#in as *const in_addr as *const c_void,
|
||||
NTOA_ADDR.as_mut_ptr(),
|
||||
16,
|
||||
NTOA_ADDR.unsafe_mut().as_mut_ptr(),
|
||||
NTOA_ADDR.unsafe_ref().len(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_ntop.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn inet_ntop(
|
||||
af: c_int,
|
||||
src: *const c_void,
|
||||
@@ -160,7 +161,7 @@ pub unsafe extern "C" fn inet_ntop(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_ntop.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn inet_pton(af: c_int, src: *const c_char, dst: *mut c_void) -> c_int {
|
||||
if af != AF_INET {
|
||||
platform::ERRNO.set(EAFNOSUPPORT);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
use crate::{c_str::CStr, platform::types::*};
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __assert_fail(
|
||||
func: *const c_char,
|
||||
file: *const c_char,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use alloc::string::{String, ToString};
|
||||
use argon2::{
|
||||
password_hash::{PasswordHash, PasswordVerifier},
|
||||
Argon2,
|
||||
password_hash::{PasswordHash, PasswordVerifier},
|
||||
};
|
||||
|
||||
pub fn crypt_argon2(key: &str, setting: &str) -> Option<String> {
|
||||
|
||||
@@ -11,7 +11,7 @@ use alloc::{
|
||||
string::{String, ToString},
|
||||
};
|
||||
use core::ptr;
|
||||
use rand::{rngs::SmallRng, RngCore, SeedableRng};
|
||||
use rand::{RngCore, SeedableRng, rngs::SmallRng};
|
||||
|
||||
use crate::{
|
||||
c_str::CStr,
|
||||
@@ -32,7 +32,7 @@ use self::{
|
||||
md5::crypt_md5,
|
||||
pbkdf2::crypt_pbkdf2,
|
||||
scrypt::crypt_scrypt,
|
||||
sha::{crypt_sha, ShaType::*},
|
||||
sha::{ShaType::*, crypt_sha},
|
||||
};
|
||||
|
||||
/// See <https://www.man7.org/linux/man-pages/man3/crypt.3.html>.
|
||||
@@ -59,7 +59,7 @@ fn gen_salt() -> Option<String> {
|
||||
}
|
||||
|
||||
/// See <https://www.man7.org/linux/man-pages/man3/crypt.3.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn crypt_r(
|
||||
key: *const c_char,
|
||||
setting: *const c_char,
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::platform::types::*;
|
||||
use alloc::string::{String, ToString};
|
||||
use base64ct::{Base64Bcrypt, Encoding};
|
||||
use core::{str, u32};
|
||||
use scrypt::{scrypt, Params};
|
||||
use scrypt::{Params, scrypt};
|
||||
|
||||
/// Map for encoding and decoding
|
||||
#[inline(always)]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use alloc::string::{String, ToString};
|
||||
|
||||
use sha_crypt::{
|
||||
sha256_crypt_b64, sha512_crypt_b64, Sha256Params, Sha512Params, ROUNDS_DEFAULT, ROUNDS_MAX,
|
||||
ROUNDS_MIN,
|
||||
ROUNDS_DEFAULT, ROUNDS_MAX, ROUNDS_MIN, Sha256Params, Sha512Params, sha256_crypt_b64,
|
||||
sha512_crypt_b64,
|
||||
};
|
||||
|
||||
use crate::platform::types::*;
|
||||
|
||||
+18
-26
@@ -10,13 +10,13 @@
|
||||
use crate::platform::types::*;
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalnum.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isalnum(c: c_int) -> c_int {
|
||||
c_int::from(isdigit(c) != 0 || isalpha(c) != 0)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalpha.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isalpha(c: c_int) -> c_int {
|
||||
c_int::from(islower(c) != 0 || isupper(c) != 0)
|
||||
}
|
||||
@@ -26,49 +26,49 @@ pub extern "C" fn isalpha(c: c_int) -> c_int {
|
||||
/// The `isascii()` function was marked obsolescent in the Open Group Base
|
||||
/// Specifications Issue 7, and removed in Issue 8.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isascii(c: c_int) -> c_int {
|
||||
c_int::from((c & !0x7f) == 0)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isblank.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isblank(c: c_int) -> c_int {
|
||||
c_int::from(c == c_int::from(b' ') || c == c_int::from(b'\t'))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iscntrl.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn iscntrl(c: c_int) -> c_int {
|
||||
c_int::from((c >= 0x00 && c <= 0x1f) || c == 0x7f)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isdigit.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isdigit(c: c_int) -> c_int {
|
||||
c_int::from(c >= c_int::from(b'0') && c <= c_int::from(b'9'))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isgraph.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isgraph(c: c_int) -> c_int {
|
||||
c_int::from(c >= 0x21 && c <= 0x7e)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/islower.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn islower(c: c_int) -> c_int {
|
||||
c_int::from(c >= c_int::from(b'a') && c <= c_int::from(b'z'))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isprint.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isprint(c: c_int) -> c_int {
|
||||
c_int::from(c >= 0x20 && c < 0x7f)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ispunct.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn ispunct(c: c_int) -> c_int {
|
||||
c_int::from(
|
||||
(c >= c_int::from(b'!') && c <= c_int::from(b'/'))
|
||||
@@ -79,7 +79,7 @@ pub extern "C" fn ispunct(c: c_int) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isspace.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isspace(c: c_int) -> c_int {
|
||||
c_int::from(
|
||||
c == c_int::from(b' ')
|
||||
@@ -92,13 +92,13 @@ pub extern "C" fn isspace(c: c_int) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isupper.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isupper(c: c_int) -> c_int {
|
||||
c_int::from(c >= c_int::from(b'A') && c <= c_int::from(b'Z'))
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isxdigit.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn isxdigit(c: c_int) -> c_int {
|
||||
c_int::from(isdigit(c) != 0 || (c | 32 >= c_int::from(b'a') && c | 32 <= c_int::from(b'f')))
|
||||
}
|
||||
@@ -108,27 +108,19 @@ pub extern "C" fn isxdigit(c: c_int) -> c_int {
|
||||
/// The `toascii()` function was marked obsolescent in the Open Group Base
|
||||
/// Specifications Issue 7, and removed in Issue 8.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn toascii(c: c_int) -> c_int {
|
||||
c & 0x7f
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tolower.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn tolower(c: c_int) -> c_int {
|
||||
if isupper(c) != 0 {
|
||||
c | 0x20
|
||||
} else {
|
||||
c
|
||||
}
|
||||
if isupper(c) != 0 { c | 0x20 } else { c }
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/toupper.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn toupper(c: c_int) -> c_int {
|
||||
if islower(c) != 0 {
|
||||
c & !0x20
|
||||
} else {
|
||||
c
|
||||
}
|
||||
if islower(c) != 0 { c & !0x20 } else { c }
|
||||
}
|
||||
|
||||
+14
-14
@@ -18,7 +18,7 @@ use crate::{
|
||||
fs::File,
|
||||
header::{fcntl, stdlib, string},
|
||||
out::Out,
|
||||
platform::{self, types::*, Pal, Sys},
|
||||
platform::{self, Pal, Sys, types::*},
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -178,13 +178,13 @@ const _: () = {
|
||||
};
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/alphasort.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn alphasort(first: *mut *const dirent, second: *mut *const dirent) -> c_int {
|
||||
unsafe { string::strcoll((**first).d_name.as_ptr(), (**second).d_name.as_ptr()) }
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/closedir.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn closedir(dir: Box<DIR>) -> c_int {
|
||||
dir.close().map(|()| 0).or_minus_one_errno()
|
||||
}
|
||||
@@ -194,7 +194,7 @@ pub extern "C" fn closedir(dir: Box<DIR>) -> c_int {
|
||||
/// FreeBSD extension that transfers ownership of the directory file descriptor to the user.
|
||||
///
|
||||
/// It doesn't matter if DIR was opened with [`opendir`] or [`fdopendir`].
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn fdclosedir(dir: Box<DIR>) -> c_int {
|
||||
let mut file = dir.file;
|
||||
file.reference = true;
|
||||
@@ -203,13 +203,13 @@ pub extern "C" fn fdclosedir(dir: Box<DIR>) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/dirfd.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn dirfd(dir: &mut DIR) -> c_int {
|
||||
*dir.file
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fdopendir.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn opendir(path: *const c_char) -> *mut DIR {
|
||||
let path = unsafe { CStr::from_ptr(path) };
|
||||
|
||||
@@ -217,13 +217,13 @@ pub unsafe extern "C" fn opendir(path: *const c_char) -> *mut DIR {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fdopendir.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn fdopendir(fd: c_int) -> *mut DIR {
|
||||
DIR::from_fd(fd).or_errno_null_mut()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_getdents.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn posix_getdents(
|
||||
fildes: c_int,
|
||||
buf: *mut c_void,
|
||||
@@ -238,7 +238,7 @@ pub extern "C" fn posix_getdents(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/readdir.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn readdir(dir: &mut DIR) -> *mut dirent {
|
||||
dir.next_dirent().or_errno_null_mut()
|
||||
}
|
||||
@@ -249,7 +249,7 @@ pub extern "C" fn readdir(dir: &mut DIR) -> *mut dirent {
|
||||
/// The `readdir_r()` function was marked obsolescent in the Open Group Base
|
||||
/// Specifications Issue 8.
|
||||
#[deprecated]
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn readdir_r(
|
||||
_dir: *mut DIR,
|
||||
_entry: *mut dirent,
|
||||
@@ -259,13 +259,13 @@ pub extern "C" fn readdir_r(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rewinddir.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn rewinddir(dir: &mut DIR) {
|
||||
dir.rewind();
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/alphasort.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn scandir(
|
||||
dirp: *const c_char,
|
||||
namelist: *mut *mut *mut dirent,
|
||||
@@ -344,7 +344,7 @@ pub unsafe extern "C" fn scandir(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/seekdir.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn seekdir(dir: &mut DIR, off: c_long) {
|
||||
dir.seek(
|
||||
off.try_into()
|
||||
@@ -353,7 +353,7 @@ pub extern "C" fn seekdir(dir: &mut DIR, off: c_long) {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/telldir.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn telldir(dir: &mut DIR) -> c_long {
|
||||
dir.opaque_offset as c_long
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct dl_tls_index {
|
||||
pub ti_offset: usize,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __tls_get_addr(ti: *mut dl_tls_index) -> *mut c_void {
|
||||
let tcb = unsafe { Tcb::current().unwrap() };
|
||||
let ti = unsafe { &*ti };
|
||||
|
||||
@@ -45,7 +45,7 @@ pub struct Dl_info {
|
||||
dli_saddr: *mut c_void,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn dladdr(_addr: *mut c_void, info: *mut Dl_info) -> c_int {
|
||||
//TODO
|
||||
unsafe {
|
||||
@@ -57,7 +57,7 @@ pub unsafe extern "C" fn dladdr(_addr: *mut c_void, info: *mut Dl_info) -> c_int
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn dlopen(cfilename: *const c_char, flags: c_int) -> *mut c_void {
|
||||
//TODO support all sort of flags
|
||||
let resolve = if flags & RTLD_NOW == RTLD_NOW {
|
||||
@@ -111,7 +111,7 @@ pub unsafe extern "C" fn dlopen(cfilename: *const c_char, flags: c_int) -> *mut
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void {
|
||||
let handle = ObjectHandle::from_ptr(handle);
|
||||
|
||||
@@ -150,7 +150,7 @@ pub unsafe extern "C" fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *m
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn dlclose(handle: *mut c_void) -> c_int {
|
||||
let tcb = match unsafe { Tcb::current() } {
|
||||
Some(tcb) => tcb,
|
||||
@@ -177,7 +177,7 @@ pub unsafe extern "C" fn dlclose(handle: *mut c_void) -> c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn dlerror() -> *mut c_char {
|
||||
ERROR.swap(0, Ordering::SeqCst) as *mut c_char
|
||||
}
|
||||
|
||||
@@ -963,7 +963,7 @@ pub const R_X86_64_IRELATIVE: usize = 37;
|
||||
pub const R_X86_64_RELATIVE64: usize = 38;
|
||||
pub const R_X86_64_NUM: usize = 39;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn _cbindgen_export_elf(
|
||||
a: Elf32_Ehdr,
|
||||
b: Elf64_Ehdr,
|
||||
|
||||
+12
-12
@@ -5,73 +5,73 @@
|
||||
use crate::platform::types::*;
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn be16toh(x: uint16_t) -> uint16_t {
|
||||
uint16_t::from_be(x)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn be32toh(x: uint32_t) -> uint32_t {
|
||||
uint32_t::from_be(x)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn be64toh(x: uint64_t) -> uint64_t {
|
||||
uint64_t::from_be(x)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn htobe16(x: uint16_t) -> uint16_t {
|
||||
x.to_be()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn htobe32(x: uint32_t) -> uint32_t {
|
||||
x.to_be()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn htobe64(x: uint64_t) -> uint64_t {
|
||||
x.to_be()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn htole16(x: uint16_t) -> uint16_t {
|
||||
x.to_le()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn htole32(x: uint32_t) -> uint32_t {
|
||||
x.to_le()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn htole64(x: uint64_t) -> uint64_t {
|
||||
x.to_le()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn le16toh(x: uint16_t) -> uint16_t {
|
||||
uint16_t::from_le(x)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn le32toh(x: uint32_t) -> uint32_t {
|
||||
uint32_t::from_le(x)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn le64toh(x: uint64_t) -> uint64_t {
|
||||
uint64_t::from_le(x)
|
||||
}
|
||||
|
||||
+16
-16
@@ -22,14 +22,14 @@
|
||||
#![allow(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
use core::{
|
||||
ffi::{c_char, c_int, VaList as va_list},
|
||||
ffi::{VaList as va_list, c_char, c_int},
|
||||
ptr,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
c_str::CStr,
|
||||
header::{
|
||||
stdio::{self, fprintf, fputc, fputs, vfprintf, FILE},
|
||||
stdio::{self, FILE, fprintf, fputc, fputs, vfprintf},
|
||||
stdlib::exit,
|
||||
string::strerror,
|
||||
},
|
||||
@@ -44,7 +44,7 @@ static mut on_exit: ExitCallback = None;
|
||||
static mut error_sink: *mut FILE = ptr::null_mut();
|
||||
|
||||
/// Set global [`FILE`] sink to write errors and warnings.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn err_set_file(fp: *mut FILE) {
|
||||
if fp.is_null() {
|
||||
error_sink = stdio::stderr;
|
||||
@@ -54,7 +54,7 @@ pub unsafe extern "C" fn err_set_file(fp: *mut FILE) {
|
||||
}
|
||||
|
||||
/// Set or remove a callback to invoke before exiting on error.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn err_set_exit(ef: ExitCallback) {
|
||||
on_exit = ef;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ pub unsafe extern "C" fn err_set_exit(ef: ExitCallback) {
|
||||
///
|
||||
/// # Return
|
||||
/// Does not return. Exits with `eval` as an error code.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn err(eval: c_int, fmt: *const c_char, mut va_list: ...) -> ! {
|
||||
let code = Some(ERRNO.get());
|
||||
err_exit(eval, code, fmt, va_list.as_va_list())
|
||||
@@ -77,7 +77,7 @@ pub unsafe extern "C" fn err(eval: c_int, fmt: *const c_char, mut va_list: ...)
|
||||
///
|
||||
/// # Return
|
||||
/// Exits with `eval` as an error code.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn errc(eval: c_int, code: c_int, fmt: *const c_char, mut va_list: ...) -> ! {
|
||||
err_exit(eval, Some(code), fmt, va_list.as_va_list())
|
||||
}
|
||||
@@ -88,7 +88,7 @@ pub unsafe extern "C" fn errc(eval: c_int, code: c_int, fmt: *const c_char, mut
|
||||
///
|
||||
/// # Return
|
||||
/// Exits with `eval` as an error code.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn errx(eval: c_int, fmt: *const c_char, mut va_list: ...) -> ! {
|
||||
err_exit(eval, None, fmt, va_list.as_va_list())
|
||||
}
|
||||
@@ -96,7 +96,7 @@ pub unsafe extern "C" fn errx(eval: c_int, fmt: *const c_char, mut va_list: ...)
|
||||
/// Print a user message and then an error message for [`ERRNO`].
|
||||
///
|
||||
/// The message format is `progname: fmt: strerror(ERRNO)`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn warn(fmt: *const c_char, mut va_list: ...) {
|
||||
let code = Some(ERRNO.get());
|
||||
display_message(code, fmt, va_list.as_va_list());
|
||||
@@ -105,7 +105,7 @@ pub unsafe extern "C" fn warn(fmt: *const c_char, mut va_list: ...) {
|
||||
/// Print a user message then an error message for `code`.
|
||||
///
|
||||
/// The message format is `progname: fmt: strerror(code)`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn warnc(code: c_int, fmt: *const c_char, mut va_list: ...) {
|
||||
display_message(Some(code), fmt, va_list.as_va_list());
|
||||
}
|
||||
@@ -113,45 +113,45 @@ pub unsafe extern "C" fn warnc(code: c_int, fmt: *const c_char, mut va_list: ...
|
||||
/// Print a user message as a warning.
|
||||
///
|
||||
/// The message format is `progname: fmt`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn warnx(fmt: *const c_char, mut va_list: ...) {
|
||||
display_message(None, fmt, va_list.as_va_list());
|
||||
}
|
||||
|
||||
/// See [`err`].
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn verr(eval: c_int, fmt: *const c_char, args: va_list) -> ! {
|
||||
let code = Some(ERRNO.get());
|
||||
err_exit(eval, code, fmt, args);
|
||||
}
|
||||
|
||||
/// See [`errc`].
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn verrc(eval: c_int, code: c_int, fmt: *const c_char, args: va_list) -> ! {
|
||||
err_exit(eval, Some(code), fmt, args)
|
||||
}
|
||||
|
||||
/// See [`errx`];
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn verrx(eval: c_int, fmt: *const c_char, args: va_list) -> ! {
|
||||
err_exit(eval, None, fmt, args)
|
||||
}
|
||||
|
||||
/// See [`warn`].
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vwarn(fmt: *const c_char, args: va_list) {
|
||||
let code = Some(ERRNO.get());
|
||||
display_message(code, fmt, args);
|
||||
}
|
||||
|
||||
/// See [`warnc`].
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vwarnc(code: c_int, fmt: *const c_char, args: va_list) {
|
||||
display_message(Some(code), fmt, args);
|
||||
}
|
||||
|
||||
/// See [`warnx`].
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vwarnx(fmt: *const c_char, args: va_list) {
|
||||
display_message(None, fmt, args);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
use crate::platform::{self, types::*};
|
||||
|
||||
//TODO: Consider removing, provided for compatibility with newlib
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __errno() -> *mut c_int {
|
||||
__errno_location()
|
||||
}
|
||||
@@ -17,7 +17,7 @@ pub extern "C" fn __errno() -> *mut c_int {
|
||||
///
|
||||
/// This is the basis of the C-facing macro definition of `errno`, and should
|
||||
/// not be used directly.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __errno_location() -> *mut c_int {
|
||||
platform::ERRNO.as_ptr()
|
||||
}
|
||||
@@ -28,9 +28,9 @@ pub extern "C" fn __errno_location() -> *mut c_int {
|
||||
/// `program_invocation_name`, and should not be used directly.
|
||||
///
|
||||
/// The `program_invocation_name` variable is a GNU extension.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char {
|
||||
unsafe { &mut platform::program_invocation_name }
|
||||
unsafe { &raw mut platform::program_invocation_name }
|
||||
}
|
||||
|
||||
/// Get the directory-less name used to invoke the program.
|
||||
@@ -39,9 +39,9 @@ pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char {
|
||||
/// `program_invocation_short_name`, and should not be used directly.
|
||||
///
|
||||
/// The `program_invocation_short_name` variable is a GNU extension.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __program_invocation_short_name() -> *mut *mut c_char {
|
||||
unsafe { &mut platform::program_invocation_short_name }
|
||||
unsafe { &raw mut platform::program_invocation_short_name }
|
||||
}
|
||||
|
||||
pub const EPERM: c_int = 1; /* Operation not permitted */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use crate::{
|
||||
c_str::CStr,
|
||||
error::ResultExt,
|
||||
platform::{types::*, Pal, Sys},
|
||||
platform::{Pal, Sys, types::*},
|
||||
};
|
||||
|
||||
pub use self::sys::*;
|
||||
@@ -36,7 +36,7 @@ pub const F_LOCK: c_int = 1;
|
||||
pub const F_TLOCK: c_int = 2;
|
||||
pub const F_TEST: c_int = 3;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int {
|
||||
unsafe { open(path, O_WRONLY | O_CREAT | O_TRUNC, mode) }
|
||||
}
|
||||
@@ -49,7 +49,7 @@ pub struct flock {
|
||||
pub l_len: off_t,
|
||||
pub l_pid: pid_t,
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fcntl(fildes: c_int, cmd: c_int, mut __valist: ...) -> c_int {
|
||||
// c_ulonglong
|
||||
let arg = match cmd {
|
||||
@@ -62,7 +62,7 @@ pub unsafe extern "C" fn fcntl(fildes: c_int, cmd: c_int, mut __valist: ...) ->
|
||||
Sys::fcntl(fildes, cmd, arg).or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn open(path: *const c_char, oflag: c_int, mut __valist: ...) -> c_int {
|
||||
let mode = if oflag & O_CREAT == O_CREAT
|
||||
/* || oflag & O_TMPFILE == O_TMPFILE */
|
||||
@@ -76,5 +76,5 @@ pub unsafe extern "C" fn open(path: *const c_char, oflag: c_int, mut __valist: .
|
||||
Sys::open(path, oflag, mode).or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cbindgen_stupid_struct_user_for_fcntl(a: flock) {}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
//! http://pubs.opengroup.org/onlinepubs/7908799/xsh/float.h.html
|
||||
|
||||
use crate::{
|
||||
header::_fenv::{fegetround, FE_TONEAREST},
|
||||
header::_fenv::{FE_TONEAREST, fegetround},
|
||||
platform::types::*,
|
||||
};
|
||||
|
||||
pub const FLT_RADIX: c_int = 2;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn flt_rounds() -> c_int {
|
||||
match fegetround() {
|
||||
FE_TONEAREST => 1,
|
||||
|
||||
@@ -9,9 +9,9 @@ use core::slice;
|
||||
|
||||
use crate::platform::types::*;
|
||||
use posix_regex::{
|
||||
PosixRegex,
|
||||
compile::{Collation, Range, Token},
|
||||
tree::{Tree, TreeBuilder},
|
||||
PosixRegex,
|
||||
};
|
||||
|
||||
const ONCE: Range = Range(1, Some(1));
|
||||
@@ -126,7 +126,7 @@ unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Tree {
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[linkage = "weak"] // often redefined in GNU programs
|
||||
pub unsafe extern "C" fn fnmatch(
|
||||
pattern: *const c_char,
|
||||
|
||||
@@ -25,7 +25,7 @@ pub struct option {
|
||||
val: c_int,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[linkage = "weak"] // often redefined in GNU programs
|
||||
pub unsafe extern "C" fn getopt_long(
|
||||
argc: c_int,
|
||||
|
||||
+7
-11
@@ -9,10 +9,10 @@ use alloc::{boxed::Box, vec::Vec};
|
||||
use crate::{
|
||||
c_str::{CStr, CString},
|
||||
header::{
|
||||
dirent::{closedir, opendir, readdir, DIR},
|
||||
dirent::{DIR, closedir, opendir, readdir},
|
||||
errno::*,
|
||||
fnmatch::{fnmatch, FNM_NOESCAPE, FNM_PERIOD},
|
||||
sys_stat::{stat, S_IFDIR, S_IFLNK, S_IFMT},
|
||||
fnmatch::{FNM_NOESCAPE, FNM_PERIOD, fnmatch},
|
||||
sys_stat::{S_IFDIR, S_IFLNK, S_IFMT, stat},
|
||||
},
|
||||
platform::{self, types::*},
|
||||
};
|
||||
@@ -53,7 +53,7 @@ pub struct glob_t {
|
||||
}
|
||||
|
||||
#[linkage = "weak"] // GNU prefers its own glob e.g. in Make
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn glob(
|
||||
pattern: *const c_char,
|
||||
flags: c_int,
|
||||
@@ -147,7 +147,7 @@ pub unsafe extern "C" fn glob(
|
||||
}
|
||||
|
||||
#[linkage = "weak"] // GNU prefers its own glob e.g. in Make
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn globfree(pglob: *mut glob_t) {
|
||||
// Retake ownership
|
||||
if unsafe { !(*pglob).__opaque.is_null() } {
|
||||
@@ -331,12 +331,8 @@ fn inner_glob(
|
||||
let mut new_dir: Vec<u8> = Vec::new();
|
||||
new_dir.extend_from_slice(current_dir.to_bytes());
|
||||
new_dir.extend_from_slice(&pattern);
|
||||
return inner_glob(
|
||||
unsafe { &CStr::from_bytes_with_nul_unchecked(&new_dir) },
|
||||
&new_glob_expr,
|
||||
flags,
|
||||
errfunc,
|
||||
);
|
||||
let new_dir_c = unsafe { CStr::from_bytes_with_nul_unchecked(&new_dir) };
|
||||
return inner_glob(&new_dir_c, &new_glob_expr, flags, errfunc);
|
||||
}
|
||||
|
||||
let mut fnmatch_flags = 0;
|
||||
|
||||
+12
-12
@@ -24,7 +24,7 @@ use crate::{
|
||||
fs::File,
|
||||
header::{errno, fcntl, limits, string::strlen, unistd},
|
||||
io,
|
||||
io::{prelude::*, BufReader, Lines},
|
||||
io::{BufReader, Lines, prelude::*},
|
||||
platform,
|
||||
platform::types::*,
|
||||
sync::Mutex,
|
||||
@@ -116,7 +116,7 @@ impl OwnedGrp {
|
||||
unsafe {
|
||||
GROUP_BUF = Some(self.buffer);
|
||||
GROUP = self.reference;
|
||||
&mut GROUP
|
||||
&raw mut GROUP
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -249,7 +249,7 @@ fn parse_grp(line: String, destbuf: Option<DestBuffer>) -> Result<OwnedGrp, Erro
|
||||
}
|
||||
|
||||
// MT-Unsafe race:grgid locale
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getgrgid(gid: gid_t) -> *mut group {
|
||||
let Ok(db) = File::open(GROUP_FILE.into(), fcntl::O_RDONLY) else {
|
||||
return ptr::null_mut();
|
||||
@@ -272,7 +272,7 @@ pub unsafe extern "C" fn getgrgid(gid: gid_t) -> *mut group {
|
||||
}
|
||||
|
||||
// MT-Unsafe race:grnam locale
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getgrnam(name: *const c_char) -> *mut group {
|
||||
let Ok(db) = File::open(GROUP_FILE.into(), fcntl::O_RDONLY) else {
|
||||
return ptr::null_mut();
|
||||
@@ -303,7 +303,7 @@ pub unsafe extern "C" fn getgrnam(name: *const c_char) -> *mut group {
|
||||
}
|
||||
|
||||
// MT-Safe locale
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getgrgid_r(
|
||||
gid: gid_t,
|
||||
result_buf: *mut group,
|
||||
@@ -343,7 +343,7 @@ pub unsafe extern "C" fn getgrgid_r(
|
||||
io::ErrorKind::NotFound => ENOENT,
|
||||
_ => EIO,
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -362,7 +362,7 @@ pub unsafe extern "C" fn getgrgid_r(
|
||||
}
|
||||
|
||||
// MT-Safe locale
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getgrnam_r(
|
||||
name: *const c_char,
|
||||
result_buf: *mut group,
|
||||
@@ -406,7 +406,7 @@ pub unsafe extern "C" fn getgrnam_r(
|
||||
}
|
||||
|
||||
// MT-Unsafe race:grent race:grentbuf locale
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getgrent() -> *mut group {
|
||||
let mut line_reader = unsafe { &mut *LINE_READER.get() };
|
||||
|
||||
@@ -436,7 +436,7 @@ pub unsafe extern "C" fn getgrent() -> *mut group {
|
||||
}
|
||||
|
||||
// MT-Unsafe race:grent locale
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn endgrent() {
|
||||
unsafe {
|
||||
*(&mut *LINE_READER.get()) = None;
|
||||
@@ -444,7 +444,7 @@ pub unsafe extern "C" fn endgrent() {
|
||||
}
|
||||
|
||||
// MT-Unsafe race:grent locale
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setgrent() {
|
||||
let mut line_reader = unsafe { &mut *LINE_READER.get() };
|
||||
let Ok(db) = File::open(GROUP_FILE.into(), fcntl::O_RDONLY) else {
|
||||
@@ -455,7 +455,7 @@ pub unsafe extern "C" fn setgrent() {
|
||||
|
||||
// MT-Safe locale
|
||||
// Not POSIX
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getgrouplist(
|
||||
user: *const c_char,
|
||||
group: gid_t,
|
||||
@@ -523,7 +523,7 @@ pub unsafe extern "C" fn getgrouplist(
|
||||
|
||||
// MT-Safe locale
|
||||
// Not POSIX
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn initgroups(user: *const c_char, gid: gid_t) -> c_int {
|
||||
let mut groups = [0; limits::NGROUPS_MAX];
|
||||
let mut count = groups.len() as c_int;
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
};
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/imaxabs.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn imaxabs(i: intmax_t) -> intmax_t {
|
||||
i.abs()
|
||||
}
|
||||
@@ -23,7 +23,7 @@ pub struct imaxdiv_t {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/imaxdiv.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn imaxdiv(i: intmax_t, j: intmax_t) -> imaxdiv_t {
|
||||
imaxdiv_t {
|
||||
quot: i / j,
|
||||
@@ -32,7 +32,7 @@ pub extern "C" fn imaxdiv(i: intmax_t, j: intmax_t) -> imaxdiv_t {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoimax.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn strtoimax(
|
||||
s: *const c_char,
|
||||
endptr: *mut *mut c_char,
|
||||
@@ -52,7 +52,7 @@ pub unsafe extern "C" fn strtoimax(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoimax.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn strtoumax(
|
||||
s: *const c_char,
|
||||
endptr: *mut *mut c_char,
|
||||
|
||||
@@ -139,7 +139,7 @@ pub const CRNCYSTR: nl_item = 56;
|
||||
/// # Safety
|
||||
/// - Caller must ensure `item` is a valid `nl_item` index.
|
||||
/// - Returns a pointer to a null-terminated string, or an empty string if the item is invalid.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn nl_langinfo(item: nl_item) -> *const c_char {
|
||||
// Validate the item and perform the lookup
|
||||
if (item as usize) < STRING_TABLE.len() {
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::platform::types::c_char;
|
||||
|
||||
use crate::header::string::strlen;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn basename(str: *mut c_char) -> *mut c_char {
|
||||
if str.is_null() || unsafe { strlen(str) == 0 } {
|
||||
return ".\0".as_ptr() as *mut c_char;
|
||||
@@ -28,7 +28,7 @@ pub unsafe extern "C" fn basename(str: *mut c_char) -> *mut c_char {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn dirname(str: *mut c_char) -> *mut c_char {
|
||||
if str.is_null() || unsafe { strlen(str) == 0 } {
|
||||
return ".\0".as_ptr() as *mut c_char;
|
||||
|
||||
@@ -54,13 +54,13 @@ static mut CURRENT_LOCALE: lconv = lconv {
|
||||
thousands_sep: EMPTY_PTR,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn localeconv() -> *mut lconv {
|
||||
&mut CURRENT_LOCALE as *mut _
|
||||
&raw mut CURRENT_LOCALE as *mut _
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setlocale(_option: c_int, _val: *const c_char) -> *mut c_char {
|
||||
// TODO actually implement
|
||||
C_LOCALE.as_mut_ptr() as *mut c_char
|
||||
&raw mut C_LOCALE as *mut c_char
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
use crate::{
|
||||
header::errno::*,
|
||||
platform::{self, types::*, Pal, Sys, ERRNO},
|
||||
platform::{self, ERRNO, Pal, Sys, types::*},
|
||||
};
|
||||
use core::ptr;
|
||||
|
||||
/// See <https://man7.org/linux/man-pages/man3/posix_memalign.3.html>.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pvalloc(size: size_t) -> *mut c_void {
|
||||
let page_size = Sys::getpagesize();
|
||||
// Find the smallest multiple of the page size in which the requested size
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::platform::types::c_char;
|
||||
|
||||
use super::{apply_grouping, FormatFlags, LocaleMonetaryInfo, DEFAULT_MONETARY};
|
||||
use super::{DEFAULT_MONETARY, FormatFlags, LocaleMonetaryInfo, apply_grouping};
|
||||
use alloc::string::{String, ToString};
|
||||
use core::{ffi::CStr, ptr, result, slice, str};
|
||||
use libm::{fabs, floor, pow, round, trunc};
|
||||
|
||||
@@ -8,7 +8,7 @@ use alloc::ffi::CString;
|
||||
|
||||
use crate::{
|
||||
c_str::CStr,
|
||||
platform::{types::*, ERRNO},
|
||||
platform::{ERRNO, types::*},
|
||||
};
|
||||
|
||||
use super::errno::ENXIO;
|
||||
@@ -40,7 +40,7 @@ const INTERFACES: &[if_nameindex] = &[
|
||||
///
|
||||
/// # Safety
|
||||
/// this is a no-op: the list returned by if_nameindex() is a ref to a constant
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn if_freenameindex(s: *mut if_nameindex) {}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/if_indextoname.html>.
|
||||
@@ -49,7 +49,7 @@ pub unsafe extern "C" fn if_freenameindex(s: *mut if_nameindex) {}
|
||||
/// Returns only static lifetime references to const names, does not reuse the buf pointer.
|
||||
/// Returns NULL in case of not found + ERRNO being set to ENXIO.
|
||||
/// Currently only checks against inteface index 1.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn if_indextoname(idx: c_uint, buf: *mut c_char) -> *const c_char {
|
||||
if idx == 1 {
|
||||
return IF_STUB_INTERFACE;
|
||||
@@ -63,7 +63,7 @@ pub unsafe extern "C" fn if_indextoname(idx: c_uint, buf: *mut c_char) -> *const
|
||||
/// # Safety
|
||||
/// Returns a constant pointer to a pre defined const stub list
|
||||
/// The end of the list is determined by an if_nameindex struct having if_index 0 and if_name NULL
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn if_nameindex() -> *const if_nameindex {
|
||||
&INTERFACES[0] as *const if_nameindex
|
||||
}
|
||||
@@ -73,7 +73,7 @@ pub unsafe extern "C" fn if_nameindex() -> *const if_nameindex {
|
||||
/// # Safety
|
||||
/// Compares the name to a constant string and only returns an int as a result.
|
||||
/// An invalid name string will return an index of 0
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn if_nametoindex(name: *const c_char) -> c_uint {
|
||||
if name == null::<c_char>() {
|
||||
return 0;
|
||||
|
||||
+16
-14
@@ -9,10 +9,11 @@ use crate::{
|
||||
unistd::SEEK_SET,
|
||||
},
|
||||
platform::{
|
||||
Pal, Sys,
|
||||
rlb::{Line, RawLineBuffer},
|
||||
types::*,
|
||||
Pal, Sys,
|
||||
},
|
||||
raw_cell::RawCell,
|
||||
};
|
||||
|
||||
use super::{bytes_to_box_str, hostent};
|
||||
@@ -25,16 +26,16 @@ pub static mut HOST_ENTRY: hostent = hostent {
|
||||
h_length: 0,
|
||||
h_addr_list: ptr::null_mut(),
|
||||
};
|
||||
pub static mut HOST_NAME: Option<Vec<u8>> = None;
|
||||
pub static mut HOST_ALIASES: Option<Vec<Vec<u8>>> = None;
|
||||
static mut _HOST_ALIASES: Option<Vec<*mut c_char>> = None;
|
||||
pub static HOST_NAME: RawCell<Option<Vec<u8>>> = RawCell::new(None);
|
||||
pub static HOST_ALIASES: RawCell<Option<Vec<Vec<u8>>>> = RawCell::new(None);
|
||||
static _HOST_ALIASES: RawCell<Option<Vec<*mut c_char>>> = RawCell::new(None);
|
||||
pub static mut HOST_ADDR: Option<in_addr> = None;
|
||||
pub static mut HOST_ADDR_LIST: [*mut c_char; 2] = [ptr::null_mut(); 2];
|
||||
pub static mut _HOST_ADDR_LIST: [u8; 4] = [0u8; 4];
|
||||
static mut H_POS: usize = 0;
|
||||
pub static mut HOST_STAYOPEN: c_int = 0;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn endhostent() {
|
||||
if HOSTDB >= 0 {
|
||||
Sys::close(HOSTDB);
|
||||
@@ -42,7 +43,7 @@ pub unsafe extern "C" fn endhostent() {
|
||||
HOSTDB = -1;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sethostent(stayopen: c_int) {
|
||||
HOST_STAYOPEN = stayopen;
|
||||
if HOSTDB < 0 {
|
||||
@@ -53,7 +54,7 @@ pub unsafe extern "C" fn sethostent(stayopen: c_int) {
|
||||
H_POS = 0;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn gethostent() -> *mut hostent {
|
||||
if HOSTDB < 0 {
|
||||
HOSTDB = Sys::open(c"/etc/hosts".into(), O_RDONLY, 0).or_minus_one_errno();
|
||||
@@ -85,7 +86,7 @@ pub unsafe extern "C" fn gethostent() -> *mut hostent {
|
||||
let addr = addr.assume_init();
|
||||
|
||||
_HOST_ADDR_LIST = addr.s_addr.to_ne_bytes();
|
||||
HOST_ADDR_LIST = [_HOST_ADDR_LIST.as_mut_ptr() as *mut c_char, ptr::null_mut()];
|
||||
HOST_ADDR_LIST = [&raw mut _HOST_ADDR_LIST as *mut c_char, ptr::null_mut()];
|
||||
|
||||
HOST_ADDR = Some(addr);
|
||||
|
||||
@@ -94,9 +95,10 @@ pub unsafe extern "C" fn gethostent() -> *mut hostent {
|
||||
let mut _host_aliases: Vec<Vec<u8>> = iter
|
||||
.map(|alias| alias.bytes().chain(Some(b'\0')).collect())
|
||||
.collect();
|
||||
HOST_ALIASES = Some(_host_aliases);
|
||||
HOST_ALIASES.unsafe_set(Some(_host_aliases));
|
||||
|
||||
let mut host_aliases: Vec<*mut c_char> = HOST_ALIASES
|
||||
.unsafe_mut()
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.iter_mut()
|
||||
@@ -104,18 +106,18 @@ pub unsafe extern "C" fn gethostent() -> *mut hostent {
|
||||
.chain([ptr::null_mut(), ptr::null_mut()])
|
||||
.collect();
|
||||
|
||||
HOST_NAME = Some(host_name);
|
||||
HOST_NAME.unsafe_set(Some(host_name));
|
||||
|
||||
HOST_ENTRY = hostent {
|
||||
h_name: HOST_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char,
|
||||
h_name: HOST_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char,
|
||||
h_aliases: host_aliases.as_mut_slice().as_mut_ptr(),
|
||||
h_addrtype: AF_INET,
|
||||
h_length: 4,
|
||||
h_addr_list: HOST_ADDR_LIST.as_mut_ptr(),
|
||||
h_addr_list: &raw mut HOST_ADDR_LIST as *mut _,
|
||||
};
|
||||
_HOST_ALIASES = Some(host_aliases);
|
||||
_HOST_ALIASES.unsafe_set(Some(host_aliases));
|
||||
if HOST_STAYOPEN == 0 {
|
||||
endhostent();
|
||||
}
|
||||
&mut HOST_ENTRY as *mut hostent
|
||||
&raw mut HOST_ENTRY as *mut hostent
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ use core::mem;
|
||||
|
||||
use crate::{
|
||||
out::Out,
|
||||
platform::{types::*, Pal, Sys},
|
||||
platform::{Pal, Sys, types::*},
|
||||
};
|
||||
|
||||
use crate::header::{
|
||||
errno::*,
|
||||
netinet_in::{htons, in_addr, sockaddr_in, IPPROTO_UDP},
|
||||
netinet_in::{IPPROTO_UDP, htons, in_addr, sockaddr_in},
|
||||
sys_socket::{
|
||||
self,
|
||||
constants::{AF_INET, SOCK_DGRAM},
|
||||
|
||||
+73
-58
@@ -27,11 +27,11 @@ use crate::{
|
||||
unistd::SEEK_SET,
|
||||
},
|
||||
platform::{
|
||||
self,
|
||||
self, Pal, Sys,
|
||||
rlb::{Line, RawLineBuffer},
|
||||
types::*,
|
||||
Pal, Sys,
|
||||
},
|
||||
raw_cell::RawCell,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -130,8 +130,8 @@ pub static mut NET_ENTRY: netent = netent {
|
||||
n_addrtype: 0,
|
||||
n_net: 0,
|
||||
};
|
||||
pub static mut NET_NAME: Option<Vec<u8>> = None;
|
||||
pub static mut NET_ALIASES: Option<Vec<Vec<u8>>> = None;
|
||||
pub static NET_NAME: RawCell<Option<Vec<u8>>> = RawCell::new(None);
|
||||
pub static NET_ALIASES: RawCell<Option<Vec<Vec<u8>>>> = RawCell::new(None);
|
||||
pub static mut NET_ADDR: Option<u32> = None;
|
||||
static mut N_POS: usize = 0;
|
||||
static mut NET_STAYOPEN: c_int = 0;
|
||||
@@ -154,8 +154,8 @@ static mut PROTO_ENTRY: protoent = protoent {
|
||||
p_aliases: ptr::null_mut(),
|
||||
p_proto: 0 as c_int,
|
||||
};
|
||||
static mut PROTO_NAME: Option<Vec<u8>> = None;
|
||||
static mut PROTO_ALIASES: Option<Vec<Vec<u8>>> = None;
|
||||
static PROTO_NAME: RawCell<Option<Vec<u8>>> = RawCell::new(None);
|
||||
static PROTO_ALIASES: RawCell<Option<Vec<Vec<u8>>>> = RawCell::new(None);
|
||||
static mut PROTO_NUM: Option<c_int> = None;
|
||||
static mut P_POS: usize = 0;
|
||||
static mut PROTO_STAYOPEN: c_int = 0;
|
||||
@@ -167,10 +167,10 @@ static mut SERV_ENTRY: servent = servent {
|
||||
s_port: 0 as c_int,
|
||||
s_proto: ptr::null_mut(),
|
||||
};
|
||||
static mut SERV_NAME: Option<Vec<u8>> = None;
|
||||
static mut SERV_ALIASES: Option<Vec<Vec<u8>>> = None;
|
||||
static SERV_NAME: RawCell<Option<Vec<u8>>> = RawCell::new(None);
|
||||
static SERV_ALIASES: RawCell<Option<Vec<Vec<u8>>>> = RawCell::new(None);
|
||||
static mut SERV_PORT: Option<c_int> = None;
|
||||
static mut SERV_PROTO: Option<Vec<u8>> = None;
|
||||
static SERV_PROTO: RawCell<Option<Vec<u8>>> = RawCell::new(None);
|
||||
static mut S_POS: usize = 0;
|
||||
static mut SERV_STAYOPEN: c_int = 0;
|
||||
|
||||
@@ -178,19 +178,19 @@ fn bytes_to_box_str(bytes: &[u8]) -> Box<str> {
|
||||
Box::from(core::str::from_utf8(bytes).unwrap_or(""))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn endnetent() {
|
||||
Sys::close(NETDB);
|
||||
NETDB = 0;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn endprotoent() {
|
||||
Sys::close(PROTODB);
|
||||
PROTODB = 0;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn endservent() {
|
||||
Sys::close(SERVDB);
|
||||
SERVDB = 0;
|
||||
@@ -214,7 +214,7 @@ pub unsafe extern "C" fn endservent() {
|
||||
/// # Deprecation
|
||||
/// Deprecated as of POSIX.1-2001 and removed in POSIX.1-2008.
|
||||
/// New code should use [`getaddrinfo`] instead.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[deprecated]
|
||||
pub unsafe extern "C" fn gethostbyaddr(
|
||||
v: *const c_void,
|
||||
@@ -267,21 +267,21 @@ pub unsafe extern "C" fn gethostbyaddr(
|
||||
_host_aliases.push(vec![b'\0']);
|
||||
let mut host_aliases: Vec<*mut c_char> = Vec::new();
|
||||
host_aliases.push(ptr::null_mut());
|
||||
HOST_ALIASES = Some(_host_aliases);
|
||||
HOST_ALIASES.unsafe_set(Some(_host_aliases));
|
||||
|
||||
match lookup_addr(addr).map(|host_names| host_names.into_iter().next()) {
|
||||
Ok(Some(host_name)) => {
|
||||
_HOST_ADDR_LIST = addr.s_addr.to_ne_bytes();
|
||||
HOST_ADDR_LIST = [_HOST_ADDR_LIST.as_mut_ptr() as *mut c_char, ptr::null_mut()];
|
||||
HOST_NAME = Some(host_name);
|
||||
HOST_ADDR_LIST = [&raw mut _HOST_ADDR_LIST as *mut c_char, ptr::null_mut()];
|
||||
HOST_NAME.unsafe_set(Some(host_name));
|
||||
HOST_ENTRY = hostent {
|
||||
h_name: HOST_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char,
|
||||
h_name: HOST_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char,
|
||||
h_aliases: host_aliases.as_mut_slice().as_mut_ptr(),
|
||||
h_addrtype: format,
|
||||
h_length: length as i32,
|
||||
h_addr_list: HOST_ADDR_LIST.as_mut_ptr(),
|
||||
h_addr_list: &raw mut HOST_ADDR_LIST as *mut _,
|
||||
};
|
||||
&mut HOST_ENTRY
|
||||
&raw mut HOST_ENTRY
|
||||
}
|
||||
// `glibc` sets errno if an address doesn't have a host name
|
||||
// `musl` uses the address as the host name in said case
|
||||
@@ -312,7 +312,7 @@ pub unsafe extern "C" fn gethostbyaddr(
|
||||
/// # Deprecation
|
||||
/// Deprecated as of POSIX.1-2001 and removed in POSIX.1-2008.
|
||||
/// New code should use [`getaddrinfo`] instead.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[deprecated]
|
||||
pub unsafe extern "C" fn gethostbyname(name: *const c_char) -> *mut hostent {
|
||||
let name_cstr =
|
||||
@@ -373,9 +373,9 @@ pub unsafe extern "C" fn gethostbyname(name: *const c_char) -> *mut hostent {
|
||||
};
|
||||
|
||||
let host_name: Vec<u8> = name_cstr.to_bytes().to_vec();
|
||||
HOST_NAME = Some(host_name);
|
||||
HOST_NAME.unsafe_set(Some(host_name));
|
||||
_HOST_ADDR_LIST = host_addr.s_addr.to_ne_bytes();
|
||||
HOST_ADDR_LIST = [_HOST_ADDR_LIST.as_mut_ptr() as *mut c_char, ptr::null_mut()];
|
||||
HOST_ADDR_LIST = [&raw mut _HOST_ADDR_LIST as *mut c_char, ptr::null_mut()];
|
||||
HOST_ADDR = Some(host_addr);
|
||||
|
||||
//TODO actually get aliases
|
||||
@@ -384,24 +384,24 @@ pub unsafe extern "C" fn gethostbyname(name: *const c_char) -> *mut hostent {
|
||||
let mut host_aliases: Vec<*mut c_char> = Vec::new();
|
||||
host_aliases.push(ptr::null_mut());
|
||||
host_aliases.push(ptr::null_mut());
|
||||
HOST_ALIASES = Some(_host_aliases);
|
||||
HOST_ALIASES.unsafe_set(Some(_host_aliases));
|
||||
|
||||
HOST_ENTRY = hostent {
|
||||
h_name: HOST_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char,
|
||||
h_name: HOST_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char,
|
||||
h_aliases: host_aliases.as_mut_slice().as_mut_ptr(),
|
||||
h_addrtype: AF_INET,
|
||||
h_length: 4,
|
||||
h_addr_list: HOST_ADDR_LIST.as_mut_ptr(),
|
||||
h_addr_list: &raw mut HOST_ADDR_LIST as *mut _,
|
||||
};
|
||||
sethostent(HOST_STAYOPEN);
|
||||
&mut HOST_ENTRY as *mut hostent
|
||||
&raw mut HOST_ENTRY as *mut hostent
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn getnetbyaddr(net: u32, net_type: c_int) -> *mut netent {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getnetbyname(name: *const c_char) -> *mut netent {
|
||||
let mut n: *mut netent;
|
||||
setnetent(NET_STAYOPEN);
|
||||
@@ -420,7 +420,7 @@ pub unsafe extern "C" fn getnetbyname(name: *const c_char) -> *mut netent {
|
||||
ptr::null_mut() as *mut netent
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getnetent() -> *mut netent {
|
||||
// TODO: Rustify implementation
|
||||
|
||||
@@ -449,7 +449,7 @@ pub unsafe extern "C" fn getnetent() -> *mut netent {
|
||||
let mut iter: SplitWhitespace = r.split_whitespace();
|
||||
|
||||
let net_name = iter.next().unwrap().bytes().chain(Some(b'\0')).collect();
|
||||
NET_NAME = Some(net_name);
|
||||
NET_NAME.unsafe_set(Some(net_name));
|
||||
|
||||
let addr_vec: Vec<u8> = iter.next().unwrap().bytes().chain(Some(b'\0')).collect();
|
||||
let addr_cstr = addr_vec.as_slice().as_ptr() as *const c_char;
|
||||
@@ -466,18 +466,18 @@ pub unsafe extern "C" fn getnetent() -> *mut netent {
|
||||
.map(|x| x.as_mut_ptr() as *mut c_char)
|
||||
.chain(Some(ptr::null_mut()))
|
||||
.collect();
|
||||
NET_ALIASES = Some(_net_aliases);
|
||||
NET_ALIASES.unsafe_set(Some(_net_aliases));
|
||||
|
||||
NET_ENTRY = netent {
|
||||
n_name: NET_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char,
|
||||
n_name: NET_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char,
|
||||
n_aliases: net_aliases.as_mut_slice().as_mut_ptr(),
|
||||
n_addrtype: AF_INET,
|
||||
n_net: NET_ADDR.unwrap() as c_ulong,
|
||||
};
|
||||
&mut NET_ENTRY as *mut netent
|
||||
&raw mut NET_ENTRY as *mut netent
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getprotobyname(name: *const c_char) -> *mut protoent {
|
||||
let mut p: *mut protoent;
|
||||
setprotoent(PROTO_STAYOPEN);
|
||||
@@ -513,7 +513,7 @@ pub unsafe extern "C" fn getprotobyname(name: *const c_char) -> *mut protoent {
|
||||
ptr::null_mut() as *mut protoent
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getprotobynumber(number: c_int) -> *mut protoent {
|
||||
setprotoent(PROTO_STAYOPEN);
|
||||
let mut p: *mut protoent;
|
||||
@@ -531,7 +531,7 @@ pub unsafe extern "C" fn getprotobynumber(number: c_int) -> *mut protoent {
|
||||
ptr::null_mut() as *mut protoent
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getprotoent() -> *mut protoent {
|
||||
if PROTODB == 0 {
|
||||
PROTODB = Sys::open(c"/etc/protocols".into(), O_RDONLY, 0).or_minus_one_errno();
|
||||
@@ -573,21 +573,26 @@ pub unsafe extern "C" fn getprotoent() -> *mut protoent {
|
||||
.chain(Some(ptr::null_mut()))
|
||||
.collect();
|
||||
|
||||
PROTO_ALIASES = Some(_proto_aliases);
|
||||
PROTO_NAME = Some(proto_name);
|
||||
PROTO_ALIASES.unsafe_set(Some(_proto_aliases));
|
||||
PROTO_NAME.unsafe_set(Some(proto_name));
|
||||
|
||||
PROTO_ENTRY = protoent {
|
||||
p_name: PROTO_NAME.as_mut().unwrap().as_mut_slice().as_mut_ptr() as *mut c_char,
|
||||
p_name: PROTO_NAME
|
||||
.unsafe_mut()
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.as_mut_slice()
|
||||
.as_mut_ptr() as *mut c_char,
|
||||
p_aliases: proto_aliases.as_mut_slice().as_mut_ptr() as *mut *mut c_char,
|
||||
p_proto: PROTO_NUM.unwrap(),
|
||||
};
|
||||
if PROTO_STAYOPEN == 0 {
|
||||
endprotoent();
|
||||
}
|
||||
&mut PROTO_ENTRY as *mut protoent
|
||||
&raw mut PROTO_ENTRY as *mut protoent
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getservbyname(name: *const c_char, proto: *const c_char) -> *mut servent {
|
||||
setservent(SERV_STAYOPEN);
|
||||
let mut p: *mut servent;
|
||||
@@ -617,7 +622,7 @@ pub unsafe extern "C" fn getservbyname(name: *const c_char, proto: *const c_char
|
||||
ptr::null_mut() as *mut servent
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getservbyport(port: c_int, proto: *const c_char) -> *mut servent {
|
||||
setservent(SERV_STAYOPEN);
|
||||
let mut p: *mut servent;
|
||||
@@ -647,7 +652,7 @@ pub unsafe extern "C" fn getservbyport(port: c_int, proto: *const c_char) -> *mu
|
||||
ptr::null_mut()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getservent() -> *mut servent {
|
||||
if SERVDB == 0 {
|
||||
// TODO: Rustify
|
||||
@@ -713,25 +718,35 @@ pub unsafe extern "C" fn getservent() -> *mut servent {
|
||||
serv_aliases.push(ptr::null_mut());
|
||||
serv_aliases.push(ptr::null_mut());
|
||||
|
||||
SERV_ALIASES = Some(_serv_aliases);
|
||||
SERV_NAME = Some(serv_name);
|
||||
SERV_PROTO = Some(proto);
|
||||
SERV_ALIASES.unsafe_set(Some(_serv_aliases));
|
||||
SERV_NAME.unsafe_set(Some(serv_name));
|
||||
SERV_PROTO.unsafe_set(Some(proto));
|
||||
|
||||
SERV_ENTRY = servent {
|
||||
s_name: SERV_NAME.as_mut().unwrap().as_mut_slice().as_mut_ptr() as *mut c_char,
|
||||
s_name: SERV_NAME
|
||||
.unsafe_mut()
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.as_mut_slice()
|
||||
.as_mut_ptr() as *mut c_char,
|
||||
s_aliases: serv_aliases.as_mut_slice().as_mut_ptr() as *mut *mut c_char,
|
||||
s_port: SERV_PORT.unwrap(),
|
||||
s_proto: SERV_PROTO.as_mut().unwrap().as_mut_slice().as_mut_ptr() as *mut c_char,
|
||||
s_proto: SERV_PROTO
|
||||
.unsafe_mut()
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.as_mut_slice()
|
||||
.as_mut_ptr() as *mut c_char,
|
||||
};
|
||||
|
||||
if SERV_STAYOPEN == 0 {
|
||||
endservent();
|
||||
}
|
||||
break &mut SERV_ENTRY as *mut servent;
|
||||
break &raw mut SERV_ENTRY as *mut servent;
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setnetent(stayopen: c_int) {
|
||||
NET_STAYOPEN = stayopen;
|
||||
if NETDB == 0 {
|
||||
@@ -742,7 +757,7 @@ pub unsafe extern "C" fn setnetent(stayopen: c_int) {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setprotoent(stayopen: c_int) {
|
||||
PROTO_STAYOPEN = stayopen;
|
||||
if PROTODB == 0 {
|
||||
@@ -753,7 +768,7 @@ pub unsafe extern "C" fn setprotoent(stayopen: c_int) {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setservent(stayopen: c_int) {
|
||||
SERV_STAYOPEN = stayopen;
|
||||
if SERVDB == 0 {
|
||||
@@ -764,7 +779,7 @@ pub unsafe extern "C" fn setservent(stayopen: c_int) {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getaddrinfo(
|
||||
node: *const c_char,
|
||||
service: *const c_char,
|
||||
@@ -869,7 +884,7 @@ pub unsafe extern "C" fn getaddrinfo(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getnameinfo(
|
||||
addr: *const sockaddr,
|
||||
addrlen: socklen_t,
|
||||
@@ -956,7 +971,7 @@ pub unsafe extern "C" fn getnameinfo(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn freeaddrinfo(res: *mut addrinfo) {
|
||||
let mut ai = res;
|
||||
while !ai.is_null() {
|
||||
@@ -977,7 +992,7 @@ pub unsafe extern "C" fn freeaddrinfo(res: *mut addrinfo) {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub const extern "C" fn gai_strerror(errcode: c_int) -> *const c_char {
|
||||
match errcode {
|
||||
EAI_BADFLAGS => c"Invalid flags",
|
||||
@@ -998,13 +1013,13 @@ pub const extern "C" fn gai_strerror(errcode: c_int) -> *const c_char {
|
||||
}
|
||||
|
||||
/// Provide a pointer to relibc's internal [`H_ERRNO`].
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[deprecated]
|
||||
pub extern "C" fn __h_errno_location() -> *mut c_int {
|
||||
H_ERRNO.as_ptr()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[deprecated]
|
||||
pub const extern "C" fn hstrerror(errcode: c_int) -> *const c_char {
|
||||
match errcode {
|
||||
@@ -1032,7 +1047,7 @@ pub const extern "C" fn hstrerror(errcode: c_int) -> *const c_char {
|
||||
/// [`H_ERRNO`], [`hstrerror`], [`herror`], and other functions are deprecated as of
|
||||
/// POSIX.1-2001 and removed as of POSIX.1-2008. These functions are provided for backwards
|
||||
/// compatibility but should not be used by new code.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[deprecated]
|
||||
pub extern "C" fn herror(prefix: *const c_char) {
|
||||
let code = H_ERRNO.get();
|
||||
|
||||
@@ -165,37 +165,37 @@ pub struct group_source_req {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub static in6addr_any: in6_addr = in6_addr {
|
||||
s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
};
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub static in6addr_loopback: in6_addr = in6_addr {
|
||||
s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
|
||||
};
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn htonl(hostlong: uint32_t) -> uint32_t {
|
||||
hostlong.to_be()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn htons(hostshort: uint16_t) -> uint16_t {
|
||||
hostshort.to_be()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn ntohl(netlong: uint32_t) -> uint32_t {
|
||||
u32::from_be(netlong)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t {
|
||||
u16::from_be(netshort)
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ use crate::{
|
||||
error::ResultExt,
|
||||
fs::File,
|
||||
header::sys_epoll::{
|
||||
epoll_create1, epoll_ctl, epoll_data, epoll_event, epoll_wait, EPOLLERR, EPOLLHUP, EPOLLIN,
|
||||
EPOLLNVAL, EPOLLOUT, EPOLLPRI, EPOLLRDBAND, EPOLLRDNORM, EPOLLWRBAND, EPOLLWRNORM,
|
||||
EPOLL_CLOEXEC, EPOLL_CTL_ADD,
|
||||
EPOLL_CLOEXEC, EPOLL_CTL_ADD, EPOLLERR, EPOLLHUP, EPOLLIN, EPOLLNVAL, EPOLLOUT, EPOLLPRI,
|
||||
EPOLLRDBAND, EPOLLRDNORM, EPOLLWRBAND, EPOLLWRNORM, epoll_create1, epoll_ctl, epoll_data,
|
||||
epoll_event, epoll_wait,
|
||||
},
|
||||
platform::types::*,
|
||||
};
|
||||
@@ -113,7 +113,7 @@ pub fn poll_epoll(fds: &mut [pollfd], timeout: c_int) -> c_int {
|
||||
count
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: c_int) -> c_int {
|
||||
trace_expr!(
|
||||
poll_epoll(
|
||||
|
||||
+19
-19
@@ -34,13 +34,13 @@ impl Default for RlctAttr {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> c_int {
|
||||
core::ptr::drop_in_place(attr);
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getdetachstate(
|
||||
attr: *const pthread_attr_t,
|
||||
detachstate: *mut c_int,
|
||||
@@ -49,7 +49,7 @@ pub unsafe extern "C" fn pthread_attr_getdetachstate(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getguardsize(
|
||||
attr: *const pthread_attr_t,
|
||||
size: *mut size_t,
|
||||
@@ -58,7 +58,7 @@ pub unsafe extern "C" fn pthread_attr_getguardsize(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getinheritsched(
|
||||
attr: *const pthread_attr_t,
|
||||
inheritsched: *mut c_int,
|
||||
@@ -67,7 +67,7 @@ pub unsafe extern "C" fn pthread_attr_getinheritsched(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getschedparam(
|
||||
attr: *const pthread_attr_t,
|
||||
param: *mut sched_param,
|
||||
@@ -76,7 +76,7 @@ pub unsafe extern "C" fn pthread_attr_getschedparam(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getschedpolicy(
|
||||
attr: *const pthread_attr_t,
|
||||
policy: *mut c_int,
|
||||
@@ -85,7 +85,7 @@ pub unsafe extern "C" fn pthread_attr_getschedpolicy(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getscope(
|
||||
attr: *const pthread_attr_t,
|
||||
scope: *mut c_int,
|
||||
@@ -94,7 +94,7 @@ pub unsafe extern "C" fn pthread_attr_getscope(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getstack(
|
||||
attr: *const pthread_attr_t,
|
||||
stackaddr: *mut *mut c_void,
|
||||
@@ -105,7 +105,7 @@ pub unsafe extern "C" fn pthread_attr_getstack(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_getstacksize(
|
||||
attr: *const pthread_attr_t,
|
||||
stacksize: *mut size_t,
|
||||
@@ -114,13 +114,13 @@ pub unsafe extern "C" fn pthread_attr_getstacksize(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int {
|
||||
core::ptr::write(attr.cast::<RlctAttr>(), RlctAttr::default());
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setdetachstate(
|
||||
attr: *mut pthread_attr_t,
|
||||
detachstate: c_int,
|
||||
@@ -129,7 +129,7 @@ pub unsafe extern "C" fn pthread_attr_setdetachstate(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setguardsize(
|
||||
attr: *mut pthread_attr_t,
|
||||
guardsize: c_int,
|
||||
@@ -138,7 +138,7 @@ pub unsafe extern "C" fn pthread_attr_setguardsize(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setinheritsched(
|
||||
attr: *mut pthread_attr_t,
|
||||
inheritsched: c_int,
|
||||
@@ -147,7 +147,7 @@ pub unsafe extern "C" fn pthread_attr_setinheritsched(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setschedparam(
|
||||
attr: *mut pthread_attr_t,
|
||||
param: *const sched_param,
|
||||
@@ -156,7 +156,7 @@ pub unsafe extern "C" fn pthread_attr_setschedparam(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setschedpolicy(
|
||||
attr: *mut pthread_attr_t,
|
||||
policy: c_int,
|
||||
@@ -165,13 +165,13 @@ pub unsafe extern "C" fn pthread_attr_setschedpolicy(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setscope(attr: *mut pthread_attr_t, scope: c_int) -> c_int {
|
||||
(*attr.cast::<RlctAttr>()).scope = scope as u8;
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setstack(
|
||||
attr: *mut pthread_attr_t,
|
||||
stackaddr: *mut c_void,
|
||||
@@ -182,7 +182,7 @@ pub unsafe extern "C" fn pthread_attr_setstack(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_attr_setstacksize(
|
||||
attr: *mut pthread_attr_t,
|
||||
stacksize: size_t,
|
||||
@@ -191,7 +191,7 @@ pub unsafe extern "C" fn pthread_attr_setstacksize(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_getattr_np(
|
||||
thread_ptr: pthread_t,
|
||||
attr_ptr: *mut pthread_attr_t,
|
||||
|
||||
@@ -22,7 +22,7 @@ impl Default for RlctBarrierAttr {
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t) -> c_int {
|
||||
// Behavior is undefined if any thread is currently waiting when this is called.
|
||||
|
||||
@@ -33,7 +33,7 @@ pub unsafe extern "C" fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrier_init(
|
||||
barrier: *mut pthread_barrier_t,
|
||||
attr: *const pthread_barrierattr_t,
|
||||
@@ -58,7 +58,7 @@ fn unlikely(condition: bool) -> bool {
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -> c_int {
|
||||
let barrier = &*barrier.cast::<RlctBarrier>();
|
||||
|
||||
@@ -69,7 +69,7 @@ pub unsafe extern "C" fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrierattr_init(attr: *mut pthread_barrierattr_t) -> c_int {
|
||||
core::ptr::write(attr.cast::<RlctBarrierAttr>(), RlctBarrierAttr::default());
|
||||
|
||||
@@ -77,7 +77,7 @@ pub unsafe extern "C" fn pthread_barrierattr_init(attr: *mut pthread_barrierattr
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrierattr_setpshared(
|
||||
attr: *mut pthread_barrierattr_t,
|
||||
pshared: c_int,
|
||||
@@ -87,7 +87,7 @@ pub unsafe extern "C" fn pthread_barrierattr_setpshared(
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrierattr_getpshared(
|
||||
attr: *const pthread_barrierattr_t,
|
||||
pshared: *mut c_int,
|
||||
@@ -97,7 +97,7 @@ pub unsafe extern "C" fn pthread_barrierattr_getpshared(
|
||||
}
|
||||
|
||||
// Not async-signal-safe.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_barrierattr_destroy(attr: *mut pthread_barrierattr_t) -> c_int {
|
||||
core::ptr::drop_in_place(attr);
|
||||
0
|
||||
|
||||
+12
-12
@@ -4,19 +4,19 @@ use super::*;
|
||||
|
||||
// PTHREAD_COND_INITIALIZER is defined manually in bits_pthread/cbindgen.toml
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> c_int {
|
||||
e((&*cond.cast::<RlctCond>()).broadcast())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_int {
|
||||
// No-op
|
||||
core::ptr::drop_in_place(cond.cast::<RlctCond>());
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_init(
|
||||
cond: *mut pthread_cond_t,
|
||||
_attr: *const pthread_condattr_t,
|
||||
@@ -26,12 +26,12 @@ pub unsafe extern "C" fn pthread_cond_init(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_signal(cond: *mut pthread_cond_t) -> c_int {
|
||||
e((&*cond.cast::<RlctCond>()).signal())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_timedwait(
|
||||
cond: *mut pthread_cond_t,
|
||||
mutex: *mut pthread_mutex_t,
|
||||
@@ -40,7 +40,7 @@ pub unsafe extern "C" fn pthread_cond_timedwait(
|
||||
e((&*cond.cast::<RlctCond>()).timedwait(&*mutex.cast::<RlctMutex>(), &*timeout))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cond_wait(
|
||||
cond: *mut pthread_cond_t,
|
||||
mutex: *mut pthread_mutex_t,
|
||||
@@ -48,14 +48,14 @@ pub unsafe extern "C" fn pthread_cond_wait(
|
||||
e((&*cond.cast::<RlctCond>()).wait(&*mutex.cast::<RlctMutex>()))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_destroy(condattr: *mut pthread_condattr_t) -> c_int {
|
||||
core::ptr::drop_in_place(condattr.cast::<RlctCondAttr>());
|
||||
// No-op
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_getclock(
|
||||
condattr: *const pthread_condattr_t,
|
||||
clock: *mut clockid_t,
|
||||
@@ -64,7 +64,7 @@ pub unsafe extern "C" fn pthread_condattr_getclock(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_getpshared(
|
||||
condattr: *const pthread_condattr_t,
|
||||
pshared: *mut c_int,
|
||||
@@ -73,7 +73,7 @@ pub unsafe extern "C" fn pthread_condattr_getpshared(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_init(condattr: *mut pthread_condattr_t) -> c_int {
|
||||
condattr
|
||||
.cast::<RlctCondAttr>()
|
||||
@@ -82,7 +82,7 @@ pub unsafe extern "C" fn pthread_condattr_init(condattr: *mut pthread_condattr_t
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_setclock(
|
||||
condattr: *mut pthread_condattr_t,
|
||||
clock: clockid_t,
|
||||
@@ -91,7 +91,7 @@ pub unsafe extern "C" fn pthread_condattr_setclock(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_condattr_setpshared(
|
||||
condattr: *mut pthread_condattr_t,
|
||||
pshared: c_int,
|
||||
|
||||
+20
-20
@@ -6,7 +6,7 @@ use core::{cell::Cell, ptr::NonNull};
|
||||
use crate::{
|
||||
error::Errno,
|
||||
header::{sched::*, time::timespec},
|
||||
platform::{types::*, Pal, Sys},
|
||||
platform::{Pal, Sys, types::*},
|
||||
pthread,
|
||||
};
|
||||
|
||||
@@ -79,7 +79,7 @@ pub use self::cond::*;
|
||||
#[thread_local]
|
||||
pub static mut fork_hooks: [LinkedList<extern "C" fn()>; 3] = [const { LinkedList::new() }; 3];
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_cancel(thread: pthread_t) -> c_int {
|
||||
match pthread::cancel(&*thread.cast()) {
|
||||
Ok(()) => 0,
|
||||
@@ -87,7 +87,7 @@ pub unsafe extern "C" fn pthread_cancel(thread: pthread_t) -> c_int {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_create(
|
||||
pthread: *mut pthread_t,
|
||||
attr: *const pthread_attr_t,
|
||||
@@ -105,7 +105,7 @@ pub unsafe extern "C" fn pthread_create(
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_detach(pthread: pthread_t) -> c_int {
|
||||
match pthread::detach(&*pthread.cast()) {
|
||||
Ok(()) => 0,
|
||||
@@ -113,13 +113,13 @@ pub unsafe extern "C" fn pthread_detach(pthread: pthread_t) -> c_int {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn pthread_equal(pthread1: pthread_t, pthread2: pthread_t) -> c_int {
|
||||
core::ptr::eq(pthread1, pthread2).into()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_atfork.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn pthread_atfork(
|
||||
prepare: Option<extern "C" fn()>,
|
||||
parent: Option<extern "C" fn()>,
|
||||
@@ -143,18 +143,18 @@ pub extern "C" fn pthread_atfork(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_exit(retval: *mut c_void) -> ! {
|
||||
pthread::exit_current_thread(pthread::Retval(retval))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_getconcurrency() -> c_int {
|
||||
// Redox and Linux threads are 1:1, not M:N.
|
||||
1
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_getcpuclockid(
|
||||
thread: pthread_t,
|
||||
clock_out: *mut clockid_t,
|
||||
@@ -168,7 +168,7 @@ pub unsafe extern "C" fn pthread_getcpuclockid(
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_getschedparam(
|
||||
thread: pthread_t,
|
||||
policy_out: *mut c_int,
|
||||
@@ -188,7 +188,7 @@ pub unsafe extern "C" fn pthread_getschedparam(
|
||||
pub mod tls;
|
||||
pub use tls::*;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_join(thread: pthread_t, retval: *mut *mut c_void) -> c_int {
|
||||
match pthread::join(&*thread.cast()) {
|
||||
Ok(pthread::Retval(ret)) => {
|
||||
@@ -210,11 +210,11 @@ pub use self::once::*;
|
||||
pub mod rwlock;
|
||||
pub use self::rwlock::*;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_self() -> pthread_t {
|
||||
pthread::current_thread().unwrap_unchecked() as *const _ as *mut _
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_setcancelstate(state: c_int, oldstate: *mut c_int) -> c_int {
|
||||
match pthread::set_cancel_state(state) {
|
||||
Ok(old) => {
|
||||
@@ -228,7 +228,7 @@ pub unsafe extern "C" fn pthread_setcancelstate(state: c_int, oldstate: *mut c_i
|
||||
Err(Errno(error)) => error,
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_setcanceltype(ty: c_int, oldty: *mut c_int) -> c_int {
|
||||
match pthread::set_cancel_type(ty) {
|
||||
Ok(old) => {
|
||||
@@ -243,13 +243,13 @@ pub unsafe extern "C" fn pthread_setcanceltype(ty: c_int, oldty: *mut c_int) ->
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn pthread_setconcurrency(concurrency: c_int) -> c_int {
|
||||
// Redox and Linux threads are 1:1, not M:N.
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_setschedparam(
|
||||
thread: pthread_t,
|
||||
policy: c_int,
|
||||
@@ -257,7 +257,7 @@ pub unsafe extern "C" fn pthread_setschedparam(
|
||||
) -> c_int {
|
||||
e(pthread::set_sched_param(&*thread.cast(), policy, &*param))
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_setschedprio(thread: pthread_t, prio: c_int) -> c_int {
|
||||
e(pthread::set_sched_priority(&*thread.cast(), prio))
|
||||
}
|
||||
@@ -265,7 +265,7 @@ pub unsafe extern "C" fn pthread_setschedprio(thread: pthread_t, prio: c_int) ->
|
||||
pub mod spin;
|
||||
pub use self::spin::*;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_testcancel() {
|
||||
pthread::testcancel();
|
||||
}
|
||||
@@ -284,14 +284,14 @@ pub(crate) static CLEANUP_LL_HEAD: Cell<*const CleanupLinkedListEntry> =
|
||||
|
||||
// TODO: unwind? setjmp/longjmp?
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __relibc_internal_pthread_cleanup_push(new_entry: *mut c_void) {
|
||||
let new_entry = &mut *new_entry.cast::<CleanupLinkedListEntry>();
|
||||
|
||||
new_entry.prev = CLEANUP_LL_HEAD.get().cast();
|
||||
CLEANUP_LL_HEAD.set(new_entry);
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __relibc_internal_pthread_cleanup_pop(execute: c_int) {
|
||||
let prev_head = CLEANUP_LL_HEAD.get().read();
|
||||
CLEANUP_LL_HEAD.set(prev_head.prev.cast());
|
||||
|
||||
+21
-21
@@ -4,18 +4,18 @@ use crate::error::Errno;
|
||||
|
||||
// PTHREAD_MUTEX_INITIALIZER is defined in bits_pthread/cbindgen.toml
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_consistent(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
e((&*mutex.cast::<RlctMutex>()).make_consistent())
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
// No-op
|
||||
core::ptr::drop_in_place(mutex.cast::<RlctMutex>());
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_getprioceiling(
|
||||
mutex: *const pthread_mutex_t,
|
||||
prioceiling: *mut c_int,
|
||||
@@ -29,7 +29,7 @@ pub unsafe extern "C" fn pthread_mutex_getprioceiling(
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_init(
|
||||
mutex: *mut pthread_mutex_t,
|
||||
attr: *const pthread_mutexattr_t,
|
||||
@@ -49,12 +49,12 @@ pub unsafe extern "C" fn pthread_mutex_init(
|
||||
Err(Errno(errno)) => errno,
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
e((&*mutex.cast::<RlctMutex>()).lock())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_setprioceiling(
|
||||
mutex: *mut pthread_mutex_t,
|
||||
prioceiling: c_int,
|
||||
@@ -69,30 +69,30 @@ pub unsafe extern "C" fn pthread_mutex_setprioceiling(
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_timedlock(
|
||||
mutex: *mut pthread_mutex_t,
|
||||
timespec: *const timespec,
|
||||
) -> c_int {
|
||||
e((&*mutex.cast::<RlctMutex>()).lock_with_timeout(&*timespec))
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
e((&*mutex.cast::<RlctMutex>()).try_lock())
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> c_int {
|
||||
e((&*mutex.cast::<RlctMutex>()).unlock())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> c_int {
|
||||
// No-op
|
||||
core::ptr::drop_in_place(attr.cast::<RlctMutexAttr>());
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_getprioceiling(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
prioceiling: *mut c_int,
|
||||
@@ -101,7 +101,7 @@ pub unsafe extern "C" fn pthread_mutexattr_getprioceiling(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_getprotocol(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
protocol: *mut c_int,
|
||||
@@ -110,7 +110,7 @@ pub unsafe extern "C" fn pthread_mutexattr_getprotocol(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_getpshared(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
pshared: *mut c_int,
|
||||
@@ -119,7 +119,7 @@ pub unsafe extern "C" fn pthread_mutexattr_getpshared(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_getrobust(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
robust: *mut c_int,
|
||||
@@ -127,7 +127,7 @@ pub unsafe extern "C" fn pthread_mutexattr_getrobust(
|
||||
robust.write((*attr.cast::<RlctMutexAttr>()).robust);
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_gettype(
|
||||
attr: *const pthread_mutexattr_t,
|
||||
ty: *mut c_int,
|
||||
@@ -135,13 +135,13 @@ pub unsafe extern "C" fn pthread_mutexattr_gettype(
|
||||
ty.write((*attr.cast::<RlctMutexAttr>()).ty);
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> c_int {
|
||||
attr.cast::<RlctMutexAttr>().write(RlctMutexAttr::default());
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_setprioceiling(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
prioceiling: c_int,
|
||||
@@ -150,7 +150,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setprioceiling(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_setprotocol(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
protocol: c_int,
|
||||
@@ -159,7 +159,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setprotocol(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_setpshared(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
pshared: c_int,
|
||||
@@ -168,7 +168,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setpshared(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_setrobust(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
robust: c_int,
|
||||
@@ -176,7 +176,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setrobust(
|
||||
(*attr.cast::<RlctMutexAttr>()).robust = robust;
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_mutexattr_settype(
|
||||
attr: *mut pthread_mutexattr_t,
|
||||
ty: c_int,
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::*;
|
||||
|
||||
// PTHREAD_ONCE_INIT
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_once(
|
||||
once: *mut pthread_once_t,
|
||||
constructor: extern "C" fn(),
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::header::errno::EBUSY;
|
||||
|
||||
use crate::pthread::Pshared;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_init(
|
||||
rwlock: *mut pthread_rwlock_t,
|
||||
attr: *const pthread_rwlockattr_t,
|
||||
@@ -21,13 +21,13 @@ pub unsafe extern "C" fn pthread_rwlock_init(
|
||||
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_rdlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
get(rwlock).acquire_read_lock(None);
|
||||
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_timedrdlock(
|
||||
rwlock: *mut pthread_rwlock_t,
|
||||
timeout: *const timespec,
|
||||
@@ -36,7 +36,7 @@ pub unsafe extern "C" fn pthread_rwlock_timedrdlock(
|
||||
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_timedwrlock(
|
||||
rwlock: *mut pthread_rwlock_t,
|
||||
timeout: *const timespec,
|
||||
@@ -45,34 +45,34 @@ pub unsafe extern "C" fn pthread_rwlock_timedwrlock(
|
||||
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_tryrdlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
match get(rwlock).try_acquire_read_lock() {
|
||||
Ok(()) => 0,
|
||||
Err(_) => EBUSY,
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_trywrlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
match get(rwlock).try_acquire_write_lock() {
|
||||
Ok(()) => 0,
|
||||
Err(_) => EBUSY,
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_unlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
get(rwlock).unlock();
|
||||
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_wrlock(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
get(rwlock).acquire_write_lock(None);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> c_int {
|
||||
attr.cast::<RlctRwlockAttr>()
|
||||
.write(RlctRwlockAttr::default());
|
||||
@@ -80,7 +80,7 @@ pub unsafe extern "C" fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlockattr_getpshared(
|
||||
attr: *const pthread_rwlockattr_t,
|
||||
pshared_out: *mut c_int,
|
||||
@@ -90,7 +90,7 @@ pub unsafe extern "C" fn pthread_rwlockattr_getpshared(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlockattr_setpshared(
|
||||
attr: *mut pthread_rwlockattr_t,
|
||||
pshared: c_int,
|
||||
@@ -101,13 +101,13 @@ pub unsafe extern "C" fn pthread_rwlockattr_setpshared(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t) -> c_int {
|
||||
core::ptr::drop_in_place(attr);
|
||||
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> c_int {
|
||||
core::ptr::drop_in_place(rwlock);
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ use super::*;
|
||||
const UNLOCKED: c_int = 0;
|
||||
const LOCKED: c_int = 1;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_destroy(spinlock: *mut pthread_spinlock_t) -> c_int {
|
||||
let _spinlock = &mut *spinlock.cast::<RlctSpinlock>();
|
||||
|
||||
// No-op
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_init(
|
||||
spinlock: *mut pthread_spinlock_t,
|
||||
_pshared: c_int,
|
||||
@@ -28,7 +28,7 @@ pub unsafe extern "C" fn pthread_spin_init(
|
||||
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_lock(spinlock: *mut pthread_spinlock_t) -> c_int {
|
||||
let spinlock = &*spinlock.cast::<RlctSpinlock>();
|
||||
|
||||
@@ -46,7 +46,7 @@ pub unsafe extern "C" fn pthread_spin_lock(spinlock: *mut pthread_spinlock_t) ->
|
||||
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_trylock(spinlock: *mut pthread_spinlock_t) -> c_int {
|
||||
let spinlock = &*spinlock.cast::<RlctSpinlock>();
|
||||
|
||||
@@ -60,7 +60,7 @@ pub unsafe extern "C" fn pthread_spin_trylock(spinlock: *mut pthread_spinlock_t)
|
||||
|
||||
0
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_spin_unlock(spinlock: *mut pthread_spinlock_t) -> c_int {
|
||||
let spinlock = &*spinlock.cast::<RlctSpinlock>();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{header::errno::EINVAL, sync::Mutex};
|
||||
// TODO: What should this limit be?
|
||||
pub const PTHREAD_KEYS_MAX: u32 = 4096 * 32;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut c_void {
|
||||
//print!("pthread_getspecific key={:#0x}: ", key);
|
||||
|
||||
@@ -28,7 +28,7 @@ pub unsafe extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut c_void
|
||||
|
||||
data
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_key_create(
|
||||
key_ptr: *mut pthread_key_t,
|
||||
destructor: Option<extern "C" fn(value: *mut c_void)>,
|
||||
@@ -55,7 +55,7 @@ pub unsafe extern "C" fn pthread_key_create(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_key_delete(key: pthread_key_t) -> c_int {
|
||||
if KEYS.lock().remove(&key).is_none() || VALUES.borrow_mut().remove(&key).is_none() {
|
||||
// We don't have to return anything, but it's not less expensive to ignore it.
|
||||
@@ -66,7 +66,7 @@ pub unsafe extern "C" fn pthread_key_delete(key: pthread_key_t) -> c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_setspecific(key: pthread_key_t, value: *const c_void) -> c_int {
|
||||
if !KEYS.lock().contains_key(&key) {
|
||||
// We don't have to return anything, but it's not less expensive to ignore it.
|
||||
@@ -76,12 +76,12 @@ pub unsafe extern "C" fn pthread_setspecific(key: pthread_key_t, value: *const c
|
||||
|
||||
let mut guard = VALUES.borrow_mut();
|
||||
|
||||
let Record { ref mut data, .. } = guard.entry(key).or_insert(Record {
|
||||
let mut record = guard.entry(key).or_insert(Record {
|
||||
data: core::ptr::null_mut(),
|
||||
});
|
||||
//println!("Valid key for pthread_setspecific key {:#0x} value {:p} (was {:p})", key, value, *data);
|
||||
//println!("Valid key for pthread_setspecific key {:#0x} value {:p} (was {:p})", key, value, record.data);
|
||||
|
||||
*data = value as *mut c_void;
|
||||
record.data = value as *mut c_void;
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ mod imp;
|
||||
mod imp;
|
||||
|
||||
/// See <https://www.man7.org/linux/man-pages/man3/openpty.3.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn openpty(
|
||||
amaster: *mut c_int,
|
||||
aslave: *mut c_int,
|
||||
@@ -53,7 +53,7 @@ pub unsafe extern "C" fn openpty(
|
||||
}
|
||||
|
||||
/// See <https://www.man7.org/linux/man-pages/man3/openpty.3.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn forkpty(
|
||||
pm: *mut c_int,
|
||||
name: *mut c_char,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
Pal, Sys,
|
||||
error::ResultExt,
|
||||
header::{fcntl, unistd},
|
||||
platform::types::*,
|
||||
Pal, Sys,
|
||||
};
|
||||
|
||||
pub(super) unsafe fn openpty(name: &mut [u8]) -> Result<(c_int, c_int), ()> {
|
||||
|
||||
+19
-18
@@ -12,8 +12,9 @@ use core::{
|
||||
use crate::{
|
||||
fs::File,
|
||||
header::{errno, fcntl, string::strcmp},
|
||||
io::{prelude::*, BufReader, SeekFrom},
|
||||
io::{BufReader, SeekFrom, prelude::*},
|
||||
platform::{self, types::*},
|
||||
raw_cell::RawCell,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -49,7 +50,7 @@ pub struct passwd {
|
||||
}
|
||||
|
||||
static mut PASSWD_BUF: Option<MaybeAllocated> = None;
|
||||
static mut PASSWD: passwd = passwd {
|
||||
static PASSWD: RawCell<passwd> = RawCell::new(passwd {
|
||||
pw_name: ptr::null_mut(),
|
||||
pw_passwd: ptr::null_mut(),
|
||||
pw_uid: 0,
|
||||
@@ -57,7 +58,7 @@ static mut PASSWD: passwd = passwd {
|
||||
pw_gecos: ptr::null_mut(),
|
||||
pw_dir: ptr::null_mut(),
|
||||
pw_shell: ptr::null_mut(),
|
||||
};
|
||||
});
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct DestBuffer {
|
||||
@@ -103,8 +104,8 @@ impl OwnedPwd {
|
||||
fn into_global(self) -> *mut passwd {
|
||||
unsafe {
|
||||
PASSWD_BUF = Some(self.buffer);
|
||||
PASSWD = self.reference;
|
||||
&mut PASSWD
|
||||
PASSWD.unsafe_set(self.reference);
|
||||
PASSWD.as_mut_ptr()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,7 +116,7 @@ enum Cause {
|
||||
Other,
|
||||
}
|
||||
|
||||
static mut READER: Option<BufReader<File>> = None;
|
||||
static READER: RawCell<Option<BufReader<File>>> = RawCell::new(None);
|
||||
|
||||
fn parsed<I, O>(buf: Option<I>) -> Option<O>
|
||||
where
|
||||
@@ -220,17 +221,17 @@ unsafe fn mux(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/endpwent.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn endpwent() {
|
||||
unsafe {
|
||||
READER = None;
|
||||
READER.unsafe_set(None);
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/endpwent.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn getpwent() -> *mut passwd {
|
||||
let reader = match unsafe { &mut READER } {
|
||||
let reader = match unsafe { &mut *READER.as_mut_ptr() } {
|
||||
Some(reader) => reader,
|
||||
None => {
|
||||
let file = match File::open(c"/etc/passwd".into(), fcntl::O_RDONLY) {
|
||||
@@ -239,8 +240,8 @@ pub extern "C" fn getpwent() -> *mut passwd {
|
||||
};
|
||||
let reader = BufReader::new(file);
|
||||
unsafe {
|
||||
READER = Some(reader);
|
||||
READER.as_mut().unwrap()
|
||||
READER.unsafe_set(Some(reader));
|
||||
READER.unsafe_mut().as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -250,7 +251,7 @@ pub extern "C" fn getpwent() -> *mut passwd {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpwnam.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn getpwnam(name: *const c_char) -> *mut passwd {
|
||||
pwd_lookup(|parts| unsafe { strcmp(parts.pw_name, name) } == 0, None)
|
||||
.map(|res| res.into_global())
|
||||
@@ -258,7 +259,7 @@ pub extern "C" fn getpwnam(name: *const c_char) -> *mut passwd {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpwnam.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getpwnam_r(
|
||||
name: *const c_char,
|
||||
out: *mut passwd,
|
||||
@@ -280,7 +281,7 @@ pub unsafe extern "C" fn getpwnam_r(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpwuid.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn getpwuid(uid: uid_t) -> *mut passwd {
|
||||
pwd_lookup(|parts| parts.pw_uid == uid, None)
|
||||
.map(|res| res.into_global())
|
||||
@@ -288,7 +289,7 @@ pub extern "C" fn getpwuid(uid: uid_t) -> *mut passwd {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpwuid.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getpwuid_r(
|
||||
uid: uid_t,
|
||||
out: *mut passwd,
|
||||
@@ -311,9 +312,9 @@ pub unsafe extern "C" fn getpwuid_r(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/endpwent.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn setpwent() {
|
||||
if let Some(reader) = unsafe { &mut READER } {
|
||||
if let Some(reader) = unsafe { &mut *READER.as_mut_ptr() } {
|
||||
let _ = reader.seek(SeekFrom::Start(0));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-10
@@ -3,7 +3,7 @@
|
||||
use crate::{header::string::strlen, platform::types::*};
|
||||
use alloc::{borrow::Cow, boxed::Box};
|
||||
use core::{mem, ptr, slice};
|
||||
use posix_regex::{compile::Error as CompileError, tree::Tree, PosixRegex, PosixRegexBuilder};
|
||||
use posix_regex::{PosixRegex, PosixRegexBuilder, compile::Error as CompileError, tree::Tree};
|
||||
|
||||
pub type regoff_t = size_t;
|
||||
|
||||
@@ -43,7 +43,7 @@ pub const REG_ERANGE: c_int = 12;
|
||||
pub const REG_ESPACE: c_int = 13;
|
||||
pub const REG_BADRPT: c_int = 14;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[linkage = "weak"] // redefined in GIT
|
||||
pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: c_int) -> c_int {
|
||||
let pat = slice::from_raw_parts(pat as *const u8, strlen(pat));
|
||||
@@ -74,13 +74,13 @@ pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags:
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[linkage = "weak"] // redefined in GIT
|
||||
pub unsafe extern "C" fn regfree(regex: *mut regex_t) {
|
||||
Box::from_raw((*regex).ptr);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[linkage = "weak"] // redefined in GIT
|
||||
pub unsafe extern "C" fn regexec(
|
||||
regex: *const regex_t,
|
||||
@@ -117,14 +117,10 @@ pub unsafe extern "C" fn regexec(
|
||||
}
|
||||
}
|
||||
|
||||
if matches.is_empty() {
|
||||
REG_NOMATCH
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if matches.is_empty() { REG_NOMATCH } else { 0 }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
#[linkage = "weak"] // redefined in GIT
|
||||
pub extern "C" fn regerror(
|
||||
code: c_int,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::{
|
||||
error::ResultExt,
|
||||
header::time::timespec,
|
||||
platform::{types::*, Pal, Sys},
|
||||
platform::{Pal, Sys, types::*},
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -15,27 +15,27 @@ pub const SCHED_FIFO: c_int = 0;
|
||||
pub const SCHED_RR: c_int = 1;
|
||||
pub const SCHED_OTHER: c_int = 2;
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn sched_get_priority_max(policy: c_int) -> c_int {
|
||||
todo!()
|
||||
}
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn sched_get_priority_min(policy: c_int) -> c_int {
|
||||
todo!()
|
||||
}
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sched_getparam(pid: pid_t, param: *mut sched_param) -> c_int {
|
||||
todo!()
|
||||
}
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn sched_rr_get_interval(pid: pid_t, time: *const timespec) -> c_int {
|
||||
todo!()
|
||||
}
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sched_setparam(pid: pid_t, param: *const sched_param) -> c_int {
|
||||
todo!()
|
||||
}
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn sched_setscheduler(
|
||||
pid: pid_t,
|
||||
policy: c_int,
|
||||
@@ -43,7 +43,7 @@ pub extern "C" fn sched_setscheduler(
|
||||
) -> c_int {
|
||||
todo!()
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn sched_yield() -> c_int {
|
||||
Sys::sched_yield().map(|()| 0).or_minus_one_errno()
|
||||
}
|
||||
|
||||
+12
-12
@@ -3,7 +3,7 @@
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/semaphore.h.html>.
|
||||
|
||||
use crate::{
|
||||
header::time::{timespec, CLOCK_MONOTONIC, CLOCK_REALTIME},
|
||||
header::time::{CLOCK_MONOTONIC, CLOCK_REALTIME, timespec},
|
||||
platform::types::*,
|
||||
};
|
||||
|
||||
@@ -18,20 +18,20 @@ pub union sem_t {
|
||||
pub type RlctSempahore = crate::sync::Semaphore;
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_close.html>.
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_close(sem: *mut sem_t) -> c_int {
|
||||
todo!("named semaphores")
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_destroy.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_destroy(sem: *mut sem_t) -> c_int {
|
||||
core::ptr::drop_in_place(sem.cast::<RlctSempahore>());
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_getvalue.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_getvalue(sem: *mut sem_t, sval: *mut c_int) -> c_int {
|
||||
sval.write(get(sem).value() as c_int);
|
||||
|
||||
@@ -39,7 +39,7 @@ pub unsafe extern "C" fn sem_getvalue(sem: *mut sem_t, sval: *mut c_int) -> c_in
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_init.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_init(sem: *mut sem_t, _pshared: c_int, value: c_uint) -> c_int {
|
||||
sem.cast::<RlctSempahore>().write(RlctSempahore::new(value));
|
||||
|
||||
@@ -48,7 +48,7 @@ pub unsafe extern "C" fn sem_init(sem: *mut sem_t, _pshared: c_int, value: c_uin
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_open.html>.
|
||||
// TODO: va_list
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_open(
|
||||
name: *const c_char,
|
||||
oflag: c_int, /* (va_list) value: c_uint */
|
||||
@@ -57,7 +57,7 @@ pub unsafe extern "C" fn sem_open(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_post.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_post(sem: *mut sem_t) -> c_int {
|
||||
get(sem).post(1);
|
||||
|
||||
@@ -65,7 +65,7 @@ pub unsafe extern "C" fn sem_post(sem: *mut sem_t) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_trywait.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_trywait(sem: *mut sem_t) -> c_int {
|
||||
get(sem).try_wait();
|
||||
|
||||
@@ -73,13 +73,13 @@ pub unsafe extern "C" fn sem_trywait(sem: *mut sem_t) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_unlink.html>.
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_unlink(name: *const c_char) -> c_int {
|
||||
todo!("named semaphores")
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_trywait.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_wait(sem: *mut sem_t) -> c_int {
|
||||
get(sem).wait(None, CLOCK_MONOTONIC);
|
||||
|
||||
@@ -87,7 +87,7 @@ pub unsafe extern "C" fn sem_wait(sem: *mut sem_t) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_clockwait.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_clockwait(
|
||||
sem: *mut sem_t,
|
||||
clock_id: clockid_t,
|
||||
@@ -99,7 +99,7 @@ pub unsafe extern "C" fn sem_clockwait(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_timedwait.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_timedwait(sem: *mut sem_t, abstime: *const timespec) -> c_int {
|
||||
get(sem).wait(Some(&*abstime), CLOCK_REALTIME);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ platform_specific! {
|
||||
}
|
||||
|
||||
//Each platform has different sizes for sigjmp_buf, currently only x86_64 is supported
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
pub fn setjmp(jb: *mut u64) -> i32;
|
||||
pub fn longjmp(jb: *mut u64, ret: i32);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::{header::sys_ioctl::*, platform::types::*};
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn gtty(fd: c_int, out: *mut sgttyb) -> c_int {
|
||||
eprintln!("unimplemented: gtty({}, {:p})", fd, out);
|
||||
-1
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
c_str::CStr,
|
||||
fs::File,
|
||||
header::{errno, fcntl, string::strlen},
|
||||
io::{prelude::*, BufReader, Lines},
|
||||
io::{BufReader, Lines, prelude::*},
|
||||
platform,
|
||||
platform::types::*,
|
||||
};
|
||||
@@ -112,7 +112,7 @@ impl OwnedSpwd {
|
||||
unsafe {
|
||||
SHADOW_BUF = Some(self.buffer);
|
||||
SHADOW = self.reference;
|
||||
&mut SHADOW
|
||||
&raw mut SHADOW
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +181,7 @@ fn parse_spwd(line: String, destbuf: Option<DestBuffer>) -> Result<OwnedSpwd, Er
|
||||
Ok(OwnedSpwd { buffer, reference })
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getspnam(name: *const c_char) -> *mut spwd {
|
||||
let Ok(db) = File::open(SHADOW_FILE.into(), fcntl::O_RDONLY) else {
|
||||
return ptr::null_mut();
|
||||
@@ -199,7 +199,7 @@ pub unsafe extern "C" fn getspnam(name: *const c_char) -> *mut spwd {
|
||||
ptr::null_mut()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getspnam_r(
|
||||
name: *const c_char,
|
||||
result_buf: *mut spwd,
|
||||
@@ -237,7 +237,7 @@ pub unsafe extern "C" fn getspnam_r(
|
||||
ENOENT
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setspent() {
|
||||
let mut line_reader = unsafe { &mut *LINE_READER.get() };
|
||||
if let Ok(db) = File::open(SHADOW_FILE.into(), fcntl::O_RDONLY) {
|
||||
@@ -245,14 +245,14 @@ pub unsafe extern "C" fn setspent() {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn endspent() {
|
||||
unsafe {
|
||||
*LINE_READER.get() = None;
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getspent() -> *mut spwd {
|
||||
let line_reader = unsafe { &mut *LINE_READER.get() };
|
||||
if line_reader.is_none() {
|
||||
|
||||
+33
-33
@@ -8,7 +8,7 @@ use crate::{
|
||||
c_str::CStr,
|
||||
error::{Errno, ResultExt},
|
||||
header::{errno, setjmp, time::timespec},
|
||||
platform::{self, types::*, Pal, PalSignal, Sys},
|
||||
platform::{self, Pal, PalSignal, Sys, types::*},
|
||||
};
|
||||
|
||||
pub use self::sys::*;
|
||||
@@ -69,7 +69,7 @@ pub struct siginfo {
|
||||
pub si_value: sigval,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn _cbindgen_export_siginfo(a: siginfo) {}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -104,13 +104,13 @@ global_asm!(
|
||||
options(att_syntax)
|
||||
);
|
||||
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
pub fn sigsetjmp(jb: *mut u64, savemask: i32) -> i32;
|
||||
}
|
||||
|
||||
//NOTE for the following two functions, to see why they're implemented slightly differently from their intended behavior, read
|
||||
// https://git.musl-libc.org/cgit/musl/commit/?id=583e55122e767b1586286a0d9c35e2a4027998ab
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn __sigsetjmp_tail(jb: *mut u64, ret: i32) -> i32 {
|
||||
let set = jb.wrapping_add(9);
|
||||
if ret > 0 {
|
||||
@@ -121,28 +121,28 @@ unsafe extern "C" fn __sigsetjmp_tail(jb: *mut u64, ret: i32) -> i32 {
|
||||
ret
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn siglongjmp(jb: *mut u64, ret: i32) {
|
||||
setjmp::longjmp(jb, ret);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn kill(pid: pid_t, sig: c_int) -> c_int {
|
||||
Sys::kill(pid, sig).map(|()| 0).or_minus_one_errno()
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn sigqueue(pid: pid_t, sig: c_int, val: sigval) -> c_int {
|
||||
Sys::sigqueue(pid, sig, val)
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
|
||||
Sys::killpg(pgrp, sig).map(|()| 0).or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_kill(thread: pthread_t, sig: c_int) -> c_int {
|
||||
let os_tid = {
|
||||
let pthread = &*(thread as *const crate::pthread::Pthread);
|
||||
@@ -151,7 +151,7 @@ pub unsafe extern "C" fn pthread_kill(thread: pthread_t, sig: c_int) -> c_int {
|
||||
crate::header::pthread::e(Sys::rlct_kill(os_tid, sig as usize))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pthread_sigmask(
|
||||
how: c_int,
|
||||
set: *const sigset_t,
|
||||
@@ -166,12 +166,12 @@ pub unsafe extern "C" fn pthread_sigmask(
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn raise(sig: c_int) -> c_int {
|
||||
Sys::raise(sig).map(|()| 0).or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigaction(
|
||||
sig: c_int,
|
||||
act: *const sigaction,
|
||||
@@ -182,7 +182,7 @@ pub unsafe extern "C" fn sigaction(
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigaddset(set: *mut sigset_t, signo: c_int) -> c_int {
|
||||
if signo <= 0 || signo as usize > NSIG.max(SIGRTMAX)
|
||||
/* TODO */
|
||||
@@ -197,14 +197,14 @@ pub unsafe extern "C" fn sigaddset(set: *mut sigset_t, signo: c_int) -> c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigaltstack(ss: *const stack_t, old_ss: *mut stack_t) -> c_int {
|
||||
Sys::sigaltstack(ss.as_ref(), old_ss.as_mut())
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigdelset(set: *mut sigset_t, signo: c_int) -> c_int {
|
||||
if signo <= 0 || signo as usize > NSIG.max(SIGRTMAX)
|
||||
/* TODO */
|
||||
@@ -219,7 +219,7 @@ pub unsafe extern "C" fn sigdelset(set: *mut sigset_t, signo: c_int) -> c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigemptyset(set: *mut sigset_t) -> c_int {
|
||||
if let Some(set) = (set as *mut SigSet).as_mut() {
|
||||
set.clear();
|
||||
@@ -227,7 +227,7 @@ pub unsafe extern "C" fn sigemptyset(set: *mut sigset_t) -> c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigfillset(set: *mut sigset_t) -> c_int {
|
||||
if let Some(set) = (set as *mut SigSet).as_mut() {
|
||||
set.fill(.., true);
|
||||
@@ -235,7 +235,7 @@ pub unsafe extern "C" fn sigfillset(set: *mut sigset_t) -> c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sighold(sig: c_int) -> c_int {
|
||||
let mut pset = mem::MaybeUninit::<sigset_t>::uninit();
|
||||
unsafe { sigemptyset(pset.as_mut_ptr()) };
|
||||
@@ -246,7 +246,7 @@ pub unsafe extern "C" fn sighold(sig: c_int) -> c_int {
|
||||
sigprocmask(SIG_BLOCK, &set, ptr::null_mut())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn sigignore(sig: c_int) -> c_int {
|
||||
let mut psa = mem::MaybeUninit::<sigaction>::uninit();
|
||||
unsafe { sigemptyset(&mut (*psa.as_mut_ptr()).sa_mask) };
|
||||
@@ -256,7 +256,7 @@ pub extern "C" fn sigignore(sig: c_int) -> c_int {
|
||||
unsafe { sigaction(sig, &mut sa, ptr::null_mut()) }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn siginterrupt(sig: c_int, flag: c_int) -> c_int {
|
||||
let mut psa = mem::MaybeUninit::<sigaction>::uninit();
|
||||
unsafe { sigaction(sig, ptr::null_mut(), psa.as_mut_ptr()) };
|
||||
@@ -270,7 +270,7 @@ pub extern "C" fn siginterrupt(sig: c_int, flag: c_int) -> c_int {
|
||||
unsafe { sigaction(sig, &mut sa, ptr::null_mut()) }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigismember(set: *const sigset_t, signo: c_int) -> c_int {
|
||||
if signo <= 0 || signo as usize > NSIG {
|
||||
platform::ERRNO.set(errno::EINVAL);
|
||||
@@ -285,7 +285,7 @@ pub unsafe extern "C" fn sigismember(set: *const sigset_t, signo: c_int) -> c_in
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn signal(
|
||||
sig: c_int,
|
||||
func: Option<extern "C" fn(c_int)>,
|
||||
@@ -304,7 +304,7 @@ pub extern "C" fn signal(
|
||||
unsafe { old_sa.assume_init() }.sa_handler
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigpause(sig: c_int) -> c_int {
|
||||
let mut pset = mem::MaybeUninit::<sigset_t>::uninit();
|
||||
sigprocmask(0, ptr::null_mut(), pset.as_mut_ptr());
|
||||
@@ -315,7 +315,7 @@ pub unsafe extern "C" fn sigpause(sig: c_int) -> c_int {
|
||||
sigsuspend(&set)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigpending(set: *mut sigset_t) -> c_int {
|
||||
(|| Sys::sigpending(set.as_mut().ok_or(Errno(EFAULT))?))()
|
||||
.map(|()| 0)
|
||||
@@ -326,7 +326,7 @@ const BELOW_SIGRTMIN_MASK: sigset_t = (1 << SIGRTMIN) - 1;
|
||||
const STANDARD_SIG_MASK: sigset_t = (1 << 32) - 1;
|
||||
const RLCT_SIGNAL_MASK: sigset_t = BELOW_SIGRTMIN_MASK & !STANDARD_SIG_MASK;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigprocmask(
|
||||
how: c_int,
|
||||
set: *const sigset_t,
|
||||
@@ -351,7 +351,7 @@ pub unsafe extern "C" fn sigprocmask(
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigrelse(sig: c_int) -> c_int {
|
||||
let mut pset = mem::MaybeUninit::<sigset_t>::uninit();
|
||||
sigemptyset(pset.as_mut_ptr());
|
||||
@@ -362,7 +362,7 @@ pub unsafe extern "C" fn sigrelse(sig: c_int) -> c_int {
|
||||
sigprocmask(SIG_UNBLOCK, &mut set, ptr::null_mut())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigset(
|
||||
sig: c_int,
|
||||
func: Option<extern "C" fn(c_int)>,
|
||||
@@ -405,12 +405,12 @@ pub unsafe extern "C" fn sigset(
|
||||
old_sa.assume_init().sa_handler
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigsuspend(sigmask: *const sigset_t) -> c_int {
|
||||
Err(Sys::sigsuspend(&*sigmask)).or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int {
|
||||
let mut pinfo = mem::MaybeUninit::<siginfo_t>::uninit();
|
||||
if sigtimedwait(set, pinfo.as_mut_ptr(), ptr::null_mut()) < 0 {
|
||||
@@ -421,7 +421,7 @@ pub unsafe extern "C" fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigtimedwait(
|
||||
set: *const sigset_t,
|
||||
// s/siginfo_t/siginfo due to https://github.com/mozilla/cbindgen/issues/621
|
||||
@@ -434,7 +434,7 @@ pub unsafe extern "C" fn sigtimedwait(
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sigwaitinfo(set: *const sigset_t, sig: *mut siginfo_t) -> c_int {
|
||||
sigtimedwait(set, sig, core::ptr::null())
|
||||
}
|
||||
@@ -473,7 +473,7 @@ pub(crate) const SIGNAL_STRINGS: [&str; 32] = [
|
||||
"Power failure\0",
|
||||
"Bad system call\0",
|
||||
];
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn psignal(sig: c_int, prefix: *const c_char) {
|
||||
let c_description = usize::try_from(sig)
|
||||
.ok()
|
||||
@@ -490,7 +490,7 @@ pub unsafe extern "C" fn psignal(sig: c_int, prefix: *const c_char) {
|
||||
string.as_bytes().len(),
|
||||
);
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn psiginfo(info: *const siginfo_t, prefix: *const c_char) {
|
||||
let siginfo_t {
|
||||
si_code,
|
||||
|
||||
@@ -181,7 +181,7 @@ pub struct mcontext {
|
||||
_opaque: [u8; 520],
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __completely_unused_cbindgen_workaround_fn_ucontext_mcontext(
|
||||
a: *const ucontext_t,
|
||||
b: *const mcontext_t,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{constants, Buffer, BUFSIZ, FILE};
|
||||
use super::{BUFSIZ, Buffer, FILE, constants};
|
||||
use core::{cell::UnsafeCell, ptr};
|
||||
|
||||
use crate::{
|
||||
@@ -54,9 +54,9 @@ pub fn default_stderr() -> &'static GlobalFile {
|
||||
DEFAULT_STDERR.call_once(|| GlobalFile::new(2, constants::F_NORD))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub static mut stdin: *mut FILE = ptr::null_mut();
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub static mut stdout: *mut FILE = ptr::null_mut();
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub static mut stderr: *mut FILE = ptr::null_mut();
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
use crate::{
|
||||
header::stdio::{FILE, F_NORD, F_NOWR},
|
||||
header::stdio::{F_NORD, F_NOWR, FILE},
|
||||
platform::types::*,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __fpending(stream: *mut FILE) -> size_t {
|
||||
let stream = unsafe { &mut *stream }.lock();
|
||||
|
||||
stream.writer.pending()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __freadable(stream: *mut FILE) -> c_int {
|
||||
let stream = unsafe { &mut *stream }.lock();
|
||||
|
||||
(stream.flags & F_NORD == 0) as c_int
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __fwritable(stream: *mut FILE) -> c_int {
|
||||
let stream = unsafe { &mut *stream }.lock();
|
||||
|
||||
@@ -25,7 +25,7 @@ pub extern "C" fn __fwritable(stream: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
//TODO: Check last operation when read-write
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __freading(stream: *mut FILE) -> c_int {
|
||||
let stream = unsafe { &mut *stream }.lock();
|
||||
|
||||
@@ -33,7 +33,7 @@ pub extern "C" fn __freading(stream: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
//TODO: Check last operation when read-write
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __fwriting(stream: *mut FILE) -> c_int {
|
||||
let stream = unsafe { &mut *stream }.lock();
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ use crate::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
header::stdio::{default_stdout, feof, ferror, F_EOF, F_ERR},
|
||||
header::stdio::{F_EOF, F_ERR, default_stdout, feof, ferror},
|
||||
platform::ERRNO,
|
||||
};
|
||||
|
||||
/// see getdelim (getline is a special case of getdelim with delim == '\n')
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getline(
|
||||
lineptr: *mut *mut c_char,
|
||||
n: *mut size_t,
|
||||
@@ -48,7 +48,7 @@ pub unsafe extern "C" fn getline(
|
||||
/// "If an error occurs, the error indicator for the stream shall be set, and the function shall
|
||||
/// return -1 and set errno to indicate the error." but in cases that produce EINVAL even glibc
|
||||
/// doesn't seem to set the error indicator, so we also don't.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getdelim(
|
||||
lineptr: *mut *mut c_char,
|
||||
n: *mut size_t,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use alloc::boxed::Box;
|
||||
|
||||
use super::{constants::*, Buffer, FILE};
|
||||
use super::{Buffer, FILE, constants::*};
|
||||
use crate::{
|
||||
c_str::CStr,
|
||||
error::Errno,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{fseek_locked, ftell_locked, FILE, SEEK_SET};
|
||||
use super::{FILE, SEEK_SET, fseek_locked, ftell_locked};
|
||||
use crate::{io::Read, platform::types::off_t};
|
||||
struct LookAheadBuffer {
|
||||
buf: *const u8,
|
||||
|
||||
+76
-84
@@ -27,7 +27,7 @@ use crate::{
|
||||
},
|
||||
io::{self, BufRead, BufWriter, LineWriter, Read, Write},
|
||||
out::Out,
|
||||
platform::{self, types::*, Pal, Sys, WriteByte, ERRNO},
|
||||
platform::{self, ERRNO, Pal, Sys, WriteByte, types::*},
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
@@ -274,24 +274,24 @@ impl<'a> Drop for LockGuard<'a> {
|
||||
}
|
||||
|
||||
/// Clears EOF and ERR indicators on a stream
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn clearerr(stream: *mut FILE) {
|
||||
let mut stream = (*stream).lock();
|
||||
stream.flags &= !(F_EOF | F_ERR);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ctermid(s: *mut c_char) -> *mut c_char {
|
||||
static mut TERMID: [u8; L_ctermid] = *b"/dev/tty\0";
|
||||
|
||||
if s.is_null() {
|
||||
return TERMID.as_mut_ptr() as *mut c_char;
|
||||
return &raw mut TERMID as *mut c_char;
|
||||
}
|
||||
|
||||
strncpy(s, TERMID.as_mut_ptr() as *mut c_char, L_ctermid)
|
||||
strncpy(s, &raw mut TERMID as *mut c_char, L_ctermid)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cuserid(s: *mut c_char) -> *mut c_char {
|
||||
let mut buf: Vec<c_char> = vec![0; 256];
|
||||
let mut pwd: pwd::passwd = unsafe { mem::zeroed() };
|
||||
@@ -322,7 +322,7 @@ pub unsafe extern "C" fn cuserid(s: *mut c_char) -> *mut c_char {
|
||||
/// This function does not guarentee that the file buffer will be flushed or that the file
|
||||
/// descriptor will be closed, so if it is important that the file be written to, use `fflush()`
|
||||
/// prior to using this function.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fclose(stream: *mut FILE) -> c_int {
|
||||
let stream = &mut *stream;
|
||||
flockfile(stream);
|
||||
@@ -345,7 +345,7 @@ pub unsafe extern "C" fn fclose(stream: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
/// Open a file from a file descriptor
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fdopen(fildes: c_int, mode: *const c_char) -> *mut FILE {
|
||||
helpers::_fdopen(fildes, CStr::from_ptr(mode))
|
||||
.map(|f| Box::into_raw(f))
|
||||
@@ -353,14 +353,14 @@ pub unsafe extern "C" fn fdopen(fildes: c_int, mode: *const c_char) -> *mut FILE
|
||||
}
|
||||
|
||||
/// Check for EOF
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn feof(stream: *mut FILE) -> c_int {
|
||||
let stream = (*stream).lock();
|
||||
stream.flags & F_EOF
|
||||
}
|
||||
|
||||
/// Check for ERR
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ferror(stream: *mut FILE) -> c_int {
|
||||
let stream = (*stream).lock();
|
||||
stream.flags & F_ERR
|
||||
@@ -369,7 +369,7 @@ pub unsafe extern "C" fn ferror(stream: *mut FILE) -> c_int {
|
||||
/// Flush output to stream, or sync read position
|
||||
/// Ensure the file is unlocked before calling this function, as it will attempt to lock the file
|
||||
/// itself.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fflush(stream: *mut FILE) -> c_int {
|
||||
if stream.is_null() {
|
||||
//TODO: flush all files!
|
||||
@@ -392,7 +392,7 @@ pub unsafe extern "C" fn fflush(stream: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
/// Get a single char from a stream
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fgetc(stream: *mut FILE) -> c_int {
|
||||
let mut stream = (*stream).lock();
|
||||
if let Err(_) = (*stream).try_set_byte_orientation_unlocked() {
|
||||
@@ -403,7 +403,7 @@ pub unsafe extern "C" fn fgetc(stream: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
/// Get the position of the stream and store it in pos
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fgetpos(stream: *mut FILE, pos: *mut fpos_t) -> c_int {
|
||||
let off = ftello(stream);
|
||||
if off < 0 {
|
||||
@@ -414,7 +414,7 @@ pub unsafe extern "C" fn fgetpos(stream: *mut FILE, pos: *mut fpos_t) -> c_int {
|
||||
}
|
||||
|
||||
/// Get a string from the stream
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fgets(
|
||||
original: *mut c_char,
|
||||
max: c_int,
|
||||
@@ -478,15 +478,11 @@ pub unsafe extern "C" fn fgets(
|
||||
// Write the NUL byte
|
||||
*out = 0;
|
||||
}
|
||||
if wrote {
|
||||
original
|
||||
} else {
|
||||
ptr::null_mut()
|
||||
}
|
||||
if wrote { original } else { ptr::null_mut() }
|
||||
}
|
||||
|
||||
/// Get the underlying file descriptor
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fileno(stream: *mut FILE) -> c_int {
|
||||
let stream = (*stream).lock();
|
||||
*stream.file
|
||||
@@ -495,13 +491,13 @@ pub unsafe extern "C" fn fileno(stream: *mut FILE) -> c_int {
|
||||
/// Lock the file
|
||||
/// Do not call any functions other than those with the `_unlocked` postfix while the file is
|
||||
/// locked
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn flockfile(file: *mut FILE) {
|
||||
(*file).lock.manual_lock();
|
||||
}
|
||||
|
||||
/// Open the file in mode `mode`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE {
|
||||
let initial_mode = *mode;
|
||||
if initial_mode != b'r' as c_char
|
||||
@@ -542,7 +538,7 @@ pub unsafe extern "C" fn fopen(filename: *const c_char, mode: *const c_char) ->
|
||||
/// Clear the buffers of a stream
|
||||
/// Ensure the file is unlocked before calling this function, as it will attempt to lock the file
|
||||
/// itself.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn __fpurge(stream: *mut FILE) {
|
||||
if !stream.is_null() {
|
||||
let mut stream = (*stream).lock();
|
||||
@@ -551,7 +547,7 @@ pub unsafe extern "C" fn __fpurge(stream: *mut FILE) {
|
||||
}
|
||||
|
||||
/// Insert a character into the stream
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fputc(c: c_int, stream: *mut FILE) -> c_int {
|
||||
let mut stream = (*stream).lock();
|
||||
if let Err(_) = (*stream).try_set_byte_orientation_unlocked() {
|
||||
@@ -562,7 +558,7 @@ pub unsafe extern "C" fn fputc(c: c_int, stream: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
/// Insert a string into a stream
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fputs(s: *const c_char, stream: *mut FILE) -> c_int {
|
||||
let mut stream = (*stream).lock();
|
||||
if let Err(_) = (*stream).try_set_byte_orientation_unlocked() {
|
||||
@@ -579,7 +575,7 @@ pub unsafe extern "C" fn fputs(s: *const c_char, stream: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
/// Read `nitems` of size `size` into `ptr` from `stream`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fread(
|
||||
ptr: *mut c_void,
|
||||
size: size_t,
|
||||
@@ -606,7 +602,7 @@ pub unsafe extern "C" fn fread(
|
||||
(read / size as usize) as size_t
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn freopen(
|
||||
filename: *const c_char,
|
||||
mode: *const c_char,
|
||||
@@ -662,13 +658,13 @@ pub unsafe extern "C" fn freopen(
|
||||
}
|
||||
|
||||
/// Seek to an offset `offset` from `whence`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int {
|
||||
fseeko(stream, offset as off_t, whence)
|
||||
}
|
||||
|
||||
/// Seek to an offset `offset` from `whence`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fseeko(stream: *mut FILE, off: off_t, whence: c_int) -> c_int {
|
||||
let mut stream = (*stream).lock();
|
||||
fseek_locked(&mut *stream, off, whence)
|
||||
@@ -699,19 +695,19 @@ pub unsafe fn fseek_locked(stream: &mut FILE, mut off: off_t, whence: c_int) ->
|
||||
}
|
||||
|
||||
/// Seek to a position `pos` in the file from the beginning of the file
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fsetpos(stream: *mut FILE, pos: *const fpos_t) -> c_int {
|
||||
fseeko(stream, *pos, SEEK_SET)
|
||||
}
|
||||
|
||||
/// Get the current position of the cursor in the file
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ftell(stream: *mut FILE) -> c_long {
|
||||
ftello(stream) as c_long
|
||||
}
|
||||
|
||||
/// Get the current position of the cursor in the file
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ftello(stream: *mut FILE) -> off_t {
|
||||
let mut stream = (*stream).lock();
|
||||
ftell_locked(&mut *stream)
|
||||
@@ -726,7 +722,7 @@ pub unsafe extern "C" fn ftell_locked(stream: &mut FILE) -> off_t {
|
||||
}
|
||||
|
||||
/// Try to lock the file. Returns 0 for success, 1 for failure
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ftrylockfile(file: *mut FILE) -> c_int {
|
||||
if (*file).lock.manual_try_lock().is_ok() {
|
||||
0
|
||||
@@ -736,13 +732,13 @@ pub unsafe extern "C" fn ftrylockfile(file: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
/// Unlock the file
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn funlockfile(file: *mut FILE) {
|
||||
(*file).lock.manual_unlock();
|
||||
}
|
||||
|
||||
/// Write `nitems` of size `size` from `ptr` to `stream`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fwrite(
|
||||
ptr: *const c_void,
|
||||
size: size_t,
|
||||
@@ -769,20 +765,20 @@ pub unsafe extern "C" fn fwrite(
|
||||
}
|
||||
|
||||
/// Get a single char from a stream
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getc(stream: *mut FILE) -> c_int {
|
||||
let mut stream = (*stream).lock();
|
||||
getc_unlocked(&mut *stream)
|
||||
}
|
||||
|
||||
/// Get a single char from `stdin`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getchar() -> c_int {
|
||||
fgetc(&mut *stdin)
|
||||
}
|
||||
|
||||
/// Get a char from a stream without locking the stream
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getc_unlocked(stream: *mut FILE) -> c_int {
|
||||
if let Err(_) = (*stream).try_set_byte_orientation_unlocked() {
|
||||
return -1;
|
||||
@@ -797,19 +793,19 @@ pub unsafe extern "C" fn getc_unlocked(stream: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
/// Get a char from `stdin` without locking `stdin`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getchar_unlocked() -> c_int {
|
||||
getc_unlocked(&mut *stdin)
|
||||
}
|
||||
|
||||
/// Get a string from `stdin`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn gets(s: *mut c_char) -> *mut c_char {
|
||||
fgets(s, c_int::max_value(), &mut *stdin)
|
||||
}
|
||||
|
||||
/// Get an integer from `stream`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getw(stream: *mut FILE) -> c_int {
|
||||
let mut ret: c_int = 0;
|
||||
if fread(
|
||||
@@ -825,7 +821,7 @@ pub unsafe extern "C" fn getw(stream: *mut FILE) -> c_int {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn pclose(stream: *mut FILE) -> c_int {
|
||||
// TODO: rusty error handling?
|
||||
let pid = {
|
||||
@@ -849,7 +845,7 @@ pub unsafe extern "C" fn pclose(stream: *mut FILE) -> c_int {
|
||||
wstatus
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn perror(s: *const c_char) {
|
||||
let err = ERRNO.get();
|
||||
let err_str = if err >= 0 && err < STR_ERROR.len() as c_int {
|
||||
@@ -868,7 +864,7 @@ pub unsafe extern "C" fn perror(s: *const c_char) {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn popen(command: *const c_char, mode: *const c_char) -> *mut FILE {
|
||||
//TODO: share code with system
|
||||
|
||||
@@ -963,20 +959,20 @@ pub unsafe extern "C" fn popen(command: *const c_char, mode: *const c_char) -> *
|
||||
}
|
||||
|
||||
/// Put a character `c` into `stream`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn putc(c: c_int, stream: *mut FILE) -> c_int {
|
||||
let mut stream = (*stream).lock();
|
||||
putc_unlocked(c, &mut *stream)
|
||||
}
|
||||
|
||||
/// Put a character `c` into `stdout`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn putchar(c: c_int) -> c_int {
|
||||
fputc(c, &mut *stdout)
|
||||
}
|
||||
|
||||
/// Put a character `c` into `stream` without locking `stream`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn putc_unlocked(c: c_int, stream: *mut FILE) -> c_int {
|
||||
if let Err(_) = (*stream).try_set_byte_orientation_unlocked() {
|
||||
return -1;
|
||||
@@ -989,13 +985,13 @@ pub unsafe extern "C" fn putc_unlocked(c: c_int, stream: *mut FILE) -> c_int {
|
||||
}
|
||||
|
||||
/// Put a character `c` into `stdout` without locking `stdout`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn putchar_unlocked(c: c_int) -> c_int {
|
||||
putc_unlocked(c, stdout)
|
||||
}
|
||||
|
||||
/// Put a string `s` into `stdout`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn puts(s: *const c_char) -> c_int {
|
||||
let mut stream = (&mut *stdout).lock();
|
||||
if let Err(_) = (*stream).try_set_byte_orientation_unlocked() {
|
||||
@@ -1014,13 +1010,13 @@ pub unsafe extern "C" fn puts(s: *const c_char) -> c_int {
|
||||
}
|
||||
|
||||
/// Put an integer `w` into `stream`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn putw(w: c_int, stream: *mut FILE) -> c_int {
|
||||
fwrite(&w as *const c_int as _, mem::size_of_val(&w), 1, stream) as i32 - 1
|
||||
}
|
||||
|
||||
/// Delete file or directory `path`
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn remove(path: *const c_char) -> c_int {
|
||||
let path = CStr::from_ptr(path);
|
||||
Sys::unlink(path)
|
||||
@@ -1029,7 +1025,7 @@ pub unsafe extern "C" fn remove(path: *const c_char) -> c_int {
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int {
|
||||
let oldpath = CStr::from_ptr(oldpath);
|
||||
let newpath = CStr::from_ptr(newpath);
|
||||
@@ -1039,13 +1035,13 @@ pub unsafe extern "C" fn rename(oldpath: *const c_char, newpath: *const c_char)
|
||||
}
|
||||
|
||||
/// Rewind `stream` back to the beginning of it
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn rewind(stream: *mut FILE) {
|
||||
fseeko(stream, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
/// Reset `stream` to use buffer `buf`. Buffer must be `BUFSIZ` in length
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setbuf(stream: *mut FILE, buf: *mut c_char) {
|
||||
setvbuf(
|
||||
stream,
|
||||
@@ -1056,14 +1052,14 @@ pub unsafe extern "C" fn setbuf(stream: *mut FILE, buf: *mut c_char) {
|
||||
}
|
||||
|
||||
/// Set buffering of `stream` to line buffered
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setlinebuf(stream: *mut FILE) {
|
||||
setvbuf(stream, ptr::null_mut(), _IOLBF, 0);
|
||||
}
|
||||
|
||||
/// Reset `stream` to use buffer `buf` of size `size`
|
||||
/// If this isn't the meaning of unsafe, idk what is
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setvbuf(
|
||||
stream: *mut FILE,
|
||||
buf: *mut c_char,
|
||||
@@ -1088,7 +1084,7 @@ pub unsafe extern "C" fn setvbuf(
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tempnam(dir: *const c_char, pfx: *const c_char) -> *mut c_char {
|
||||
unsafe fn is_appropriate(pos_dir: *const c_char) -> bool {
|
||||
!pos_dir.is_null() && unistd::access(pos_dir, unistd::W_OK) == 0
|
||||
@@ -1131,7 +1127,7 @@ pub unsafe extern "C" fn tempnam(dir: *const c_char, pfx: *const c_char) -> *mut
|
||||
out_buf
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tmpfile() -> *mut FILE {
|
||||
let mut file_name = *b"/tmp/tmpfileXXXXXX\0";
|
||||
let file_name = file_name.as_mut_ptr() as *mut c_char;
|
||||
@@ -1154,10 +1150,10 @@ pub unsafe extern "C" fn tmpfile() -> *mut FILE {
|
||||
fp
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tmpnam(s: *mut c_char) -> *mut c_char {
|
||||
let buf = if s.is_null() {
|
||||
TMPNAM_BUF.as_mut_ptr()
|
||||
&raw mut TMPNAM_BUF as *mut _
|
||||
} else {
|
||||
s
|
||||
};
|
||||
@@ -1176,15 +1172,11 @@ unsafe extern "C" fn tmpnam_inner(buf: *mut c_char, offset: usize) -> *mut c_cha
|
||||
stdlib::mktemp(buf);
|
||||
platform::ERRNO.set(err);
|
||||
|
||||
if *buf == 0 {
|
||||
ptr::null_mut()
|
||||
} else {
|
||||
buf
|
||||
}
|
||||
if *buf == 0 { ptr::null_mut() } else { buf }
|
||||
}
|
||||
|
||||
/// Push character `c` back onto `stream` so it'll be read next
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ungetc(c: c_int, stream: *mut FILE) -> c_int {
|
||||
let mut stream = (*stream).lock();
|
||||
if let Err(_) = (*stream).try_set_byte_orientation_unlocked() {
|
||||
@@ -1195,7 +1187,7 @@ pub unsafe extern "C" fn ungetc(c: c_int, stream: *mut FILE) -> c_int {
|
||||
c
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vfprintf(file: *mut FILE, format: *const c_char, ap: va_list) -> c_int {
|
||||
let mut file = (*file).lock();
|
||||
if let Err(_) = file.try_set_byte_orientation_unlocked() {
|
||||
@@ -1204,7 +1196,7 @@ pub unsafe extern "C" fn vfprintf(file: *mut FILE, format: *const c_char, ap: va
|
||||
|
||||
printf::printf(&mut *file, format, ap)
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fprintf(
|
||||
file: *mut FILE,
|
||||
format: *const c_char,
|
||||
@@ -1213,7 +1205,7 @@ pub unsafe extern "C" fn fprintf(
|
||||
vfprintf(file, format, __valist.as_va_list())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vdprintf(fd: c_int, format: *const c_char, ap: va_list) -> c_int {
|
||||
let mut f = File::new(fd);
|
||||
|
||||
@@ -1223,21 +1215,21 @@ pub unsafe extern "C" fn vdprintf(fd: c_int, format: *const c_char, ap: va_list)
|
||||
|
||||
printf::printf(f, format, ap)
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn dprintf(fd: c_int, format: *const c_char, mut __valist: ...) -> c_int {
|
||||
vdprintf(fd, format, __valist.as_va_list())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vprintf(format: *const c_char, ap: va_list) -> c_int {
|
||||
vfprintf(&mut *stdout, format, ap)
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn printf(format: *const c_char, mut __valist: ...) -> c_int {
|
||||
vfprintf(&mut *stdout, format, __valist.as_va_list())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vasprintf(
|
||||
strp: *mut *mut c_char,
|
||||
format: *const c_char,
|
||||
@@ -1250,7 +1242,7 @@ pub unsafe extern "C" fn vasprintf(
|
||||
*strp = alloc_writer.leak() as *mut c_char;
|
||||
ret
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn asprintf(
|
||||
strp: *mut *mut c_char,
|
||||
format: *const c_char,
|
||||
@@ -1259,7 +1251,7 @@ pub unsafe extern "C" fn asprintf(
|
||||
vasprintf(strp, format, __valist.as_va_list())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vsnprintf(
|
||||
s: *mut c_char,
|
||||
n: size_t,
|
||||
@@ -1272,7 +1264,7 @@ pub unsafe extern "C" fn vsnprintf(
|
||||
ap,
|
||||
)
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn snprintf(
|
||||
s: *mut c_char,
|
||||
n: size_t,
|
||||
@@ -1286,11 +1278,11 @@ pub unsafe extern "C" fn snprintf(
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vsprintf(s: *mut c_char, format: *const c_char, ap: va_list) -> c_int {
|
||||
printf::printf(&mut platform::UnsafeStringWriter(s as *mut u8), format, ap)
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sprintf(
|
||||
s: *mut c_char,
|
||||
format: *const c_char,
|
||||
@@ -1303,7 +1295,7 @@ pub unsafe extern "C" fn sprintf(
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vfscanf(file: *mut FILE, format: *const c_char, ap: va_list) -> c_int {
|
||||
let ret = {
|
||||
let mut file = (*file).lock();
|
||||
@@ -1317,7 +1309,7 @@ pub unsafe extern "C" fn vfscanf(file: *mut FILE, format: *const c_char, ap: va_
|
||||
};
|
||||
ret
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn fscanf(
|
||||
file: *mut FILE,
|
||||
format: *const c_char,
|
||||
@@ -1326,21 +1318,21 @@ pub unsafe extern "C" fn fscanf(
|
||||
vfscanf(file, format, __valist.as_va_list())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vscanf(format: *const c_char, ap: va_list) -> c_int {
|
||||
vfscanf(&mut *stdin, format, ap)
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn scanf(format: *const c_char, mut __valist: ...) -> c_int {
|
||||
vfscanf(&mut *stdin, format, __valist.as_va_list())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn vsscanf(s: *const c_char, format: *const c_char, ap: va_list) -> c_int {
|
||||
let reader = (s as *const u8).into();
|
||||
scanf::scanf(reader, format, ap)
|
||||
}
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sscanf(
|
||||
s: *const c_char,
|
||||
format: *const c_char,
|
||||
|
||||
@@ -109,9 +109,13 @@ impl VaArg {
|
||||
|
||||
(FmtKind::Char, _)
|
||||
| (FmtKind::Unsigned, IntKind::Byte)
|
||||
| (FmtKind::Signed, IntKind::Byte) => VaArg::c_char(ap.arg::<c_char>()),
|
||||
| (FmtKind::Signed, IntKind::Byte) => {
|
||||
// c_int is passed but truncated to c_char
|
||||
VaArg::c_char(ap.arg::<c_int>() as c_char)
|
||||
}
|
||||
(FmtKind::Unsigned, IntKind::Short) | (FmtKind::Signed, IntKind::Short) => {
|
||||
VaArg::c_short(ap.arg::<c_short>())
|
||||
// c_int is passed but truncated to c_short
|
||||
VaArg::c_short(ap.arg::<c_int>() as c_short)
|
||||
}
|
||||
(FmtKind::Unsigned, IntKind::Int) | (FmtKind::Signed, IntKind::Int) => {
|
||||
VaArg::c_int(ap.arg::<c_int>())
|
||||
|
||||
@@ -19,11 +19,7 @@ enum IntKind {
|
||||
unsafe fn next_byte(string: &mut *const c_char) -> Result<u8, c_int> {
|
||||
let c = **string as u8;
|
||||
*string = string.offset(1);
|
||||
if c == 0 {
|
||||
Err(-1)
|
||||
} else {
|
||||
Ok(c)
|
||||
}
|
||||
if c == 0 { Err(-1) } else { Ok(c) }
|
||||
}
|
||||
|
||||
unsafe fn inner_scanf(
|
||||
|
||||
+146
-145
@@ -4,8 +4,8 @@
|
||||
|
||||
use core::{convert::TryFrom, intrinsics, iter, mem, ptr, slice};
|
||||
use rand::{
|
||||
distributions::{Alphanumeric, Distribution, Uniform},
|
||||
Rng, SeedableRng,
|
||||
distributions::{Alphanumeric, Distribution, Uniform},
|
||||
};
|
||||
use rand_jitter::JitterRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
@@ -23,12 +23,13 @@ use crate::{
|
||||
string::*,
|
||||
sys_ioctl::*,
|
||||
time::constants::CLOCK_MONOTONIC,
|
||||
unistd::{self, sysconf, _SC_PAGESIZE},
|
||||
unistd::{self, _SC_PAGESIZE, sysconf},
|
||||
wchar::*,
|
||||
},
|
||||
ld_so,
|
||||
out::Out,
|
||||
platform::{self, types::*, Pal, Sys},
|
||||
platform::{self, Pal, Sys, types::*},
|
||||
raw_cell::RawCell,
|
||||
sync::Once,
|
||||
};
|
||||
|
||||
@@ -50,9 +51,9 @@ pub const MB_CUR_MAX: c_int = 4;
|
||||
//Maximum number of bytes in a multibyte characters for any locale
|
||||
pub const MB_LEN_MAX: c_int = 4;
|
||||
|
||||
static mut ATEXIT_FUNCS: [Option<extern "C" fn()>; 32] = [None; 32];
|
||||
static mut AT_QUICK_EXIT_FUNCS: [Option<extern "C" fn()>; 32] = [None; 32];
|
||||
static mut L64A_BUFFER: [c_char; 7] = [0; 7]; // up to 6 digits plus null terminator
|
||||
static ATEXIT_FUNCS: RawCell<[Option<extern "C" fn()>; 32]> = RawCell::new([None; 32]);
|
||||
static AT_QUICK_EXIT_FUNCS: RawCell<[Option<extern "C" fn()>; 32]> = RawCell::new([None; 32]);
|
||||
static L64A_BUFFER: RawCell<[c_char; 7]> = RawCell::new([0; 7]); // up to 6 digits plus null terminator
|
||||
static mut RNG: Option<XorShiftRng> = None;
|
||||
|
||||
// TODO: This could be const fn, but the trait system won't allow that.
|
||||
@@ -63,13 +64,13 @@ fn rng_sampler() -> &'static Uniform<c_int> {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/_Exit.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn _Exit(status: c_int) -> ! {
|
||||
unistd::_exit(status);
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/a64l.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn a64l(s: *const c_char) -> c_long {
|
||||
// Early return upon null pointer argument
|
||||
if s.is_null() {
|
||||
@@ -107,33 +108,33 @@ pub unsafe extern "C" fn a64l(s: *const c_char) -> c_long {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/abort.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn abort() -> ! {
|
||||
eprintln!("Abort");
|
||||
intrinsics::abort();
|
||||
}
|
||||
|
||||
#[cfg(not(target_pointer_width = "64"))]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
static __stack_chk_guard: uintptr_t = 0x19fcadfe;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
static __stack_chk_guard: uintptr_t = 0xd048c37519fcadfe;
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn __stack_chk_fail() -> ! {
|
||||
abort();
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/abs.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn abs(i: c_int) -> c_int {
|
||||
i.abs()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/aligned_alloc.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void {
|
||||
if size % alignment == 0 {
|
||||
/* The size-is-multiple-of-alignment requirement is the only
|
||||
@@ -146,11 +147,11 @@ pub unsafe extern "C" fn aligned_alloc(alignment: size_t, size: size_t) -> *mut
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/at_quick_exit.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn at_quick_exit(func: Option<extern "C" fn()>) -> c_int {
|
||||
for i in 0..AT_QUICK_EXIT_FUNCS.len() {
|
||||
if AT_QUICK_EXIT_FUNCS[i] == None {
|
||||
AT_QUICK_EXIT_FUNCS[i] = func;
|
||||
for i in 0..AT_QUICK_EXIT_FUNCS.unsafe_ref().len() {
|
||||
if AT_QUICK_EXIT_FUNCS.unsafe_ref()[i] == None {
|
||||
AT_QUICK_EXIT_FUNCS.unsafe_mut()[i] = func;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -159,11 +160,11 @@ pub unsafe extern "C" fn at_quick_exit(func: Option<extern "C" fn()>) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atexit.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn atexit(func: Option<extern "C" fn()>) -> c_int {
|
||||
for i in 0..ATEXIT_FUNCS.len() {
|
||||
if ATEXIT_FUNCS[i] == None {
|
||||
ATEXIT_FUNCS[i] = func;
|
||||
for i in 0..ATEXIT_FUNCS.unsafe_ref().len() {
|
||||
if ATEXIT_FUNCS.unsafe_ref()[i] == None {
|
||||
ATEXIT_FUNCS.unsafe_mut()[i] = func;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -172,7 +173,7 @@ pub unsafe extern "C" fn atexit(func: Option<extern "C" fn()>) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atof.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn atof(s: *const c_char) -> c_double {
|
||||
strtod(s, ptr::null_mut())
|
||||
}
|
||||
@@ -205,28 +206,24 @@ macro_rules! dec_num_from_ascii {
|
||||
s = s.offset(1);
|
||||
}
|
||||
|
||||
if neg_sign {
|
||||
n
|
||||
} else {
|
||||
-n
|
||||
}
|
||||
if neg_sign { n } else { -n }
|
||||
}};
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atoi.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn atoi(s: *const c_char) -> c_int {
|
||||
dec_num_from_ascii!(s, c_int)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atol.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn atol(s: *const c_char) -> c_long {
|
||||
dec_num_from_ascii!(s, c_long)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atol.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn atoll(s: *const c_char) -> c_longlong {
|
||||
dec_num_from_ascii!(s, c_longlong)
|
||||
}
|
||||
@@ -236,7 +233,7 @@ unsafe extern "C" fn void_cmp(a: *const c_void, b: *const c_void) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/bsearch.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn bsearch(
|
||||
key: *const c_void,
|
||||
base: *const c_void,
|
||||
@@ -262,7 +259,7 @@ pub unsafe extern "C" fn bsearch(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/calloc.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn calloc(nelem: size_t, elsize: size_t) -> *mut c_void {
|
||||
//Handle possible integer overflow in size calculation
|
||||
match nelem.checked_mul(elsize) {
|
||||
@@ -291,7 +288,7 @@ pub struct div_t {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/div.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn div(numer: c_int, denom: c_int) -> div_t {
|
||||
div_t {
|
||||
quot: numer / denom,
|
||||
@@ -304,7 +301,7 @@ pub extern "C" fn div(numer: c_int, denom: c_int) -> div_t {
|
||||
/// # Panics
|
||||
/// Panics if the function is unable to obtain a lock on the generator's global
|
||||
/// state.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn drand48() -> c_double {
|
||||
let params = rand48::params();
|
||||
let mut xsubi = rand48::xsubi_lock();
|
||||
@@ -318,7 +315,7 @@ pub extern "C" fn drand48() -> c_double {
|
||||
/// The `ecvt()` function was marked as legacy in the Open Group Base
|
||||
/// Specifications Issue 6, and the function was removed in Issue 7.
|
||||
#[deprecated]
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn ecvt(
|
||||
value: c_double,
|
||||
ndigit: c_int,
|
||||
@@ -337,7 +334,7 @@ pub extern "C" fn ecvt(
|
||||
/// # Panics
|
||||
/// Panics if the function is unable to obtain a lock on the generator's global
|
||||
/// state.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn erand48(xsubi: *mut c_ushort) -> c_double {
|
||||
let params = rand48::params();
|
||||
let xsubi_mut: &mut [c_ushort; 3] = slice::from_raw_parts_mut(xsubi, 3).try_into().unwrap();
|
||||
@@ -347,17 +344,17 @@ pub unsafe extern "C" fn erand48(xsubi: *mut c_ushort) -> c_double {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exit.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn exit(status: c_int) -> ! {
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
static __fini_array_start: extern "C" fn();
|
||||
static __fini_array_end: extern "C" fn();
|
||||
|
||||
fn _fini();
|
||||
}
|
||||
|
||||
for i in (0..ATEXIT_FUNCS.len()).rev() {
|
||||
if let Some(func) = ATEXIT_FUNCS[i] {
|
||||
for i in (0..ATEXIT_FUNCS.unsafe_ref().len()).rev() {
|
||||
if let Some(func) = ATEXIT_FUNCS.unsafe_ref()[i] {
|
||||
(func)();
|
||||
}
|
||||
}
|
||||
@@ -390,7 +387,7 @@ pub unsafe extern "C" fn exit(status: c_int) -> ! {
|
||||
/// The `fcvt()` function was marked as legacy in the Open Group Base
|
||||
/// Specifications Issue 6, and the function was removed in Issue 7.
|
||||
#[deprecated]
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn fcvt(
|
||||
value: c_double,
|
||||
ndigit: c_int,
|
||||
@@ -401,7 +398,7 @@ pub extern "C" fn fcvt(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/free.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn free(ptr: *mut c_void) {
|
||||
platform::free(ptr);
|
||||
}
|
||||
@@ -412,7 +409,7 @@ pub unsafe extern "C" fn free(ptr: *mut c_void) {
|
||||
/// The `gcvt()` function was marked as legacy in the Open Group Base
|
||||
/// Specifications Issue 6, and the function was removed in Issue 7.
|
||||
#[deprecated]
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn gcvt(value: c_double, ndigit: c_int, buf: *mut c_char) -> *mut c_char {
|
||||
unimplemented!();
|
||||
}
|
||||
@@ -445,13 +442,13 @@ unsafe fn find_env(search: *const c_char) -> Option<(usize, *mut c_char)> {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getenv.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getenv(name: *const c_char) -> *mut c_char {
|
||||
find_env(name).map(|val| val.1).unwrap_or(ptr::null_mut())
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getsubopt.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn getsubopt(
|
||||
optionp: *mut *mut c_char,
|
||||
tokens: *const *mut c_char,
|
||||
@@ -487,7 +484,7 @@ pub unsafe extern "C" fn getsubopt(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/grantpt.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn grantpt(fildes: c_int) -> c_int {
|
||||
// No-op on Linux and Redox
|
||||
0
|
||||
@@ -495,7 +492,7 @@ pub extern "C" fn grantpt(fildes: c_int) -> c_int {
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/initstate.html>.
|
||||
// Ported from musl
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn initstate(seed: c_uint, state: *mut c_char, size: size_t) -> *mut c_char {
|
||||
if size < 8 {
|
||||
ptr::null_mut()
|
||||
@@ -528,7 +525,7 @@ pub unsafe extern "C" fn initstate(seed: c_uint, state: *mut c_char, size: size_
|
||||
/// # Panics
|
||||
/// Panics if the function is unable to obtain a lock on the generator's global
|
||||
/// state.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn jrand48(xsubi: *mut c_ushort) -> c_long {
|
||||
let params = rand48::params();
|
||||
let xsubi_mut: &mut [c_ushort; 3] = slice::from_raw_parts_mut(xsubi, 3).try_into().unwrap();
|
||||
@@ -538,7 +535,7 @@ pub unsafe extern "C" fn jrand48(xsubi: *mut c_ushort) -> c_long {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/a64l.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn l64a(value: c_long) -> *mut c_char {
|
||||
// POSIX says we should only consider the lower 32 bits of value.
|
||||
let value_as_i32 = value as i32;
|
||||
@@ -551,13 +548,13 @@ pub unsafe extern "C" fn l64a(value: c_long) -> *mut c_char {
|
||||
let num_output_digits = usize::try_from(6 - (value_as_i32.leading_zeros() + 4) / 6).unwrap();
|
||||
|
||||
// Reset buffer (and have null terminator in place for any result)
|
||||
L64A_BUFFER = [0; 7];
|
||||
L64A_BUFFER.unsafe_set([0; 7]);
|
||||
|
||||
for i in 0..num_output_digits {
|
||||
// Conversion to c_char always succeeds for the range 0..=63
|
||||
let digit_value = c_char::try_from((value_as_i32 >> 6 * i) & 63).unwrap();
|
||||
|
||||
L64A_BUFFER[i] = match digit_value {
|
||||
L64A_BUFFER.unsafe_mut()[i] = match digit_value {
|
||||
0..=11 => {
|
||||
// ./0123456789 for values 0 to 11. b'.' == 46
|
||||
46 + digit_value
|
||||
@@ -574,11 +571,11 @@ pub unsafe extern "C" fn l64a(value: c_long) -> *mut c_char {
|
||||
};
|
||||
}
|
||||
|
||||
L64A_BUFFER.as_mut_ptr()
|
||||
L64A_BUFFER.unsafe_mut().as_mut_ptr()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/labs.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn labs(i: c_long) -> c_long {
|
||||
i.abs()
|
||||
}
|
||||
@@ -592,7 +589,7 @@ pub extern "C" fn labs(i: c_long) -> c_long {
|
||||
/// # Panics
|
||||
/// Panics if the function is unable to obtain a lock on the generator's global
|
||||
/// state.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn lcong48(param: *mut c_ushort) {
|
||||
let mut xsubi = rand48::xsubi_lock();
|
||||
let mut params = rand48::params_mut();
|
||||
@@ -615,7 +612,7 @@ pub struct ldiv_t {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ldiv.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn ldiv(numer: c_long, denom: c_long) -> ldiv_t {
|
||||
ldiv_t {
|
||||
quot: numer / denom,
|
||||
@@ -624,7 +621,7 @@ pub extern "C" fn ldiv(numer: c_long, denom: c_long) -> ldiv_t {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/labs.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn llabs(i: c_longlong) -> c_longlong {
|
||||
i.abs()
|
||||
}
|
||||
@@ -637,7 +634,7 @@ pub struct lldiv_t {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ldiv.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t {
|
||||
lldiv_t {
|
||||
quot: numer / denom,
|
||||
@@ -650,7 +647,7 @@ pub extern "C" fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t {
|
||||
/// # Panics
|
||||
/// Panics if the function is unable to obtain a lock on the generator's global
|
||||
/// state.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn lrand48() -> c_long {
|
||||
let params = rand48::params();
|
||||
let mut xsubi = rand48::xsubi_lock();
|
||||
@@ -659,7 +656,7 @@ pub extern "C" fn lrand48() -> c_long {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/malloc.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
|
||||
let ptr = platform::alloc(size);
|
||||
if ptr.is_null() {
|
||||
@@ -670,7 +667,7 @@ pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
|
||||
|
||||
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/posix_memalign.3.html>.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn memalign(alignment: size_t, size: size_t) -> *mut c_void {
|
||||
if alignment.is_power_of_two() {
|
||||
let ptr = platform::alloc_align(size, alignment);
|
||||
@@ -685,7 +682,7 @@ pub unsafe extern "C" fn memalign(alignment: size_t, size: size_t) -> *mut c_voi
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mblen.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mblen(s: *const c_char, n: size_t) -> c_int {
|
||||
let mut wc: wchar_t = 0;
|
||||
let mut state: mbstate_t = mbstate_t {};
|
||||
@@ -702,14 +699,14 @@ pub unsafe extern "C" fn mblen(s: *const c_char, n: size_t) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mbstowcs.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mbstowcs(pwcs: *mut wchar_t, mut s: *const c_char, n: size_t) -> size_t {
|
||||
let mut state: mbstate_t = mbstate_t {};
|
||||
mbsrtowcs(pwcs, &mut s, n, &mut state)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mbtowc.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mbtowc(pwc: *mut wchar_t, s: *const c_char, n: size_t) -> c_int {
|
||||
let mut state: mbstate_t = mbstate_t {};
|
||||
mbrtowc(pwc, s, n, &mut state) as c_int
|
||||
@@ -767,7 +764,7 @@ fn get_nstime() -> u64 {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkdtemp.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mkdtemp(name: *mut c_char) -> *mut c_char {
|
||||
inner_mktemp(name, 0, || {
|
||||
let name_c = CStr::from_ptr(name);
|
||||
@@ -780,13 +777,13 @@ pub unsafe extern "C" fn mkdtemp(name: *mut c_char) -> *mut c_char {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkdtemp.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mkostemp(name: *mut c_char, flags: c_int) -> c_int {
|
||||
mkostemps(name, 0, flags)
|
||||
}
|
||||
|
||||
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/mkstemp.3.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mkostemps(
|
||||
name: *mut c_char,
|
||||
suffix_len: c_int,
|
||||
@@ -801,23 +798,19 @@ pub unsafe extern "C" fn mkostemps(
|
||||
let name = CStr::from_ptr(name);
|
||||
let fd = Sys::open(name, flags, 0o600).or_minus_one_errno();
|
||||
|
||||
if fd >= 0 {
|
||||
Some(fd)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if fd >= 0 { Some(fd) } else { None }
|
||||
})
|
||||
.unwrap_or(-1)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkdtemp.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mkstemp(name: *mut c_char) -> c_int {
|
||||
mkostemps(name, 0, 0)
|
||||
}
|
||||
|
||||
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/mkstemp.3.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mkstemps(name: *mut c_char, suffix_len: c_int) -> c_int {
|
||||
mkostemps(name, suffix_len, 0)
|
||||
}
|
||||
@@ -828,7 +821,7 @@ pub unsafe extern "C" fn mkstemps(name: *mut c_char, suffix_len: c_int) -> c_int
|
||||
/// The `mktemp()` function was marked as legacy in the Open Group Base
|
||||
/// Specifications Issue 6, and the function was removed in Issue 7.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mktemp(name: *mut c_char) -> *mut c_char {
|
||||
if inner_mktemp(name, 0, || {
|
||||
let name = CStr::from_ptr(name);
|
||||
@@ -850,7 +843,7 @@ pub unsafe extern "C" fn mktemp(name: *mut c_char) -> *mut c_char {
|
||||
/// # Panics
|
||||
/// Panics if the function is unable to obtain a lock on the generator's global
|
||||
/// state.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn mrand48() -> c_long {
|
||||
let params = rand48::params();
|
||||
let mut xsubi = rand48::xsubi_lock();
|
||||
@@ -867,7 +860,7 @@ pub extern "C" fn mrand48() -> c_long {
|
||||
/// # Panics
|
||||
/// Panics if the function is unable to obtain a lock on the generator's global
|
||||
/// state.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn nrand48(xsubi: *mut c_ushort) -> c_long {
|
||||
let params = rand48::params();
|
||||
let xsubi_mut: &mut [c_ushort; 3] = slice::from_raw_parts_mut(xsubi, 3).try_into().unwrap();
|
||||
@@ -877,7 +870,7 @@ pub unsafe extern "C" fn nrand48(xsubi: *mut c_ushort) -> c_long {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_memalign.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn posix_memalign(
|
||||
memptr: *mut *mut c_void,
|
||||
alignment: size_t,
|
||||
@@ -888,11 +881,7 @@ pub unsafe extern "C" fn posix_memalign(
|
||||
if alignment % VOID_PTR_SIZE == 0 && alignment.is_power_of_two() {
|
||||
let ptr = platform::alloc_align(size, alignment);
|
||||
*memptr = ptr;
|
||||
if ptr.is_null() {
|
||||
ENOMEM
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if ptr.is_null() { ENOMEM } else { 0 }
|
||||
} else {
|
||||
*memptr = ptr::null_mut();
|
||||
EINVAL
|
||||
@@ -900,7 +889,7 @@ pub unsafe extern "C" fn posix_memalign(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_openpt.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn posix_openpt(flags: c_int) -> c_int {
|
||||
#[cfg(target_os = "redox")]
|
||||
let r = open((b"/scheme/pty\0" as *const u8).cast(), O_CREAT);
|
||||
@@ -916,19 +905,19 @@ pub unsafe extern "C" fn posix_openpt(flags: c_int) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ptsname.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ptsname(fd: c_int) -> *mut c_char {
|
||||
static mut PTS_BUFFER: [c_char; 9 + mem::size_of::<c_int>() * 3 + 1] =
|
||||
[0; 9 + mem::size_of::<c_int>() * 3 + 1];
|
||||
if ptsname_r(fd, PTS_BUFFER.as_mut_ptr(), PTS_BUFFER.len()) != 0 {
|
||||
const PTS_BUFFER_LEN: usize = 9 + mem::size_of::<c_int>() * 3 + 1;
|
||||
static mut PTS_BUFFER: [c_char; PTS_BUFFER_LEN] = [0; PTS_BUFFER_LEN];
|
||||
if ptsname_r(fd, &raw mut PTS_BUFFER as *mut _, PTS_BUFFER_LEN) != 0 {
|
||||
ptr::null_mut()
|
||||
} else {
|
||||
PTS_BUFFER.as_mut_ptr()
|
||||
&raw mut PTS_BUFFER as *mut _
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ptsname.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
|
||||
if buf.is_null() {
|
||||
platform::ERRNO.set(EINVAL);
|
||||
@@ -989,22 +978,28 @@ unsafe fn __ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
|
||||
unsafe fn put_new_env(insert: *mut c_char) {
|
||||
// XXX: Another problem is that `environ` can be set to any pointer, which means there is a
|
||||
// chance of a memory leak. But we can check if it was the same as before, like musl does.
|
||||
if platform::environ == platform::OUR_ENVIRON.as_mut_ptr() {
|
||||
*platform::OUR_ENVIRON.last_mut().unwrap() = insert;
|
||||
platform::OUR_ENVIRON.push(core::ptr::null_mut());
|
||||
if platform::environ == platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr() {
|
||||
{
|
||||
let mut our_environ = &mut *platform::OUR_ENVIRON.as_mut_ptr();
|
||||
*our_environ.last_mut().unwrap() = insert;
|
||||
our_environ.push(core::ptr::null_mut());
|
||||
}
|
||||
// Likely a no-op but is needed due to Stacked Borrows.
|
||||
platform::environ = platform::OUR_ENVIRON.as_mut_ptr();
|
||||
platform::environ = platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr();
|
||||
} else {
|
||||
platform::OUR_ENVIRON.clear();
|
||||
platform::OUR_ENVIRON.extend(platform::environ_iter());
|
||||
platform::OUR_ENVIRON.push(insert);
|
||||
platform::OUR_ENVIRON.push(core::ptr::null_mut());
|
||||
platform::environ = platform::OUR_ENVIRON.as_mut_ptr();
|
||||
{
|
||||
let mut our_environ = &mut *platform::OUR_ENVIRON.as_mut_ptr();
|
||||
our_environ.clear();
|
||||
our_environ.extend(platform::environ_iter());
|
||||
our_environ.push(insert);
|
||||
our_environ.push(core::ptr::null_mut());
|
||||
}
|
||||
platform::environ = platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr();
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/putenv.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn putenv(insert: *mut c_char) -> c_int {
|
||||
assert_ne!(insert, ptr::null_mut(), "putenv(NULL)");
|
||||
if let Some((i, _)) = find_env(insert) {
|
||||
@@ -1019,7 +1014,7 @@ pub unsafe extern "C" fn putenv(insert: *mut c_char) -> c_int {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/qsort.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn qsort(
|
||||
base: *mut c_void,
|
||||
nel: size_t,
|
||||
@@ -1037,7 +1032,7 @@ pub unsafe extern "C" fn qsort(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/qsort.html>.
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn qsort_r(
|
||||
base: *mut c_void,
|
||||
nel: size_t,
|
||||
@@ -1049,10 +1044,10 @@ pub unsafe extern "C" fn qsort_r(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/quick_exit.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn quick_exit(status: c_int) -> ! {
|
||||
for i in (0..AT_QUICK_EXIT_FUNCS.len()).rev() {
|
||||
if let Some(func) = AT_QUICK_EXIT_FUNCS[i] {
|
||||
for i in (0..AT_QUICK_EXIT_FUNCS.unsafe_ref().len()).rev() {
|
||||
if let Some(func) = AT_QUICK_EXIT_FUNCS.unsafe_ref()[i] {
|
||||
(func)();
|
||||
}
|
||||
}
|
||||
@@ -1061,7 +1056,7 @@ pub unsafe extern "C" fn quick_exit(status: c_int) -> ! {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rand.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn rand() -> c_int {
|
||||
match RNG {
|
||||
Some(ref mut rng) => rng_sampler().sample(rng),
|
||||
@@ -1079,7 +1074,7 @@ pub unsafe extern "C" fn rand() -> c_int {
|
||||
/// # Deprecation
|
||||
/// The `rand_r()` function was marked as obsolescent in the Open Group Base
|
||||
/// Specifications Issue 7, and the function was removed in Issue 8.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn rand_r(seed: *mut c_uint) -> c_int {
|
||||
if seed.is_null() {
|
||||
errno::EINVAL
|
||||
@@ -1098,7 +1093,7 @@ pub unsafe extern "C" fn rand_r(seed: *mut c_uint) -> c_int {
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/initstate.html>.
|
||||
// Ported from musl
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn random() -> c_long {
|
||||
let mut random_state = random::state_lock();
|
||||
|
||||
@@ -1137,7 +1132,7 @@ pub unsafe extern "C" fn random() -> c_long {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/realloc.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void {
|
||||
let new_ptr = platform::realloc(ptr, size);
|
||||
if new_ptr.is_null() {
|
||||
@@ -1147,7 +1142,7 @@ pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/realloc.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn reallocarray(ptr: *mut c_void, m: size_t, n: size_t) -> *mut c_void {
|
||||
//Handle possible integer overflow in size calculation
|
||||
match m.checked_mul(n) {
|
||||
@@ -1161,7 +1156,7 @@ pub unsafe extern "C" fn reallocarray(ptr: *mut c_void, m: size_t, n: size_t) ->
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/realpath.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn realpath(pathname: *const c_char, resolved: *mut c_char) -> *mut c_char {
|
||||
let ptr = if resolved.is_null() {
|
||||
malloc(limits::PATH_MAX) as *mut c_char
|
||||
@@ -1191,7 +1186,7 @@ pub unsafe extern "C" fn realpath(pathname: *const c_char, resolved: *mut c_char
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getenv.html>.
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn secure_getenv(name: *const c_char) -> *mut c_char {
|
||||
unimplemented!();
|
||||
}
|
||||
@@ -1207,7 +1202,7 @@ pub unsafe extern "C" fn secure_getenv(name: *const c_char) -> *mut c_char {
|
||||
/// # Panics
|
||||
/// Panics if the function is unable to obtain a lock on the generator's global
|
||||
/// state.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn seed48(seed16v: *mut c_ushort) -> *mut c_ushort {
|
||||
static mut BUFFER: [c_ushort; 3] = [0; 3];
|
||||
|
||||
@@ -1219,7 +1214,7 @@ pub unsafe extern "C" fn seed48(seed16v: *mut c_ushort) -> *mut c_ushort {
|
||||
BUFFER = (*xsubi).into();
|
||||
*xsubi = seed16v_ref.into();
|
||||
params.reset();
|
||||
BUFFER.as_mut_ptr()
|
||||
&raw mut BUFFER as *mut _
|
||||
}
|
||||
|
||||
unsafe fn copy_kv(
|
||||
@@ -1236,7 +1231,7 @@ unsafe fn copy_kv(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setenv.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setenv(
|
||||
key: *const c_char,
|
||||
value: *const c_char,
|
||||
@@ -1281,14 +1276,14 @@ pub unsafe extern "C" fn setenv(
|
||||
/// The `setkey()` function was marked as obsolescent in the Open Group Base
|
||||
/// Specifications Issue 8.
|
||||
#[deprecated]
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setkey(key: *const c_char) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/initstate.html>.
|
||||
// Ported from musl. The state parameter is no longer const in newer versions of POSIX.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn setstate(state: *mut c_char) -> *mut c_char {
|
||||
let mut random_state = random::state_lock();
|
||||
|
||||
@@ -1299,7 +1294,7 @@ pub unsafe extern "C" fn setstate(state: *mut c_char) -> *mut c_char {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rand.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn srand(seed: c_uint) {
|
||||
RNG = Some(XorShiftRng::from_seed([seed as u8; 16]));
|
||||
}
|
||||
@@ -1309,7 +1304,7 @@ pub unsafe extern "C" fn srand(seed: c_uint) {
|
||||
/// # Panics
|
||||
/// Panics if the function is unable to obtain a lock on the generator's global
|
||||
/// state.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn srand48(seedval: c_long) {
|
||||
let mut params = rand48::params_mut();
|
||||
let mut xsubi = rand48::xsubi_lock();
|
||||
@@ -1325,7 +1320,7 @@ pub extern "C" fn srand48(seedval: c_long) {
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/initstate.html>.
|
||||
// Ported from musl
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn srandom(seed: c_uint) {
|
||||
let mut random_state = random::state_lock();
|
||||
|
||||
@@ -1440,19 +1435,19 @@ pub unsafe fn convert_integer(s: *const c_char, base: c_int) -> Option<(c_ulong,
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtod.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn strtod(s: *const c_char, endptr: *mut *mut c_char) -> c_double {
|
||||
strto_float_impl!(c_double, s, endptr)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtod.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn strtof(s: *const c_char, endptr: *mut *mut c_char) -> c_float {
|
||||
strto_float_impl!(c_float, s, endptr)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtol.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn strtol(s: *const c_char, endptr: *mut *mut c_char, base: c_int) -> c_long {
|
||||
strto_impl!(
|
||||
c_long,
|
||||
@@ -1468,7 +1463,7 @@ pub unsafe extern "C" fn strtol(s: *const c_char, endptr: *mut *mut c_char, base
|
||||
// TODO: strtold(), when long double is available
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtol.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn strtoll(
|
||||
s: *const c_char,
|
||||
endptr: *mut *mut c_char,
|
||||
@@ -1486,7 +1481,7 @@ pub unsafe extern "C" fn strtoll(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoul.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn strtoul(
|
||||
s: *const c_char,
|
||||
endptr: *mut *mut c_char,
|
||||
@@ -1504,7 +1499,7 @@ pub unsafe extern "C" fn strtoul(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoul.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn strtoull(
|
||||
s: *const c_char,
|
||||
endptr: *mut *mut c_char,
|
||||
@@ -1522,7 +1517,7 @@ pub unsafe extern "C" fn strtoull(
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/system.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn system(command: *const c_char) -> c_int {
|
||||
// TODO: rusty error handling?
|
||||
//TODO: share code with popen
|
||||
@@ -1574,39 +1569,45 @@ pub unsafe extern "C" fn system(command: *const c_char) -> c_int {
|
||||
/// The `ttyslot()` function was marked as obsolescent in the Open Group Base
|
||||
/// Specifications Issue 5, and the function was removed in Issue 6.
|
||||
#[deprecated]
|
||||
// #[no_mangle]
|
||||
// #[unsafe(no_mangle)]
|
||||
pub extern "C" fn ttyslot() -> c_int {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/unlockpt.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn unlockpt(fildes: c_int) -> c_int {
|
||||
let mut u: c_int = 0;
|
||||
ioctl(fildes, TIOCSPTLCK, &mut u as *mut i32 as *mut c_void)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/unsetenv.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn unsetenv(key: *const c_char) -> c_int {
|
||||
if let Some((i, _)) = find_env(key) {
|
||||
if platform::environ == platform::OUR_ENVIRON.as_mut_ptr() {
|
||||
if platform::environ == platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr() {
|
||||
// No need to worry about updating the pointer, this does not
|
||||
// reallocate in any way. And the final null is already shifted back.
|
||||
platform::OUR_ENVIRON.remove(i);
|
||||
{
|
||||
let mut our_environ = &mut *platform::OUR_ENVIRON.as_mut_ptr();
|
||||
our_environ.remove(i);
|
||||
}
|
||||
|
||||
// My UB paranoia.
|
||||
platform::environ = platform::OUR_ENVIRON.as_mut_ptr();
|
||||
platform::environ = platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr();
|
||||
} else {
|
||||
platform::OUR_ENVIRON.clear();
|
||||
platform::OUR_ENVIRON.extend(
|
||||
platform::environ_iter()
|
||||
.enumerate()
|
||||
.filter(|&(j, _)| j != i)
|
||||
.map(|(_, v)| v),
|
||||
);
|
||||
platform::OUR_ENVIRON.push(core::ptr::null_mut());
|
||||
platform::environ = platform::OUR_ENVIRON.as_mut_ptr();
|
||||
{
|
||||
let mut our_environ = &mut *platform::OUR_ENVIRON.as_mut_ptr();
|
||||
our_environ.clear();
|
||||
our_environ.extend(
|
||||
platform::environ_iter()
|
||||
.enumerate()
|
||||
.filter(|&(j, _)| j != i)
|
||||
.map(|(_, v)| v),
|
||||
);
|
||||
our_environ.push(core::ptr::null_mut());
|
||||
}
|
||||
platform::environ = platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr();
|
||||
}
|
||||
}
|
||||
0
|
||||
@@ -1618,7 +1619,7 @@ pub unsafe extern "C" fn unsetenv(key: *const c_char) -> c_int {
|
||||
/// The `valloc()` function was marked as obsolescent in the Open Group Base
|
||||
/// Specifications Issue 5, and the function was removed in Issue 6.
|
||||
#[deprecated]
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn valloc(size: size_t) -> *mut c_void {
|
||||
/* sysconf(_SC_PAGESIZE) is a c_long and may in principle not
|
||||
* convert correctly to a size_t. */
|
||||
@@ -1640,14 +1641,14 @@ pub unsafe extern "C" fn valloc(size: size_t) -> *mut c_void {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/wcstombs.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wcstombs(s: *mut c_char, mut pwcs: *const wchar_t, n: size_t) -> size_t {
|
||||
let mut state: mbstate_t = mbstate_t {};
|
||||
wcsrtombs(s, &mut pwcs, n, &mut state)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/wctomb.html>.
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn wctomb(s: *mut c_char, wc: wchar_t) -> c_int {
|
||||
let mut state: mbstate_t = mbstate_t {};
|
||||
let result: usize = wcrtomb(s, wc, &mut state);
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
use crate::{
|
||||
platform::types::*,
|
||||
sync::{
|
||||
rwlock::{self, RwLock},
|
||||
Mutex, MutexGuard,
|
||||
rwlock::{self, RwLock},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user