Support nightly-2025-10-03

Changed files
+1440 -1574
generic-rt
ld_so
redox-rt
src
crt0
crti
crtn
header
_aio
_fenv
_template
arch_aarch64_user
arch_riscv64_user
arch_x64_user
arpa_inet
assert
crypt
ctype
dirent
dl-tls
dlfcn
elf
endian
err
errno
fcntl
float
fnmatch
getopt
glob
grp
inttypes
langinfo
libgen
locale
malloc
monetary
net_if
netdb
netinet_in
poll
pthread
pty
pwd
regex
sched
semaphore
setjmp
sgtty
shadow
signal
stdio
stdlib
string
strings
sys_auxv
sys_epoll
sys_file
sys_ioctl
sys_mman
sys_procfs
sys_ptrace
sys_random
sys_resource
sys_select
sys_socket
sys_stat
sys_statvfs
sys_syslog
sys_time
sys_timeb
sys_times
sys_uio
sys_utsname
sys_wait
termios
time
unistd
utime
utmp
wchar
wctype
io
ld_so
platform
pthread
sync
tests
+1 -1
Cargo.toml
··· 2 2 name = "relibc" 3 3 version = "0.2.5" 4 4 authors = ["Jeremy Soller <jackpot51@gmail.com>"] 5 - edition = "2021" 5 + edition = "2024" 6 6 7 7 [lib] 8 8 name = "relibc"
+1 -1
Makefile
··· 236 236 $(BUILD)/release/librelibc.a: $(SRC) 237 237 $(CARGO) rustc --release $(CARGOFLAGS) -- --emit link=$@ $(RUSTCFLAGS) 238 238 # TODO: Better to only allow a certain whitelisted set of symbols? Perhaps 239 - # use some cbindgen hook, specify them manually, or grep for #[no_mangle]. 239 + # use some cbindgen hook, specify them manually, or grep for #[unsafe(no_mangle)]. 240 240 ./renamesyms.sh "$@" "$(BUILD)/release/deps/" 241 241 touch $@ 242 242
+1 -1
bindgen_transform.sh
··· 1 1 sed -i 's/::std::os::raw:://g' $1 2 - perl -i -p0e 's/extern "C" \{\n pub fn/#[no_mangle]\npub extern "C" fn/g' $1 2 + perl -i -p0e 's/extern "C" \{\n pub fn/#[unsafe(no_mangle)]\npub extern "C" fn/g' $1 3 3 perl -i -p0e 's/;\n\}/ {\n unimplemented!();\n\}\n/g' $1 4 4 rustfmt $1
+1 -1
generic-rt/Cargo.toml
··· 1 1 [package] 2 2 name = "generic-rt" 3 3 version = "0.1.0" 4 - edition = "2021" 4 + edition = "2024" 5 5 6 6 [dependencies]
+1 -1
ld_so/Cargo.toml
··· 2 2 name = "ld_so" 3 3 version = "0.1.0" 4 4 authors = ["Jeremy Soller <jackpot51@gmail.com>"] 5 - edition = "2021" 5 + edition = "2024" 6 6 7 7 [lib] 8 8 name = "ld_so"
+1 -1
ld_so/ld_script/aarch64-unknown-redox.ld
··· 250 250 * 251 251 * .init_array also depends on TLS and is discarded as we don't need it. 252 252 */ 253 - *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) 253 + *(.gnu.linkonce.tb.*) *(.tcommon) 254 254 *(.init_array) 255 255 } 256 256 }
+1 -1
ld_so/ld_script/i686-unknown-redox.ld
··· 250 250 * 251 251 * .init_array also depends on TLS and is discarded as we don't need it. 252 252 */ 253 - *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) 253 + *(.gnu.linkonce.tb.*) *(.tcommon) 254 254 *(.init_array) 255 255 } 256 256 }
+1 -1
ld_so/ld_script/riscv64gc-unknown-redox.ld
··· 241 241 * 242 242 * .init_array also depends on TLS and is discarded as we don't need it. 243 243 */ 244 - *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) 244 + *(.gnu.linkonce.tb.*) *(.tcommon) 245 245 *(.init_array) 246 246 } 247 247 }
+1 -1
ld_so/ld_script/x86_64-unknown-linux-gnu.ld
··· 253 253 * 254 254 * .init_array also depends on TLS and is discarded as we don't need it. 255 255 */ 256 - *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) 256 + *(.gnu.linkonce.tb.*) *(.tcommon) 257 257 *(.init_array) 258 258 } 259 259 }
+1 -1
ld_so/ld_script/x86_64-unknown-redox.ld
··· 250 250 * 251 251 * .init_array also depends on TLS and is discarded as we don't need it. 252 252 */ 253 - *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) 253 + *(.gnu.linkonce.tb.*) *(.tcommon) 254 254 *(.init_array) 255 255 } 256 256 }
+2 -3
ld_so/src/lib.rs
··· 73 73 " 74 74 ); 75 75 76 - #[no_mangle] 76 + #[unsafe(no_mangle)] 77 77 pub unsafe extern "C" fn main(_argc: isize, _argv: *const *const i8) -> usize { 78 78 // LD 79 79 0x1D 80 80 } 81 81 82 82 #[linkage = "weak"] 83 - #[no_mangle] 83 + #[unsafe(no_mangle)] 84 84 extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! { 85 85 loop {} 86 86 } 87 87 88 88 #[panic_handler] 89 89 #[linkage = "weak"] 90 - #[no_mangle] 91 90 pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { 92 91 relibc_panic(pi) 93 92 }
+1 -1
redox-rt/Cargo.toml
··· 2 2 name = "redox-rt" 3 3 authors = ["4lDO2 <4lDO2@protonmail.com>"] 4 4 version = "0.1.0" 5 - edition = "2021" 5 + edition = "2024" 6 6 license = "MIT" 7 7 description = "Libc-independent runtime for Redox" 8 8
+3 -3
redox-rt/src/arch/aarch64.rs
··· 3 3 use syscall::{data::*, error::*}; 4 4 5 5 use crate::{ 6 - proc::{fork_inner, FdGuard, ForkArgs}, 7 - protocol::{ProcCall, RtSigInfo}, 8 - signal::{inner_c, PosixStackt, RtSigarea, SigStack, PROC_CONTROL_STRUCT}, 9 6 RtTcb, Tcb, 7 + proc::{FdGuard, ForkArgs, fork_inner}, 8 + protocol::{ProcCall, RtSigInfo}, 9 + signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, inner_c}, 10 10 }; 11 11 12 12 // Setup a stack starting from the very end of the address space, and then growing downwards.
+5 -5
redox-rt/src/arch/i686.rs
··· 3 3 use syscall::*; 4 4 5 5 use crate::{ 6 - proc::{fork_inner, FdGuard, ForkArgs}, 7 - protocol::{ProcCall, RtSigInfo}, 8 - signal::{inner_fastcall, PosixStackt, RtSigarea, SigStack, PROC_CONTROL_STRUCT}, 9 6 RtTcb, 7 + proc::{FdGuard, ForkArgs, fork_inner}, 8 + protocol::{ProcCall, RtSigInfo}, 9 + signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, inner_fastcall}, 10 10 }; 11 11 12 12 // Setup a stack starting from the very end of the address space, and then growing downwards. ··· 363 363 364 364 ret 365 365 "] <= []); 366 - extern "C" { 366 + unsafe extern "C" { 367 367 fn __relibc_internal_sigentry_crit_first(); 368 368 fn __relibc_internal_sigentry_crit_second(); 369 369 fn __relibc_internal_sigentry_crit_third(); ··· 384 384 flags: 0, // TODO 385 385 } 386 386 } 387 - #[no_mangle] 387 + #[unsafe(no_mangle)] 388 388 pub unsafe fn manually_enter_trampoline() { 389 389 let c = &crate::Tcb::current().unwrap().os_specific.control; 390 390 c.control_flags.store(
+4 -4
redox-rt/src/arch/riscv64.rs
··· 1 1 use core::cell::SyncUnsafeCell; 2 2 3 3 use crate::{ 4 - proc::{fork_inner, FdGuard, ForkArgs}, 5 - protocol::{ProcCall, RtSigInfo}, 6 - signal::{get_sigaltstack, inner_c, PosixStackt, RtSigarea, SigStack}, 7 4 RtTcb, Tcb, 5 + proc::{FdGuard, ForkArgs, fork_inner}, 6 + protocol::{ProcCall, RtSigInfo}, 7 + signal::{PosixStackt, RtSigarea, SigStack, get_sigaltstack, inner_c}, 8 8 }; 9 9 use core::{mem::offset_of, ptr::NonNull, sync::atomic::Ordering}; 10 10 use syscall::{data::*, error::*}; ··· 614 614 ", inout("t0") ip_location => _, out("ra") _); 615 615 } 616 616 617 - extern "C" { 617 + unsafe extern "C" { 618 618 fn __relibc_internal_sigentry_crit_first(); 619 619 fn __relibc_internal_sigentry_crit_second(); 620 620 fn __relibc_internal_sigentry_crit_third();
+5 -5
redox-rt/src/arch/x86_64.rs
··· 11 11 }; 12 12 13 13 use crate::{ 14 - proc::{fork_inner, FdGuard, ForkArgs}, 15 - protocol::{ProcCall, RtSigInfo}, 16 - signal::{get_sigaltstack, inner_c, PosixStackt, RtSigarea, SigStack, PROC_CONTROL_STRUCT}, 17 14 Tcb, 15 + proc::{FdGuard, ForkArgs, fork_inner}, 16 + protocol::{ProcCall, RtSigInfo}, 17 + signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, get_sigaltstack, inner_c}, 18 18 }; 19 19 20 20 // Setup a stack starting from the very end of the address space, and then growing downwards. ··· 465 465 proc_fd = sym PROC_FD, 466 466 ]); 467 467 468 - extern "C" { 468 + unsafe extern "C" { 469 469 fn __relibc_internal_sigentry_crit_first(); 470 470 fn __relibc_internal_sigentry_crit_second(); 471 471 fn __relibc_internal_sigentry_crit_third(); ··· 499 499 pub(crate) static SUPPORTS_AVX: AtomicU8 = AtomicU8::new(0); 500 500 501 501 // __relibc will be prepended to the name, so no_mangle is fine 502 - #[no_mangle] 502 + #[unsafe(no_mangle)] 503 503 pub unsafe fn manually_enter_trampoline() { 504 504 let c = &Tcb::current().unwrap().os_specific.control; 505 505 c.control_flags.store(
+2 -2
redox-rt/src/lib.rs
··· 11 11 12 12 use core::{ 13 13 cell::UnsafeCell, 14 - mem::{size_of, MaybeUninit}, 14 + mem::{MaybeUninit, size_of}, 15 15 }; 16 16 17 17 use generic_rt::{ExpectTlsFree, GenericTcb}; ··· 38 38 .size ", stringify!($name), ", . - ", stringify!($name), " 39 39 "), $($decl = $(sym $symname)?$(const $constval)?),*); 40 40 41 - extern "C" { 41 + unsafe extern "C" { 42 42 pub fn $name($($(_: $arg),*)?) $(-> $ret)?; 43 43 } 44 44 }
+6 -6
redox-rt/src/proc.rs
··· 1 1 use core::{ 2 2 cell::SyncUnsafeCell, 3 3 fmt::Debug, 4 - mem::{size_of, MaybeUninit}, 4 + mem::{MaybeUninit, size_of}, 5 5 }; 6 6 7 7 use crate::{ 8 + DYNAMIC_PROC_INFO, RtTcb, StaticProcInfo, 8 9 arch::*, 9 10 auxv_defs::*, 10 11 protocol::{ProcCall, ThreadCall}, 11 12 read_proc_meta, 12 13 sys::{proc_call, thread_call}, 13 - RtTcb, StaticProcInfo, DYNAMIC_PROC_INFO, 14 14 }; 15 15 16 16 use alloc::{boxed::Box, collections::BTreeMap, vec}; ··· 19 19 #[cfg(target_pointer_width = "32")] 20 20 use goblin::elf32::{ 21 21 header::Header, 22 - program_header::program_header32::{ProgramHeader, PF_R, PF_W, PF_X, PT_INTERP, PT_LOAD}, 22 + program_header::program_header32::{PF_R, PF_W, PF_X, PT_INTERP, PT_LOAD, ProgramHeader}, 23 23 }; 24 24 #[cfg(target_pointer_width = "64")] 25 25 use goblin::elf64::{ 26 26 header::Header, 27 - program_header::program_header64::{ProgramHeader, PF_R, PF_W, PF_X, PT_INTERP, PT_LOAD}, 27 + program_header::program_header64::{PF_R, PF_W, PF_X, PT_INTERP, PT_LOAD, ProgramHeader}, 28 28 }; 29 29 30 30 use syscall::{ 31 + CallFlags, GrantDesc, GrantFlags, MAP_FIXED_NOREPLACE, MAP_SHARED, Map, PAGE_SIZE, PROT_EXEC, 32 + PROT_READ, PROT_WRITE, SetSighandlerData, 31 33 error::*, 32 34 flag::{MapFlags, SEEK_SET}, 33 - CallFlags, GrantDesc, GrantFlags, Map, SetSighandlerData, MAP_FIXED_NOREPLACE, MAP_SHARED, 34 - PAGE_SIZE, PROT_EXEC, PROT_READ, PROT_WRITE, 35 35 }; 36 36 37 37 pub enum FexecResult {
+7 -7
redox-rt/src/signal.rs
··· 1 1 use core::{ffi::c_int, ptr::NonNull, sync::atomic::Ordering}; 2 2 3 3 use syscall::{ 4 - data::AtomicU64, CallFlags, Error, RawAction, Result, SenderInfo, SetSighandlerData, 5 - SigProcControl, Sigcontrol, SigcontrolFlags, TimeSpec, EAGAIN, EINTR, EINVAL, ENOMEM, EPERM, 4 + CallFlags, EAGAIN, EINTR, EINVAL, ENOMEM, EPERM, Error, RawAction, Result, SenderInfo, 5 + SetSighandlerData, SigProcControl, Sigcontrol, SigcontrolFlags, TimeSpec, data::AtomicU64, 6 6 }; 7 7 8 8 use crate::{ 9 + RtTcb, Tcb, 9 10 arch::*, 10 11 current_proc_fd, 11 12 proc::FdGuard, 12 13 protocol::{ 13 - ProcCall, RtSigInfo, ThreadCall, SIGCHLD, SIGCONT, SIGKILL, SIGSTOP, SIGTSTP, SIGTTIN, 14 - SIGTTOU, SIGURG, SIGWINCH, 14 + ProcCall, RtSigInfo, SIGCHLD, SIGCONT, SIGKILL, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, 15 + SIGWINCH, ThreadCall, 15 16 }, 16 17 static_proc_info, 17 18 sync::Mutex, 18 19 sys::{proc_call, this_thread_call}, 19 - RtTcb, Tcb, 20 20 }; 21 21 22 22 #[cfg(target_arch = "x86_64")] ··· 133 133 (area.tmp_rt_inf.pid, area.tmp_rt_inf.uid) 134 134 } else { 135 135 stack.sig_code = 0; // TODO: SI_USER constant? 136 - // TODO: Handle SIGCHLD. Maybe that should always be queued though? 136 + // TODO: Handle SIGCHLD. Maybe that should always be queued though? 137 137 let inf = SenderInfo::from_raw(area.tmp_id_inf); 138 138 (inf.pid, inf.ruid) 139 139 } ··· 778 778 res?; 779 779 unreachable!() 780 780 } 781 - /*#[no_mangle] 781 + /*#[unsafe(no_mangle)] 782 782 pub extern "C" fn __redox_rt_debug_sigctl() { 783 783 let tcb = &RtTcb::current().control; 784 784 let _ = syscall::write(1, alloc::format!("SIGCTL: {tcb:#x?}\n").as_bytes());
+3 -3
redox-rt/src/sys.rs
··· 5 5 }; 6 6 7 7 use syscall::{ 8 - error::{self, Error, Result, EINTR}, 9 - CallFlags, TimeSpec, EINVAL, ERESTART, 8 + CallFlags, EINVAL, ERESTART, TimeSpec, 9 + error::{self, EINTR, Error, Result}, 10 10 }; 11 11 12 12 use crate::{ 13 + DYNAMIC_PROC_INFO, DynamicProcInfo, RtTcb, Tcb, 13 14 arch::manually_enter_trampoline, 14 15 protocol::{ProcCall, ProcKillTarget, RtSigInfo, ThreadCall, WaitFlags}, 15 16 read_proc_meta, 16 17 signal::tmp_disable_signals, 17 - DynamicProcInfo, RtTcb, Tcb, DYNAMIC_PROC_INFO, 18 18 }; 19 19 20 20 #[inline]
+1 -1
redox-rt/src/thread.rs
··· 2 2 3 3 use syscall::Result; 4 4 5 - use crate::{arch::*, proc::*, signal::tmp_disable_signals, static_proc_info, RtTcb}; 5 + use crate::{RtTcb, arch::*, proc::*, signal::tmp_disable_signals, static_proc_info}; 6 6 7 7 /// Spawns a new context sharing the same address space as the current one (i.e. a new thread). 8 8 pub unsafe fn rlct_clone_impl(stack: *mut usize) -> Result<FdGuard> {
+1 -1
rust-toolchain.toml
··· 1 1 [toolchain] 2 - channel = "nightly-2025-01-12" 2 + channel = "nightly-2025-10-03" 3 3 components = ["rust-src"]
+1 -1
rustfmt.toml
··· 2 2 blank_lines_upper_bound = 1 3 3 brace_style = "SameLineWhere" 4 4 disable_all_formatting = false 5 - edition = "2018" 5 + edition = "2024" 6 6 empty_item_single_line = true 7 7 fn_single_line = false 8 8 force_explicit_abi = true
+1 -1
src/c_vec.rs
··· 2 2 3 3 use crate::{ 4 4 io::{self, Write}, 5 - platform::{self, types::*, WriteByte}, 5 + platform::{self, WriteByte, types::*}, 6 6 }; 7 7 use core::{ 8 8 cmp, fmt,
+1 -1
src/crt0/Cargo.toml
··· 2 2 name = "crt0" 3 3 version = "0.1.0" 4 4 authors = ["Jeremy Soller <jackpot51@gmail.com>"] 5 - edition = "2021" 5 + edition = "2024" 6 6 7 7 [lib] 8 8 name = "crt0"
+3 -4
src/crt0/src/lib.rs
··· 74 74 " 75 75 ); 76 76 77 - #[no_mangle] 77 + #[unsafe(no_mangle)] 78 78 pub unsafe extern "C" fn relibc_crt0(sp: usize) -> ! { 79 79 // This wrapper ensures a dynamic libc.so can access a hidden main function 80 80 //TODO: common definition of types 81 - extern "C" { 81 + unsafe extern "C" { 82 82 fn main(argc: isize, argv: *mut *mut c_char, envp: *mut *mut c_char) -> c_int; 83 83 fn relibc_start_v1( 84 84 sp: usize, ··· 93 93 } 94 94 95 95 #[linkage = "weak"] 96 - #[no_mangle] 96 + #[unsafe(no_mangle)] 97 97 pub extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! { 98 98 loop {} 99 99 } 100 100 101 101 #[panic_handler] 102 102 #[linkage = "weak"] 103 - #[no_mangle] 104 103 pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { 105 104 relibc_panic(pi) 106 105 }
+1 -1
src/crti/Cargo.toml
··· 2 2 name = "crti" 3 3 version = "0.1.0" 4 4 authors = ["jD91mZM2 <me@krake.one>"] 5 - edition = "2021" 5 + edition = "2024" 6 6 7 7 [lib] 8 8 name = "crti"
+1 -2
src/crti/src/lib.rs
··· 75 75 // risc-v has no _init / _fini functions; it exclusively uses init/fini arrays 76 76 77 77 #[linkage = "weak"] 78 - #[no_mangle] 78 + #[unsafe(no_mangle)] 79 79 extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! { 80 80 loop {} 81 81 } 82 82 83 83 #[panic_handler] 84 84 #[linkage = "weak"] 85 - #[no_mangle] 86 85 pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { 87 86 relibc_panic(pi) 88 87 }
+1 -1
src/crtn/Cargo.toml
··· 2 2 name = "crtn" 3 3 version = "0.1.0" 4 4 authors = ["jD91mZM2 <me@krake.one>"] 5 - edition = "2021" 5 + edition = "2024" 6 6 7 7 [lib] 8 8 name = "crtn"
+1 -2
src/crtn/src/lib.rs
··· 61 61 // risc-v has no _init / _fini functions; it exclusively uses init/fini arrays 62 62 63 63 #[linkage = "weak"] 64 - #[no_mangle] 64 + #[unsafe(no_mangle)] 65 65 extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! { 66 66 loop {} 67 67 } 68 68 69 69 #[panic_handler] 70 70 #[linkage = "weak"] 71 - #[no_mangle] 72 71 pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { 73 72 relibc_panic(pi) 74 73 }
+7 -6
src/cxa.rs
··· 1 - use crate::platform::types::*; 1 + use crate::{platform::types::*, raw_cell::RawCell}; 2 2 3 3 // TODO: Implement cxa_finalize and uncomment this 4 4 ··· 9 9 //dso: *mut c_void, 10 10 } 11 11 12 - static mut CXA_ATEXIT_FUNCS: [Option<CxaAtExitFunc>; 32] = [None; 32]; 12 + static CXA_ATEXIT_FUNCS: RawCell<[Option<CxaAtExitFunc>; 32]> = RawCell::new([None; 32]); 13 13 14 - #[no_mangle] 14 + #[unsafe(no_mangle)] 15 15 pub unsafe extern "C" fn __cxa_atexit( 16 16 func_opt: Option<extern "C" fn(*mut c_void)>, 17 17 arg: *mut c_void, 18 18 dso: *mut c_void, 19 19 ) -> c_int { 20 - for item in &mut CXA_ATEXIT_FUNCS { 21 - if item.is_none() { 22 - *item = func_opt.map(|func| CxaAtExitFunc {} /*{ func, arg, dso }*/); 20 + for i in 0..CXA_ATEXIT_FUNCS.unsafe_ref().len() { 21 + if CXA_ATEXIT_FUNCS.unsafe_ref()[i].is_none() { 22 + CXA_ATEXIT_FUNCS.unsafe_mut()[i] = 23 + func_opt.map(|func| CxaAtExitFunc {} /*{ func, arg, dso }*/); 23 24 return 0; 24 25 } 25 26 }
+1 -1
src/fs.rs
··· 6 6 unistd::{SEEK_CUR, SEEK_END, SEEK_SET}, 7 7 }, 8 8 io, 9 - platform::{types::*, Pal, Sys}, 9 + platform::{Pal, Sys, types::*}, 10 10 }; 11 11 use core::ops::Deref; 12 12
+8 -8
src/header/_aio/mod.rs
··· 12 12 pub aio_sigevent: sigevent, 13 13 } 14 14 15 - // #[no_mangle] 15 + // #[unsafe(no_mangle)] 16 16 pub extern "C" fn aio_read(aiocbp: *mut aiocb) -> c_int { 17 17 unimplemented!(); 18 18 } 19 19 20 - // #[no_mangle] 20 + // #[unsafe(no_mangle)] 21 21 pub extern "C" fn aio_write(aiocbp: *mut aiocb) -> c_int { 22 22 unimplemented!(); 23 23 } 24 24 25 - // #[no_mangle] 25 + // #[unsafe(no_mangle)] 26 26 pub extern "C" fn lio_listio( 27 27 mode: c_int, 28 28 list: *const *const aiocb, ··· 32 32 unimplemented!(); 33 33 } 34 34 35 - // #[no_mangle] 35 + // #[unsafe(no_mangle)] 36 36 pub extern "C" fn aio_error(aiocbp: *const aiocb) -> c_int { 37 37 unimplemented!(); 38 38 } 39 39 40 - // #[no_mangle] 40 + // #[unsafe(no_mangle)] 41 41 pub extern "C" fn aio_return(aiocbp: *mut aiocb) -> usize { 42 42 unimplemented!(); 43 43 } 44 44 45 - // #[no_mangle] 45 + // #[unsafe(no_mangle)] 46 46 pub extern "C" fn aio_cancel(fildes: c_int, aiocbp: *mut aiocb) -> c_int { 47 47 unimplemented!(); 48 48 } 49 49 50 - // #[no_mangle] 50 + // #[unsafe(no_mangle)] 51 51 pub extern "C" fn aio_suspend( 52 52 list: *const *const aiocb, 53 53 nent: c_int, ··· 56 56 unimplemented!(); 57 57 } 58 58 59 - // #[no_mangle] 59 + // #[unsafe(no_mangle)] 60 60 pub extern "C" fn aio_fsync(operation: c_int, aiocbp: *mut aiocb) -> c_int { 61 61 unimplemented!(); 62 62 }
+11 -11
src/header/_fenv/mod.rs
··· 13 13 pub cw: u64, 14 14 } 15 15 16 - // #[no_mangle] 16 + // #[unsafe(no_mangle)] 17 17 pub unsafe extern "C" fn feclearexcept(excepts: c_int) -> c_int { 18 18 unimplemented!(); 19 19 } 20 20 21 - // #[no_mangle] 21 + // #[unsafe(no_mangle)] 22 22 pub unsafe extern "C" fn fegenenv(envp: *mut fenv_t) -> c_int { 23 23 unimplemented!(); 24 24 } 25 25 26 - // #[no_mangle] 26 + // #[unsafe(no_mangle)] 27 27 pub unsafe extern "C" fn fegetexceptflag(flagp: *mut fexcept_t, excepts: c_int) -> c_int { 28 28 unimplemented!(); 29 29 } 30 30 31 - // #[no_mangle] 31 + // #[unsafe(no_mangle)] 32 32 pub unsafe extern "C" fn fegetround() -> c_int { 33 33 FE_TONEAREST 34 34 } 35 35 36 - // #[no_mangle] 36 + // #[unsafe(no_mangle)] 37 37 pub unsafe extern "C" fn feholdexcept(envp: *mut fenv_t) -> c_int { 38 38 unimplemented!(); 39 39 } 40 40 41 - // #[no_mangle] 41 + // #[unsafe(no_mangle)] 42 42 pub unsafe extern "C" fn feraiseexcept(except: c_int) -> c_int { 43 43 unimplemented!(); 44 44 } 45 45 46 - // #[no_mangle] 46 + // #[unsafe(no_mangle)] 47 47 pub unsafe extern "C" fn fesetenv(envp: *const fenv_t) -> c_int { 48 48 unimplemented!(); 49 49 } 50 50 51 - // #[no_mangle] 51 + // #[unsafe(no_mangle)] 52 52 pub unsafe extern "C" fn fesetexceptflag(flagp: *const fexcept_t, excepts: c_int) -> c_int { 53 53 unimplemented!(); 54 54 } 55 55 56 - // #[no_mangle] 56 + // #[unsafe(no_mangle)] 57 57 pub unsafe extern "C" fn fesetround(round: c_int) -> c_int { 58 58 unimplemented!(); 59 59 } 60 60 61 - // #[no_mangle] 61 + // #[unsafe(no_mangle)] 62 62 pub unsafe extern "C" fn fetestexcept(excepts: c_int) -> c_int { 63 63 unimplemented!(); 64 64 } 65 65 66 - // #[no_mangle] 66 + // #[unsafe(no_mangle)] 67 67 pub unsafe extern "C" fn feupdateenv(envp: *const fenv_t) -> c_int { 68 68 unimplemented!(); 69 69 }
+1 -1
src/header/_template/mod.rs
··· 3 3 use platform::types::*; 4 4 5 5 /* 6 - #[no_mangle] 6 + #[unsafe(no_mangle)] 7 7 pub extern "C" fn func(args) -> c_int { 8 8 unimplemented!(); 9 9 }
+1 -1
src/header/arch_aarch64_user/mod.rs
··· 19 19 pub type elf_gregset_t = [c_ulong; 34]; 20 20 pub type elf_fpregset_t = user_fpsimd_struct; 21 21 22 - #[no_mangle] 22 + #[unsafe(no_mangle)] 23 23 pub extern "C" fn _cbindgen_export_aarch64_user( 24 24 a: user_regs_struct, 25 25 b: user_fpsimd_struct,
+1 -1
src/header/arch_riscv64_user/mod.rs
··· 28 28 pub type elf_gregset_t = user_regs_struct; 29 29 pub type elf_fpregset_t = user_fpregs_struct; 30 30 31 - #[no_mangle] 31 + #[unsafe(no_mangle)] 32 32 pub extern "C" fn _cbindgen_only_generates_structs_if_they_are_mentioned_which_is_dumb_riscv64_user( 33 33 a: user_regs_struct, 34 34 b: user_fpregs_struct,
+1 -1
src/header/arch_x64_user/mod.rs
··· 71 71 pub u_debugreg: [c_ulong; 8], 72 72 } 73 73 74 - #[no_mangle] 74 + #[unsafe(no_mangle)] 75 75 pub extern "C" fn _cbindgen_export_x86_user( 76 76 a: user_fpregs_struct, 77 77 b: user_regs_struct,
+14 -13
src/header/arpa_inet/mod.rs
··· 14 14 c_str::CStr, 15 15 header::{ 16 16 errno::*, 17 - netinet_in::{in_addr, in_addr_t, ntohl, INADDR_NONE}, 17 + netinet_in::{INADDR_NONE, in_addr, in_addr_t, ntohl}, 18 18 sys_socket::{constants::*, socklen_t}, 19 19 }, 20 20 platform::{self, types::*}, 21 + raw_cell::RawCell, 21 22 }; 22 23 23 24 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_addr.html>. ··· 26 27 /// The `inet_addr()` function was marked obsolescent in the Open Group Base 27 28 /// Specifications Issue 8. 28 29 #[deprecated] 29 - #[no_mangle] 30 + #[unsafe(no_mangle)] 30 31 pub unsafe extern "C" fn inet_addr(cp: *const c_char) -> in_addr_t { 31 32 let mut val: in_addr = in_addr { s_addr: 0 }; 32 33 ··· 38 39 } 39 40 40 41 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/inet_aton.3.html>. 41 - #[no_mangle] 42 + #[unsafe(no_mangle)] 42 43 pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_int { 43 44 // TODO: octal/hex 44 45 unsafe { inet_pton(AF_INET, cp, inp as *mut c_void) } ··· 50 51 /// The `inet_lnaof()` function was specified in Networking Services Issue 5, 51 52 /// but not in the Open Group Base Specifications Issue 6 and later. 52 53 #[deprecated] 53 - #[no_mangle] 54 + #[unsafe(no_mangle)] 54 55 pub extern "C" fn inet_lnaof(r#in: in_addr) -> in_addr_t { 55 56 if r#in.s_addr >> 24 < 128 { 56 57 r#in.s_addr & 0xff_ffff ··· 67 68 /// The `inet_makeaddr()` function was specified in Networking Services Issue 68 69 /// 5, but not in the Open Group Base Specifications Issue 6 and later. 69 70 #[deprecated] 70 - #[no_mangle] 71 + #[unsafe(no_mangle)] 71 72 pub extern "C" fn inet_makeaddr(net: in_addr_t, lna: in_addr_t) -> in_addr { 72 73 let mut output: in_addr = in_addr { s_addr: 0 }; 73 74 ··· 88 89 /// The `inet_netof()` function was specified in Networking Services Issue 5, 89 90 /// but not in the Open Group Base Specifications Issue 6 and later. 90 91 #[deprecated] 91 - #[no_mangle] 92 + #[unsafe(no_mangle)] 92 93 pub extern "C" fn inet_netof(r#in: in_addr) -> in_addr_t { 93 94 if r#in.s_addr >> 24 < 128 { 94 95 r#in.s_addr & 0xff_ffff ··· 105 106 /// The `inet_network()` function was specified in Networking Services Issue 5, 106 107 /// but not in the Open Group Base Specifications Issue 6 and later. 107 108 #[deprecated] 108 - #[no_mangle] 109 + #[unsafe(no_mangle)] 109 110 pub unsafe extern "C" fn inet_network(cp: *const c_char) -> in_addr_t { 110 111 ntohl(unsafe { inet_addr(cp) }) 111 112 } ··· 116 117 /// The `inet_ntoa()` function was marked obsolescent in the Open Group Base 117 118 /// Specifications Issue 8. 118 119 #[deprecated] 119 - #[no_mangle] 120 + #[unsafe(no_mangle)] 120 121 pub unsafe extern "C" fn inet_ntoa(r#in: in_addr) -> *const c_char { 121 - static mut NTOA_ADDR: [c_char; 16] = [0; 16]; 122 + static NTOA_ADDR: RawCell<[c_char; 16]> = RawCell::new([0; 16]); 122 123 123 124 unsafe { 124 125 inet_ntop( 125 126 AF_INET, 126 127 &r#in as *const in_addr as *const c_void, 127 - NTOA_ADDR.as_mut_ptr(), 128 - 16, 128 + NTOA_ADDR.unsafe_mut().as_mut_ptr(), 129 + NTOA_ADDR.unsafe_ref().len(), 129 130 ) 130 131 } 131 132 } 132 133 133 134 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_ntop.html>. 134 - #[no_mangle] 135 + #[unsafe(no_mangle)] 135 136 pub unsafe extern "C" fn inet_ntop( 136 137 af: c_int, 137 138 src: *const c_void, ··· 160 161 } 161 162 162 163 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_ntop.html>. 163 - #[no_mangle] 164 + #[unsafe(no_mangle)] 164 165 pub unsafe extern "C" fn inet_pton(af: c_int, src: *const c_char, dst: *mut c_void) -> c_int { 165 166 if af != AF_INET { 166 167 platform::ERRNO.set(EAFNOSUPPORT);
+1 -1
src/header/assert/mod.rs
··· 5 5 6 6 use crate::{c_str::CStr, platform::types::*}; 7 7 8 - #[no_mangle] 8 + #[unsafe(no_mangle)] 9 9 pub unsafe extern "C" fn __assert_fail( 10 10 func: *const c_char, 11 11 file: *const c_char,
+1 -1
src/header/crypt/argon2.rs
··· 1 1 use alloc::string::{String, ToString}; 2 2 use argon2::{ 3 - password_hash::{PasswordHash, PasswordVerifier}, 4 3 Argon2, 4 + password_hash::{PasswordHash, PasswordVerifier}, 5 5 }; 6 6 7 7 pub fn crypt_argon2(key: &str, setting: &str) -> Option<String> {
+3 -3
src/header/crypt/mod.rs
··· 11 11 string::{String, ToString}, 12 12 }; 13 13 use core::ptr; 14 - use rand::{rngs::SmallRng, RngCore, SeedableRng}; 14 + use rand::{RngCore, SeedableRng, rngs::SmallRng}; 15 15 16 16 use crate::{ 17 17 c_str::CStr, ··· 32 32 md5::crypt_md5, 33 33 pbkdf2::crypt_pbkdf2, 34 34 scrypt::crypt_scrypt, 35 - sha::{crypt_sha, ShaType::*}, 35 + sha::{ShaType::*, crypt_sha}, 36 36 }; 37 37 38 38 /// See <https://www.man7.org/linux/man-pages/man3/crypt.3.html>. ··· 59 59 } 60 60 61 61 /// See <https://www.man7.org/linux/man-pages/man3/crypt.3.html>. 62 - #[no_mangle] 62 + #[unsafe(no_mangle)] 63 63 pub unsafe extern "C" fn crypt_r( 64 64 key: *const c_char, 65 65 setting: *const c_char,
+1 -1
src/header/crypt/scrypt.rs
··· 3 3 use alloc::string::{String, ToString}; 4 4 use base64ct::{Base64Bcrypt, Encoding}; 5 5 use core::{str, u32}; 6 - use scrypt::{scrypt, Params}; 6 + use scrypt::{Params, scrypt}; 7 7 8 8 /// Map for encoding and decoding 9 9 #[inline(always)]
+2 -2
src/header/crypt/sha.rs
··· 1 1 use alloc::string::{String, ToString}; 2 2 3 3 use sha_crypt::{ 4 - sha256_crypt_b64, sha512_crypt_b64, Sha256Params, Sha512Params, ROUNDS_DEFAULT, ROUNDS_MAX, 5 - ROUNDS_MIN, 4 + ROUNDS_DEFAULT, ROUNDS_MAX, ROUNDS_MIN, Sha256Params, Sha512Params, sha256_crypt_b64, 5 + sha512_crypt_b64, 6 6 }; 7 7 8 8 use crate::platform::types::*;
+18 -26
src/header/ctype/mod.rs
··· 10 10 use crate::platform::types::*; 11 11 12 12 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalnum.html>. 13 - #[no_mangle] 13 + #[unsafe(no_mangle)] 14 14 pub extern "C" fn isalnum(c: c_int) -> c_int { 15 15 c_int::from(isdigit(c) != 0 || isalpha(c) != 0) 16 16 } 17 17 18 18 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isalpha.html>. 19 - #[no_mangle] 19 + #[unsafe(no_mangle)] 20 20 pub extern "C" fn isalpha(c: c_int) -> c_int { 21 21 c_int::from(islower(c) != 0 || isupper(c) != 0) 22 22 } ··· 26 26 /// The `isascii()` function was marked obsolescent in the Open Group Base 27 27 /// Specifications Issue 7, and removed in Issue 8. 28 28 #[deprecated] 29 - #[no_mangle] 29 + #[unsafe(no_mangle)] 30 30 pub extern "C" fn isascii(c: c_int) -> c_int { 31 31 c_int::from((c & !0x7f) == 0) 32 32 } 33 33 34 34 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isblank.html>. 35 - #[no_mangle] 35 + #[unsafe(no_mangle)] 36 36 pub extern "C" fn isblank(c: c_int) -> c_int { 37 37 c_int::from(c == c_int::from(b' ') || c == c_int::from(b'\t')) 38 38 } 39 39 40 40 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iscntrl.html>. 41 - #[no_mangle] 41 + #[unsafe(no_mangle)] 42 42 pub extern "C" fn iscntrl(c: c_int) -> c_int { 43 43 c_int::from((c >= 0x00 && c <= 0x1f) || c == 0x7f) 44 44 } 45 45 46 46 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isdigit.html>. 47 - #[no_mangle] 47 + #[unsafe(no_mangle)] 48 48 pub extern "C" fn isdigit(c: c_int) -> c_int { 49 49 c_int::from(c >= c_int::from(b'0') && c <= c_int::from(b'9')) 50 50 } 51 51 52 52 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isgraph.html>. 53 - #[no_mangle] 53 + #[unsafe(no_mangle)] 54 54 pub extern "C" fn isgraph(c: c_int) -> c_int { 55 55 c_int::from(c >= 0x21 && c <= 0x7e) 56 56 } 57 57 58 58 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/islower.html>. 59 - #[no_mangle] 59 + #[unsafe(no_mangle)] 60 60 pub extern "C" fn islower(c: c_int) -> c_int { 61 61 c_int::from(c >= c_int::from(b'a') && c <= c_int::from(b'z')) 62 62 } 63 63 64 64 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isprint.html>. 65 - #[no_mangle] 65 + #[unsafe(no_mangle)] 66 66 pub extern "C" fn isprint(c: c_int) -> c_int { 67 67 c_int::from(c >= 0x20 && c < 0x7f) 68 68 } 69 69 70 70 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ispunct.html>. 71 - #[no_mangle] 71 + #[unsafe(no_mangle)] 72 72 pub extern "C" fn ispunct(c: c_int) -> c_int { 73 73 c_int::from( 74 74 (c >= c_int::from(b'!') && c <= c_int::from(b'/')) ··· 79 79 } 80 80 81 81 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isspace.html>. 82 - #[no_mangle] 82 + #[unsafe(no_mangle)] 83 83 pub extern "C" fn isspace(c: c_int) -> c_int { 84 84 c_int::from( 85 85 c == c_int::from(b' ') ··· 92 92 } 93 93 94 94 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isupper.html>. 95 - #[no_mangle] 95 + #[unsafe(no_mangle)] 96 96 pub extern "C" fn isupper(c: c_int) -> c_int { 97 97 c_int::from(c >= c_int::from(b'A') && c <= c_int::from(b'Z')) 98 98 } 99 99 100 100 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isxdigit.html>. 101 - #[no_mangle] 101 + #[unsafe(no_mangle)] 102 102 pub extern "C" fn isxdigit(c: c_int) -> c_int { 103 103 c_int::from(isdigit(c) != 0 || (c | 32 >= c_int::from(b'a') && c | 32 <= c_int::from(b'f'))) 104 104 } ··· 108 108 /// The `toascii()` function was marked obsolescent in the Open Group Base 109 109 /// Specifications Issue 7, and removed in Issue 8. 110 110 #[deprecated] 111 - #[no_mangle] 111 + #[unsafe(no_mangle)] 112 112 pub extern "C" fn toascii(c: c_int) -> c_int { 113 113 c & 0x7f 114 114 } 115 115 116 116 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tolower.html>. 117 - #[no_mangle] 117 + #[unsafe(no_mangle)] 118 118 pub extern "C" fn tolower(c: c_int) -> c_int { 119 - if isupper(c) != 0 { 120 - c | 0x20 121 - } else { 122 - c 123 - } 119 + if isupper(c) != 0 { c | 0x20 } else { c } 124 120 } 125 121 126 122 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/toupper.html>. 127 - #[no_mangle] 123 + #[unsafe(no_mangle)] 128 124 pub extern "C" fn toupper(c: c_int) -> c_int { 129 - if islower(c) != 0 { 130 - c & !0x20 131 - } else { 132 - c 133 - } 125 + if islower(c) != 0 { c & !0x20 } else { c } 134 126 }
+14 -14
src/header/dirent/mod.rs
··· 18 18 fs::File, 19 19 header::{fcntl, stdlib, string}, 20 20 out::Out, 21 - platform::{self, types::*, Pal, Sys}, 21 + platform::{self, Pal, Sys, types::*}, 22 22 }; 23 23 24 24 use super::{ ··· 178 178 }; 179 179 180 180 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/alphasort.html>. 181 - #[no_mangle] 181 + #[unsafe(no_mangle)] 182 182 pub unsafe extern "C" fn alphasort(first: *mut *const dirent, second: *mut *const dirent) -> c_int { 183 183 unsafe { string::strcoll((**first).d_name.as_ptr(), (**second).d_name.as_ptr()) } 184 184 } 185 185 186 186 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/closedir.html>. 187 - #[no_mangle] 187 + #[unsafe(no_mangle)] 188 188 pub extern "C" fn closedir(dir: Box<DIR>) -> c_int { 189 189 dir.close().map(|()| 0).or_minus_one_errno() 190 190 } ··· 194 194 /// FreeBSD extension that transfers ownership of the directory file descriptor to the user. 195 195 /// 196 196 /// It doesn't matter if DIR was opened with [`opendir`] or [`fdopendir`]. 197 - #[no_mangle] 197 + #[unsafe(no_mangle)] 198 198 pub extern "C" fn fdclosedir(dir: Box<DIR>) -> c_int { 199 199 let mut file = dir.file; 200 200 file.reference = true; ··· 203 203 } 204 204 205 205 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/dirfd.html>. 206 - #[no_mangle] 206 + #[unsafe(no_mangle)] 207 207 pub extern "C" fn dirfd(dir: &mut DIR) -> c_int { 208 208 *dir.file 209 209 } 210 210 211 211 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fdopendir.html>. 212 - #[no_mangle] 212 + #[unsafe(no_mangle)] 213 213 pub unsafe extern "C" fn opendir(path: *const c_char) -> *mut DIR { 214 214 let path = unsafe { CStr::from_ptr(path) }; 215 215 ··· 217 217 } 218 218 219 219 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fdopendir.html>. 220 - #[no_mangle] 220 + #[unsafe(no_mangle)] 221 221 pub extern "C" fn fdopendir(fd: c_int) -> *mut DIR { 222 222 DIR::from_fd(fd).or_errno_null_mut() 223 223 } 224 224 225 225 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_getdents.html>. 226 - #[no_mangle] 226 + #[unsafe(no_mangle)] 227 227 pub extern "C" fn posix_getdents( 228 228 fildes: c_int, 229 229 buf: *mut c_void, ··· 238 238 } 239 239 240 240 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/readdir.html>. 241 - #[no_mangle] 241 + #[unsafe(no_mangle)] 242 242 pub extern "C" fn readdir(dir: &mut DIR) -> *mut dirent { 243 243 dir.next_dirent().or_errno_null_mut() 244 244 } ··· 249 249 /// The `readdir_r()` function was marked obsolescent in the Open Group Base 250 250 /// Specifications Issue 8. 251 251 #[deprecated] 252 - // #[no_mangle] 252 + // #[unsafe(no_mangle)] 253 253 pub extern "C" fn readdir_r( 254 254 _dir: *mut DIR, 255 255 _entry: *mut dirent, ··· 259 259 } 260 260 261 261 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rewinddir.html>. 262 - #[no_mangle] 262 + #[unsafe(no_mangle)] 263 263 pub extern "C" fn rewinddir(dir: &mut DIR) { 264 264 dir.rewind(); 265 265 } 266 266 267 267 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/alphasort.html>. 268 - #[no_mangle] 268 + #[unsafe(no_mangle)] 269 269 pub unsafe extern "C" fn scandir( 270 270 dirp: *const c_char, 271 271 namelist: *mut *mut *mut dirent, ··· 344 344 } 345 345 346 346 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/seekdir.html>. 347 - #[no_mangle] 347 + #[unsafe(no_mangle)] 348 348 pub extern "C" fn seekdir(dir: &mut DIR, off: c_long) { 349 349 dir.seek( 350 350 off.try_into() ··· 353 353 } 354 354 355 355 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/telldir.html>. 356 - #[no_mangle] 356 + #[unsafe(no_mangle)] 357 357 pub extern "C" fn telldir(dir: &mut DIR) -> c_long { 358 358 dir.opaque_offset as c_long 359 359 }
+1 -1
src/header/dl-tls/mod.rs
··· 14 14 pub ti_offset: usize, 15 15 } 16 16 17 - #[no_mangle] 17 + #[unsafe(no_mangle)] 18 18 pub unsafe extern "C" fn __tls_get_addr(ti: *mut dl_tls_index) -> *mut c_void { 19 19 let tcb = unsafe { Tcb::current().unwrap() }; 20 20 let ti = unsafe { &*ti };
+5 -5
src/header/dlfcn/mod.rs
··· 45 45 dli_saddr: *mut c_void, 46 46 } 47 47 48 - #[no_mangle] 48 + #[unsafe(no_mangle)] 49 49 pub unsafe extern "C" fn dladdr(_addr: *mut c_void, info: *mut Dl_info) -> c_int { 50 50 //TODO 51 51 unsafe { ··· 57 57 0 58 58 } 59 59 60 - #[no_mangle] 60 + #[unsafe(no_mangle)] 61 61 pub unsafe extern "C" fn dlopen(cfilename: *const c_char, flags: c_int) -> *mut c_void { 62 62 //TODO support all sort of flags 63 63 let resolve = if flags & RTLD_NOW == RTLD_NOW { ··· 111 111 } 112 112 } 113 113 114 - #[no_mangle] 114 + #[unsafe(no_mangle)] 115 115 pub unsafe extern "C" fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void { 116 116 let handle = ObjectHandle::from_ptr(handle); 117 117 ··· 150 150 } 151 151 } 152 152 153 - #[no_mangle] 153 + #[unsafe(no_mangle)] 154 154 pub unsafe extern "C" fn dlclose(handle: *mut c_void) -> c_int { 155 155 let tcb = match unsafe { Tcb::current() } { 156 156 Some(tcb) => tcb, ··· 177 177 0 178 178 } 179 179 180 - #[no_mangle] 180 + #[unsafe(no_mangle)] 181 181 pub extern "C" fn dlerror() -> *mut c_char { 182 182 ERROR.swap(0, Ordering::SeqCst) as *mut c_char 183 183 }
+1 -1
src/header/elf/mod.rs
··· 963 963 pub const R_X86_64_RELATIVE64: usize = 38; 964 964 pub const R_X86_64_NUM: usize = 39; 965 965 966 - #[no_mangle] 966 + #[unsafe(no_mangle)] 967 967 pub extern "C" fn _cbindgen_export_elf( 968 968 a: Elf32_Ehdr, 969 969 b: Elf64_Ehdr,
+12 -12
src/header/endian/mod.rs
··· 5 5 use crate::platform::types::*; 6 6 7 7 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 8 - #[no_mangle] 8 + #[unsafe(no_mangle)] 9 9 pub extern "C" fn be16toh(x: uint16_t) -> uint16_t { 10 10 uint16_t::from_be(x) 11 11 } 12 12 13 13 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 14 - #[no_mangle] 14 + #[unsafe(no_mangle)] 15 15 pub extern "C" fn be32toh(x: uint32_t) -> uint32_t { 16 16 uint32_t::from_be(x) 17 17 } 18 18 19 19 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 20 - #[no_mangle] 20 + #[unsafe(no_mangle)] 21 21 pub extern "C" fn be64toh(x: uint64_t) -> uint64_t { 22 22 uint64_t::from_be(x) 23 23 } 24 24 25 25 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 26 - #[no_mangle] 26 + #[unsafe(no_mangle)] 27 27 pub extern "C" fn htobe16(x: uint16_t) -> uint16_t { 28 28 x.to_be() 29 29 } 30 30 31 31 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 32 - #[no_mangle] 32 + #[unsafe(no_mangle)] 33 33 pub extern "C" fn htobe32(x: uint32_t) -> uint32_t { 34 34 x.to_be() 35 35 } 36 36 37 37 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 38 - #[no_mangle] 38 + #[unsafe(no_mangle)] 39 39 pub extern "C" fn htobe64(x: uint64_t) -> uint64_t { 40 40 x.to_be() 41 41 } 42 42 43 43 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 44 - #[no_mangle] 44 + #[unsafe(no_mangle)] 45 45 pub extern "C" fn htole16(x: uint16_t) -> uint16_t { 46 46 x.to_le() 47 47 } 48 48 49 49 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 50 - #[no_mangle] 50 + #[unsafe(no_mangle)] 51 51 pub extern "C" fn htole32(x: uint32_t) -> uint32_t { 52 52 x.to_le() 53 53 } 54 54 55 55 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 56 - #[no_mangle] 56 + #[unsafe(no_mangle)] 57 57 pub extern "C" fn htole64(x: uint64_t) -> uint64_t { 58 58 x.to_le() 59 59 } 60 60 61 61 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 62 - #[no_mangle] 62 + #[unsafe(no_mangle)] 63 63 pub extern "C" fn le16toh(x: uint16_t) -> uint16_t { 64 64 uint16_t::from_le(x) 65 65 } 66 66 67 67 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 68 - #[no_mangle] 68 + #[unsafe(no_mangle)] 69 69 pub extern "C" fn le32toh(x: uint32_t) -> uint32_t { 70 70 uint32_t::from_le(x) 71 71 } 72 72 73 73 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/be16toh.html>. 74 - #[no_mangle] 74 + #[unsafe(no_mangle)] 75 75 pub extern "C" fn le64toh(x: uint64_t) -> uint64_t { 76 76 uint64_t::from_le(x) 77 77 }
+16 -16
src/header/err/mod.rs
··· 22 22 #![allow(unsafe_op_in_unsafe_fn)] 23 23 24 24 use core::{ 25 - ffi::{c_char, c_int, VaList as va_list}, 25 + ffi::{VaList as va_list, c_char, c_int}, 26 26 ptr, 27 27 }; 28 28 29 29 use crate::{ 30 30 c_str::CStr, 31 31 header::{ 32 - stdio::{self, fprintf, fputc, fputs, vfprintf, FILE}, 32 + stdio::{self, FILE, fprintf, fputc, fputs, vfprintf}, 33 33 stdlib::exit, 34 34 string::strerror, 35 35 }, ··· 44 44 static mut error_sink: *mut FILE = ptr::null_mut(); 45 45 46 46 /// Set global [`FILE`] sink to write errors and warnings. 47 - #[no_mangle] 47 + #[unsafe(no_mangle)] 48 48 pub unsafe extern "C" fn err_set_file(fp: *mut FILE) { 49 49 if fp.is_null() { 50 50 error_sink = stdio::stderr; ··· 54 54 } 55 55 56 56 /// Set or remove a callback to invoke before exiting on error. 57 - #[no_mangle] 57 + #[unsafe(no_mangle)] 58 58 pub unsafe extern "C" fn err_set_exit(ef: ExitCallback) { 59 59 on_exit = ef; 60 60 } ··· 65 65 /// 66 66 /// # Return 67 67 /// Does not return. Exits with `eval` as an error code. 68 - #[no_mangle] 68 + #[unsafe(no_mangle)] 69 69 pub unsafe extern "C" fn err(eval: c_int, fmt: *const c_char, mut va_list: ...) -> ! { 70 70 let code = Some(ERRNO.get()); 71 71 err_exit(eval, code, fmt, va_list.as_va_list()) ··· 77 77 /// 78 78 /// # Return 79 79 /// Exits with `eval` as an error code. 80 - #[no_mangle] 80 + #[unsafe(no_mangle)] 81 81 pub unsafe extern "C" fn errc(eval: c_int, code: c_int, fmt: *const c_char, mut va_list: ...) -> ! { 82 82 err_exit(eval, Some(code), fmt, va_list.as_va_list()) 83 83 } ··· 88 88 /// 89 89 /// # Return 90 90 /// Exits with `eval` as an error code. 91 - #[no_mangle] 91 + #[unsafe(no_mangle)] 92 92 pub unsafe extern "C" fn errx(eval: c_int, fmt: *const c_char, mut va_list: ...) -> ! { 93 93 err_exit(eval, None, fmt, va_list.as_va_list()) 94 94 } ··· 96 96 /// Print a user message and then an error message for [`ERRNO`]. 97 97 /// 98 98 /// The message format is `progname: fmt: strerror(ERRNO)` 99 - #[no_mangle] 99 + #[unsafe(no_mangle)] 100 100 pub unsafe extern "C" fn warn(fmt: *const c_char, mut va_list: ...) { 101 101 let code = Some(ERRNO.get()); 102 102 display_message(code, fmt, va_list.as_va_list()); ··· 105 105 /// Print a user message then an error message for `code`. 106 106 /// 107 107 /// The message format is `progname: fmt: strerror(code)` 108 - #[no_mangle] 108 + #[unsafe(no_mangle)] 109 109 pub unsafe extern "C" fn warnc(code: c_int, fmt: *const c_char, mut va_list: ...) { 110 110 display_message(Some(code), fmt, va_list.as_va_list()); 111 111 } ··· 113 113 /// Print a user message as a warning. 114 114 /// 115 115 /// The message format is `progname: fmt` 116 - #[no_mangle] 116 + #[unsafe(no_mangle)] 117 117 pub unsafe extern "C" fn warnx(fmt: *const c_char, mut va_list: ...) { 118 118 display_message(None, fmt, va_list.as_va_list()); 119 119 } 120 120 121 121 /// See [`err`]. 122 - #[no_mangle] 122 + #[unsafe(no_mangle)] 123 123 pub unsafe extern "C" fn verr(eval: c_int, fmt: *const c_char, args: va_list) -> ! { 124 124 let code = Some(ERRNO.get()); 125 125 err_exit(eval, code, fmt, args); 126 126 } 127 127 128 128 /// See [`errc`]. 129 - #[no_mangle] 129 + #[unsafe(no_mangle)] 130 130 pub unsafe extern "C" fn verrc(eval: c_int, code: c_int, fmt: *const c_char, args: va_list) -> ! { 131 131 err_exit(eval, Some(code), fmt, args) 132 132 } 133 133 134 134 /// See [`errx`]; 135 - #[no_mangle] 135 + #[unsafe(no_mangle)] 136 136 pub unsafe extern "C" fn verrx(eval: c_int, fmt: *const c_char, args: va_list) -> ! { 137 137 err_exit(eval, None, fmt, args) 138 138 } 139 139 140 140 /// See [`warn`]. 141 - #[no_mangle] 141 + #[unsafe(no_mangle)] 142 142 pub unsafe extern "C" fn vwarn(fmt: *const c_char, args: va_list) { 143 143 let code = Some(ERRNO.get()); 144 144 display_message(code, fmt, args); 145 145 } 146 146 147 147 /// See [`warnc`]. 148 - #[no_mangle] 148 + #[unsafe(no_mangle)] 149 149 pub unsafe extern "C" fn vwarnc(code: c_int, fmt: *const c_char, args: va_list) { 150 150 display_message(Some(code), fmt, args); 151 151 } 152 152 153 153 /// See [`warnx`]. 154 - #[no_mangle] 154 + #[unsafe(no_mangle)] 155 155 pub unsafe extern "C" fn vwarnx(fmt: *const c_char, args: va_list) { 156 156 display_message(None, fmt, args); 157 157 }
+6 -6
src/header/errno/mod.rs
··· 8 8 use crate::platform::{self, types::*}; 9 9 10 10 //TODO: Consider removing, provided for compatibility with newlib 11 - #[no_mangle] 11 + #[unsafe(no_mangle)] 12 12 pub extern "C" fn __errno() -> *mut c_int { 13 13 __errno_location() 14 14 } ··· 17 17 /// 18 18 /// This is the basis of the C-facing macro definition of `errno`, and should 19 19 /// not be used directly. 20 - #[no_mangle] 20 + #[unsafe(no_mangle)] 21 21 pub extern "C" fn __errno_location() -> *mut c_int { 22 22 platform::ERRNO.as_ptr() 23 23 } ··· 28 28 /// `program_invocation_name`, and should not be used directly. 29 29 /// 30 30 /// The `program_invocation_name` variable is a GNU extension. 31 - #[no_mangle] 31 + #[unsafe(no_mangle)] 32 32 pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char { 33 - unsafe { &mut platform::program_invocation_name } 33 + unsafe { &raw mut platform::program_invocation_name } 34 34 } 35 35 36 36 /// Get the directory-less name used to invoke the program. ··· 39 39 /// `program_invocation_short_name`, and should not be used directly. 40 40 /// 41 41 /// The `program_invocation_short_name` variable is a GNU extension. 42 - #[no_mangle] 42 + #[unsafe(no_mangle)] 43 43 pub unsafe extern "C" fn __program_invocation_short_name() -> *mut *mut c_char { 44 - unsafe { &mut platform::program_invocation_short_name } 44 + unsafe { &raw mut platform::program_invocation_short_name } 45 45 } 46 46 47 47 pub const EPERM: c_int = 1; /* Operation not permitted */
+5 -5
src/header/fcntl/mod.rs
··· 5 5 use crate::{ 6 6 c_str::CStr, 7 7 error::ResultExt, 8 - platform::{types::*, Pal, Sys}, 8 + platform::{Pal, Sys, types::*}, 9 9 }; 10 10 11 11 pub use self::sys::*; ··· 36 36 pub const F_TLOCK: c_int = 2; 37 37 pub const F_TEST: c_int = 3; 38 38 39 - #[no_mangle] 39 + #[unsafe(no_mangle)] 40 40 pub unsafe extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int { 41 41 unsafe { open(path, O_WRONLY | O_CREAT | O_TRUNC, mode) } 42 42 } ··· 49 49 pub l_len: off_t, 50 50 pub l_pid: pid_t, 51 51 } 52 - #[no_mangle] 52 + #[unsafe(no_mangle)] 53 53 pub unsafe extern "C" fn fcntl(fildes: c_int, cmd: c_int, mut __valist: ...) -> c_int { 54 54 // c_ulonglong 55 55 let arg = match cmd { ··· 62 62 Sys::fcntl(fildes, cmd, arg).or_minus_one_errno() 63 63 } 64 64 65 - #[no_mangle] 65 + #[unsafe(no_mangle)] 66 66 pub unsafe extern "C" fn open(path: *const c_char, oflag: c_int, mut __valist: ...) -> c_int { 67 67 let mode = if oflag & O_CREAT == O_CREAT 68 68 /* || oflag & O_TMPFILE == O_TMPFILE */ ··· 76 76 Sys::open(path, oflag, mode).or_minus_one_errno() 77 77 } 78 78 79 - #[no_mangle] 79 + #[unsafe(no_mangle)] 80 80 pub unsafe extern "C" fn cbindgen_stupid_struct_user_for_fcntl(a: flock) {}
+2 -2
src/header/float/mod.rs
··· 2 2 //! http://pubs.opengroup.org/onlinepubs/7908799/xsh/float.h.html 3 3 4 4 use crate::{ 5 - header::_fenv::{fegetround, FE_TONEAREST}, 5 + header::_fenv::{FE_TONEAREST, fegetround}, 6 6 platform::types::*, 7 7 }; 8 8 9 9 pub const FLT_RADIX: c_int = 2; 10 10 11 - #[no_mangle] 11 + #[unsafe(no_mangle)] 12 12 pub unsafe extern "C" fn flt_rounds() -> c_int { 13 13 match fegetround() { 14 14 FE_TONEAREST => 1,
+2 -2
src/header/fnmatch/mod.rs
··· 9 9 10 10 use crate::platform::types::*; 11 11 use posix_regex::{ 12 + PosixRegex, 12 13 compile::{Collation, Range, Token}, 13 14 tree::{Tree, TreeBuilder}, 14 - PosixRegex, 15 15 }; 16 16 17 17 const ONCE: Range = Range(1, Some(1)); ··· 126 126 builder.finish() 127 127 } 128 128 129 - #[no_mangle] 129 + #[unsafe(no_mangle)] 130 130 #[linkage = "weak"] // often redefined in GNU programs 131 131 pub unsafe extern "C" fn fnmatch( 132 132 pattern: *const c_char,
+1 -1
src/header/getopt/mod.rs
··· 25 25 val: c_int, 26 26 } 27 27 28 - #[no_mangle] 28 + #[unsafe(no_mangle)] 29 29 #[linkage = "weak"] // often redefined in GNU programs 30 30 pub unsafe extern "C" fn getopt_long( 31 31 argc: c_int,
+7 -11
src/header/glob/mod.rs
··· 9 9 use crate::{ 10 10 c_str::{CStr, CString}, 11 11 header::{ 12 - dirent::{closedir, opendir, readdir, DIR}, 12 + dirent::{DIR, closedir, opendir, readdir}, 13 13 errno::*, 14 - fnmatch::{fnmatch, FNM_NOESCAPE, FNM_PERIOD}, 15 - sys_stat::{stat, S_IFDIR, S_IFLNK, S_IFMT}, 14 + fnmatch::{FNM_NOESCAPE, FNM_PERIOD, fnmatch}, 15 + sys_stat::{S_IFDIR, S_IFLNK, S_IFMT, stat}, 16 16 }, 17 17 platform::{self, types::*}, 18 18 }; ··· 53 53 } 54 54 55 55 #[linkage = "weak"] // GNU prefers its own glob e.g. in Make 56 - #[no_mangle] 56 + #[unsafe(no_mangle)] 57 57 pub unsafe extern "C" fn glob( 58 58 pattern: *const c_char, 59 59 flags: c_int, ··· 147 147 } 148 148 149 149 #[linkage = "weak"] // GNU prefers its own glob e.g. in Make 150 - #[no_mangle] 150 + #[unsafe(no_mangle)] 151 151 pub unsafe extern "C" fn globfree(pglob: *mut glob_t) { 152 152 // Retake ownership 153 153 if unsafe { !(*pglob).__opaque.is_null() } { ··· 331 331 let mut new_dir: Vec<u8> = Vec::new(); 332 332 new_dir.extend_from_slice(current_dir.to_bytes()); 333 333 new_dir.extend_from_slice(&pattern); 334 - return inner_glob( 335 - unsafe { &CStr::from_bytes_with_nul_unchecked(&new_dir) }, 336 - &new_glob_expr, 337 - flags, 338 - errfunc, 339 - ); 334 + let new_dir_c = unsafe { CStr::from_bytes_with_nul_unchecked(&new_dir) }; 335 + return inner_glob(&new_dir_c, &new_glob_expr, flags, errfunc); 340 336 } 341 337 342 338 let mut fnmatch_flags = 0;
+12 -12
src/header/grp/mod.rs
··· 24 24 fs::File, 25 25 header::{errno, fcntl, limits, string::strlen, unistd}, 26 26 io, 27 - io::{prelude::*, BufReader, Lines}, 27 + io::{BufReader, Lines, prelude::*}, 28 28 platform, 29 29 platform::types::*, 30 30 sync::Mutex, ··· 116 116 unsafe { 117 117 GROUP_BUF = Some(self.buffer); 118 118 GROUP = self.reference; 119 - &mut GROUP 119 + &raw mut GROUP 120 120 } 121 121 } 122 122 } ··· 249 249 } 250 250 251 251 // MT-Unsafe race:grgid locale 252 - #[no_mangle] 252 + #[unsafe(no_mangle)] 253 253 pub unsafe extern "C" fn getgrgid(gid: gid_t) -> *mut group { 254 254 let Ok(db) = File::open(GROUP_FILE.into(), fcntl::O_RDONLY) else { 255 255 return ptr::null_mut(); ··· 272 272 } 273 273 274 274 // MT-Unsafe race:grnam locale 275 - #[no_mangle] 275 + #[unsafe(no_mangle)] 276 276 pub unsafe extern "C" fn getgrnam(name: *const c_char) -> *mut group { 277 277 let Ok(db) = File::open(GROUP_FILE.into(), fcntl::O_RDONLY) else { 278 278 return ptr::null_mut(); ··· 303 303 } 304 304 305 305 // MT-Safe locale 306 - #[no_mangle] 306 + #[unsafe(no_mangle)] 307 307 pub unsafe extern "C" fn getgrgid_r( 308 308 gid: gid_t, 309 309 result_buf: *mut group, ··· 343 343 io::ErrorKind::NotFound => ENOENT, 344 344 _ => EIO, 345 345 }, 346 - } 346 + }; 347 347 } 348 348 }; 349 349 ··· 362 362 } 363 363 364 364 // MT-Safe locale 365 - #[no_mangle] 365 + #[unsafe(no_mangle)] 366 366 pub unsafe extern "C" fn getgrnam_r( 367 367 name: *const c_char, 368 368 result_buf: *mut group, ··· 406 406 } 407 407 408 408 // MT-Unsafe race:grent race:grentbuf locale 409 - #[no_mangle] 409 + #[unsafe(no_mangle)] 410 410 pub unsafe extern "C" fn getgrent() -> *mut group { 411 411 let mut line_reader = unsafe { &mut *LINE_READER.get() }; 412 412 ··· 436 436 } 437 437 438 438 // MT-Unsafe race:grent locale 439 - #[no_mangle] 439 + #[unsafe(no_mangle)] 440 440 pub unsafe extern "C" fn endgrent() { 441 441 unsafe { 442 442 *(&mut *LINE_READER.get()) = None; ··· 444 444 } 445 445 446 446 // MT-Unsafe race:grent locale 447 - #[no_mangle] 447 + #[unsafe(no_mangle)] 448 448 pub unsafe extern "C" fn setgrent() { 449 449 let mut line_reader = unsafe { &mut *LINE_READER.get() }; 450 450 let Ok(db) = File::open(GROUP_FILE.into(), fcntl::O_RDONLY) else { ··· 455 455 456 456 // MT-Safe locale 457 457 // Not POSIX 458 - #[no_mangle] 458 + #[unsafe(no_mangle)] 459 459 pub unsafe extern "C" fn getgrouplist( 460 460 user: *const c_char, 461 461 group: gid_t, ··· 523 523 524 524 // MT-Safe locale 525 525 // Not POSIX 526 - #[no_mangle] 526 + #[unsafe(no_mangle)] 527 527 pub unsafe extern "C" fn initgroups(user: *const c_char, gid: gid_t) -> c_int { 528 528 let mut groups = [0; limits::NGROUPS_MAX]; 529 529 let mut count = groups.len() as c_int;
+4 -4
src/header/inttypes/mod.rs
··· 10 10 }; 11 11 12 12 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/imaxabs.html>. 13 - #[no_mangle] 13 + #[unsafe(no_mangle)] 14 14 pub extern "C" fn imaxabs(i: intmax_t) -> intmax_t { 15 15 i.abs() 16 16 } ··· 23 23 } 24 24 25 25 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/imaxdiv.html>. 26 - #[no_mangle] 26 + #[unsafe(no_mangle)] 27 27 pub extern "C" fn imaxdiv(i: intmax_t, j: intmax_t) -> imaxdiv_t { 28 28 imaxdiv_t { 29 29 quot: i / j, ··· 32 32 } 33 33 34 34 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoimax.html>. 35 - #[no_mangle] 35 + #[unsafe(no_mangle)] 36 36 pub unsafe extern "C" fn strtoimax( 37 37 s: *const c_char, 38 38 endptr: *mut *mut c_char, ··· 52 52 } 53 53 54 54 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoimax.html>. 55 - #[no_mangle] 55 + #[unsafe(no_mangle)] 56 56 pub unsafe extern "C" fn strtoumax( 57 57 s: *const c_char, 58 58 endptr: *mut *mut c_char,
+1 -1
src/header/langinfo/mod.rs
··· 139 139 /// # Safety 140 140 /// - Caller must ensure `item` is a valid `nl_item` index. 141 141 /// - Returns a pointer to a null-terminated string, or an empty string if the item is invalid. 142 - #[no_mangle] 142 + #[unsafe(no_mangle)] 143 143 pub unsafe extern "C" fn nl_langinfo(item: nl_item) -> *const c_char { 144 144 // Validate the item and perform the lookup 145 145 if (item as usize) < STRING_TABLE.len() {
+2 -2
src/header/libgen/mod.rs
··· 6 6 7 7 use crate::header::string::strlen; 8 8 9 - #[no_mangle] 9 + #[unsafe(no_mangle)] 10 10 pub unsafe extern "C" fn basename(str: *mut c_char) -> *mut c_char { 11 11 if str.is_null() || unsafe { strlen(str) == 0 } { 12 12 return ".\0".as_ptr() as *mut c_char; ··· 28 28 } 29 29 } 30 30 31 - #[no_mangle] 31 + #[unsafe(no_mangle)] 32 32 pub unsafe extern "C" fn dirname(str: *mut c_char) -> *mut c_char { 33 33 if str.is_null() || unsafe { strlen(str) == 0 } { 34 34 return ".\0".as_ptr() as *mut c_char;
+4 -4
src/header/locale/mod.rs
··· 54 54 thousands_sep: EMPTY_PTR, 55 55 }; 56 56 57 - #[no_mangle] 57 + #[unsafe(no_mangle)] 58 58 pub unsafe extern "C" fn localeconv() -> *mut lconv { 59 - &mut CURRENT_LOCALE as *mut _ 59 + &raw mut CURRENT_LOCALE as *mut _ 60 60 } 61 61 62 - #[no_mangle] 62 + #[unsafe(no_mangle)] 63 63 pub unsafe extern "C" fn setlocale(_option: c_int, _val: *const c_char) -> *mut c_char { 64 64 // TODO actually implement 65 - C_LOCALE.as_mut_ptr() as *mut c_char 65 + &raw mut C_LOCALE as *mut c_char 66 66 }
+2 -2
src/header/malloc/mod.rs
··· 4 4 5 5 use crate::{ 6 6 header::errno::*, 7 - platform::{self, types::*, Pal, Sys, ERRNO}, 7 + platform::{self, ERRNO, Pal, Sys, types::*}, 8 8 }; 9 9 use core::ptr; 10 10 11 11 /// See <https://man7.org/linux/man-pages/man3/posix_memalign.3.html>. 12 12 #[deprecated] 13 - #[no_mangle] 13 + #[unsafe(no_mangle)] 14 14 pub unsafe extern "C" fn pvalloc(size: size_t) -> *mut c_void { 15 15 let page_size = Sys::getpagesize(); 16 16 // Find the smallest multiple of the page size in which the requested size
+1 -1
src/header/monetary/strfmon.rs
··· 1 1 use crate::platform::types::c_char; 2 2 3 - use super::{apply_grouping, FormatFlags, LocaleMonetaryInfo, DEFAULT_MONETARY}; 3 + use super::{DEFAULT_MONETARY, FormatFlags, LocaleMonetaryInfo, apply_grouping}; 4 4 use alloc::string::{String, ToString}; 5 5 use core::{ffi::CStr, ptr, result, slice, str}; 6 6 use libm::{fabs, floor, pow, round, trunc};
+5 -5
src/header/net_if/mod.rs
··· 8 8 9 9 use crate::{ 10 10 c_str::CStr, 11 - platform::{types::*, ERRNO}, 11 + platform::{ERRNO, types::*}, 12 12 }; 13 13 14 14 use super::errno::ENXIO; ··· 40 40 /// 41 41 /// # Safety 42 42 /// this is a no-op: the list returned by if_nameindex() is a ref to a constant 43 - #[no_mangle] 43 + #[unsafe(no_mangle)] 44 44 pub unsafe extern "C" fn if_freenameindex(s: *mut if_nameindex) {} 45 45 46 46 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/if_indextoname.html>. ··· 49 49 /// Returns only static lifetime references to const names, does not reuse the buf pointer. 50 50 /// Returns NULL in case of not found + ERRNO being set to ENXIO. 51 51 /// Currently only checks against inteface index 1. 52 - #[no_mangle] 52 + #[unsafe(no_mangle)] 53 53 pub unsafe extern "C" fn if_indextoname(idx: c_uint, buf: *mut c_char) -> *const c_char { 54 54 if idx == 1 { 55 55 return IF_STUB_INTERFACE; ··· 63 63 /// # Safety 64 64 /// Returns a constant pointer to a pre defined const stub list 65 65 /// The end of the list is determined by an if_nameindex struct having if_index 0 and if_name NULL 66 - #[no_mangle] 66 + #[unsafe(no_mangle)] 67 67 pub unsafe extern "C" fn if_nameindex() -> *const if_nameindex { 68 68 &INTERFACES[0] as *const if_nameindex 69 69 } ··· 73 73 /// # Safety 74 74 /// Compares the name to a constant string and only returns an int as a result. 75 75 /// An invalid name string will return an index of 0 76 - #[no_mangle] 76 + #[unsafe(no_mangle)] 77 77 pub unsafe extern "C" fn if_nametoindex(name: *const c_char) -> c_uint { 78 78 if name == null::<c_char>() { 79 79 return 0;
+16 -14
src/header/netdb/host.rs
··· 9 9 unistd::SEEK_SET, 10 10 }, 11 11 platform::{ 12 + Pal, Sys, 12 13 rlb::{Line, RawLineBuffer}, 13 14 types::*, 14 - Pal, Sys, 15 15 }, 16 + raw_cell::RawCell, 16 17 }; 17 18 18 19 use super::{bytes_to_box_str, hostent}; ··· 25 26 h_length: 0, 26 27 h_addr_list: ptr::null_mut(), 27 28 }; 28 - pub static mut HOST_NAME: Option<Vec<u8>> = None; 29 - pub static mut HOST_ALIASES: Option<Vec<Vec<u8>>> = None; 30 - static mut _HOST_ALIASES: Option<Vec<*mut c_char>> = None; 29 + pub static HOST_NAME: RawCell<Option<Vec<u8>>> = RawCell::new(None); 30 + pub static HOST_ALIASES: RawCell<Option<Vec<Vec<u8>>>> = RawCell::new(None); 31 + static _HOST_ALIASES: RawCell<Option<Vec<*mut c_char>>> = RawCell::new(None); 31 32 pub static mut HOST_ADDR: Option<in_addr> = None; 32 33 pub static mut HOST_ADDR_LIST: [*mut c_char; 2] = [ptr::null_mut(); 2]; 33 34 pub static mut _HOST_ADDR_LIST: [u8; 4] = [0u8; 4]; 34 35 static mut H_POS: usize = 0; 35 36 pub static mut HOST_STAYOPEN: c_int = 0; 36 37 37 - #[no_mangle] 38 + #[unsafe(no_mangle)] 38 39 pub unsafe extern "C" fn endhostent() { 39 40 if HOSTDB >= 0 { 40 41 Sys::close(HOSTDB); ··· 42 43 HOSTDB = -1; 43 44 } 44 45 45 - #[no_mangle] 46 + #[unsafe(no_mangle)] 46 47 pub unsafe extern "C" fn sethostent(stayopen: c_int) { 47 48 HOST_STAYOPEN = stayopen; 48 49 if HOSTDB < 0 { ··· 53 54 H_POS = 0; 54 55 } 55 56 56 - #[no_mangle] 57 + #[unsafe(no_mangle)] 57 58 pub unsafe extern "C" fn gethostent() -> *mut hostent { 58 59 if HOSTDB < 0 { 59 60 HOSTDB = Sys::open(c"/etc/hosts".into(), O_RDONLY, 0).or_minus_one_errno(); ··· 85 86 let addr = addr.assume_init(); 86 87 87 88 _HOST_ADDR_LIST = addr.s_addr.to_ne_bytes(); 88 - HOST_ADDR_LIST = [_HOST_ADDR_LIST.as_mut_ptr() as *mut c_char, ptr::null_mut()]; 89 + HOST_ADDR_LIST = [&raw mut _HOST_ADDR_LIST as *mut c_char, ptr::null_mut()]; 89 90 90 91 HOST_ADDR = Some(addr); 91 92 ··· 94 95 let mut _host_aliases: Vec<Vec<u8>> = iter 95 96 .map(|alias| alias.bytes().chain(Some(b'\0')).collect()) 96 97 .collect(); 97 - HOST_ALIASES = Some(_host_aliases); 98 + *HOST_ALIASES.as_mut_ptr() = Some(_host_aliases); 98 99 99 100 let mut host_aliases: Vec<*mut c_char> = HOST_ALIASES 101 + .unsafe_mut() 100 102 .as_mut() 101 103 .unwrap() 102 104 .iter_mut() ··· 104 106 .chain([ptr::null_mut(), ptr::null_mut()]) 105 107 .collect(); 106 108 107 - HOST_NAME = Some(host_name); 109 + *HOST_NAME.as_mut_ptr() = Some(host_name); 108 110 109 111 HOST_ENTRY = hostent { 110 - h_name: HOST_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char, 112 + h_name: HOST_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char, 111 113 h_aliases: host_aliases.as_mut_slice().as_mut_ptr(), 112 114 h_addrtype: AF_INET, 113 115 h_length: 4, 114 - h_addr_list: HOST_ADDR_LIST.as_mut_ptr(), 116 + h_addr_list: &raw mut HOST_ADDR_LIST as *mut _, 115 117 }; 116 - _HOST_ALIASES = Some(host_aliases); 118 + *_HOST_ALIASES.as_mut_ptr() = Some(host_aliases); 117 119 if HOST_STAYOPEN == 0 { 118 120 endhostent(); 119 121 } 120 - &mut HOST_ENTRY as *mut hostent 122 + &raw mut HOST_ENTRY as *mut hostent 121 123 }
+2 -2
src/header/netdb/lookup.rs
··· 7 7 8 8 use crate::{ 9 9 out::Out, 10 - platform::{types::*, Pal, Sys}, 10 + platform::{Pal, Sys, types::*}, 11 11 }; 12 12 13 13 use crate::header::{ 14 14 errno::*, 15 - netinet_in::{htons, in_addr, sockaddr_in, IPPROTO_UDP}, 15 + netinet_in::{IPPROTO_UDP, htons, in_addr, sockaddr_in}, 16 16 sys_socket::{ 17 17 self, 18 18 constants::{AF_INET, SOCK_DGRAM},
+73 -58
src/header/netdb/mod.rs
··· 27 27 unistd::SEEK_SET, 28 28 }, 29 29 platform::{ 30 - self, 30 + self, Pal, Sys, 31 31 rlb::{Line, RawLineBuffer}, 32 32 types::*, 33 - Pal, Sys, 34 33 }, 34 + raw_cell::RawCell, 35 35 }; 36 36 37 37 #[cfg(target_os = "linux")] ··· 130 130 n_addrtype: 0, 131 131 n_net: 0, 132 132 }; 133 - pub static mut NET_NAME: Option<Vec<u8>> = None; 134 - pub static mut NET_ALIASES: Option<Vec<Vec<u8>>> = None; 133 + pub static NET_NAME: RawCell<Option<Vec<u8>>> = RawCell::new(None); 134 + pub static NET_ALIASES: RawCell<Option<Vec<Vec<u8>>>> = RawCell::new(None); 135 135 pub static mut NET_ADDR: Option<u32> = None; 136 136 static mut N_POS: usize = 0; 137 137 static mut NET_STAYOPEN: c_int = 0; ··· 154 154 p_aliases: ptr::null_mut(), 155 155 p_proto: 0 as c_int, 156 156 }; 157 - static mut PROTO_NAME: Option<Vec<u8>> = None; 158 - static mut PROTO_ALIASES: Option<Vec<Vec<u8>>> = None; 157 + static PROTO_NAME: RawCell<Option<Vec<u8>>> = RawCell::new(None); 158 + static PROTO_ALIASES: RawCell<Option<Vec<Vec<u8>>>> = RawCell::new(None); 159 159 static mut PROTO_NUM: Option<c_int> = None; 160 160 static mut P_POS: usize = 0; 161 161 static mut PROTO_STAYOPEN: c_int = 0; ··· 167 167 s_port: 0 as c_int, 168 168 s_proto: ptr::null_mut(), 169 169 }; 170 - static mut SERV_NAME: Option<Vec<u8>> = None; 171 - static mut SERV_ALIASES: Option<Vec<Vec<u8>>> = None; 170 + static SERV_NAME: RawCell<Option<Vec<u8>>> = RawCell::new(None); 171 + static SERV_ALIASES: RawCell<Option<Vec<Vec<u8>>>> = RawCell::new(None); 172 172 static mut SERV_PORT: Option<c_int> = None; 173 - static mut SERV_PROTO: Option<Vec<u8>> = None; 173 + static SERV_PROTO: RawCell<Option<Vec<u8>>> = RawCell::new(None); 174 174 static mut S_POS: usize = 0; 175 175 static mut SERV_STAYOPEN: c_int = 0; 176 176 ··· 178 178 Box::from(core::str::from_utf8(bytes).unwrap_or("")) 179 179 } 180 180 181 - #[no_mangle] 181 + #[unsafe(no_mangle)] 182 182 pub unsafe extern "C" fn endnetent() { 183 183 Sys::close(NETDB); 184 184 NETDB = 0; 185 185 } 186 186 187 - #[no_mangle] 187 + #[unsafe(no_mangle)] 188 188 pub unsafe extern "C" fn endprotoent() { 189 189 Sys::close(PROTODB); 190 190 PROTODB = 0; 191 191 } 192 192 193 - #[no_mangle] 193 + #[unsafe(no_mangle)] 194 194 pub unsafe extern "C" fn endservent() { 195 195 Sys::close(SERVDB); 196 196 SERVDB = 0; ··· 214 214 /// # Deprecation 215 215 /// Deprecated as of POSIX.1-2001 and removed in POSIX.1-2008. 216 216 /// New code should use [`getaddrinfo`] instead. 217 - #[no_mangle] 217 + #[unsafe(no_mangle)] 218 218 #[deprecated] 219 219 pub unsafe extern "C" fn gethostbyaddr( 220 220 v: *const c_void, ··· 267 267 _host_aliases.push(vec![b'\0']); 268 268 let mut host_aliases: Vec<*mut c_char> = Vec::new(); 269 269 host_aliases.push(ptr::null_mut()); 270 - HOST_ALIASES = Some(_host_aliases); 270 + *HOST_ALIASES.as_mut_ptr() = Some(_host_aliases); 271 271 272 272 match lookup_addr(addr).map(|host_names| host_names.into_iter().next()) { 273 273 Ok(Some(host_name)) => { 274 274 _HOST_ADDR_LIST = addr.s_addr.to_ne_bytes(); 275 - HOST_ADDR_LIST = [_HOST_ADDR_LIST.as_mut_ptr() as *mut c_char, ptr::null_mut()]; 276 - HOST_NAME = Some(host_name); 275 + HOST_ADDR_LIST = [&raw mut _HOST_ADDR_LIST as *mut c_char, ptr::null_mut()]; 276 + *HOST_NAME.as_mut_ptr() = Some(host_name); 277 277 HOST_ENTRY = hostent { 278 - h_name: HOST_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char, 278 + h_name: HOST_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char, 279 279 h_aliases: host_aliases.as_mut_slice().as_mut_ptr(), 280 280 h_addrtype: format, 281 281 h_length: length as i32, 282 - h_addr_list: HOST_ADDR_LIST.as_mut_ptr(), 282 + h_addr_list: &raw mut HOST_ADDR_LIST as *mut _, 283 283 }; 284 - &mut HOST_ENTRY 284 + &raw mut HOST_ENTRY 285 285 } 286 286 // `glibc` sets errno if an address doesn't have a host name 287 287 // `musl` uses the address as the host name in said case ··· 312 312 /// # Deprecation 313 313 /// Deprecated as of POSIX.1-2001 and removed in POSIX.1-2008. 314 314 /// New code should use [`getaddrinfo`] instead. 315 - #[no_mangle] 315 + #[unsafe(no_mangle)] 316 316 #[deprecated] 317 317 pub unsafe extern "C" fn gethostbyname(name: *const c_char) -> *mut hostent { 318 318 let name_cstr = ··· 373 373 }; 374 374 375 375 let host_name: Vec<u8> = name_cstr.to_bytes().to_vec(); 376 - HOST_NAME = Some(host_name); 376 + *HOST_NAME.as_mut_ptr() = Some(host_name); 377 377 _HOST_ADDR_LIST = host_addr.s_addr.to_ne_bytes(); 378 - HOST_ADDR_LIST = [_HOST_ADDR_LIST.as_mut_ptr() as *mut c_char, ptr::null_mut()]; 378 + HOST_ADDR_LIST = [&raw mut _HOST_ADDR_LIST as *mut c_char, ptr::null_mut()]; 379 379 HOST_ADDR = Some(host_addr); 380 380 381 381 //TODO actually get aliases ··· 384 384 let mut host_aliases: Vec<*mut c_char> = Vec::new(); 385 385 host_aliases.push(ptr::null_mut()); 386 386 host_aliases.push(ptr::null_mut()); 387 - HOST_ALIASES = Some(_host_aliases); 387 + *HOST_ALIASES.as_mut_ptr() = Some(_host_aliases); 388 388 389 389 HOST_ENTRY = hostent { 390 - h_name: HOST_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char, 390 + h_name: HOST_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char, 391 391 h_aliases: host_aliases.as_mut_slice().as_mut_ptr(), 392 392 h_addrtype: AF_INET, 393 393 h_length: 4, 394 - h_addr_list: HOST_ADDR_LIST.as_mut_ptr(), 394 + h_addr_list: &raw mut HOST_ADDR_LIST as *mut _, 395 395 }; 396 396 sethostent(HOST_STAYOPEN); 397 - &mut HOST_ENTRY as *mut hostent 397 + &raw mut HOST_ENTRY as *mut hostent 398 398 } 399 399 400 400 pub unsafe extern "C" fn getnetbyaddr(net: u32, net_type: c_int) -> *mut netent { 401 401 unimplemented!(); 402 402 } 403 403 404 - #[no_mangle] 404 + #[unsafe(no_mangle)] 405 405 pub unsafe extern "C" fn getnetbyname(name: *const c_char) -> *mut netent { 406 406 let mut n: *mut netent; 407 407 setnetent(NET_STAYOPEN); ··· 420 420 ptr::null_mut() as *mut netent 421 421 } 422 422 423 - #[no_mangle] 423 + #[unsafe(no_mangle)] 424 424 pub unsafe extern "C" fn getnetent() -> *mut netent { 425 425 // TODO: Rustify implementation 426 426 ··· 449 449 let mut iter: SplitWhitespace = r.split_whitespace(); 450 450 451 451 let net_name = iter.next().unwrap().bytes().chain(Some(b'\0')).collect(); 452 - NET_NAME = Some(net_name); 452 + *NET_NAME.as_mut_ptr() = Some(net_name); 453 453 454 454 let addr_vec: Vec<u8> = iter.next().unwrap().bytes().chain(Some(b'\0')).collect(); 455 455 let addr_cstr = addr_vec.as_slice().as_ptr() as *const c_char; ··· 466 466 .map(|x| x.as_mut_ptr() as *mut c_char) 467 467 .chain(Some(ptr::null_mut())) 468 468 .collect(); 469 - NET_ALIASES = Some(_net_aliases); 469 + *NET_ALIASES.as_mut_ptr() = Some(_net_aliases); 470 470 471 471 NET_ENTRY = netent { 472 - n_name: NET_NAME.as_mut().unwrap().as_mut_ptr() as *mut c_char, 472 + n_name: NET_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char, 473 473 n_aliases: net_aliases.as_mut_slice().as_mut_ptr(), 474 474 n_addrtype: AF_INET, 475 475 n_net: NET_ADDR.unwrap() as c_ulong, 476 476 }; 477 - &mut NET_ENTRY as *mut netent 477 + &raw mut NET_ENTRY as *mut netent 478 478 } 479 479 480 - #[no_mangle] 480 + #[unsafe(no_mangle)] 481 481 pub unsafe extern "C" fn getprotobyname(name: *const c_char) -> *mut protoent { 482 482 let mut p: *mut protoent; 483 483 setprotoent(PROTO_STAYOPEN); ··· 513 513 ptr::null_mut() as *mut protoent 514 514 } 515 515 516 - #[no_mangle] 516 + #[unsafe(no_mangle)] 517 517 pub unsafe extern "C" fn getprotobynumber(number: c_int) -> *mut protoent { 518 518 setprotoent(PROTO_STAYOPEN); 519 519 let mut p: *mut protoent; ··· 531 531 ptr::null_mut() as *mut protoent 532 532 } 533 533 534 - #[no_mangle] 534 + #[unsafe(no_mangle)] 535 535 pub unsafe extern "C" fn getprotoent() -> *mut protoent { 536 536 if PROTODB == 0 { 537 537 PROTODB = Sys::open(c"/etc/protocols".into(), O_RDONLY, 0).or_minus_one_errno(); ··· 573 573 .chain(Some(ptr::null_mut())) 574 574 .collect(); 575 575 576 - PROTO_ALIASES = Some(_proto_aliases); 577 - PROTO_NAME = Some(proto_name); 576 + *PROTO_ALIASES.as_mut_ptr() = Some(_proto_aliases); 577 + *PROTO_NAME.as_mut_ptr() = Some(proto_name); 578 578 579 579 PROTO_ENTRY = protoent { 580 - p_name: PROTO_NAME.as_mut().unwrap().as_mut_slice().as_mut_ptr() as *mut c_char, 580 + p_name: PROTO_NAME 581 + .unsafe_mut() 582 + .as_mut() 583 + .unwrap() 584 + .as_mut_slice() 585 + .as_mut_ptr() as *mut c_char, 581 586 p_aliases: proto_aliases.as_mut_slice().as_mut_ptr() as *mut *mut c_char, 582 587 p_proto: PROTO_NUM.unwrap(), 583 588 }; 584 589 if PROTO_STAYOPEN == 0 { 585 590 endprotoent(); 586 591 } 587 - &mut PROTO_ENTRY as *mut protoent 592 + &raw mut PROTO_ENTRY as *mut protoent 588 593 } 589 594 590 - #[no_mangle] 595 + #[unsafe(no_mangle)] 591 596 pub unsafe extern "C" fn getservbyname(name: *const c_char, proto: *const c_char) -> *mut servent { 592 597 setservent(SERV_STAYOPEN); 593 598 let mut p: *mut servent; ··· 617 622 ptr::null_mut() as *mut servent 618 623 } 619 624 620 - #[no_mangle] 625 + #[unsafe(no_mangle)] 621 626 pub unsafe extern "C" fn getservbyport(port: c_int, proto: *const c_char) -> *mut servent { 622 627 setservent(SERV_STAYOPEN); 623 628 let mut p: *mut servent; ··· 647 652 ptr::null_mut() 648 653 } 649 654 650 - #[no_mangle] 655 + #[unsafe(no_mangle)] 651 656 pub unsafe extern "C" fn getservent() -> *mut servent { 652 657 if SERVDB == 0 { 653 658 // TODO: Rustify ··· 713 718 serv_aliases.push(ptr::null_mut()); 714 719 serv_aliases.push(ptr::null_mut()); 715 720 716 - SERV_ALIASES = Some(_serv_aliases); 717 - SERV_NAME = Some(serv_name); 718 - SERV_PROTO = Some(proto); 721 + *SERV_ALIASES.as_mut_ptr() = Some(_serv_aliases); 722 + *SERV_NAME.as_mut_ptr() = Some(serv_name); 723 + *SERV_PROTO.as_mut_ptr() = Some(proto); 719 724 720 725 SERV_ENTRY = servent { 721 - s_name: SERV_NAME.as_mut().unwrap().as_mut_slice().as_mut_ptr() as *mut c_char, 726 + s_name: SERV_NAME 727 + .unsafe_mut() 728 + .as_mut() 729 + .unwrap() 730 + .as_mut_slice() 731 + .as_mut_ptr() as *mut c_char, 722 732 s_aliases: serv_aliases.as_mut_slice().as_mut_ptr() as *mut *mut c_char, 723 733 s_port: SERV_PORT.unwrap(), 724 - s_proto: SERV_PROTO.as_mut().unwrap().as_mut_slice().as_mut_ptr() as *mut c_char, 734 + s_proto: SERV_PROTO 735 + .unsafe_mut() 736 + .as_mut() 737 + .unwrap() 738 + .as_mut_slice() 739 + .as_mut_ptr() as *mut c_char, 725 740 }; 726 741 727 742 if SERV_STAYOPEN == 0 { 728 743 endservent(); 729 744 } 730 - break &mut SERV_ENTRY as *mut servent; 745 + break &raw mut SERV_ENTRY as *mut servent; 731 746 } 732 747 } 733 748 734 - #[no_mangle] 749 + #[unsafe(no_mangle)] 735 750 pub unsafe extern "C" fn setnetent(stayopen: c_int) { 736 751 NET_STAYOPEN = stayopen; 737 752 if NETDB == 0 { ··· 742 757 } 743 758 } 744 759 745 - #[no_mangle] 760 + #[unsafe(no_mangle)] 746 761 pub unsafe extern "C" fn setprotoent(stayopen: c_int) { 747 762 PROTO_STAYOPEN = stayopen; 748 763 if PROTODB == 0 { ··· 753 768 } 754 769 } 755 770 756 - #[no_mangle] 771 + #[unsafe(no_mangle)] 757 772 pub unsafe extern "C" fn setservent(stayopen: c_int) { 758 773 SERV_STAYOPEN = stayopen; 759 774 if SERVDB == 0 { ··· 764 779 } 765 780 } 766 781 767 - #[no_mangle] 782 + #[unsafe(no_mangle)] 768 783 pub unsafe extern "C" fn getaddrinfo( 769 784 node: *const c_char, 770 785 service: *const c_char, ··· 869 884 0 870 885 } 871 886 872 - #[no_mangle] 887 + #[unsafe(no_mangle)] 873 888 pub unsafe extern "C" fn getnameinfo( 874 889 addr: *const sockaddr, 875 890 addrlen: socklen_t, ··· 956 971 0 957 972 } 958 973 959 - #[no_mangle] 974 + #[unsafe(no_mangle)] 960 975 pub unsafe extern "C" fn freeaddrinfo(res: *mut addrinfo) { 961 976 let mut ai = res; 962 977 while !ai.is_null() { ··· 977 992 } 978 993 } 979 994 980 - #[no_mangle] 995 + #[unsafe(no_mangle)] 981 996 pub const extern "C" fn gai_strerror(errcode: c_int) -> *const c_char { 982 997 match errcode { 983 998 EAI_BADFLAGS => c"Invalid flags", ··· 998 1013 } 999 1014 1000 1015 /// Provide a pointer to relibc's internal [`H_ERRNO`]. 1001 - #[no_mangle] 1016 + #[unsafe(no_mangle)] 1002 1017 #[deprecated] 1003 1018 pub extern "C" fn __h_errno_location() -> *mut c_int { 1004 1019 H_ERRNO.as_ptr() 1005 1020 } 1006 1021 1007 - #[no_mangle] 1022 + #[unsafe(no_mangle)] 1008 1023 #[deprecated] 1009 1024 pub const extern "C" fn hstrerror(errcode: c_int) -> *const c_char { 1010 1025 match errcode { ··· 1032 1047 /// [`H_ERRNO`], [`hstrerror`], [`herror`], and other functions are deprecated as of 1033 1048 /// POSIX.1-2001 and removed as of POSIX.1-2008. These functions are provided for backwards 1034 1049 /// compatibility but should not be used by new code. 1035 - #[no_mangle] 1050 + #[unsafe(no_mangle)] 1036 1051 #[deprecated] 1037 1052 pub extern "C" fn herror(prefix: *const c_char) { 1038 1053 let code = H_ERRNO.get();
+6 -6
src/header/netinet_in/mod.rs
··· 165 165 } 166 166 167 167 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>. 168 - #[no_mangle] 168 + #[unsafe(no_mangle)] 169 169 pub static in6addr_any: in6_addr = in6_addr { 170 170 s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 171 171 }; 172 172 173 173 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>. 174 - #[no_mangle] 174 + #[unsafe(no_mangle)] 175 175 pub static in6addr_loopback: in6_addr = in6_addr { 176 176 s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 177 177 }; 178 178 179 179 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>. 180 - #[no_mangle] 180 + #[unsafe(no_mangle)] 181 181 pub extern "C" fn htonl(hostlong: uint32_t) -> uint32_t { 182 182 hostlong.to_be() 183 183 } 184 184 185 185 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>. 186 - #[no_mangle] 186 + #[unsafe(no_mangle)] 187 187 pub extern "C" fn htons(hostshort: uint16_t) -> uint16_t { 188 188 hostshort.to_be() 189 189 } 190 190 191 191 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>. 192 - #[no_mangle] 192 + #[unsafe(no_mangle)] 193 193 pub extern "C" fn ntohl(netlong: uint32_t) -> uint32_t { 194 194 u32::from_be(netlong) 195 195 } 196 196 197 197 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>. 198 - #[no_mangle] 198 + #[unsafe(no_mangle)] 199 199 pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t { 200 200 u16::from_be(netshort) 201 201 }
+4 -4
src/header/poll/mod.rs
··· 9 9 error::ResultExt, 10 10 fs::File, 11 11 header::sys_epoll::{ 12 - epoll_create1, epoll_ctl, epoll_data, epoll_event, epoll_wait, EPOLLERR, EPOLLHUP, EPOLLIN, 13 - EPOLLNVAL, EPOLLOUT, EPOLLPRI, EPOLLRDBAND, EPOLLRDNORM, EPOLLWRBAND, EPOLLWRNORM, 14 - EPOLL_CLOEXEC, EPOLL_CTL_ADD, 12 + EPOLL_CLOEXEC, EPOLL_CTL_ADD, EPOLLERR, EPOLLHUP, EPOLLIN, EPOLLNVAL, EPOLLOUT, EPOLLPRI, 13 + EPOLLRDBAND, EPOLLRDNORM, EPOLLWRBAND, EPOLLWRNORM, epoll_create1, epoll_ctl, epoll_data, 14 + epoll_event, epoll_wait, 15 15 }, 16 16 platform::types::*, 17 17 }; ··· 113 113 count 114 114 } 115 115 116 - #[no_mangle] 116 + #[unsafe(no_mangle)] 117 117 pub unsafe extern "C" fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: c_int) -> c_int { 118 118 trace_expr!( 119 119 poll_epoll(
+19 -19
src/header/pthread/attr.rs
··· 34 34 } 35 35 } 36 36 37 - #[no_mangle] 37 + #[unsafe(no_mangle)] 38 38 pub unsafe extern "C" fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> c_int { 39 39 core::ptr::drop_in_place(attr); 40 40 0 41 41 } 42 42 43 - #[no_mangle] 43 + #[unsafe(no_mangle)] 44 44 pub unsafe extern "C" fn pthread_attr_getdetachstate( 45 45 attr: *const pthread_attr_t, 46 46 detachstate: *mut c_int, ··· 49 49 0 50 50 } 51 51 52 - #[no_mangle] 52 + #[unsafe(no_mangle)] 53 53 pub unsafe extern "C" fn pthread_attr_getguardsize( 54 54 attr: *const pthread_attr_t, 55 55 size: *mut size_t, ··· 58 58 0 59 59 } 60 60 61 - #[no_mangle] 61 + #[unsafe(no_mangle)] 62 62 pub unsafe extern "C" fn pthread_attr_getinheritsched( 63 63 attr: *const pthread_attr_t, 64 64 inheritsched: *mut c_int, ··· 67 67 0 68 68 } 69 69 70 - #[no_mangle] 70 + #[unsafe(no_mangle)] 71 71 pub unsafe extern "C" fn pthread_attr_getschedparam( 72 72 attr: *const pthread_attr_t, 73 73 param: *mut sched_param, ··· 76 76 0 77 77 } 78 78 79 - #[no_mangle] 79 + #[unsafe(no_mangle)] 80 80 pub unsafe extern "C" fn pthread_attr_getschedpolicy( 81 81 attr: *const pthread_attr_t, 82 82 policy: *mut c_int, ··· 85 85 0 86 86 } 87 87 88 - #[no_mangle] 88 + #[unsafe(no_mangle)] 89 89 pub unsafe extern "C" fn pthread_attr_getscope( 90 90 attr: *const pthread_attr_t, 91 91 scope: *mut c_int, ··· 94 94 0 95 95 } 96 96 97 - #[no_mangle] 97 + #[unsafe(no_mangle)] 98 98 pub unsafe extern "C" fn pthread_attr_getstack( 99 99 attr: *const pthread_attr_t, 100 100 stackaddr: *mut *mut c_void, ··· 105 105 0 106 106 } 107 107 108 - #[no_mangle] 108 + #[unsafe(no_mangle)] 109 109 pub unsafe extern "C" fn pthread_attr_getstacksize( 110 110 attr: *const pthread_attr_t, 111 111 stacksize: *mut size_t, ··· 114 114 0 115 115 } 116 116 117 - #[no_mangle] 117 + #[unsafe(no_mangle)] 118 118 pub unsafe extern "C" fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int { 119 119 core::ptr::write(attr.cast::<RlctAttr>(), RlctAttr::default()); 120 120 0 121 121 } 122 122 123 - #[no_mangle] 123 + #[unsafe(no_mangle)] 124 124 pub unsafe extern "C" fn pthread_attr_setdetachstate( 125 125 attr: *mut pthread_attr_t, 126 126 detachstate: c_int, ··· 129 129 0 130 130 } 131 131 132 - #[no_mangle] 132 + #[unsafe(no_mangle)] 133 133 pub unsafe extern "C" fn pthread_attr_setguardsize( 134 134 attr: *mut pthread_attr_t, 135 135 guardsize: c_int, ··· 138 138 0 139 139 } 140 140 141 - #[no_mangle] 141 + #[unsafe(no_mangle)] 142 142 pub unsafe extern "C" fn pthread_attr_setinheritsched( 143 143 attr: *mut pthread_attr_t, 144 144 inheritsched: c_int, ··· 147 147 0 148 148 } 149 149 150 - #[no_mangle] 150 + #[unsafe(no_mangle)] 151 151 pub unsafe extern "C" fn pthread_attr_setschedparam( 152 152 attr: *mut pthread_attr_t, 153 153 param: *const sched_param, ··· 156 156 0 157 157 } 158 158 159 - #[no_mangle] 159 + #[unsafe(no_mangle)] 160 160 pub unsafe extern "C" fn pthread_attr_setschedpolicy( 161 161 attr: *mut pthread_attr_t, 162 162 policy: c_int, ··· 165 165 0 166 166 } 167 167 168 - #[no_mangle] 168 + #[unsafe(no_mangle)] 169 169 pub unsafe extern "C" fn pthread_attr_setscope(attr: *mut pthread_attr_t, scope: c_int) -> c_int { 170 170 (*attr.cast::<RlctAttr>()).scope = scope as u8; 171 171 0 172 172 } 173 173 174 - #[no_mangle] 174 + #[unsafe(no_mangle)] 175 175 pub unsafe extern "C" fn pthread_attr_setstack( 176 176 attr: *mut pthread_attr_t, 177 177 stackaddr: *mut c_void, ··· 182 182 0 183 183 } 184 184 185 - #[no_mangle] 185 + #[unsafe(no_mangle)] 186 186 pub unsafe extern "C" fn pthread_attr_setstacksize( 187 187 attr: *mut pthread_attr_t, 188 188 stacksize: size_t, ··· 191 191 0 192 192 } 193 193 194 - #[no_mangle] 194 + #[unsafe(no_mangle)] 195 195 pub unsafe extern "C" fn pthread_getattr_np( 196 196 thread_ptr: pthread_t, 197 197 attr_ptr: *mut pthread_attr_t,
+7 -7
src/header/pthread/barrier.rs
··· 22 22 } 23 23 24 24 // Not async-signal-safe. 25 - #[no_mangle] 25 + #[unsafe(no_mangle)] 26 26 pub unsafe extern "C" fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t) -> c_int { 27 27 // Behavior is undefined if any thread is currently waiting when this is called. 28 28 ··· 33 33 } 34 34 35 35 // Not async-signal-safe. 36 - #[no_mangle] 36 + #[unsafe(no_mangle)] 37 37 pub unsafe extern "C" fn pthread_barrier_init( 38 38 barrier: *mut pthread_barrier_t, 39 39 attr: *const pthread_barrierattr_t, ··· 58 58 } 59 59 60 60 // Not async-signal-safe. 61 - #[no_mangle] 61 + #[unsafe(no_mangle)] 62 62 pub unsafe extern "C" fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -> c_int { 63 63 let barrier = &*barrier.cast::<RlctBarrier>(); 64 64 ··· 69 69 } 70 70 71 71 // Not async-signal-safe. 72 - #[no_mangle] 72 + #[unsafe(no_mangle)] 73 73 pub unsafe extern "C" fn pthread_barrierattr_init(attr: *mut pthread_barrierattr_t) -> c_int { 74 74 core::ptr::write(attr.cast::<RlctBarrierAttr>(), RlctBarrierAttr::default()); 75 75 ··· 77 77 } 78 78 79 79 // Not async-signal-safe. 80 - #[no_mangle] 80 + #[unsafe(no_mangle)] 81 81 pub unsafe extern "C" fn pthread_barrierattr_setpshared( 82 82 attr: *mut pthread_barrierattr_t, 83 83 pshared: c_int, ··· 87 87 } 88 88 89 89 // Not async-signal-safe. 90 - #[no_mangle] 90 + #[unsafe(no_mangle)] 91 91 pub unsafe extern "C" fn pthread_barrierattr_getpshared( 92 92 attr: *const pthread_barrierattr_t, 93 93 pshared: *mut c_int, ··· 97 97 } 98 98 99 99 // Not async-signal-safe. 100 - #[no_mangle] 100 + #[unsafe(no_mangle)] 101 101 pub unsafe extern "C" fn pthread_barrierattr_destroy(attr: *mut pthread_barrierattr_t) -> c_int { 102 102 core::ptr::drop_in_place(attr); 103 103 0
+12 -12
src/header/pthread/cond.rs
··· 4 4 5 5 // PTHREAD_COND_INITIALIZER is defined manually in bits_pthread/cbindgen.toml 6 6 7 - #[no_mangle] 7 + #[unsafe(no_mangle)] 8 8 pub unsafe extern "C" fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> c_int { 9 9 e((&*cond.cast::<RlctCond>()).broadcast()) 10 10 } 11 11 12 - #[no_mangle] 12 + #[unsafe(no_mangle)] 13 13 pub unsafe extern "C" fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> c_int { 14 14 // No-op 15 15 core::ptr::drop_in_place(cond.cast::<RlctCond>()); 16 16 0 17 17 } 18 18 19 - #[no_mangle] 19 + #[unsafe(no_mangle)] 20 20 pub unsafe extern "C" fn pthread_cond_init( 21 21 cond: *mut pthread_cond_t, 22 22 _attr: *const pthread_condattr_t, ··· 26 26 0 27 27 } 28 28 29 - #[no_mangle] 29 + #[unsafe(no_mangle)] 30 30 pub unsafe extern "C" fn pthread_cond_signal(cond: *mut pthread_cond_t) -> c_int { 31 31 e((&*cond.cast::<RlctCond>()).signal()) 32 32 } 33 33 34 - #[no_mangle] 34 + #[unsafe(no_mangle)] 35 35 pub unsafe extern "C" fn pthread_cond_timedwait( 36 36 cond: *mut pthread_cond_t, 37 37 mutex: *mut pthread_mutex_t, ··· 40 40 e((&*cond.cast::<RlctCond>()).timedwait(&*mutex.cast::<RlctMutex>(), &*timeout)) 41 41 } 42 42 43 - #[no_mangle] 43 + #[unsafe(no_mangle)] 44 44 pub unsafe extern "C" fn pthread_cond_wait( 45 45 cond: *mut pthread_cond_t, 46 46 mutex: *mut pthread_mutex_t, ··· 48 48 e((&*cond.cast::<RlctCond>()).wait(&*mutex.cast::<RlctMutex>())) 49 49 } 50 50 51 - #[no_mangle] 51 + #[unsafe(no_mangle)] 52 52 pub unsafe extern "C" fn pthread_condattr_destroy(condattr: *mut pthread_condattr_t) -> c_int { 53 53 core::ptr::drop_in_place(condattr.cast::<RlctCondAttr>()); 54 54 // No-op 55 55 0 56 56 } 57 57 58 - #[no_mangle] 58 + #[unsafe(no_mangle)] 59 59 pub unsafe extern "C" fn pthread_condattr_getclock( 60 60 condattr: *const pthread_condattr_t, 61 61 clock: *mut clockid_t, ··· 64 64 0 65 65 } 66 66 67 - #[no_mangle] 67 + #[unsafe(no_mangle)] 68 68 pub unsafe extern "C" fn pthread_condattr_getpshared( 69 69 condattr: *const pthread_condattr_t, 70 70 pshared: *mut c_int, ··· 73 73 0 74 74 } 75 75 76 - #[no_mangle] 76 + #[unsafe(no_mangle)] 77 77 pub unsafe extern "C" fn pthread_condattr_init(condattr: *mut pthread_condattr_t) -> c_int { 78 78 condattr 79 79 .cast::<RlctCondAttr>() ··· 82 82 0 83 83 } 84 84 85 - #[no_mangle] 85 + #[unsafe(no_mangle)] 86 86 pub unsafe extern "C" fn pthread_condattr_setclock( 87 87 condattr: *mut pthread_condattr_t, 88 88 clock: clockid_t, ··· 91 91 0 92 92 } 93 93 94 - #[no_mangle] 94 + #[unsafe(no_mangle)] 95 95 pub unsafe extern "C" fn pthread_condattr_setpshared( 96 96 condattr: *mut pthread_condattr_t, 97 97 pshared: c_int,
+20 -20
src/header/pthread/mod.rs
··· 6 6 use crate::{ 7 7 error::Errno, 8 8 header::{sched::*, time::timespec}, 9 - platform::{types::*, Pal, Sys}, 9 + platform::{Pal, Sys, types::*}, 10 10 pthread, 11 11 }; 12 12 ··· 79 79 #[thread_local] 80 80 pub static mut fork_hooks: [LinkedList<extern "C" fn()>; 3] = [const { LinkedList::new() }; 3]; 81 81 82 - #[no_mangle] 82 + #[unsafe(no_mangle)] 83 83 pub unsafe extern "C" fn pthread_cancel(thread: pthread_t) -> c_int { 84 84 match pthread::cancel(&*thread.cast()) { 85 85 Ok(()) => 0, ··· 87 87 } 88 88 } 89 89 90 - #[no_mangle] 90 + #[unsafe(no_mangle)] 91 91 pub unsafe extern "C" fn pthread_create( 92 92 pthread: *mut pthread_t, 93 93 attr: *const pthread_attr_t, ··· 105 105 } 106 106 } 107 107 108 - #[no_mangle] 108 + #[unsafe(no_mangle)] 109 109 pub unsafe extern "C" fn pthread_detach(pthread: pthread_t) -> c_int { 110 110 match pthread::detach(&*pthread.cast()) { 111 111 Ok(()) => 0, ··· 113 113 } 114 114 } 115 115 116 - #[no_mangle] 116 + #[unsafe(no_mangle)] 117 117 pub extern "C" fn pthread_equal(pthread1: pthread_t, pthread2: pthread_t) -> c_int { 118 118 core::ptr::eq(pthread1, pthread2).into() 119 119 } 120 120 121 121 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_atfork.html>. 122 - #[no_mangle] 122 + #[unsafe(no_mangle)] 123 123 pub extern "C" fn pthread_atfork( 124 124 prepare: Option<extern "C" fn()>, 125 125 parent: Option<extern "C" fn()>, ··· 143 143 0 144 144 } 145 145 146 - #[no_mangle] 146 + #[unsafe(no_mangle)] 147 147 pub unsafe extern "C" fn pthread_exit(retval: *mut c_void) -> ! { 148 148 pthread::exit_current_thread(pthread::Retval(retval)) 149 149 } 150 150 151 - #[no_mangle] 151 + #[unsafe(no_mangle)] 152 152 pub unsafe extern "C" fn pthread_getconcurrency() -> c_int { 153 153 // Redox and Linux threads are 1:1, not M:N. 154 154 1 155 155 } 156 156 157 - #[no_mangle] 157 + #[unsafe(no_mangle)] 158 158 pub unsafe extern "C" fn pthread_getcpuclockid( 159 159 thread: pthread_t, 160 160 clock_out: *mut clockid_t, ··· 168 168 } 169 169 } 170 170 171 - #[no_mangle] 171 + #[unsafe(no_mangle)] 172 172 pub unsafe extern "C" fn pthread_getschedparam( 173 173 thread: pthread_t, 174 174 policy_out: *mut c_int, ··· 188 188 pub mod tls; 189 189 pub use tls::*; 190 190 191 - #[no_mangle] 191 + #[unsafe(no_mangle)] 192 192 pub unsafe extern "C" fn pthread_join(thread: pthread_t, retval: *mut *mut c_void) -> c_int { 193 193 match pthread::join(&*thread.cast()) { 194 194 Ok(pthread::Retval(ret)) => { ··· 210 210 pub mod rwlock; 211 211 pub use self::rwlock::*; 212 212 213 - #[no_mangle] 213 + #[unsafe(no_mangle)] 214 214 pub unsafe extern "C" fn pthread_self() -> pthread_t { 215 215 pthread::current_thread().unwrap_unchecked() as *const _ as *mut _ 216 216 } 217 - #[no_mangle] 217 + #[unsafe(no_mangle)] 218 218 pub unsafe extern "C" fn pthread_setcancelstate(state: c_int, oldstate: *mut c_int) -> c_int { 219 219 match pthread::set_cancel_state(state) { 220 220 Ok(old) => { ··· 228 228 Err(Errno(error)) => error, 229 229 } 230 230 } 231 - #[no_mangle] 231 + #[unsafe(no_mangle)] 232 232 pub unsafe extern "C" fn pthread_setcanceltype(ty: c_int, oldty: *mut c_int) -> c_int { 233 233 match pthread::set_cancel_type(ty) { 234 234 Ok(old) => { ··· 243 243 } 244 244 } 245 245 246 - #[no_mangle] 246 + #[unsafe(no_mangle)] 247 247 pub extern "C" fn pthread_setconcurrency(concurrency: c_int) -> c_int { 248 248 // Redox and Linux threads are 1:1, not M:N. 249 249 0 250 250 } 251 251 252 - #[no_mangle] 252 + #[unsafe(no_mangle)] 253 253 pub unsafe extern "C" fn pthread_setschedparam( 254 254 thread: pthread_t, 255 255 policy: c_int, ··· 257 257 ) -> c_int { 258 258 e(pthread::set_sched_param(&*thread.cast(), policy, &*param)) 259 259 } 260 - #[no_mangle] 260 + #[unsafe(no_mangle)] 261 261 pub unsafe extern "C" fn pthread_setschedprio(thread: pthread_t, prio: c_int) -> c_int { 262 262 e(pthread::set_sched_priority(&*thread.cast(), prio)) 263 263 } ··· 265 265 pub mod spin; 266 266 pub use self::spin::*; 267 267 268 - #[no_mangle] 268 + #[unsafe(no_mangle)] 269 269 pub unsafe extern "C" fn pthread_testcancel() { 270 270 pthread::testcancel(); 271 271 } ··· 284 284 285 285 // TODO: unwind? setjmp/longjmp? 286 286 287 - #[no_mangle] 287 + #[unsafe(no_mangle)] 288 288 pub unsafe extern "C" fn __relibc_internal_pthread_cleanup_push(new_entry: *mut c_void) { 289 289 let new_entry = &mut *new_entry.cast::<CleanupLinkedListEntry>(); 290 290 291 291 new_entry.prev = CLEANUP_LL_HEAD.get().cast(); 292 292 CLEANUP_LL_HEAD.set(new_entry); 293 293 } 294 - #[no_mangle] 294 + #[unsafe(no_mangle)] 295 295 pub unsafe extern "C" fn __relibc_internal_pthread_cleanup_pop(execute: c_int) { 296 296 let prev_head = CLEANUP_LL_HEAD.get().read(); 297 297 CLEANUP_LL_HEAD.set(prev_head.prev.cast());
+21 -21
src/header/pthread/mutex.rs
··· 4 4 5 5 // PTHREAD_MUTEX_INITIALIZER is defined in bits_pthread/cbindgen.toml 6 6 7 - #[no_mangle] 7 + #[unsafe(no_mangle)] 8 8 pub unsafe extern "C" fn pthread_mutex_consistent(mutex: *mut pthread_mutex_t) -> c_int { 9 9 e((&*mutex.cast::<RlctMutex>()).make_consistent()) 10 10 } 11 - #[no_mangle] 11 + #[unsafe(no_mangle)] 12 12 pub unsafe extern "C" fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> c_int { 13 13 // No-op 14 14 core::ptr::drop_in_place(mutex.cast::<RlctMutex>()); 15 15 0 16 16 } 17 17 18 - #[no_mangle] 18 + #[unsafe(no_mangle)] 19 19 pub unsafe extern "C" fn pthread_mutex_getprioceiling( 20 20 mutex: *const pthread_mutex_t, 21 21 prioceiling: *mut c_int, ··· 29 29 } 30 30 } 31 31 32 - #[no_mangle] 32 + #[unsafe(no_mangle)] 33 33 pub unsafe extern "C" fn pthread_mutex_init( 34 34 mutex: *mut pthread_mutex_t, 35 35 attr: *const pthread_mutexattr_t, ··· 49 49 Err(Errno(errno)) => errno, 50 50 } 51 51 } 52 - #[no_mangle] 52 + #[unsafe(no_mangle)] 53 53 pub unsafe extern "C" fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> c_int { 54 54 e((&*mutex.cast::<RlctMutex>()).lock()) 55 55 } 56 56 57 - #[no_mangle] 57 + #[unsafe(no_mangle)] 58 58 pub unsafe extern "C" fn pthread_mutex_setprioceiling( 59 59 mutex: *mut pthread_mutex_t, 60 60 prioceiling: c_int, ··· 69 69 } 70 70 } 71 71 72 - #[no_mangle] 72 + #[unsafe(no_mangle)] 73 73 pub unsafe extern "C" fn pthread_mutex_timedlock( 74 74 mutex: *mut pthread_mutex_t, 75 75 timespec: *const timespec, 76 76 ) -> c_int { 77 77 e((&*mutex.cast::<RlctMutex>()).lock_with_timeout(&*timespec)) 78 78 } 79 - #[no_mangle] 79 + #[unsafe(no_mangle)] 80 80 pub unsafe extern "C" fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> c_int { 81 81 e((&*mutex.cast::<RlctMutex>()).try_lock()) 82 82 } 83 - #[no_mangle] 83 + #[unsafe(no_mangle)] 84 84 pub unsafe extern "C" fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> c_int { 85 85 e((&*mutex.cast::<RlctMutex>()).unlock()) 86 86 } 87 87 88 - #[no_mangle] 88 + #[unsafe(no_mangle)] 89 89 pub unsafe extern "C" fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> c_int { 90 90 // No-op 91 91 core::ptr::drop_in_place(attr.cast::<RlctMutexAttr>()); 92 92 0 93 93 } 94 94 95 - #[no_mangle] 95 + #[unsafe(no_mangle)] 96 96 pub unsafe extern "C" fn pthread_mutexattr_getprioceiling( 97 97 attr: *const pthread_mutexattr_t, 98 98 prioceiling: *mut c_int, ··· 101 101 0 102 102 } 103 103 104 - #[no_mangle] 104 + #[unsafe(no_mangle)] 105 105 pub unsafe extern "C" fn pthread_mutexattr_getprotocol( 106 106 attr: *const pthread_mutexattr_t, 107 107 protocol: *mut c_int, ··· 110 110 0 111 111 } 112 112 113 - #[no_mangle] 113 + #[unsafe(no_mangle)] 114 114 pub unsafe extern "C" fn pthread_mutexattr_getpshared( 115 115 attr: *const pthread_mutexattr_t, 116 116 pshared: *mut c_int, ··· 119 119 0 120 120 } 121 121 122 - #[no_mangle] 122 + #[unsafe(no_mangle)] 123 123 pub unsafe extern "C" fn pthread_mutexattr_getrobust( 124 124 attr: *const pthread_mutexattr_t, 125 125 robust: *mut c_int, ··· 127 127 robust.write((*attr.cast::<RlctMutexAttr>()).robust); 128 128 0 129 129 } 130 - #[no_mangle] 130 + #[unsafe(no_mangle)] 131 131 pub unsafe extern "C" fn pthread_mutexattr_gettype( 132 132 attr: *const pthread_mutexattr_t, 133 133 ty: *mut c_int, ··· 135 135 ty.write((*attr.cast::<RlctMutexAttr>()).ty); 136 136 0 137 137 } 138 - #[no_mangle] 138 + #[unsafe(no_mangle)] 139 139 pub unsafe extern "C" fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> c_int { 140 140 attr.cast::<RlctMutexAttr>().write(RlctMutexAttr::default()); 141 141 0 142 142 } 143 143 144 - #[no_mangle] 144 + #[unsafe(no_mangle)] 145 145 pub unsafe extern "C" fn pthread_mutexattr_setprioceiling( 146 146 attr: *mut pthread_mutexattr_t, 147 147 prioceiling: c_int, ··· 150 150 0 151 151 } 152 152 153 - #[no_mangle] 153 + #[unsafe(no_mangle)] 154 154 pub unsafe extern "C" fn pthread_mutexattr_setprotocol( 155 155 attr: *mut pthread_mutexattr_t, 156 156 protocol: c_int, ··· 159 159 0 160 160 } 161 161 162 - #[no_mangle] 162 + #[unsafe(no_mangle)] 163 163 pub unsafe extern "C" fn pthread_mutexattr_setpshared( 164 164 attr: *mut pthread_mutexattr_t, 165 165 pshared: c_int, ··· 168 168 0 169 169 } 170 170 171 - #[no_mangle] 171 + #[unsafe(no_mangle)] 172 172 pub unsafe extern "C" fn pthread_mutexattr_setrobust( 173 173 attr: *mut pthread_mutexattr_t, 174 174 robust: c_int, ··· 176 176 (*attr.cast::<RlctMutexAttr>()).robust = robust; 177 177 0 178 178 } 179 - #[no_mangle] 179 + #[unsafe(no_mangle)] 180 180 pub unsafe extern "C" fn pthread_mutexattr_settype( 181 181 attr: *mut pthread_mutexattr_t, 182 182 ty: c_int,
+1 -1
src/header/pthread/once.rs
··· 2 2 3 3 // PTHREAD_ONCE_INIT 4 4 5 - #[no_mangle] 5 + #[unsafe(no_mangle)] 6 6 pub unsafe extern "C" fn pthread_once( 7 7 once: *mut pthread_once_t, 8 8 constructor: extern "C" fn(),
+13 -13
src/header/pthread/rwlock.rs
··· 4 4 5 5 use crate::pthread::Pshared; 6 6 7 - #[no_mangle] 7 + #[unsafe(no_mangle)] 8 8 pub unsafe extern "C" fn pthread_rwlock_init( 9 9 rwlock: *mut pthread_rwlock_t, 10 10 attr: *const pthread_rwlockattr_t, ··· 21 21 22 22 0 23 23 } 24 - #[no_mangle] 24 + #[unsafe(no_mangle)] 25 25 pub unsafe extern "C" fn pthread_rwlock_rdlock(rwlock: *mut pthread_rwlock_t) -> c_int { 26 26 get(rwlock).acquire_read_lock(None); 27 27 28 28 0 29 29 } 30 - #[no_mangle] 30 + #[unsafe(no_mangle)] 31 31 pub unsafe extern "C" fn pthread_rwlock_timedrdlock( 32 32 rwlock: *mut pthread_rwlock_t, 33 33 timeout: *const timespec, ··· 36 36 37 37 0 38 38 } 39 - #[no_mangle] 39 + #[unsafe(no_mangle)] 40 40 pub unsafe extern "C" fn pthread_rwlock_timedwrlock( 41 41 rwlock: *mut pthread_rwlock_t, 42 42 timeout: *const timespec, ··· 45 45 46 46 0 47 47 } 48 - #[no_mangle] 48 + #[unsafe(no_mangle)] 49 49 pub unsafe extern "C" fn pthread_rwlock_tryrdlock(rwlock: *mut pthread_rwlock_t) -> c_int { 50 50 match get(rwlock).try_acquire_read_lock() { 51 51 Ok(()) => 0, 52 52 Err(_) => EBUSY, 53 53 } 54 54 } 55 - #[no_mangle] 55 + #[unsafe(no_mangle)] 56 56 pub unsafe extern "C" fn pthread_rwlock_trywrlock(rwlock: *mut pthread_rwlock_t) -> c_int { 57 57 match get(rwlock).try_acquire_write_lock() { 58 58 Ok(()) => 0, 59 59 Err(_) => EBUSY, 60 60 } 61 61 } 62 - #[no_mangle] 62 + #[unsafe(no_mangle)] 63 63 pub unsafe extern "C" fn pthread_rwlock_unlock(rwlock: *mut pthread_rwlock_t) -> c_int { 64 64 get(rwlock).unlock(); 65 65 66 66 0 67 67 } 68 - #[no_mangle] 68 + #[unsafe(no_mangle)] 69 69 pub unsafe extern "C" fn pthread_rwlock_wrlock(rwlock: *mut pthread_rwlock_t) -> c_int { 70 70 get(rwlock).acquire_write_lock(None); 71 71 72 72 0 73 73 } 74 74 75 - #[no_mangle] 75 + #[unsafe(no_mangle)] 76 76 pub unsafe extern "C" fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> c_int { 77 77 attr.cast::<RlctRwlockAttr>() 78 78 .write(RlctRwlockAttr::default()); ··· 80 80 0 81 81 } 82 82 83 - #[no_mangle] 83 + #[unsafe(no_mangle)] 84 84 pub unsafe extern "C" fn pthread_rwlockattr_getpshared( 85 85 attr: *const pthread_rwlockattr_t, 86 86 pshared_out: *mut c_int, ··· 90 90 0 91 91 } 92 92 93 - #[no_mangle] 93 + #[unsafe(no_mangle)] 94 94 pub unsafe extern "C" fn pthread_rwlockattr_setpshared( 95 95 attr: *mut pthread_rwlockattr_t, 96 96 pshared: c_int, ··· 101 101 0 102 102 } 103 103 104 - #[no_mangle] 104 + #[unsafe(no_mangle)] 105 105 pub unsafe extern "C" fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t) -> c_int { 106 106 core::ptr::drop_in_place(attr); 107 107 108 108 0 109 109 } 110 - #[no_mangle] 110 + #[unsafe(no_mangle)] 111 111 pub unsafe extern "C" fn pthread_rwlock_destroy(rwlock: *mut pthread_rwlock_t) -> c_int { 112 112 core::ptr::drop_in_place(rwlock); 113 113
+5 -5
src/header/pthread/spin.rs
··· 7 7 const UNLOCKED: c_int = 0; 8 8 const LOCKED: c_int = 1; 9 9 10 - #[no_mangle] 10 + #[unsafe(no_mangle)] 11 11 pub unsafe extern "C" fn pthread_spin_destroy(spinlock: *mut pthread_spinlock_t) -> c_int { 12 12 let _spinlock = &mut *spinlock.cast::<RlctSpinlock>(); 13 13 14 14 // No-op 15 15 0 16 16 } 17 - #[no_mangle] 17 + #[unsafe(no_mangle)] 18 18 pub unsafe extern "C" fn pthread_spin_init( 19 19 spinlock: *mut pthread_spinlock_t, 20 20 _pshared: c_int, ··· 28 28 29 29 0 30 30 } 31 - #[no_mangle] 31 + #[unsafe(no_mangle)] 32 32 pub unsafe extern "C" fn pthread_spin_lock(spinlock: *mut pthread_spinlock_t) -> c_int { 33 33 let spinlock = &*spinlock.cast::<RlctSpinlock>(); 34 34 ··· 46 46 47 47 0 48 48 } 49 - #[no_mangle] 49 + #[unsafe(no_mangle)] 50 50 pub unsafe extern "C" fn pthread_spin_trylock(spinlock: *mut pthread_spinlock_t) -> c_int { 51 51 let spinlock = &*spinlock.cast::<RlctSpinlock>(); 52 52 ··· 60 60 61 61 0 62 62 } 63 - #[no_mangle] 63 + #[unsafe(no_mangle)] 64 64 pub unsafe extern "C" fn pthread_spin_unlock(spinlock: *mut pthread_spinlock_t) -> c_int { 65 65 let spinlock = &*spinlock.cast::<RlctSpinlock>(); 66 66
+7 -7
src/header/pthread/tls.rs
··· 10 10 // TODO: What should this limit be? 11 11 pub const PTHREAD_KEYS_MAX: u32 = 4096 * 32; 12 12 13 - #[no_mangle] 13 + #[unsafe(no_mangle)] 14 14 pub unsafe extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut c_void { 15 15 //print!("pthread_getspecific key={:#0x}: ", key); 16 16 ··· 28 28 29 29 data 30 30 } 31 - #[no_mangle] 31 + #[unsafe(no_mangle)] 32 32 pub unsafe extern "C" fn pthread_key_create( 33 33 key_ptr: *mut pthread_key_t, 34 34 destructor: Option<extern "C" fn(value: *mut c_void)>, ··· 55 55 0 56 56 } 57 57 58 - #[no_mangle] 58 + #[unsafe(no_mangle)] 59 59 pub unsafe extern "C" fn pthread_key_delete(key: pthread_key_t) -> c_int { 60 60 if KEYS.lock().remove(&key).is_none() || VALUES.borrow_mut().remove(&key).is_none() { 61 61 // We don't have to return anything, but it's not less expensive to ignore it. ··· 66 66 0 67 67 } 68 68 69 - #[no_mangle] 69 + #[unsafe(no_mangle)] 70 70 pub unsafe extern "C" fn pthread_setspecific(key: pthread_key_t, value: *const c_void) -> c_int { 71 71 if !KEYS.lock().contains_key(&key) { 72 72 // We don't have to return anything, but it's not less expensive to ignore it. ··· 76 76 77 77 let mut guard = VALUES.borrow_mut(); 78 78 79 - let Record { ref mut data, .. } = guard.entry(key).or_insert(Record { 79 + let mut record = guard.entry(key).or_insert(Record { 80 80 data: core::ptr::null_mut(), 81 81 }); 82 - //println!("Valid key for pthread_setspecific key {:#0x} value {:p} (was {:p})", key, value, *data); 82 + //println!("Valid key for pthread_setspecific key {:#0x} value {:p} (was {:p})", key, value, record.data); 83 83 84 - *data = value as *mut c_void; 84 + record.data = value as *mut c_void; 85 85 86 86 0 87 87 }
+2 -2
src/header/pty/mod.rs
··· 18 18 mod imp; 19 19 20 20 /// See <https://www.man7.org/linux/man-pages/man3/openpty.3.html>. 21 - #[no_mangle] 21 + #[unsafe(no_mangle)] 22 22 pub unsafe extern "C" fn openpty( 23 23 amaster: *mut c_int, 24 24 aslave: *mut c_int, ··· 53 53 } 54 54 55 55 /// See <https://www.man7.org/linux/man-pages/man3/openpty.3.html>. 56 - #[no_mangle] 56 + #[unsafe(no_mangle)] 57 57 pub unsafe extern "C" fn forkpty( 58 58 pm: *mut c_int, 59 59 name: *mut c_char,
+1 -1
src/header/pty/redox.rs
··· 1 1 use crate::{ 2 + Pal, Sys, 2 3 error::ResultExt, 3 4 header::{fcntl, unistd}, 4 5 platform::types::*, 5 - Pal, Sys, 6 6 }; 7 7 8 8 pub(super) unsafe fn openpty(name: &mut [u8]) -> Result<(c_int, c_int), ()> {
+19 -18
src/header/pwd/mod.rs
··· 12 12 use crate::{ 13 13 fs::File, 14 14 header::{errno, fcntl, string::strcmp}, 15 - io::{prelude::*, BufReader, SeekFrom}, 15 + io::{BufReader, SeekFrom, prelude::*}, 16 16 platform::{self, types::*}, 17 + raw_cell::RawCell, 17 18 }; 18 19 19 20 #[cfg(target_os = "linux")] ··· 49 50 } 50 51 51 52 static mut PASSWD_BUF: Option<MaybeAllocated> = None; 52 - static mut PASSWD: passwd = passwd { 53 + static PASSWD: RawCell<passwd> = RawCell::new(passwd { 53 54 pw_name: ptr::null_mut(), 54 55 pw_passwd: ptr::null_mut(), 55 56 pw_uid: 0, ··· 57 58 pw_gecos: ptr::null_mut(), 58 59 pw_dir: ptr::null_mut(), 59 60 pw_shell: ptr::null_mut(), 60 - }; 61 + }); 61 62 62 63 #[derive(Clone, Copy, Debug)] 63 64 struct DestBuffer { ··· 103 104 fn into_global(self) -> *mut passwd { 104 105 unsafe { 105 106 PASSWD_BUF = Some(self.buffer); 106 - PASSWD = self.reference; 107 - &mut PASSWD 107 + *PASSWD.as_mut_ptr() = self.reference; 108 + PASSWD.as_mut_ptr() 108 109 } 109 110 } 110 111 } ··· 115 116 Other, 116 117 } 117 118 118 - static mut READER: Option<BufReader<File>> = None; 119 + static READER: RawCell<Option<BufReader<File>>> = RawCell::new(None); 119 120 120 121 fn parsed<I, O>(buf: Option<I>) -> Option<O> 121 122 where ··· 220 221 } 221 222 222 223 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/endpwent.html>. 223 - #[no_mangle] 224 + #[unsafe(no_mangle)] 224 225 pub extern "C" fn endpwent() { 225 226 unsafe { 226 - READER = None; 227 + *READER.as_mut_ptr() = None; 227 228 } 228 229 } 229 230 230 231 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/endpwent.html>. 231 - #[no_mangle] 232 + #[unsafe(no_mangle)] 232 233 pub extern "C" fn getpwent() -> *mut passwd { 233 - let reader = match unsafe { &mut READER } { 234 + let reader = match unsafe { &mut *READER.as_mut_ptr() } { 234 235 Some(reader) => reader, 235 236 None => { 236 237 let file = match File::open(c"/etc/passwd".into(), fcntl::O_RDONLY) { ··· 239 240 }; 240 241 let reader = BufReader::new(file); 241 242 unsafe { 242 - READER = Some(reader); 243 - READER.as_mut().unwrap() 243 + *READER.as_mut_ptr() = Some(reader); 244 + READER.unsafe_mut().as_mut().unwrap() 244 245 } 245 246 } 246 247 }; ··· 250 251 } 251 252 252 253 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpwnam.html>. 253 - #[no_mangle] 254 + #[unsafe(no_mangle)] 254 255 pub extern "C" fn getpwnam(name: *const c_char) -> *mut passwd { 255 256 pwd_lookup(|parts| unsafe { strcmp(parts.pw_name, name) } == 0, None) 256 257 .map(|res| res.into_global()) ··· 258 259 } 259 260 260 261 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpwnam.html>. 261 - #[no_mangle] 262 + #[unsafe(no_mangle)] 262 263 pub unsafe extern "C" fn getpwnam_r( 263 264 name: *const c_char, 264 265 out: *mut passwd, ··· 280 281 } 281 282 282 283 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpwuid.html>. 283 - #[no_mangle] 284 + #[unsafe(no_mangle)] 284 285 pub extern "C" fn getpwuid(uid: uid_t) -> *mut passwd { 285 286 pwd_lookup(|parts| parts.pw_uid == uid, None) 286 287 .map(|res| res.into_global()) ··· 288 289 } 289 290 290 291 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpwuid.html>. 291 - #[no_mangle] 292 + #[unsafe(no_mangle)] 292 293 pub unsafe extern "C" fn getpwuid_r( 293 294 uid: uid_t, 294 295 out: *mut passwd, ··· 311 312 } 312 313 313 314 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/endpwent.html>. 314 - #[no_mangle] 315 + #[unsafe(no_mangle)] 315 316 pub extern "C" fn setpwent() { 316 - if let Some(reader) = unsafe { &mut READER } { 317 + if let Some(reader) = unsafe { &mut *READER.as_mut_ptr() } { 317 318 let _ = reader.seek(SeekFrom::Start(0)); 318 319 } 319 320 }
+6 -10
src/header/regex/mod.rs
··· 3 3 use crate::{header::string::strlen, platform::types::*}; 4 4 use alloc::{borrow::Cow, boxed::Box}; 5 5 use core::{mem, ptr, slice}; 6 - use posix_regex::{compile::Error as CompileError, tree::Tree, PosixRegex, PosixRegexBuilder}; 6 + use posix_regex::{PosixRegex, PosixRegexBuilder, compile::Error as CompileError, tree::Tree}; 7 7 8 8 pub type regoff_t = size_t; 9 9 ··· 43 43 pub const REG_ESPACE: c_int = 13; 44 44 pub const REG_BADRPT: c_int = 14; 45 45 46 - #[no_mangle] 46 + #[unsafe(no_mangle)] 47 47 #[linkage = "weak"] // redefined in GIT 48 48 pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: c_int) -> c_int { 49 49 let pat = slice::from_raw_parts(pat as *const u8, strlen(pat)); ··· 74 74 } 75 75 } 76 76 77 - #[no_mangle] 77 + #[unsafe(no_mangle)] 78 78 #[linkage = "weak"] // redefined in GIT 79 79 pub unsafe extern "C" fn regfree(regex: *mut regex_t) { 80 80 Box::from_raw((*regex).ptr); 81 81 } 82 82 83 - #[no_mangle] 83 + #[unsafe(no_mangle)] 84 84 #[linkage = "weak"] // redefined in GIT 85 85 pub unsafe extern "C" fn regexec( 86 86 regex: *const regex_t, ··· 117 117 } 118 118 } 119 119 120 - if matches.is_empty() { 121 - REG_NOMATCH 122 - } else { 123 - 0 124 - } 120 + if matches.is_empty() { REG_NOMATCH } else { 0 } 125 121 } 126 122 127 - #[no_mangle] 123 + #[unsafe(no_mangle)] 128 124 #[linkage = "weak"] // redefined in GIT 129 125 pub extern "C" fn regerror( 130 126 code: c_int,
+8 -8
src/header/sched/mod.rs
··· 3 3 use crate::{ 4 4 error::ResultExt, 5 5 header::time::timespec, 6 - platform::{types::*, Pal, Sys}, 6 + platform::{Pal, Sys, types::*}, 7 7 }; 8 8 9 9 #[derive(Clone, Copy, Debug)] ··· 15 15 pub const SCHED_RR: c_int = 1; 16 16 pub const SCHED_OTHER: c_int = 2; 17 17 18 - // #[no_mangle] 18 + // #[unsafe(no_mangle)] 19 19 pub extern "C" fn sched_get_priority_max(policy: c_int) -> c_int { 20 20 todo!() 21 21 } 22 - // #[no_mangle] 22 + // #[unsafe(no_mangle)] 23 23 pub extern "C" fn sched_get_priority_min(policy: c_int) -> c_int { 24 24 todo!() 25 25 } 26 - // #[no_mangle] 26 + // #[unsafe(no_mangle)] 27 27 pub unsafe extern "C" fn sched_getparam(pid: pid_t, param: *mut sched_param) -> c_int { 28 28 todo!() 29 29 } 30 - // #[no_mangle] 30 + // #[unsafe(no_mangle)] 31 31 pub extern "C" fn sched_rr_get_interval(pid: pid_t, time: *const timespec) -> c_int { 32 32 todo!() 33 33 } 34 - // #[no_mangle] 34 + // #[unsafe(no_mangle)] 35 35 pub unsafe extern "C" fn sched_setparam(pid: pid_t, param: *const sched_param) -> c_int { 36 36 todo!() 37 37 } 38 - // #[no_mangle] 38 + // #[unsafe(no_mangle)] 39 39 pub extern "C" fn sched_setscheduler( 40 40 pid: pid_t, 41 41 policy: c_int, ··· 43 43 ) -> c_int { 44 44 todo!() 45 45 } 46 - #[no_mangle] 46 + #[unsafe(no_mangle)] 47 47 pub extern "C" fn sched_yield() -> c_int { 48 48 Sys::sched_yield().map(|()| 0).or_minus_one_errno() 49 49 }
+12 -12
src/header/semaphore/mod.rs
··· 3 3 //! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/semaphore.h.html>. 4 4 5 5 use crate::{ 6 - header::time::{timespec, CLOCK_MONOTONIC, CLOCK_REALTIME}, 6 + header::time::{CLOCK_MONOTONIC, CLOCK_REALTIME, timespec}, 7 7 platform::types::*, 8 8 }; 9 9 ··· 18 18 pub type RlctSempahore = crate::sync::Semaphore; 19 19 20 20 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_close.html>. 21 - // #[no_mangle] 21 + // #[unsafe(no_mangle)] 22 22 pub unsafe extern "C" fn sem_close(sem: *mut sem_t) -> c_int { 23 23 todo!("named semaphores") 24 24 } 25 25 26 26 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_destroy.html>. 27 - #[no_mangle] 27 + #[unsafe(no_mangle)] 28 28 pub unsafe extern "C" fn sem_destroy(sem: *mut sem_t) -> c_int { 29 29 core::ptr::drop_in_place(sem.cast::<RlctSempahore>()); 30 30 0 31 31 } 32 32 33 33 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_getvalue.html>. 34 - #[no_mangle] 34 + #[unsafe(no_mangle)] 35 35 pub unsafe extern "C" fn sem_getvalue(sem: *mut sem_t, sval: *mut c_int) -> c_int { 36 36 sval.write(get(sem).value() as c_int); 37 37 ··· 39 39 } 40 40 41 41 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_init.html>. 42 - #[no_mangle] 42 + #[unsafe(no_mangle)] 43 43 pub unsafe extern "C" fn sem_init(sem: *mut sem_t, _pshared: c_int, value: c_uint) -> c_int { 44 44 sem.cast::<RlctSempahore>().write(RlctSempahore::new(value)); 45 45 ··· 48 48 49 49 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_open.html>. 50 50 // TODO: va_list 51 - // #[no_mangle] 51 + // #[unsafe(no_mangle)] 52 52 pub unsafe extern "C" fn sem_open( 53 53 name: *const c_char, 54 54 oflag: c_int, /* (va_list) value: c_uint */ ··· 57 57 } 58 58 59 59 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_post.html>. 60 - #[no_mangle] 60 + #[unsafe(no_mangle)] 61 61 pub unsafe extern "C" fn sem_post(sem: *mut sem_t) -> c_int { 62 62 get(sem).post(1); 63 63 ··· 65 65 } 66 66 67 67 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_trywait.html>. 68 - #[no_mangle] 68 + #[unsafe(no_mangle)] 69 69 pub unsafe extern "C" fn sem_trywait(sem: *mut sem_t) -> c_int { 70 70 get(sem).try_wait(); 71 71 ··· 73 73 } 74 74 75 75 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_unlink.html>. 76 - // #[no_mangle] 76 + // #[unsafe(no_mangle)] 77 77 pub unsafe extern "C" fn sem_unlink(name: *const c_char) -> c_int { 78 78 todo!("named semaphores") 79 79 } 80 80 81 81 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_trywait.html>. 82 - #[no_mangle] 82 + #[unsafe(no_mangle)] 83 83 pub unsafe extern "C" fn sem_wait(sem: *mut sem_t) -> c_int { 84 84 get(sem).wait(None, CLOCK_MONOTONIC); 85 85 ··· 87 87 } 88 88 89 89 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_clockwait.html>. 90 - #[no_mangle] 90 + #[unsafe(no_mangle)] 91 91 pub unsafe extern "C" fn sem_clockwait( 92 92 sem: *mut sem_t, 93 93 clock_id: clockid_t, ··· 99 99 } 100 100 101 101 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_timedwait.html>. 102 - #[no_mangle] 102 + #[unsafe(no_mangle)] 103 103 pub unsafe extern "C" fn sem_timedwait(sem: *mut sem_t, abstime: *const timespec) -> c_int { 104 104 get(sem).wait(Some(&*abstime), CLOCK_REALTIME); 105 105
+1 -1
src/header/setjmp/mod.rs
··· 21 21 } 22 22 23 23 //Each platform has different sizes for sigjmp_buf, currently only x86_64 is supported 24 - extern "C" { 24 + unsafe extern "C" { 25 25 pub fn setjmp(jb: *mut u64) -> i32; 26 26 pub fn longjmp(jb: *mut u64, ret: i32); 27 27 }
+1 -1
src/header/sgtty/mod.rs
··· 2 2 3 3 use crate::{header::sys_ioctl::*, platform::types::*}; 4 4 5 - #[no_mangle] 5 + #[unsafe(no_mangle)] 6 6 pub extern "C" fn gtty(fd: c_int, out: *mut sgttyb) -> c_int { 7 7 eprintln!("unimplemented: gtty({}, {:p})", fd, out); 8 8 -1
+7 -7
src/header/shadow/mod.rs
··· 16 16 c_str::CStr, 17 17 fs::File, 18 18 header::{errno, fcntl, string::strlen}, 19 - io::{prelude::*, BufReader, Lines}, 19 + io::{BufReader, Lines, prelude::*}, 20 20 platform, 21 21 platform::types::*, 22 22 }; ··· 112 112 unsafe { 113 113 SHADOW_BUF = Some(self.buffer); 114 114 SHADOW = self.reference; 115 - &mut SHADOW 115 + &raw mut SHADOW 116 116 } 117 117 } 118 118 } ··· 181 181 Ok(OwnedSpwd { buffer, reference }) 182 182 } 183 183 184 - #[no_mangle] 184 + #[unsafe(no_mangle)] 185 185 pub unsafe extern "C" fn getspnam(name: *const c_char) -> *mut spwd { 186 186 let Ok(db) = File::open(SHADOW_FILE.into(), fcntl::O_RDONLY) else { 187 187 return ptr::null_mut(); ··· 199 199 ptr::null_mut() 200 200 } 201 201 202 - #[no_mangle] 202 + #[unsafe(no_mangle)] 203 203 pub unsafe extern "C" fn getspnam_r( 204 204 name: *const c_char, 205 205 result_buf: *mut spwd, ··· 237 237 ENOENT 238 238 } 239 239 240 - #[no_mangle] 240 + #[unsafe(no_mangle)] 241 241 pub unsafe extern "C" fn setspent() { 242 242 let mut line_reader = unsafe { &mut *LINE_READER.get() }; 243 243 if let Ok(db) = File::open(SHADOW_FILE.into(), fcntl::O_RDONLY) { ··· 245 245 } 246 246 } 247 247 248 - #[no_mangle] 248 + #[unsafe(no_mangle)] 249 249 pub unsafe extern "C" fn endspent() { 250 250 unsafe { 251 251 *LINE_READER.get() = None; 252 252 } 253 253 } 254 254 255 - #[no_mangle] 255 + #[unsafe(no_mangle)] 256 256 pub unsafe extern "C" fn getspent() -> *mut spwd { 257 257 let line_reader = unsafe { &mut *LINE_READER.get() }; 258 258 if line_reader.is_none() {
+33 -33
src/header/signal/mod.rs
··· 8 8 c_str::CStr, 9 9 error::{Errno, ResultExt}, 10 10 header::{errno, setjmp, time::timespec}, 11 - platform::{self, types::*, Pal, PalSignal, Sys}, 11 + platform::{self, Pal, PalSignal, Sys, types::*}, 12 12 }; 13 13 14 14 pub use self::sys::*; ··· 69 69 pub si_value: sigval, 70 70 } 71 71 72 - #[no_mangle] 72 + #[unsafe(no_mangle)] 73 73 pub extern "C" fn _cbindgen_export_siginfo(a: siginfo) {} 74 74 75 75 #[derive(Clone, Copy)] ··· 104 104 options(att_syntax) 105 105 ); 106 106 107 - extern "C" { 107 + unsafe extern "C" { 108 108 pub fn sigsetjmp(jb: *mut u64, savemask: i32) -> i32; 109 109 } 110 110 111 111 //NOTE for the following two functions, to see why they're implemented slightly differently from their intended behavior, read 112 112 // https://git.musl-libc.org/cgit/musl/commit/?id=583e55122e767b1586286a0d9c35e2a4027998ab 113 - #[no_mangle] 113 + #[unsafe(no_mangle)] 114 114 unsafe extern "C" fn __sigsetjmp_tail(jb: *mut u64, ret: i32) -> i32 { 115 115 let set = jb.wrapping_add(9); 116 116 if ret > 0 { ··· 121 121 ret 122 122 } 123 123 124 - #[no_mangle] 124 + #[unsafe(no_mangle)] 125 125 pub unsafe extern "C" fn siglongjmp(jb: *mut u64, ret: i32) { 126 126 setjmp::longjmp(jb, ret); 127 127 } 128 128 129 - #[no_mangle] 129 + #[unsafe(no_mangle)] 130 130 pub extern "C" fn kill(pid: pid_t, sig: c_int) -> c_int { 131 131 Sys::kill(pid, sig).map(|()| 0).or_minus_one_errno() 132 132 } 133 - #[no_mangle] 133 + #[unsafe(no_mangle)] 134 134 pub extern "C" fn sigqueue(pid: pid_t, sig: c_int, val: sigval) -> c_int { 135 135 Sys::sigqueue(pid, sig, val) 136 136 .map(|()| 0) 137 137 .or_minus_one_errno() 138 138 } 139 139 140 - #[no_mangle] 140 + #[unsafe(no_mangle)] 141 141 pub extern "C" fn killpg(pgrp: pid_t, sig: c_int) -> c_int { 142 142 Sys::killpg(pgrp, sig).map(|()| 0).or_minus_one_errno() 143 143 } 144 144 145 - #[no_mangle] 145 + #[unsafe(no_mangle)] 146 146 pub unsafe extern "C" fn pthread_kill(thread: pthread_t, sig: c_int) -> c_int { 147 147 let os_tid = { 148 148 let pthread = &*(thread as *const crate::pthread::Pthread); ··· 151 151 crate::header::pthread::e(Sys::rlct_kill(os_tid, sig as usize)) 152 152 } 153 153 154 - #[no_mangle] 154 + #[unsafe(no_mangle)] 155 155 pub unsafe extern "C" fn pthread_sigmask( 156 156 how: c_int, 157 157 set: *const sigset_t, ··· 166 166 } 167 167 } 168 168 169 - #[no_mangle] 169 + #[unsafe(no_mangle)] 170 170 pub extern "C" fn raise(sig: c_int) -> c_int { 171 171 Sys::raise(sig).map(|()| 0).or_minus_one_errno() 172 172 } 173 173 174 - #[no_mangle] 174 + #[unsafe(no_mangle)] 175 175 pub unsafe extern "C" fn sigaction( 176 176 sig: c_int, 177 177 act: *const sigaction, ··· 182 182 .or_minus_one_errno() 183 183 } 184 184 185 - #[no_mangle] 185 + #[unsafe(no_mangle)] 186 186 pub unsafe extern "C" fn sigaddset(set: *mut sigset_t, signo: c_int) -> c_int { 187 187 if signo <= 0 || signo as usize > NSIG.max(SIGRTMAX) 188 188 /* TODO */ ··· 197 197 0 198 198 } 199 199 200 - #[no_mangle] 200 + #[unsafe(no_mangle)] 201 201 pub unsafe extern "C" fn sigaltstack(ss: *const stack_t, old_ss: *mut stack_t) -> c_int { 202 202 Sys::sigaltstack(ss.as_ref(), old_ss.as_mut()) 203 203 .map(|()| 0) 204 204 .or_minus_one_errno() 205 205 } 206 206 207 - #[no_mangle] 207 + #[unsafe(no_mangle)] 208 208 pub unsafe extern "C" fn sigdelset(set: *mut sigset_t, signo: c_int) -> c_int { 209 209 if signo <= 0 || signo as usize > NSIG.max(SIGRTMAX) 210 210 /* TODO */ ··· 219 219 0 220 220 } 221 221 222 - #[no_mangle] 222 + #[unsafe(no_mangle)] 223 223 pub unsafe extern "C" fn sigemptyset(set: *mut sigset_t) -> c_int { 224 224 if let Some(set) = (set as *mut SigSet).as_mut() { 225 225 set.clear(); ··· 227 227 0 228 228 } 229 229 230 - #[no_mangle] 230 + #[unsafe(no_mangle)] 231 231 pub unsafe extern "C" fn sigfillset(set: *mut sigset_t) -> c_int { 232 232 if let Some(set) = (set as *mut SigSet).as_mut() { 233 233 set.fill(.., true); ··· 235 235 0 236 236 } 237 237 238 - #[no_mangle] 238 + #[unsafe(no_mangle)] 239 239 pub unsafe extern "C" fn sighold(sig: c_int) -> c_int { 240 240 let mut pset = mem::MaybeUninit::<sigset_t>::uninit(); 241 241 unsafe { sigemptyset(pset.as_mut_ptr()) }; ··· 246 246 sigprocmask(SIG_BLOCK, &set, ptr::null_mut()) 247 247 } 248 248 249 - #[no_mangle] 249 + #[unsafe(no_mangle)] 250 250 pub extern "C" fn sigignore(sig: c_int) -> c_int { 251 251 let mut psa = mem::MaybeUninit::<sigaction>::uninit(); 252 252 unsafe { sigemptyset(&mut (*psa.as_mut_ptr()).sa_mask) }; ··· 256 256 unsafe { sigaction(sig, &mut sa, ptr::null_mut()) } 257 257 } 258 258 259 - #[no_mangle] 259 + #[unsafe(no_mangle)] 260 260 pub extern "C" fn siginterrupt(sig: c_int, flag: c_int) -> c_int { 261 261 let mut psa = mem::MaybeUninit::<sigaction>::uninit(); 262 262 unsafe { sigaction(sig, ptr::null_mut(), psa.as_mut_ptr()) }; ··· 270 270 unsafe { sigaction(sig, &mut sa, ptr::null_mut()) } 271 271 } 272 272 273 - #[no_mangle] 273 + #[unsafe(no_mangle)] 274 274 pub unsafe extern "C" fn sigismember(set: *const sigset_t, signo: c_int) -> c_int { 275 275 if signo <= 0 || signo as usize > NSIG { 276 276 platform::ERRNO.set(errno::EINVAL); ··· 285 285 0 286 286 } 287 287 288 - #[no_mangle] 288 + #[unsafe(no_mangle)] 289 289 pub extern "C" fn signal( 290 290 sig: c_int, 291 291 func: Option<extern "C" fn(c_int)>, ··· 304 304 unsafe { old_sa.assume_init() }.sa_handler 305 305 } 306 306 307 - #[no_mangle] 307 + #[unsafe(no_mangle)] 308 308 pub unsafe extern "C" fn sigpause(sig: c_int) -> c_int { 309 309 let mut pset = mem::MaybeUninit::<sigset_t>::uninit(); 310 310 sigprocmask(0, ptr::null_mut(), pset.as_mut_ptr()); ··· 315 315 sigsuspend(&set) 316 316 } 317 317 318 - #[no_mangle] 318 + #[unsafe(no_mangle)] 319 319 pub unsafe extern "C" fn sigpending(set: *mut sigset_t) -> c_int { 320 320 (|| Sys::sigpending(set.as_mut().ok_or(Errno(EFAULT))?))() 321 321 .map(|()| 0) ··· 326 326 const STANDARD_SIG_MASK: sigset_t = (1 << 32) - 1; 327 327 const RLCT_SIGNAL_MASK: sigset_t = BELOW_SIGRTMIN_MASK & !STANDARD_SIG_MASK; 328 328 329 - #[no_mangle] 329 + #[unsafe(no_mangle)] 330 330 pub unsafe extern "C" fn sigprocmask( 331 331 how: c_int, 332 332 set: *const sigset_t, ··· 351 351 .or_minus_one_errno() 352 352 } 353 353 354 - #[no_mangle] 354 + #[unsafe(no_mangle)] 355 355 pub unsafe extern "C" fn sigrelse(sig: c_int) -> c_int { 356 356 let mut pset = mem::MaybeUninit::<sigset_t>::uninit(); 357 357 sigemptyset(pset.as_mut_ptr()); ··· 362 362 sigprocmask(SIG_UNBLOCK, &mut set, ptr::null_mut()) 363 363 } 364 364 365 - #[no_mangle] 365 + #[unsafe(no_mangle)] 366 366 pub unsafe extern "C" fn sigset( 367 367 sig: c_int, 368 368 func: Option<extern "C" fn(c_int)>, ··· 405 405 old_sa.assume_init().sa_handler 406 406 } 407 407 408 - #[no_mangle] 408 + #[unsafe(no_mangle)] 409 409 pub unsafe extern "C" fn sigsuspend(sigmask: *const sigset_t) -> c_int { 410 410 Err(Sys::sigsuspend(&*sigmask)).or_minus_one_errno() 411 411 } 412 412 413 - #[no_mangle] 413 + #[unsafe(no_mangle)] 414 414 pub unsafe extern "C" fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int { 415 415 let mut pinfo = mem::MaybeUninit::<siginfo_t>::uninit(); 416 416 if sigtimedwait(set, pinfo.as_mut_ptr(), ptr::null_mut()) < 0 { ··· 421 421 0 422 422 } 423 423 424 - #[no_mangle] 424 + #[unsafe(no_mangle)] 425 425 pub unsafe extern "C" fn sigtimedwait( 426 426 set: *const sigset_t, 427 427 // s/siginfo_t/siginfo due to https://github.com/mozilla/cbindgen/issues/621 ··· 434 434 .map(|()| 0) 435 435 .or_minus_one_errno() 436 436 } 437 - #[no_mangle] 437 + #[unsafe(no_mangle)] 438 438 pub unsafe extern "C" fn sigwaitinfo(set: *const sigset_t, sig: *mut siginfo_t) -> c_int { 439 439 sigtimedwait(set, sig, core::ptr::null()) 440 440 } ··· 473 473 "Power failure\0", 474 474 "Bad system call\0", 475 475 ]; 476 - #[no_mangle] 476 + #[unsafe(no_mangle)] 477 477 pub unsafe extern "C" fn psignal(sig: c_int, prefix: *const c_char) { 478 478 let c_description = usize::try_from(sig) 479 479 .ok() ··· 490 490 string.as_bytes().len(), 491 491 ); 492 492 } 493 - #[no_mangle] 493 + #[unsafe(no_mangle)] 494 494 pub unsafe extern "C" fn psiginfo(info: *const siginfo_t, prefix: *const c_char) { 495 495 let siginfo_t { 496 496 si_code,
+1 -1
src/header/signal/redox.rs
··· 181 181 _opaque: [u8; 520], 182 182 } 183 183 184 - #[no_mangle] 184 + #[unsafe(no_mangle)] 185 185 pub extern "C" fn __completely_unused_cbindgen_workaround_fn_ucontext_mcontext( 186 186 a: *const ucontext_t, 187 187 b: *const mcontext_t,
+4 -4
src/header/stdio/default.rs
··· 1 - use super::{constants, Buffer, BUFSIZ, FILE}; 1 + use super::{BUFSIZ, Buffer, FILE, constants}; 2 2 use core::{cell::UnsafeCell, ptr}; 3 3 4 4 use crate::{ ··· 54 54 DEFAULT_STDERR.call_once(|| GlobalFile::new(2, constants::F_NORD)) 55 55 } 56 56 57 - #[no_mangle] 57 + #[unsafe(no_mangle)] 58 58 pub static mut stdin: *mut FILE = ptr::null_mut(); 59 - #[no_mangle] 59 + #[unsafe(no_mangle)] 60 60 pub static mut stdout: *mut FILE = ptr::null_mut(); 61 - #[no_mangle] 61 + #[unsafe(no_mangle)] 62 62 pub static mut stderr: *mut FILE = ptr::null_mut();
+6 -6
src/header/stdio/ext.rs
··· 1 1 use crate::{ 2 - header::stdio::{FILE, F_NORD, F_NOWR}, 2 + header::stdio::{F_NORD, F_NOWR, FILE}, 3 3 platform::types::*, 4 4 }; 5 5 6 - #[no_mangle] 6 + #[unsafe(no_mangle)] 7 7 pub extern "C" fn __fpending(stream: *mut FILE) -> size_t { 8 8 let stream = unsafe { &mut *stream }.lock(); 9 9 10 10 stream.writer.pending() 11 11 } 12 12 13 - #[no_mangle] 13 + #[unsafe(no_mangle)] 14 14 pub extern "C" fn __freadable(stream: *mut FILE) -> c_int { 15 15 let stream = unsafe { &mut *stream }.lock(); 16 16 17 17 (stream.flags & F_NORD == 0) as c_int 18 18 } 19 19 20 - #[no_mangle] 20 + #[unsafe(no_mangle)] 21 21 pub extern "C" fn __fwritable(stream: *mut FILE) -> c_int { 22 22 let stream = unsafe { &mut *stream }.lock(); 23 23 ··· 25 25 } 26 26 27 27 //TODO: Check last operation when read-write 28 - #[no_mangle] 28 + #[unsafe(no_mangle)] 29 29 pub extern "C" fn __freading(stream: *mut FILE) -> c_int { 30 30 let stream = unsafe { &mut *stream }.lock(); 31 31 ··· 33 33 } 34 34 35 35 //TODO: Check last operation when read-write 36 - #[no_mangle] 36 + #[unsafe(no_mangle)] 37 37 pub extern "C" fn __fwriting(stream: *mut FILE) -> c_int { 38 38 let stream = unsafe { &mut *stream }.lock(); 39 39
+3 -3
src/header/stdio/getdelim.rs
··· 16 16 }; 17 17 18 18 use crate::{ 19 - header::stdio::{default_stdout, feof, ferror, F_EOF, F_ERR}, 19 + header::stdio::{F_EOF, F_ERR, default_stdout, feof, ferror}, 20 20 platform::ERRNO, 21 21 }; 22 22 23 23 /// see getdelim (getline is a special case of getdelim with delim == '\n') 24 - #[no_mangle] 24 + #[unsafe(no_mangle)] 25 25 pub unsafe extern "C" fn getline( 26 26 lineptr: *mut *mut c_char, 27 27 n: *mut size_t, ··· 48 48 /// "If an error occurs, the error indicator for the stream shall be set, and the function shall 49 49 /// return -1 and set errno to indicate the error." but in cases that produce EINVAL even glibc 50 50 /// doesn't seem to set the error indicator, so we also don't. 51 - #[no_mangle] 51 + #[unsafe(no_mangle)] 52 52 pub unsafe extern "C" fn getdelim( 53 53 lineptr: *mut *mut c_char, 54 54 n: *mut size_t,
+1 -1
src/header/stdio/helpers.rs
··· 1 1 use alloc::boxed::Box; 2 2 3 - use super::{constants::*, Buffer, FILE}; 3 + use super::{Buffer, FILE, constants::*}; 4 4 use crate::{ 5 5 c_str::CStr, 6 6 error::Errno,
+1 -1
src/header/stdio/lookaheadreader.rs
··· 1 - use super::{fseek_locked, ftell_locked, FILE, SEEK_SET}; 1 + use super::{FILE, SEEK_SET, fseek_locked, ftell_locked}; 2 2 use crate::{io::Read, platform::types::off_t}; 3 3 struct LookAheadBuffer { 4 4 buf: *const u8,
+76 -84
src/header/stdio/mod.rs
··· 27 27 }, 28 28 io::{self, BufRead, BufWriter, LineWriter, Read, Write}, 29 29 out::Out, 30 - platform::{self, types::*, Pal, Sys, WriteByte, ERRNO}, 30 + platform::{self, ERRNO, Pal, Sys, WriteByte, types::*}, 31 31 sync::Mutex, 32 32 }; 33 33 ··· 274 274 } 275 275 276 276 /// Clears EOF and ERR indicators on a stream 277 - #[no_mangle] 277 + #[unsafe(no_mangle)] 278 278 pub unsafe extern "C" fn clearerr(stream: *mut FILE) { 279 279 let mut stream = (*stream).lock(); 280 280 stream.flags &= !(F_EOF | F_ERR); 281 281 } 282 282 283 - #[no_mangle] 283 + #[unsafe(no_mangle)] 284 284 pub unsafe extern "C" fn ctermid(s: *mut c_char) -> *mut c_char { 285 285 static mut TERMID: [u8; L_ctermid] = *b"/dev/tty\0"; 286 286 287 287 if s.is_null() { 288 - return TERMID.as_mut_ptr() as *mut c_char; 288 + return &raw mut TERMID as *mut c_char; 289 289 } 290 290 291 - strncpy(s, TERMID.as_mut_ptr() as *mut c_char, L_ctermid) 291 + strncpy(s, &raw mut TERMID as *mut c_char, L_ctermid) 292 292 } 293 293 294 - // #[no_mangle] 294 + // #[unsafe(no_mangle)] 295 295 pub unsafe extern "C" fn cuserid(s: *mut c_char) -> *mut c_char { 296 296 let mut buf: Vec<c_char> = vec![0; 256]; 297 297 let mut pwd: pwd::passwd = unsafe { mem::zeroed() }; ··· 322 322 /// This function does not guarentee that the file buffer will be flushed or that the file 323 323 /// descriptor will be closed, so if it is important that the file be written to, use `fflush()` 324 324 /// prior to using this function. 325 - #[no_mangle] 325 + #[unsafe(no_mangle)] 326 326 pub unsafe extern "C" fn fclose(stream: *mut FILE) -> c_int { 327 327 let stream = &mut *stream; 328 328 flockfile(stream); ··· 345 345 } 346 346 347 347 /// Open a file from a file descriptor 348 - #[no_mangle] 348 + #[unsafe(no_mangle)] 349 349 pub unsafe extern "C" fn fdopen(fildes: c_int, mode: *const c_char) -> *mut FILE { 350 350 helpers::_fdopen(fildes, CStr::from_ptr(mode)) 351 351 .map(|f| Box::into_raw(f)) ··· 353 353 } 354 354 355 355 /// Check for EOF 356 - #[no_mangle] 356 + #[unsafe(no_mangle)] 357 357 pub unsafe extern "C" fn feof(stream: *mut FILE) -> c_int { 358 358 let stream = (*stream).lock(); 359 359 stream.flags & F_EOF 360 360 } 361 361 362 362 /// Check for ERR 363 - #[no_mangle] 363 + #[unsafe(no_mangle)] 364 364 pub unsafe extern "C" fn ferror(stream: *mut FILE) -> c_int { 365 365 let stream = (*stream).lock(); 366 366 stream.flags & F_ERR ··· 369 369 /// Flush output to stream, or sync read position 370 370 /// Ensure the file is unlocked before calling this function, as it will attempt to lock the file 371 371 /// itself. 372 - #[no_mangle] 372 + #[unsafe(no_mangle)] 373 373 pub unsafe extern "C" fn fflush(stream: *mut FILE) -> c_int { 374 374 if stream.is_null() { 375 375 //TODO: flush all files! ··· 392 392 } 393 393 394 394 /// Get a single char from a stream 395 - #[no_mangle] 395 + #[unsafe(no_mangle)] 396 396 pub unsafe extern "C" fn fgetc(stream: *mut FILE) -> c_int { 397 397 let mut stream = (*stream).lock(); 398 398 if let Err(_) = (*stream).try_set_byte_orientation_unlocked() { ··· 403 403 } 404 404 405 405 /// Get the position of the stream and store it in pos 406 - #[no_mangle] 406 + #[unsafe(no_mangle)] 407 407 pub unsafe extern "C" fn fgetpos(stream: *mut FILE, pos: *mut fpos_t) -> c_int { 408 408 let off = ftello(stream); 409 409 if off < 0 { ··· 414 414 } 415 415 416 416 /// Get a string from the stream 417 - #[no_mangle] 417 + #[unsafe(no_mangle)] 418 418 pub unsafe extern "C" fn fgets( 419 419 original: *mut c_char, 420 420 max: c_int, ··· 478 478 // Write the NUL byte 479 479 *out = 0; 480 480 } 481 - if wrote { 482 - original 483 - } else { 484 - ptr::null_mut() 485 - } 481 + if wrote { original } else { ptr::null_mut() } 486 482 } 487 483 488 484 /// Get the underlying file descriptor 489 - #[no_mangle] 485 + #[unsafe(no_mangle)] 490 486 pub unsafe extern "C" fn fileno(stream: *mut FILE) -> c_int { 491 487 let stream = (*stream).lock(); 492 488 *stream.file ··· 495 491 /// Lock the file 496 492 /// Do not call any functions other than those with the `_unlocked` postfix while the file is 497 493 /// locked 498 - #[no_mangle] 494 + #[unsafe(no_mangle)] 499 495 pub unsafe extern "C" fn flockfile(file: *mut FILE) { 500 496 (*file).lock.manual_lock(); 501 497 } 502 498 503 499 /// Open the file in mode `mode` 504 - #[no_mangle] 500 + #[unsafe(no_mangle)] 505 501 pub unsafe extern "C" fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE { 506 502 let initial_mode = *mode; 507 503 if initial_mode != b'r' as c_char ··· 542 538 /// Clear the buffers of a stream 543 539 /// Ensure the file is unlocked before calling this function, as it will attempt to lock the file 544 540 /// itself. 545 - #[no_mangle] 541 + #[unsafe(no_mangle)] 546 542 pub unsafe extern "C" fn __fpurge(stream: *mut FILE) { 547 543 if !stream.is_null() { 548 544 let mut stream = (*stream).lock(); ··· 551 547 } 552 548 553 549 /// Insert a character into the stream 554 - #[no_mangle] 550 + #[unsafe(no_mangle)] 555 551 pub unsafe extern "C" fn fputc(c: c_int, stream: *mut FILE) -> c_int { 556 552 let mut stream = (*stream).lock(); 557 553 if let Err(_) = (*stream).try_set_byte_orientation_unlocked() { ··· 562 558 } 563 559 564 560 /// Insert a string into a stream 565 - #[no_mangle] 561 + #[unsafe(no_mangle)] 566 562 pub unsafe extern "C" fn fputs(s: *const c_char, stream: *mut FILE) -> c_int { 567 563 let mut stream = (*stream).lock(); 568 564 if let Err(_) = (*stream).try_set_byte_orientation_unlocked() { ··· 579 575 } 580 576 581 577 /// Read `nitems` of size `size` into `ptr` from `stream` 582 - #[no_mangle] 578 + #[unsafe(no_mangle)] 583 579 pub unsafe extern "C" fn fread( 584 580 ptr: *mut c_void, 585 581 size: size_t, ··· 606 602 (read / size as usize) as size_t 607 603 } 608 604 609 - #[no_mangle] 605 + #[unsafe(no_mangle)] 610 606 pub unsafe extern "C" fn freopen( 611 607 filename: *const c_char, 612 608 mode: *const c_char, ··· 662 658 } 663 659 664 660 /// Seek to an offset `offset` from `whence` 665 - #[no_mangle] 661 + #[unsafe(no_mangle)] 666 662 pub unsafe extern "C" fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int { 667 663 fseeko(stream, offset as off_t, whence) 668 664 } 669 665 670 666 /// Seek to an offset `offset` from `whence` 671 - #[no_mangle] 667 + #[unsafe(no_mangle)] 672 668 pub unsafe extern "C" fn fseeko(stream: *mut FILE, off: off_t, whence: c_int) -> c_int { 673 669 let mut stream = (*stream).lock(); 674 670 fseek_locked(&mut *stream, off, whence) ··· 699 695 } 700 696 701 697 /// Seek to a position `pos` in the file from the beginning of the file 702 - #[no_mangle] 698 + #[unsafe(no_mangle)] 703 699 pub unsafe extern "C" fn fsetpos(stream: *mut FILE, pos: *const fpos_t) -> c_int { 704 700 fseeko(stream, *pos, SEEK_SET) 705 701 } 706 702 707 703 /// Get the current position of the cursor in the file 708 - #[no_mangle] 704 + #[unsafe(no_mangle)] 709 705 pub unsafe extern "C" fn ftell(stream: *mut FILE) -> c_long { 710 706 ftello(stream) as c_long 711 707 } 712 708 713 709 /// Get the current position of the cursor in the file 714 - #[no_mangle] 710 + #[unsafe(no_mangle)] 715 711 pub unsafe extern "C" fn ftello(stream: *mut FILE) -> off_t { 716 712 let mut stream = (*stream).lock(); 717 713 ftell_locked(&mut *stream) ··· 726 722 } 727 723 728 724 /// Try to lock the file. Returns 0 for success, 1 for failure 729 - #[no_mangle] 725 + #[unsafe(no_mangle)] 730 726 pub unsafe extern "C" fn ftrylockfile(file: *mut FILE) -> c_int { 731 727 if (*file).lock.manual_try_lock().is_ok() { 732 728 0 ··· 736 732 } 737 733 738 734 /// Unlock the file 739 - #[no_mangle] 735 + #[unsafe(no_mangle)] 740 736 pub unsafe extern "C" fn funlockfile(file: *mut FILE) { 741 737 (*file).lock.manual_unlock(); 742 738 } 743 739 744 740 /// Write `nitems` of size `size` from `ptr` to `stream` 745 - #[no_mangle] 741 + #[unsafe(no_mangle)] 746 742 pub unsafe extern "C" fn fwrite( 747 743 ptr: *const c_void, 748 744 size: size_t, ··· 769 765 } 770 766 771 767 /// Get a single char from a stream 772 - #[no_mangle] 768 + #[unsafe(no_mangle)] 773 769 pub unsafe extern "C" fn getc(stream: *mut FILE) -> c_int { 774 770 let mut stream = (*stream).lock(); 775 771 getc_unlocked(&mut *stream) 776 772 } 777 773 778 774 /// Get a single char from `stdin` 779 - #[no_mangle] 775 + #[unsafe(no_mangle)] 780 776 pub unsafe extern "C" fn getchar() -> c_int { 781 777 fgetc(&mut *stdin) 782 778 } 783 779 784 780 /// Get a char from a stream without locking the stream 785 - #[no_mangle] 781 + #[unsafe(no_mangle)] 786 782 pub unsafe extern "C" fn getc_unlocked(stream: *mut FILE) -> c_int { 787 783 if let Err(_) = (*stream).try_set_byte_orientation_unlocked() { 788 784 return -1; ··· 797 793 } 798 794 799 795 /// Get a char from `stdin` without locking `stdin` 800 - #[no_mangle] 796 + #[unsafe(no_mangle)] 801 797 pub unsafe extern "C" fn getchar_unlocked() -> c_int { 802 798 getc_unlocked(&mut *stdin) 803 799 } 804 800 805 801 /// Get a string from `stdin` 806 - #[no_mangle] 802 + #[unsafe(no_mangle)] 807 803 pub unsafe extern "C" fn gets(s: *mut c_char) -> *mut c_char { 808 804 fgets(s, c_int::max_value(), &mut *stdin) 809 805 } 810 806 811 807 /// Get an integer from `stream` 812 - #[no_mangle] 808 + #[unsafe(no_mangle)] 813 809 pub unsafe extern "C" fn getw(stream: *mut FILE) -> c_int { 814 810 let mut ret: c_int = 0; 815 811 if fread( ··· 825 821 } 826 822 } 827 823 828 - #[no_mangle] 824 + #[unsafe(no_mangle)] 829 825 pub unsafe extern "C" fn pclose(stream: *mut FILE) -> c_int { 830 826 // TODO: rusty error handling? 831 827 let pid = { ··· 849 845 wstatus 850 846 } 851 847 852 - #[no_mangle] 848 + #[unsafe(no_mangle)] 853 849 pub unsafe extern "C" fn perror(s: *const c_char) { 854 850 let err = ERRNO.get(); 855 851 let err_str = if err >= 0 && err < STR_ERROR.len() as c_int { ··· 868 864 } 869 865 } 870 866 871 - #[no_mangle] 867 + #[unsafe(no_mangle)] 872 868 pub unsafe extern "C" fn popen(command: *const c_char, mode: *const c_char) -> *mut FILE { 873 869 //TODO: share code with system 874 870 ··· 963 959 } 964 960 965 961 /// Put a character `c` into `stream` 966 - #[no_mangle] 962 + #[unsafe(no_mangle)] 967 963 pub unsafe extern "C" fn putc(c: c_int, stream: *mut FILE) -> c_int { 968 964 let mut stream = (*stream).lock(); 969 965 putc_unlocked(c, &mut *stream) 970 966 } 971 967 972 968 /// Put a character `c` into `stdout` 973 - #[no_mangle] 969 + #[unsafe(no_mangle)] 974 970 pub unsafe extern "C" fn putchar(c: c_int) -> c_int { 975 971 fputc(c, &mut *stdout) 976 972 } 977 973 978 974 /// Put a character `c` into `stream` without locking `stream` 979 - #[no_mangle] 975 + #[unsafe(no_mangle)] 980 976 pub unsafe extern "C" fn putc_unlocked(c: c_int, stream: *mut FILE) -> c_int { 981 977 if let Err(_) = (*stream).try_set_byte_orientation_unlocked() { 982 978 return -1; ··· 989 985 } 990 986 991 987 /// Put a character `c` into `stdout` without locking `stdout` 992 - #[no_mangle] 988 + #[unsafe(no_mangle)] 993 989 pub unsafe extern "C" fn putchar_unlocked(c: c_int) -> c_int { 994 990 putc_unlocked(c, stdout) 995 991 } 996 992 997 993 /// Put a string `s` into `stdout` 998 - #[no_mangle] 994 + #[unsafe(no_mangle)] 999 995 pub unsafe extern "C" fn puts(s: *const c_char) -> c_int { 1000 996 let mut stream = (&mut *stdout).lock(); 1001 997 if let Err(_) = (*stream).try_set_byte_orientation_unlocked() { ··· 1014 1010 } 1015 1011 1016 1012 /// Put an integer `w` into `stream` 1017 - #[no_mangle] 1013 + #[unsafe(no_mangle)] 1018 1014 pub unsafe extern "C" fn putw(w: c_int, stream: *mut FILE) -> c_int { 1019 1015 fwrite(&w as *const c_int as _, mem::size_of_val(&w), 1, stream) as i32 - 1 1020 1016 } 1021 1017 1022 1018 /// Delete file or directory `path` 1023 - #[no_mangle] 1019 + #[unsafe(no_mangle)] 1024 1020 pub unsafe extern "C" fn remove(path: *const c_char) -> c_int { 1025 1021 let path = CStr::from_ptr(path); 1026 1022 Sys::unlink(path) ··· 1029 1025 .or_minus_one_errno() 1030 1026 } 1031 1027 1032 - #[no_mangle] 1028 + #[unsafe(no_mangle)] 1033 1029 pub unsafe extern "C" fn rename(oldpath: *const c_char, newpath: *const c_char) -> c_int { 1034 1030 let oldpath = CStr::from_ptr(oldpath); 1035 1031 let newpath = CStr::from_ptr(newpath); ··· 1039 1035 } 1040 1036 1041 1037 /// Rewind `stream` back to the beginning of it 1042 - #[no_mangle] 1038 + #[unsafe(no_mangle)] 1043 1039 pub unsafe extern "C" fn rewind(stream: *mut FILE) { 1044 1040 fseeko(stream, 0, SEEK_SET); 1045 1041 } 1046 1042 1047 1043 /// Reset `stream` to use buffer `buf`. Buffer must be `BUFSIZ` in length 1048 - #[no_mangle] 1044 + #[unsafe(no_mangle)] 1049 1045 pub unsafe extern "C" fn setbuf(stream: *mut FILE, buf: *mut c_char) { 1050 1046 setvbuf( 1051 1047 stream, ··· 1056 1052 } 1057 1053 1058 1054 /// Set buffering of `stream` to line buffered 1059 - #[no_mangle] 1055 + #[unsafe(no_mangle)] 1060 1056 pub unsafe extern "C" fn setlinebuf(stream: *mut FILE) { 1061 1057 setvbuf(stream, ptr::null_mut(), _IOLBF, 0); 1062 1058 } 1063 1059 1064 1060 /// Reset `stream` to use buffer `buf` of size `size` 1065 1061 /// If this isn't the meaning of unsafe, idk what is 1066 - #[no_mangle] 1062 + #[unsafe(no_mangle)] 1067 1063 pub unsafe extern "C" fn setvbuf( 1068 1064 stream: *mut FILE, 1069 1065 buf: *mut c_char, ··· 1088 1084 0 1089 1085 } 1090 1086 1091 - #[no_mangle] 1087 + #[unsafe(no_mangle)] 1092 1088 pub unsafe extern "C" fn tempnam(dir: *const c_char, pfx: *const c_char) -> *mut c_char { 1093 1089 unsafe fn is_appropriate(pos_dir: *const c_char) -> bool { 1094 1090 !pos_dir.is_null() && unistd::access(pos_dir, unistd::W_OK) == 0 ··· 1131 1127 out_buf 1132 1128 } 1133 1129 1134 - #[no_mangle] 1130 + #[unsafe(no_mangle)] 1135 1131 pub unsafe extern "C" fn tmpfile() -> *mut FILE { 1136 1132 let mut file_name = *b"/tmp/tmpfileXXXXXX\0"; 1137 1133 let file_name = file_name.as_mut_ptr() as *mut c_char; ··· 1154 1150 fp 1155 1151 } 1156 1152 1157 - #[no_mangle] 1153 + #[unsafe(no_mangle)] 1158 1154 pub unsafe extern "C" fn tmpnam(s: *mut c_char) -> *mut c_char { 1159 1155 let buf = if s.is_null() { 1160 - TMPNAM_BUF.as_mut_ptr() 1156 + &raw mut TMPNAM_BUF as *mut _ 1161 1157 } else { 1162 1158 s 1163 1159 }; ··· 1176 1172 stdlib::mktemp(buf); 1177 1173 platform::ERRNO.set(err); 1178 1174 1179 - if *buf == 0 { 1180 - ptr::null_mut() 1181 - } else { 1182 - buf 1183 - } 1175 + if *buf == 0 { ptr::null_mut() } else { buf } 1184 1176 } 1185 1177 1186 1178 /// Push character `c` back onto `stream` so it'll be read next 1187 - #[no_mangle] 1179 + #[unsafe(no_mangle)] 1188 1180 pub unsafe extern "C" fn ungetc(c: c_int, stream: *mut FILE) -> c_int { 1189 1181 let mut stream = (*stream).lock(); 1190 1182 if let Err(_) = (*stream).try_set_byte_orientation_unlocked() { ··· 1195 1187 c 1196 1188 } 1197 1189 1198 - #[no_mangle] 1190 + #[unsafe(no_mangle)] 1199 1191 pub unsafe extern "C" fn vfprintf(file: *mut FILE, format: *const c_char, ap: va_list) -> c_int { 1200 1192 let mut file = (*file).lock(); 1201 1193 if let Err(_) = file.try_set_byte_orientation_unlocked() { ··· 1204 1196 1205 1197 printf::printf(&mut *file, format, ap) 1206 1198 } 1207 - #[no_mangle] 1199 + #[unsafe(no_mangle)] 1208 1200 pub unsafe extern "C" fn fprintf( 1209 1201 file: *mut FILE, 1210 1202 format: *const c_char, ··· 1213 1205 vfprintf(file, format, __valist.as_va_list()) 1214 1206 } 1215 1207 1216 - #[no_mangle] 1208 + #[unsafe(no_mangle)] 1217 1209 pub unsafe extern "C" fn vdprintf(fd: c_int, format: *const c_char, ap: va_list) -> c_int { 1218 1210 let mut f = File::new(fd); 1219 1211 ··· 1223 1215 1224 1216 printf::printf(f, format, ap) 1225 1217 } 1226 - #[no_mangle] 1218 + #[unsafe(no_mangle)] 1227 1219 pub unsafe extern "C" fn dprintf(fd: c_int, format: *const c_char, mut __valist: ...) -> c_int { 1228 1220 vdprintf(fd, format, __valist.as_va_list()) 1229 1221 } 1230 1222 1231 - #[no_mangle] 1223 + #[unsafe(no_mangle)] 1232 1224 pub unsafe extern "C" fn vprintf(format: *const c_char, ap: va_list) -> c_int { 1233 1225 vfprintf(&mut *stdout, format, ap) 1234 1226 } 1235 - #[no_mangle] 1227 + #[unsafe(no_mangle)] 1236 1228 pub unsafe extern "C" fn printf(format: *const c_char, mut __valist: ...) -> c_int { 1237 1229 vfprintf(&mut *stdout, format, __valist.as_va_list()) 1238 1230 } 1239 1231 1240 - #[no_mangle] 1232 + #[unsafe(no_mangle)] 1241 1233 pub unsafe extern "C" fn vasprintf( 1242 1234 strp: *mut *mut c_char, 1243 1235 format: *const c_char, ··· 1250 1242 *strp = alloc_writer.leak() as *mut c_char; 1251 1243 ret 1252 1244 } 1253 - #[no_mangle] 1245 + #[unsafe(no_mangle)] 1254 1246 pub unsafe extern "C" fn asprintf( 1255 1247 strp: *mut *mut c_char, 1256 1248 format: *const c_char, ··· 1259 1251 vasprintf(strp, format, __valist.as_va_list()) 1260 1252 } 1261 1253 1262 - #[no_mangle] 1254 + #[unsafe(no_mangle)] 1263 1255 pub unsafe extern "C" fn vsnprintf( 1264 1256 s: *mut c_char, 1265 1257 n: size_t, ··· 1272 1264 ap, 1273 1265 ) 1274 1266 } 1275 - #[no_mangle] 1267 + #[unsafe(no_mangle)] 1276 1268 pub unsafe extern "C" fn snprintf( 1277 1269 s: *mut c_char, 1278 1270 n: size_t, ··· 1286 1278 ) 1287 1279 } 1288 1280 1289 - #[no_mangle] 1281 + #[unsafe(no_mangle)] 1290 1282 pub unsafe extern "C" fn vsprintf(s: *mut c_char, format: *const c_char, ap: va_list) -> c_int { 1291 1283 printf::printf(&mut platform::UnsafeStringWriter(s as *mut u8), format, ap) 1292 1284 } 1293 - #[no_mangle] 1285 + #[unsafe(no_mangle)] 1294 1286 pub unsafe extern "C" fn sprintf( 1295 1287 s: *mut c_char, 1296 1288 format: *const c_char, ··· 1303 1295 ) 1304 1296 } 1305 1297 1306 - #[no_mangle] 1298 + #[unsafe(no_mangle)] 1307 1299 pub unsafe extern "C" fn vfscanf(file: *mut FILE, format: *const c_char, ap: va_list) -> c_int { 1308 1300 let ret = { 1309 1301 let mut file = (*file).lock(); ··· 1317 1309 }; 1318 1310 ret 1319 1311 } 1320 - #[no_mangle] 1312 + #[unsafe(no_mangle)] 1321 1313 pub unsafe extern "C" fn fscanf( 1322 1314 file: *mut FILE, 1323 1315 format: *const c_char, ··· 1326 1318 vfscanf(file, format, __valist.as_va_list()) 1327 1319 } 1328 1320 1329 - #[no_mangle] 1321 + #[unsafe(no_mangle)] 1330 1322 pub unsafe extern "C" fn vscanf(format: *const c_char, ap: va_list) -> c_int { 1331 1323 vfscanf(&mut *stdin, format, ap) 1332 1324 } 1333 - #[no_mangle] 1325 + #[unsafe(no_mangle)] 1334 1326 pub unsafe extern "C" fn scanf(format: *const c_char, mut __valist: ...) -> c_int { 1335 1327 vfscanf(&mut *stdin, format, __valist.as_va_list()) 1336 1328 } 1337 1329 1338 - #[no_mangle] 1330 + #[unsafe(no_mangle)] 1339 1331 pub unsafe extern "C" fn vsscanf(s: *const c_char, format: *const c_char, ap: va_list) -> c_int { 1340 1332 let reader = (s as *const u8).into(); 1341 1333 scanf::scanf(reader, format, ap) 1342 1334 } 1343 - #[no_mangle] 1335 + #[unsafe(no_mangle)] 1344 1336 pub unsafe extern "C" fn sscanf( 1345 1337 s: *const c_char, 1346 1338 format: *const c_char,
+6 -2
src/header/stdio/printf.rs
··· 109 109 110 110 (FmtKind::Char, _) 111 111 | (FmtKind::Unsigned, IntKind::Byte) 112 - | (FmtKind::Signed, IntKind::Byte) => VaArg::c_char(ap.arg::<c_char>()), 112 + | (FmtKind::Signed, IntKind::Byte) => { 113 + // c_int is passed but truncated to c_char 114 + VaArg::c_char(ap.arg::<c_int>() as c_char) 115 + } 113 116 (FmtKind::Unsigned, IntKind::Short) | (FmtKind::Signed, IntKind::Short) => { 114 - VaArg::c_short(ap.arg::<c_short>()) 117 + // c_int is passed but truncated to c_short 118 + VaArg::c_short(ap.arg::<c_int>() as c_short) 115 119 } 116 120 (FmtKind::Unsigned, IntKind::Int) | (FmtKind::Signed, IntKind::Int) => { 117 121 VaArg::c_int(ap.arg::<c_int>())
+1 -5
src/header/stdio/scanf.rs
··· 19 19 unsafe fn next_byte(string: &mut *const c_char) -> Result<u8, c_int> { 20 20 let c = **string as u8; 21 21 *string = string.offset(1); 22 - if c == 0 { 23 - Err(-1) 24 - } else { 25 - Ok(c) 26 - } 22 + if c == 0 { Err(-1) } else { Ok(c) } 27 23 } 28 24 29 25 unsafe fn inner_scanf(
+146 -145
src/header/stdlib/mod.rs
··· 4 4 5 5 use core::{convert::TryFrom, intrinsics, iter, mem, ptr, slice}; 6 6 use rand::{ 7 - distributions::{Alphanumeric, Distribution, Uniform}, 8 7 Rng, SeedableRng, 8 + distributions::{Alphanumeric, Distribution, Uniform}, 9 9 }; 10 10 use rand_jitter::JitterRng; 11 11 use rand_xorshift::XorShiftRng; ··· 23 23 string::*, 24 24 sys_ioctl::*, 25 25 time::constants::CLOCK_MONOTONIC, 26 - unistd::{self, sysconf, _SC_PAGESIZE}, 26 + unistd::{self, _SC_PAGESIZE, sysconf}, 27 27 wchar::*, 28 28 }, 29 29 ld_so, 30 30 out::Out, 31 - platform::{self, types::*, Pal, Sys}, 31 + platform::{self, Pal, Sys, types::*}, 32 + raw_cell::RawCell, 32 33 sync::Once, 33 34 }; 34 35 ··· 50 51 //Maximum number of bytes in a multibyte characters for any locale 51 52 pub const MB_LEN_MAX: c_int = 4; 52 53 53 - static mut ATEXIT_FUNCS: [Option<extern "C" fn()>; 32] = [None; 32]; 54 - static mut AT_QUICK_EXIT_FUNCS: [Option<extern "C" fn()>; 32] = [None; 32]; 55 - static mut L64A_BUFFER: [c_char; 7] = [0; 7]; // up to 6 digits plus null terminator 54 + static ATEXIT_FUNCS: RawCell<[Option<extern "C" fn()>; 32]> = RawCell::new([None; 32]); 55 + static AT_QUICK_EXIT_FUNCS: RawCell<[Option<extern "C" fn()>; 32]> = RawCell::new([None; 32]); 56 + static L64A_BUFFER: RawCell<[c_char; 7]> = RawCell::new([0; 7]); // up to 6 digits plus null terminator 56 57 static mut RNG: Option<XorShiftRng> = None; 57 58 58 59 // TODO: This could be const fn, but the trait system won't allow that. ··· 63 64 } 64 65 65 66 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/_Exit.html>. 66 - #[no_mangle] 67 + #[unsafe(no_mangle)] 67 68 pub extern "C" fn _Exit(status: c_int) -> ! { 68 69 unistd::_exit(status); 69 70 } 70 71 71 72 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/a64l.html>. 72 - #[no_mangle] 73 + #[unsafe(no_mangle)] 73 74 pub unsafe extern "C" fn a64l(s: *const c_char) -> c_long { 74 75 // Early return upon null pointer argument 75 76 if s.is_null() { ··· 107 108 } 108 109 109 110 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/abort.html>. 110 - #[no_mangle] 111 + #[unsafe(no_mangle)] 111 112 pub unsafe extern "C" fn abort() -> ! { 112 113 eprintln!("Abort"); 113 114 intrinsics::abort(); 114 115 } 115 116 116 117 #[cfg(not(target_pointer_width = "64"))] 117 - #[no_mangle] 118 + #[unsafe(no_mangle)] 118 119 static __stack_chk_guard: uintptr_t = 0x19fcadfe; 119 120 120 121 #[cfg(target_pointer_width = "64")] 121 - #[no_mangle] 122 + #[unsafe(no_mangle)] 122 123 static __stack_chk_guard: uintptr_t = 0xd048c37519fcadfe; 123 124 124 - #[no_mangle] 125 + #[unsafe(no_mangle)] 125 126 unsafe extern "C" fn __stack_chk_fail() -> ! { 126 127 abort(); 127 128 } 128 129 129 130 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/abs.html>. 130 - #[no_mangle] 131 + #[unsafe(no_mangle)] 131 132 pub extern "C" fn abs(i: c_int) -> c_int { 132 133 i.abs() 133 134 } 134 135 135 136 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/aligned_alloc.html>. 136 - #[no_mangle] 137 + #[unsafe(no_mangle)] 137 138 pub unsafe extern "C" fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void { 138 139 if size % alignment == 0 { 139 140 /* The size-is-multiple-of-alignment requirement is the only ··· 146 147 } 147 148 148 149 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/at_quick_exit.html>. 149 - #[no_mangle] 150 + #[unsafe(no_mangle)] 150 151 pub unsafe extern "C" fn at_quick_exit(func: Option<extern "C" fn()>) -> c_int { 151 - for i in 0..AT_QUICK_EXIT_FUNCS.len() { 152 - if AT_QUICK_EXIT_FUNCS[i] == None { 153 - AT_QUICK_EXIT_FUNCS[i] = func; 152 + for i in 0..AT_QUICK_EXIT_FUNCS.unsafe_ref().len() { 153 + if AT_QUICK_EXIT_FUNCS.unsafe_ref()[i] == None { 154 + AT_QUICK_EXIT_FUNCS.unsafe_mut()[i] = func; 154 155 return 0; 155 156 } 156 157 } ··· 159 160 } 160 161 161 162 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atexit.html>. 162 - #[no_mangle] 163 + #[unsafe(no_mangle)] 163 164 pub unsafe extern "C" fn atexit(func: Option<extern "C" fn()>) -> c_int { 164 - for i in 0..ATEXIT_FUNCS.len() { 165 - if ATEXIT_FUNCS[i] == None { 166 - ATEXIT_FUNCS[i] = func; 165 + for i in 0..ATEXIT_FUNCS.unsafe_ref().len() { 166 + if ATEXIT_FUNCS.unsafe_ref()[i] == None { 167 + ATEXIT_FUNCS.unsafe_mut()[i] = func; 167 168 return 0; 168 169 } 169 170 } ··· 172 173 } 173 174 174 175 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atof.html>. 175 - #[no_mangle] 176 + #[unsafe(no_mangle)] 176 177 pub unsafe extern "C" fn atof(s: *const c_char) -> c_double { 177 178 strtod(s, ptr::null_mut()) 178 179 } ··· 205 206 s = s.offset(1); 206 207 } 207 208 208 - if neg_sign { 209 - n 210 - } else { 211 - -n 212 - } 209 + if neg_sign { n } else { -n } 213 210 }}; 214 211 } 215 212 216 213 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atoi.html>. 217 - #[no_mangle] 214 + #[unsafe(no_mangle)] 218 215 pub unsafe extern "C" fn atoi(s: *const c_char) -> c_int { 219 216 dec_num_from_ascii!(s, c_int) 220 217 } 221 218 222 219 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atol.html>. 223 - #[no_mangle] 220 + #[unsafe(no_mangle)] 224 221 pub unsafe extern "C" fn atol(s: *const c_char) -> c_long { 225 222 dec_num_from_ascii!(s, c_long) 226 223 } 227 224 228 225 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/atol.html>. 229 - #[no_mangle] 226 + #[unsafe(no_mangle)] 230 227 pub unsafe extern "C" fn atoll(s: *const c_char) -> c_longlong { 231 228 dec_num_from_ascii!(s, c_longlong) 232 229 } ··· 236 233 } 237 234 238 235 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/bsearch.html>. 239 - #[no_mangle] 236 + #[unsafe(no_mangle)] 240 237 pub unsafe extern "C" fn bsearch( 241 238 key: *const c_void, 242 239 base: *const c_void, ··· 262 259 } 263 260 264 261 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/calloc.html>. 265 - #[no_mangle] 262 + #[unsafe(no_mangle)] 266 263 pub unsafe extern "C" fn calloc(nelem: size_t, elsize: size_t) -> *mut c_void { 267 264 //Handle possible integer overflow in size calculation 268 265 match nelem.checked_mul(elsize) { ··· 291 288 } 292 289 293 290 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/div.html>. 294 - #[no_mangle] 291 + #[unsafe(no_mangle)] 295 292 pub extern "C" fn div(numer: c_int, denom: c_int) -> div_t { 296 293 div_t { 297 294 quot: numer / denom, ··· 304 301 /// # Panics 305 302 /// Panics if the function is unable to obtain a lock on the generator's global 306 303 /// state. 307 - #[no_mangle] 304 + #[unsafe(no_mangle)] 308 305 pub extern "C" fn drand48() -> c_double { 309 306 let params = rand48::params(); 310 307 let mut xsubi = rand48::xsubi_lock(); ··· 318 315 /// The `ecvt()` function was marked as legacy in the Open Group Base 319 316 /// Specifications Issue 6, and the function was removed in Issue 7. 320 317 #[deprecated] 321 - // #[no_mangle] 318 + // #[unsafe(no_mangle)] 322 319 pub extern "C" fn ecvt( 323 320 value: c_double, 324 321 ndigit: c_int, ··· 337 334 /// # Panics 338 335 /// Panics if the function is unable to obtain a lock on the generator's global 339 336 /// state. 340 - #[no_mangle] 337 + #[unsafe(no_mangle)] 341 338 pub unsafe extern "C" fn erand48(xsubi: *mut c_ushort) -> c_double { 342 339 let params = rand48::params(); 343 340 let xsubi_mut: &mut [c_ushort; 3] = slice::from_raw_parts_mut(xsubi, 3).try_into().unwrap(); ··· 347 344 } 348 345 349 346 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exit.html>. 350 - #[no_mangle] 347 + #[unsafe(no_mangle)] 351 348 pub unsafe extern "C" fn exit(status: c_int) -> ! { 352 - extern "C" { 349 + unsafe extern "C" { 353 350 static __fini_array_start: extern "C" fn(); 354 351 static __fini_array_end: extern "C" fn(); 355 352 356 353 fn _fini(); 357 354 } 358 355 359 - for i in (0..ATEXIT_FUNCS.len()).rev() { 360 - if let Some(func) = ATEXIT_FUNCS[i] { 356 + for i in (0..ATEXIT_FUNCS.unsafe_ref().len()).rev() { 357 + if let Some(func) = ATEXIT_FUNCS.unsafe_ref()[i] { 361 358 (func)(); 362 359 } 363 360 } ··· 390 387 /// The `fcvt()` function was marked as legacy in the Open Group Base 391 388 /// Specifications Issue 6, and the function was removed in Issue 7. 392 389 #[deprecated] 393 - // #[no_mangle] 390 + // #[unsafe(no_mangle)] 394 391 pub extern "C" fn fcvt( 395 392 value: c_double, 396 393 ndigit: c_int, ··· 401 398 } 402 399 403 400 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/free.html>. 404 - #[no_mangle] 401 + #[unsafe(no_mangle)] 405 402 pub unsafe extern "C" fn free(ptr: *mut c_void) { 406 403 platform::free(ptr); 407 404 } ··· 412 409 /// The `gcvt()` function was marked as legacy in the Open Group Base 413 410 /// Specifications Issue 6, and the function was removed in Issue 7. 414 411 #[deprecated] 415 - // #[no_mangle] 412 + // #[unsafe(no_mangle)] 416 413 pub extern "C" fn gcvt(value: c_double, ndigit: c_int, buf: *mut c_char) -> *mut c_char { 417 414 unimplemented!(); 418 415 } ··· 445 442 } 446 443 447 444 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getenv.html>. 448 - #[no_mangle] 445 + #[unsafe(no_mangle)] 449 446 pub unsafe extern "C" fn getenv(name: *const c_char) -> *mut c_char { 450 447 find_env(name).map(|val| val.1).unwrap_or(ptr::null_mut()) 451 448 } 452 449 453 450 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getsubopt.html>. 454 - #[no_mangle] 451 + #[unsafe(no_mangle)] 455 452 pub unsafe extern "C" fn getsubopt( 456 453 optionp: *mut *mut c_char, 457 454 tokens: *const *mut c_char, ··· 487 484 } 488 485 489 486 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/grantpt.html>. 490 - #[no_mangle] 487 + #[unsafe(no_mangle)] 491 488 pub extern "C" fn grantpt(fildes: c_int) -> c_int { 492 489 // No-op on Linux and Redox 493 490 0 ··· 495 492 496 493 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/initstate.html>. 497 494 // Ported from musl 498 - #[no_mangle] 495 + #[unsafe(no_mangle)] 499 496 pub unsafe extern "C" fn initstate(seed: c_uint, state: *mut c_char, size: size_t) -> *mut c_char { 500 497 if size < 8 { 501 498 ptr::null_mut() ··· 528 525 /// # Panics 529 526 /// Panics if the function is unable to obtain a lock on the generator's global 530 527 /// state. 531 - #[no_mangle] 528 + #[unsafe(no_mangle)] 532 529 pub unsafe extern "C" fn jrand48(xsubi: *mut c_ushort) -> c_long { 533 530 let params = rand48::params(); 534 531 let xsubi_mut: &mut [c_ushort; 3] = slice::from_raw_parts_mut(xsubi, 3).try_into().unwrap(); ··· 538 535 } 539 536 540 537 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/a64l.html>. 541 - #[no_mangle] 538 + #[unsafe(no_mangle)] 542 539 pub unsafe extern "C" fn l64a(value: c_long) -> *mut c_char { 543 540 // POSIX says we should only consider the lower 32 bits of value. 544 541 let value_as_i32 = value as i32; ··· 551 548 let num_output_digits = usize::try_from(6 - (value_as_i32.leading_zeros() + 4) / 6).unwrap(); 552 549 553 550 // Reset buffer (and have null terminator in place for any result) 554 - L64A_BUFFER = [0; 7]; 551 + *L64A_BUFFER.as_mut_ptr() = [0; 7]; 555 552 556 553 for i in 0..num_output_digits { 557 554 // Conversion to c_char always succeeds for the range 0..=63 558 555 let digit_value = c_char::try_from((value_as_i32 >> 6 * i) & 63).unwrap(); 559 556 560 - L64A_BUFFER[i] = match digit_value { 557 + L64A_BUFFER.unsafe_mut()[i] = match digit_value { 561 558 0..=11 => { 562 559 // ./0123456789 for values 0 to 11. b'.' == 46 563 560 46 + digit_value ··· 574 571 }; 575 572 } 576 573 577 - L64A_BUFFER.as_mut_ptr() 574 + L64A_BUFFER.unsafe_mut().as_mut_ptr() 578 575 } 579 576 580 577 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/labs.html>. 581 - #[no_mangle] 578 + #[unsafe(no_mangle)] 582 579 pub extern "C" fn labs(i: c_long) -> c_long { 583 580 i.abs() 584 581 } ··· 592 589 /// # Panics 593 590 /// Panics if the function is unable to obtain a lock on the generator's global 594 591 /// state. 595 - #[no_mangle] 592 + #[unsafe(no_mangle)] 596 593 pub unsafe extern "C" fn lcong48(param: *mut c_ushort) { 597 594 let mut xsubi = rand48::xsubi_lock(); 598 595 let mut params = rand48::params_mut(); ··· 615 612 } 616 613 617 614 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ldiv.html>. 618 - #[no_mangle] 615 + #[unsafe(no_mangle)] 619 616 pub extern "C" fn ldiv(numer: c_long, denom: c_long) -> ldiv_t { 620 617 ldiv_t { 621 618 quot: numer / denom, ··· 624 621 } 625 622 626 623 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/labs.html>. 627 - #[no_mangle] 624 + #[unsafe(no_mangle)] 628 625 pub extern "C" fn llabs(i: c_longlong) -> c_longlong { 629 626 i.abs() 630 627 } ··· 637 634 } 638 635 639 636 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ldiv.html>. 640 - #[no_mangle] 637 + #[unsafe(no_mangle)] 641 638 pub extern "C" fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t { 642 639 lldiv_t { 643 640 quot: numer / denom, ··· 650 647 /// # Panics 651 648 /// Panics if the function is unable to obtain a lock on the generator's global 652 649 /// state. 653 - #[no_mangle] 650 + #[unsafe(no_mangle)] 654 651 pub extern "C" fn lrand48() -> c_long { 655 652 let params = rand48::params(); 656 653 let mut xsubi = rand48::xsubi_lock(); ··· 659 656 } 660 657 661 658 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/malloc.html>. 662 - #[no_mangle] 659 + #[unsafe(no_mangle)] 663 660 pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void { 664 661 let ptr = platform::alloc(size); 665 662 if ptr.is_null() { ··· 670 667 671 668 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/posix_memalign.3.html>. 672 669 #[deprecated] 673 - #[no_mangle] 670 + #[unsafe(no_mangle)] 674 671 pub unsafe extern "C" fn memalign(alignment: size_t, size: size_t) -> *mut c_void { 675 672 if alignment.is_power_of_two() { 676 673 let ptr = platform::alloc_align(size, alignment); ··· 685 682 } 686 683 687 684 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mblen.html>. 688 - #[no_mangle] 685 + #[unsafe(no_mangle)] 689 686 pub unsafe extern "C" fn mblen(s: *const c_char, n: size_t) -> c_int { 690 687 let mut wc: wchar_t = 0; 691 688 let mut state: mbstate_t = mbstate_t {}; ··· 702 699 } 703 700 704 701 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mbstowcs.html>. 705 - #[no_mangle] 702 + #[unsafe(no_mangle)] 706 703 pub unsafe extern "C" fn mbstowcs(pwcs: *mut wchar_t, mut s: *const c_char, n: size_t) -> size_t { 707 704 let mut state: mbstate_t = mbstate_t {}; 708 705 mbsrtowcs(pwcs, &mut s, n, &mut state) 709 706 } 710 707 711 708 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mbtowc.html>. 712 - #[no_mangle] 709 + #[unsafe(no_mangle)] 713 710 pub unsafe extern "C" fn mbtowc(pwc: *mut wchar_t, s: *const c_char, n: size_t) -> c_int { 714 711 let mut state: mbstate_t = mbstate_t {}; 715 712 mbrtowc(pwc, s, n, &mut state) as c_int ··· 767 764 } 768 765 769 766 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkdtemp.html>. 770 - #[no_mangle] 767 + #[unsafe(no_mangle)] 771 768 pub unsafe extern "C" fn mkdtemp(name: *mut c_char) -> *mut c_char { 772 769 inner_mktemp(name, 0, || { 773 770 let name_c = CStr::from_ptr(name); ··· 780 777 } 781 778 782 779 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkdtemp.html>. 783 - #[no_mangle] 780 + #[unsafe(no_mangle)] 784 781 pub unsafe extern "C" fn mkostemp(name: *mut c_char, flags: c_int) -> c_int { 785 782 mkostemps(name, 0, flags) 786 783 } 787 784 788 785 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/mkstemp.3.html>. 789 - #[no_mangle] 786 + #[unsafe(no_mangle)] 790 787 pub unsafe extern "C" fn mkostemps( 791 788 name: *mut c_char, 792 789 suffix_len: c_int, ··· 801 798 let name = CStr::from_ptr(name); 802 799 let fd = Sys::open(name, flags, 0o600).or_minus_one_errno(); 803 800 804 - if fd >= 0 { 805 - Some(fd) 806 - } else { 807 - None 808 - } 801 + if fd >= 0 { Some(fd) } else { None } 809 802 }) 810 803 .unwrap_or(-1) 811 804 } 812 805 813 806 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkdtemp.html>. 814 - #[no_mangle] 807 + #[unsafe(no_mangle)] 815 808 pub unsafe extern "C" fn mkstemp(name: *mut c_char) -> c_int { 816 809 mkostemps(name, 0, 0) 817 810 } 818 811 819 812 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/mkstemp.3.html>. 820 - #[no_mangle] 813 + #[unsafe(no_mangle)] 821 814 pub unsafe extern "C" fn mkstemps(name: *mut c_char, suffix_len: c_int) -> c_int { 822 815 mkostemps(name, suffix_len, 0) 823 816 } ··· 828 821 /// The `mktemp()` function was marked as legacy in the Open Group Base 829 822 /// Specifications Issue 6, and the function was removed in Issue 7. 830 823 #[deprecated] 831 - #[no_mangle] 824 + #[unsafe(no_mangle)] 832 825 pub unsafe extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { 833 826 if inner_mktemp(name, 0, || { 834 827 let name = CStr::from_ptr(name); ··· 850 843 /// # Panics 851 844 /// Panics if the function is unable to obtain a lock on the generator's global 852 845 /// state. 853 - #[no_mangle] 846 + #[unsafe(no_mangle)] 854 847 pub extern "C" fn mrand48() -> c_long { 855 848 let params = rand48::params(); 856 849 let mut xsubi = rand48::xsubi_lock(); ··· 867 860 /// # Panics 868 861 /// Panics if the function is unable to obtain a lock on the generator's global 869 862 /// state. 870 - #[no_mangle] 863 + #[unsafe(no_mangle)] 871 864 pub unsafe extern "C" fn nrand48(xsubi: *mut c_ushort) -> c_long { 872 865 let params = rand48::params(); 873 866 let xsubi_mut: &mut [c_ushort; 3] = slice::from_raw_parts_mut(xsubi, 3).try_into().unwrap(); ··· 877 870 } 878 871 879 872 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_memalign.html>. 880 - #[no_mangle] 873 + #[unsafe(no_mangle)] 881 874 pub unsafe extern "C" fn posix_memalign( 882 875 memptr: *mut *mut c_void, 883 876 alignment: size_t, ··· 888 881 if alignment % VOID_PTR_SIZE == 0 && alignment.is_power_of_two() { 889 882 let ptr = platform::alloc_align(size, alignment); 890 883 *memptr = ptr; 891 - if ptr.is_null() { 892 - ENOMEM 893 - } else { 894 - 0 895 - } 884 + if ptr.is_null() { ENOMEM } else { 0 } 896 885 } else { 897 886 *memptr = ptr::null_mut(); 898 887 EINVAL ··· 900 889 } 901 890 902 891 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_openpt.html>. 903 - #[no_mangle] 892 + #[unsafe(no_mangle)] 904 893 pub unsafe extern "C" fn posix_openpt(flags: c_int) -> c_int { 905 894 #[cfg(target_os = "redox")] 906 895 let r = open((b"/scheme/pty\0" as *const u8).cast(), O_CREAT); ··· 916 905 } 917 906 918 907 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ptsname.html>. 919 - #[no_mangle] 908 + #[unsafe(no_mangle)] 920 909 pub unsafe extern "C" fn ptsname(fd: c_int) -> *mut c_char { 921 - static mut PTS_BUFFER: [c_char; 9 + mem::size_of::<c_int>() * 3 + 1] = 922 - [0; 9 + mem::size_of::<c_int>() * 3 + 1]; 923 - if ptsname_r(fd, PTS_BUFFER.as_mut_ptr(), PTS_BUFFER.len()) != 0 { 910 + const PTS_BUFFER_LEN: usize = 9 + mem::size_of::<c_int>() * 3 + 1; 911 + static mut PTS_BUFFER: [c_char; PTS_BUFFER_LEN] = [0; PTS_BUFFER_LEN]; 912 + if ptsname_r(fd, &raw mut PTS_BUFFER as *mut _, PTS_BUFFER_LEN) != 0 { 924 913 ptr::null_mut() 925 914 } else { 926 - PTS_BUFFER.as_mut_ptr() 915 + &raw mut PTS_BUFFER as *mut _ 927 916 } 928 917 } 929 918 930 919 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ptsname.html>. 931 - #[no_mangle] 920 + #[unsafe(no_mangle)] 932 921 pub unsafe extern "C" fn ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int { 933 922 if buf.is_null() { 934 923 platform::ERRNO.set(EINVAL); ··· 989 978 unsafe fn put_new_env(insert: *mut c_char) { 990 979 // XXX: Another problem is that `environ` can be set to any pointer, which means there is a 991 980 // chance of a memory leak. But we can check if it was the same as before, like musl does. 992 - if platform::environ == platform::OUR_ENVIRON.as_mut_ptr() { 993 - *platform::OUR_ENVIRON.last_mut().unwrap() = insert; 994 - platform::OUR_ENVIRON.push(core::ptr::null_mut()); 981 + if platform::environ == platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr() { 982 + { 983 + let mut our_environ = &mut *platform::OUR_ENVIRON.as_mut_ptr(); 984 + *our_environ.last_mut().unwrap() = insert; 985 + our_environ.push(core::ptr::null_mut()); 986 + } 995 987 // Likely a no-op but is needed due to Stacked Borrows. 996 - platform::environ = platform::OUR_ENVIRON.as_mut_ptr(); 988 + platform::environ = platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr(); 997 989 } else { 998 - platform::OUR_ENVIRON.clear(); 999 - platform::OUR_ENVIRON.extend(platform::environ_iter()); 1000 - platform::OUR_ENVIRON.push(insert); 1001 - platform::OUR_ENVIRON.push(core::ptr::null_mut()); 1002 - platform::environ = platform::OUR_ENVIRON.as_mut_ptr(); 990 + { 991 + let mut our_environ = &mut *platform::OUR_ENVIRON.as_mut_ptr(); 992 + our_environ.clear(); 993 + our_environ.extend(platform::environ_iter()); 994 + our_environ.push(insert); 995 + our_environ.push(core::ptr::null_mut()); 996 + } 997 + platform::environ = platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr(); 1003 998 } 1004 999 } 1005 1000 1006 1001 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/putenv.html>. 1007 - #[no_mangle] 1002 + #[unsafe(no_mangle)] 1008 1003 pub unsafe extern "C" fn putenv(insert: *mut c_char) -> c_int { 1009 1004 assert_ne!(insert, ptr::null_mut(), "putenv(NULL)"); 1010 1005 if let Some((i, _)) = find_env(insert) { ··· 1019 1014 } 1020 1015 1021 1016 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/qsort.html>. 1022 - #[no_mangle] 1017 + #[unsafe(no_mangle)] 1023 1018 pub unsafe extern "C" fn qsort( 1024 1019 base: *mut c_void, 1025 1020 nel: size_t, ··· 1037 1032 } 1038 1033 1039 1034 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/qsort.html>. 1040 - // #[no_mangle] 1035 + // #[unsafe(no_mangle)] 1041 1036 pub unsafe extern "C" fn qsort_r( 1042 1037 base: *mut c_void, 1043 1038 nel: size_t, ··· 1049 1044 } 1050 1045 1051 1046 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/quick_exit.html>. 1052 - #[no_mangle] 1047 + #[unsafe(no_mangle)] 1053 1048 pub unsafe extern "C" fn quick_exit(status: c_int) -> ! { 1054 - for i in (0..AT_QUICK_EXIT_FUNCS.len()).rev() { 1055 - if let Some(func) = AT_QUICK_EXIT_FUNCS[i] { 1049 + for i in (0..AT_QUICK_EXIT_FUNCS.unsafe_ref().len()).rev() { 1050 + if let Some(func) = AT_QUICK_EXIT_FUNCS.unsafe_ref()[i] { 1056 1051 (func)(); 1057 1052 } 1058 1053 } ··· 1061 1056 } 1062 1057 1063 1058 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rand.html>. 1064 - #[no_mangle] 1059 + #[unsafe(no_mangle)] 1065 1060 pub unsafe extern "C" fn rand() -> c_int { 1066 1061 match RNG { 1067 1062 Some(ref mut rng) => rng_sampler().sample(rng), ··· 1079 1074 /// # Deprecation 1080 1075 /// The `rand_r()` function was marked as obsolescent in the Open Group Base 1081 1076 /// Specifications Issue 7, and the function was removed in Issue 8. 1082 - #[no_mangle] 1077 + #[unsafe(no_mangle)] 1083 1078 pub unsafe extern "C" fn rand_r(seed: *mut c_uint) -> c_int { 1084 1079 if seed.is_null() { 1085 1080 errno::EINVAL ··· 1098 1093 1099 1094 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/initstate.html>. 1100 1095 // Ported from musl 1101 - #[no_mangle] 1096 + #[unsafe(no_mangle)] 1102 1097 pub unsafe extern "C" fn random() -> c_long { 1103 1098 let mut random_state = random::state_lock(); 1104 1099 ··· 1137 1132 } 1138 1133 1139 1134 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/realloc.html>. 1140 - #[no_mangle] 1135 + #[unsafe(no_mangle)] 1141 1136 pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void { 1142 1137 let new_ptr = platform::realloc(ptr, size); 1143 1138 if new_ptr.is_null() { ··· 1147 1142 } 1148 1143 1149 1144 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/realloc.html>. 1150 - #[no_mangle] 1145 + #[unsafe(no_mangle)] 1151 1146 pub unsafe extern "C" fn reallocarray(ptr: *mut c_void, m: size_t, n: size_t) -> *mut c_void { 1152 1147 //Handle possible integer overflow in size calculation 1153 1148 match m.checked_mul(n) { ··· 1161 1156 } 1162 1157 1163 1158 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/realpath.html>. 1164 - #[no_mangle] 1159 + #[unsafe(no_mangle)] 1165 1160 pub unsafe extern "C" fn realpath(pathname: *const c_char, resolved: *mut c_char) -> *mut c_char { 1166 1161 let ptr = if resolved.is_null() { 1167 1162 malloc(limits::PATH_MAX) as *mut c_char ··· 1191 1186 } 1192 1187 1193 1188 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getenv.html>. 1194 - // #[no_mangle] 1189 + // #[unsafe(no_mangle)] 1195 1190 pub unsafe extern "C" fn secure_getenv(name: *const c_char) -> *mut c_char { 1196 1191 unimplemented!(); 1197 1192 } ··· 1207 1202 /// # Panics 1208 1203 /// Panics if the function is unable to obtain a lock on the generator's global 1209 1204 /// state. 1210 - #[no_mangle] 1205 + #[unsafe(no_mangle)] 1211 1206 pub unsafe extern "C" fn seed48(seed16v: *mut c_ushort) -> *mut c_ushort { 1212 1207 static mut BUFFER: [c_ushort; 3] = [0; 3]; 1213 1208 ··· 1219 1214 BUFFER = (*xsubi).into(); 1220 1215 *xsubi = seed16v_ref.into(); 1221 1216 params.reset(); 1222 - BUFFER.as_mut_ptr() 1217 + &raw mut BUFFER as *mut _ 1223 1218 } 1224 1219 1225 1220 unsafe fn copy_kv( ··· 1236 1231 } 1237 1232 1238 1233 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setenv.html>. 1239 - #[no_mangle] 1234 + #[unsafe(no_mangle)] 1240 1235 pub unsafe extern "C" fn setenv( 1241 1236 key: *const c_char, 1242 1237 value: *const c_char, ··· 1281 1276 /// The `setkey()` function was marked as obsolescent in the Open Group Base 1282 1277 /// Specifications Issue 8. 1283 1278 #[deprecated] 1284 - // #[no_mangle] 1279 + // #[unsafe(no_mangle)] 1285 1280 pub unsafe extern "C" fn setkey(key: *const c_char) { 1286 1281 unimplemented!(); 1287 1282 } 1288 1283 1289 1284 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/initstate.html>. 1290 1285 // Ported from musl. The state parameter is no longer const in newer versions of POSIX. 1291 - #[no_mangle] 1286 + #[unsafe(no_mangle)] 1292 1287 pub unsafe extern "C" fn setstate(state: *mut c_char) -> *mut c_char { 1293 1288 let mut random_state = random::state_lock(); 1294 1289 ··· 1299 1294 } 1300 1295 1301 1296 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rand.html>. 1302 - #[no_mangle] 1297 + #[unsafe(no_mangle)] 1303 1298 pub unsafe extern "C" fn srand(seed: c_uint) { 1304 1299 RNG = Some(XorShiftRng::from_seed([seed as u8; 16])); 1305 1300 } ··· 1309 1304 /// # Panics 1310 1305 /// Panics if the function is unable to obtain a lock on the generator's global 1311 1306 /// state. 1312 - #[no_mangle] 1307 + #[unsafe(no_mangle)] 1313 1308 pub extern "C" fn srand48(seedval: c_long) { 1314 1309 let mut params = rand48::params_mut(); 1315 1310 let mut xsubi = rand48::xsubi_lock(); ··· 1325 1320 1326 1321 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/initstate.html>. 1327 1322 // Ported from musl 1328 - #[no_mangle] 1323 + #[unsafe(no_mangle)] 1329 1324 pub unsafe extern "C" fn srandom(seed: c_uint) { 1330 1325 let mut random_state = random::state_lock(); 1331 1326 ··· 1440 1435 } 1441 1436 1442 1437 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtod.html>. 1443 - #[no_mangle] 1438 + #[unsafe(no_mangle)] 1444 1439 pub unsafe extern "C" fn strtod(s: *const c_char, endptr: *mut *mut c_char) -> c_double { 1445 1440 strto_float_impl!(c_double, s, endptr) 1446 1441 } 1447 1442 1448 1443 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtod.html>. 1449 - #[no_mangle] 1444 + #[unsafe(no_mangle)] 1450 1445 pub unsafe extern "C" fn strtof(s: *const c_char, endptr: *mut *mut c_char) -> c_float { 1451 1446 strto_float_impl!(c_float, s, endptr) 1452 1447 } 1453 1448 1454 1449 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtol.html>. 1455 - #[no_mangle] 1450 + #[unsafe(no_mangle)] 1456 1451 pub unsafe extern "C" fn strtol(s: *const c_char, endptr: *mut *mut c_char, base: c_int) -> c_long { 1457 1452 strto_impl!( 1458 1453 c_long, ··· 1468 1463 // TODO: strtold(), when long double is available 1469 1464 1470 1465 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtol.html>. 1471 - #[no_mangle] 1466 + #[unsafe(no_mangle)] 1472 1467 pub unsafe extern "C" fn strtoll( 1473 1468 s: *const c_char, 1474 1469 endptr: *mut *mut c_char, ··· 1486 1481 } 1487 1482 1488 1483 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoul.html>. 1489 - #[no_mangle] 1484 + #[unsafe(no_mangle)] 1490 1485 pub unsafe extern "C" fn strtoul( 1491 1486 s: *const c_char, 1492 1487 endptr: *mut *mut c_char, ··· 1504 1499 } 1505 1500 1506 1501 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoul.html>. 1507 - #[no_mangle] 1502 + #[unsafe(no_mangle)] 1508 1503 pub unsafe extern "C" fn strtoull( 1509 1504 s: *const c_char, 1510 1505 endptr: *mut *mut c_char, ··· 1522 1517 } 1523 1518 1524 1519 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/system.html>. 1525 - #[no_mangle] 1520 + #[unsafe(no_mangle)] 1526 1521 pub unsafe extern "C" fn system(command: *const c_char) -> c_int { 1527 1522 // TODO: rusty error handling? 1528 1523 //TODO: share code with popen ··· 1574 1569 /// The `ttyslot()` function was marked as obsolescent in the Open Group Base 1575 1570 /// Specifications Issue 5, and the function was removed in Issue 6. 1576 1571 #[deprecated] 1577 - // #[no_mangle] 1572 + // #[unsafe(no_mangle)] 1578 1573 pub extern "C" fn ttyslot() -> c_int { 1579 1574 unimplemented!(); 1580 1575 } 1581 1576 1582 1577 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/unlockpt.html>. 1583 - #[no_mangle] 1578 + #[unsafe(no_mangle)] 1584 1579 pub unsafe extern "C" fn unlockpt(fildes: c_int) -> c_int { 1585 1580 let mut u: c_int = 0; 1586 1581 ioctl(fildes, TIOCSPTLCK, &mut u as *mut i32 as *mut c_void) 1587 1582 } 1588 1583 1589 1584 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/unsetenv.html>. 1590 - #[no_mangle] 1585 + #[unsafe(no_mangle)] 1591 1586 pub unsafe extern "C" fn unsetenv(key: *const c_char) -> c_int { 1592 1587 if let Some((i, _)) = find_env(key) { 1593 - if platform::environ == platform::OUR_ENVIRON.as_mut_ptr() { 1588 + if platform::environ == platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr() { 1594 1589 // No need to worry about updating the pointer, this does not 1595 1590 // reallocate in any way. And the final null is already shifted back. 1596 - platform::OUR_ENVIRON.remove(i); 1591 + { 1592 + let mut our_environ = &mut *platform::OUR_ENVIRON.as_mut_ptr(); 1593 + our_environ.remove(i); 1594 + } 1597 1595 1598 1596 // My UB paranoia. 1599 - platform::environ = platform::OUR_ENVIRON.as_mut_ptr(); 1597 + platform::environ = platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr(); 1600 1598 } else { 1601 - platform::OUR_ENVIRON.clear(); 1602 - platform::OUR_ENVIRON.extend( 1603 - platform::environ_iter() 1604 - .enumerate() 1605 - .filter(|&(j, _)| j != i) 1606 - .map(|(_, v)| v), 1607 - ); 1608 - platform::OUR_ENVIRON.push(core::ptr::null_mut()); 1609 - platform::environ = platform::OUR_ENVIRON.as_mut_ptr(); 1599 + { 1600 + let mut our_environ = &mut *platform::OUR_ENVIRON.as_mut_ptr(); 1601 + our_environ.clear(); 1602 + our_environ.extend( 1603 + platform::environ_iter() 1604 + .enumerate() 1605 + .filter(|&(j, _)| j != i) 1606 + .map(|(_, v)| v), 1607 + ); 1608 + our_environ.push(core::ptr::null_mut()); 1609 + } 1610 + platform::environ = platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr(); 1610 1611 } 1611 1612 } 1612 1613 0 ··· 1618 1619 /// The `valloc()` function was marked as obsolescent in the Open Group Base 1619 1620 /// Specifications Issue 5, and the function was removed in Issue 6. 1620 1621 #[deprecated] 1621 - #[no_mangle] 1622 + #[unsafe(no_mangle)] 1622 1623 pub unsafe extern "C" fn valloc(size: size_t) -> *mut c_void { 1623 1624 /* sysconf(_SC_PAGESIZE) is a c_long and may in principle not 1624 1625 * convert correctly to a size_t. */ ··· 1640 1641 } 1641 1642 1642 1643 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/wcstombs.html>. 1643 - #[no_mangle] 1644 + #[unsafe(no_mangle)] 1644 1645 pub unsafe extern "C" fn wcstombs(s: *mut c_char, mut pwcs: *const wchar_t, n: size_t) -> size_t { 1645 1646 let mut state: mbstate_t = mbstate_t {}; 1646 1647 wcsrtombs(s, &mut pwcs, n, &mut state) 1647 1648 } 1648 1649 1649 1650 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/wctomb.html>. 1650 - #[no_mangle] 1651 + #[unsafe(no_mangle)] 1651 1652 pub unsafe extern "C" fn wctomb(s: *mut c_char, wc: wchar_t) -> c_int { 1652 1653 let mut state: mbstate_t = mbstate_t {}; 1653 1654 let result: usize = wcrtomb(s, wc, &mut state);
+1 -1
src/header/stdlib/rand48.rs
··· 3 3 use crate::{ 4 4 platform::types::*, 5 5 sync::{ 6 - rwlock::{self, RwLock}, 7 6 Mutex, MutexGuard, 7 + rwlock::{self, RwLock}, 8 8 }, 9 9 }; 10 10
+57 -161
src/header/string/mod.rs
··· 3 3 //! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/string.h.html>. 4 4 5 5 use core::{ 6 - iter::{once, zip}, 6 + iter::once, 7 7 mem::{self, MaybeUninit}, 8 8 ptr, slice, usize, 9 9 }; ··· 14 14 header::{errno::*, signal}, 15 15 iter::{NulTerminated, NulTerminatedInclusive, SrcDstPtrIter}, 16 16 platform::{self, types::*}, 17 + raw_cell::RawCell, 17 18 }; 18 19 19 20 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memccpy.html>. 20 - #[no_mangle] 21 + #[unsafe(no_mangle)] 21 22 pub unsafe extern "C" fn memccpy( 22 23 dest: *mut c_void, 23 24 src: *const c_void, ··· 36 37 } 37 38 38 39 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memchr.html>. 39 - #[no_mangle] 40 + #[unsafe(no_mangle)] 40 41 pub unsafe extern "C" fn memchr( 41 42 haystack: *const c_void, 42 43 needle: c_int, ··· 51 52 } 52 53 53 54 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memcmp.html>. 54 - #[no_mangle] 55 - #[no_mangle] 55 + #[unsafe(no_mangle)] 56 + #[unsafe(no_mangle)] 56 57 pub unsafe extern "C" fn memcmp(s1: *const c_void, s2: *const c_void, n: usize) -> c_int { 57 58 let (div, rem) = (n / mem::size_of::<usize>(), n % mem::size_of::<usize>()); 58 59 let mut a = s1 as *const usize; ··· 92 93 /// - `s1` is convertible to a `&mut [MaybeUninit<u8>]` with length `n`, 93 94 /// and 94 95 /// - `s2` is convertible to a `&[MaybeUninit<u8>]` with length `n`. 95 - #[no_mangle] 96 + #[unsafe(no_mangle)] 96 97 pub unsafe extern "C" fn memcpy(s1: *mut c_void, s2: *const c_void, n: size_t) -> *mut c_void { 97 - // Avoid creating slices for n == 0. This is because we are required to 98 - // avoid UB for n == 0, even if either s1 or s2 is null, to comply with the 99 - // expectations of Rust's core library, as well as C2y (N3322). 100 - // See https://doc.rust-lang.org/core/index.html for details. 101 - if n != 0 { 102 - // SAFETY: the caller is required to ensure that the provided pointers 103 - // are valid. The slices are required to have a length of at most 104 - // isize::MAX; this implicitly ensured by requiring valid pointers to 105 - // two nonoverlapping slices. 106 - let s1_slice = unsafe { slice::from_raw_parts_mut(s1.cast::<MaybeUninit<u8>>(), n) }; 107 - let s2_slice = unsafe { slice::from_raw_parts(s2.cast::<MaybeUninit<u8>>(), n) }; 108 - 109 - // At this point, it may seem tempting to use 110 - // s1_slice.copy_from_slice(s2_slice) here, but memcpy is one of the 111 - // handful of symbols whose existence is assumed by Rust's core 112 - // library, and thus we need to be careful here not to rely on any 113 - // function that calls memcpy internally. 114 - // See https://doc.rust-lang.org/core/index.html for details. 115 - // 116 - // Instead, we check the alignment of the two slices and try to 117 - // identify the largest Rust primitive type that is well-aligned for 118 - // copying in chunks. s1_slice and s2_slice will be divided into 119 - // (prefix, middle, suffix), where only the "middle" part is copyable 120 - // using the larger primitive type. 121 - let s1_addr = s1.addr(); 122 - let s2_addr = s2.addr(); 123 - // Find the number of similar trailing bits in the two addresses to let 124 - // us find the largest possible chunk size 125 - let equal_trailing_bits_count = (s1_addr ^ s2_addr).trailing_zeros(); 126 - let chunk_size = match equal_trailing_bits_count { 127 - 0 => 1, 128 - 1 => 2, 129 - 2 => 4, 130 - 3 => 8, 131 - _ => 16, // use u128 chunks for any higher alignments 132 - }; 133 - let chunk_align_offset = s1.align_offset(chunk_size); 134 - let prefix_len = chunk_align_offset.min(n); 135 - 136 - // Copy "prefix" bytes 137 - for (s1_elem, s2_elem) in zip(&mut s1_slice[..prefix_len], &s2_slice[..prefix_len]) { 138 - *s1_elem = *s2_elem; 139 - } 140 - 141 - if chunk_align_offset < n { 142 - fn copy_chunks_and_remainder<const N: usize, T: Copy>( 143 - dst: &mut [MaybeUninit<u8>], 144 - src: &[MaybeUninit<u8>], 145 - ) { 146 - // Check sanity 147 - assert_eq!(N, mem::size_of::<T>()); 148 - assert_eq!(0, N % mem::align_of::<T>()); 149 - assert!(dst.as_mut_ptr().is_aligned_to(N)); 150 - assert!(src.as_ptr().is_aligned_to(N)); 151 - 152 - // Split into "middle" and "suffix" 153 - let (dst_chunks, dst_remainder) = dst.as_chunks_mut::<N>(); 154 - let (src_chunks, src_remainder) = src.as_chunks::<N>(); 155 - 156 - // Copy "middle" 157 - for (dst_chunk, src_chunk) in zip(dst_chunks, src_chunks) { 158 - // SAFETY: the chunks are safely subsliced from s1 and 159 - // s2. Alignment is ensured through the use of 160 - // "align_offset", while the size of the chunks is 161 - // explicitly taken to match the primitive size. 162 - let dst_chunk_primitive: &mut MaybeUninit<T> = 163 - unsafe { &mut *dst_chunk.as_mut_ptr().cast() }; 164 - let src_chunk_primitive: &MaybeUninit<T> = 165 - unsafe { &*src_chunk.as_ptr().cast() }; 166 - *dst_chunk_primitive = *src_chunk_primitive; 167 - } 168 - 169 - // Copy "suffix" 170 - for (dst_elem, src_elem) in zip(dst_remainder, src_remainder) { 171 - *dst_elem = *src_elem; 172 - } 173 - } 174 - 175 - // Copy "middle" bytes (if length is sufficient) and any remaining 176 - // "suffix" bytes. 177 - let s1_middle_and_suffix = &mut s1_slice[prefix_len..]; 178 - let s2_middle_and_suffix = &s2_slice[prefix_len..]; 179 - match chunk_size { 180 - 1 => { 181 - for (s1_elem, s2_elem) in zip(s1_middle_and_suffix, s2_middle_and_suffix) { 182 - *s1_elem = *s2_elem; 183 - } 184 - } 185 - 2 => { 186 - copy_chunks_and_remainder::<2, u16>(s1_middle_and_suffix, s2_middle_and_suffix) 187 - } 188 - 4 => { 189 - copy_chunks_and_remainder::<4, u32>(s1_middle_and_suffix, s2_middle_and_suffix) 190 - } 191 - 8 => { 192 - copy_chunks_and_remainder::<8, u64>(s1_middle_and_suffix, s2_middle_and_suffix) 193 - } 194 - 16 => copy_chunks_and_remainder::<16, u128>( 195 - s1_middle_and_suffix, 196 - s2_middle_and_suffix, 197 - ), 198 - _ => unreachable!(), 199 - } 200 - } 98 + for i in 0..n { 99 + *(s1 as *mut u8).add(i) = *(s2 as *const u8).add(i); 201 100 } 202 - 203 101 s1 204 102 } 205 103 ··· 209 107 /// The caller must ensure that: 210 108 /// - `haystack` is convertible to a `&[u8]` with length `haystacklen`, and 211 109 /// - `needle` is convertible to a `&[u8]` with length `needlelen`. 212 - #[no_mangle] 110 + #[unsafe(no_mangle)] 213 111 pub unsafe extern "C" fn memmem( 214 112 haystack: *const c_void, 215 113 haystacklen: size_t, ··· 241 139 } 242 140 243 141 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memmove.html>. 244 - #[no_mangle] 142 + #[unsafe(no_mangle)] 245 143 pub unsafe extern "C" fn memmove(s1: *mut c_void, s2: *const c_void, n: size_t) -> *mut c_void { 246 144 if s2 < s1 as *const c_void { 247 145 // copy from end ··· 262 160 } 263 161 264 162 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/memchr.3.html>. 265 - #[no_mangle] 163 + #[unsafe(no_mangle)] 266 164 pub unsafe extern "C" fn memrchr( 267 165 haystack: *const c_void, 268 166 needle: c_int, ··· 277 175 } 278 176 279 177 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/memset.html>. 280 - #[no_mangle] 178 + #[unsafe(no_mangle)] 281 179 pub unsafe extern "C" fn memset(s: *mut c_void, c: c_int, n: size_t) -> *mut c_void { 282 180 for i in 0..n { 283 181 *(s as *mut u8).add(i) = c as u8; ··· 286 184 } 287 185 288 186 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcpy.html>. 289 - #[no_mangle] 187 + #[unsafe(no_mangle)] 290 188 pub unsafe extern "C" fn stpcpy(mut s1: *mut c_char, mut s2: *const c_char) -> *mut c_char { 291 189 loop { 292 190 *s1 = *s2; ··· 303 201 } 304 202 305 203 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncpy.html>. 306 - #[no_mangle] 204 + #[unsafe(no_mangle)] 307 205 pub unsafe extern "C" fn stpncpy( 308 206 mut s1: *mut c_char, 309 207 mut s2: *const c_char, ··· 327 225 } 328 226 329 227 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/strstr.3.html>. 330 - #[no_mangle] 228 + #[unsafe(no_mangle)] 331 229 pub unsafe extern "C" fn strcasestr(haystack: *const c_char, needle: *const c_char) -> *mut c_char { 332 230 inner_strstr(haystack, needle, !32) 333 231 } 334 232 335 233 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcat.html>. 336 - #[no_mangle] 234 + #[unsafe(no_mangle)] 337 235 pub unsafe extern "C" fn strcat(s1: *mut c_char, s2: *const c_char) -> *mut c_char { 338 236 strncat(s1, s2, usize::MAX) 339 237 } ··· 344 242 /// The caller is required to ensure that `s` is a valid pointer to a buffer 345 243 /// containing at least one nul value. The pointed-to buffer must not be 346 244 /// modified for the duration of the call. 347 - #[no_mangle] 245 + #[unsafe(no_mangle)] 348 246 pub unsafe extern "C" fn strchr(mut s: *const c_char, c: c_int) -> *mut c_char { 349 247 let c_as_c_char = c as c_char; 350 248 ··· 361 259 } 362 260 363 261 /// Non-POSIX, see <https://man7.org/linux/man-pages/man3/strchr.3.html>. 364 - #[no_mangle] 262 + #[unsafe(no_mangle)] 365 263 pub unsafe extern "C" fn strchrnul(s: *const c_char, c: c_int) -> *mut c_char { 366 264 let mut s = s.cast_mut(); 367 265 loop { ··· 377 275 } 378 276 379 277 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcmp.html>. 380 - #[no_mangle] 278 + #[unsafe(no_mangle)] 381 279 pub unsafe extern "C" fn strcmp(s1: *const c_char, s2: *const c_char) -> c_int { 382 280 strncmp(s1, s2, usize::MAX) 383 281 } 384 282 385 283 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcoll.html>. 386 - #[no_mangle] 284 + #[unsafe(no_mangle)] 387 285 pub unsafe extern "C" fn strcoll(s1: *const c_char, s2: *const c_char) -> c_int { 388 286 // relibc has no locale stuff (yet) 389 287 strcmp(s1, s2) ··· 392 290 // TODO: strcoll_l 393 291 394 292 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcpy.html>. 395 - #[no_mangle] 293 + #[unsafe(no_mangle)] 396 294 pub unsafe extern "C" fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char { 397 295 let src_iter = unsafe { NulTerminated::new(src).unwrap() }; 398 296 let src_dest_iter = unsafe { SrcDstPtrIter::new(src_iter.chain(once(&0)), dst) }; ··· 431 329 } 432 330 433 331 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcspn.html>. 434 - #[no_mangle] 332 + #[unsafe(no_mangle)] 435 333 pub unsafe extern "C" fn strcspn(s1: *const c_char, s2: *const c_char) -> size_t { 436 334 inner_strspn(s1, s2, false) 437 335 } 438 336 439 337 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strdup.html>. 440 - #[no_mangle] 338 + #[unsafe(no_mangle)] 441 339 pub unsafe extern "C" fn strdup(s1: *const c_char) -> *mut c_char { 442 340 strndup(s1, usize::MAX) 443 341 } 444 342 445 343 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strerror.html>. 446 - #[no_mangle] 344 + #[unsafe(no_mangle)] 447 345 pub unsafe extern "C" fn strerror(errnum: c_int) -> *mut c_char { 448 346 use core::fmt::Write; 449 347 450 - static mut strerror_buf: [u8; STRERROR_MAX] = [0; STRERROR_MAX]; 451 - let mut w = platform::StringWriter(strerror_buf.as_mut_ptr(), strerror_buf.len()); 348 + static strerror_buf: RawCell<[u8; STRERROR_MAX]> = RawCell::new([0; STRERROR_MAX]); 349 + let mut w = platform::StringWriter( 350 + strerror_buf.unsafe_mut().as_mut_ptr(), 351 + strerror_buf.unsafe_ref().len(), 352 + ); 452 353 453 354 let _ = match STR_ERROR.get(errnum as usize) { 454 355 Some(e) => w.write_str(e), 455 356 None => w.write_fmt(format_args!("Unknown error {}", errnum)), 456 357 }; 457 358 458 - strerror_buf.as_mut_ptr() as *mut c_char 359 + strerror_buf.unsafe_mut().as_mut_ptr() as *mut c_char 459 360 } 460 361 461 362 // TODO: strerror_l 462 363 463 364 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strerror.html>. 464 - #[no_mangle] 365 + #[unsafe(no_mangle)] 465 366 pub unsafe extern "C" fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int { 466 367 let msg = strerror(errnum); 467 368 let len = strlen(msg); ··· 479 380 } 480 381 481 382 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strlcat.html>. 482 - #[no_mangle] 383 + #[unsafe(no_mangle)] 483 384 pub unsafe extern "C" fn strlcat(dst: *mut c_char, src: *const c_char, n: size_t) -> size_t { 484 385 let len = strlen(dst) as isize; 485 386 let d = dst.offset(len); ··· 487 388 strlcpy(d, src, n) 488 389 } 489 390 490 - #[no_mangle] 391 + #[unsafe(no_mangle)] 491 392 pub unsafe extern "C" fn strsep(str_: *mut *mut c_char, sep: *const c_char) -> *mut c_char { 492 393 let s = *str_; 493 394 if s.is_null() { ··· 505 406 } 506 407 507 408 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strlcat.html>. 508 - #[no_mangle] 409 + #[unsafe(no_mangle)] 509 410 pub unsafe extern "C" fn strlcpy(dst: *mut c_char, src: *const c_char, n: size_t) -> size_t { 510 411 let mut i = 0; 511 412 ··· 520 421 } 521 422 522 423 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strlen.html>. 523 - #[no_mangle] 424 + #[unsafe(no_mangle)] 524 425 pub unsafe extern "C" fn strlen(s: *const c_char) -> size_t { 525 426 unsafe { NulTerminated::new(s).unwrap() }.count() 526 427 } 527 428 528 429 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncat.html>. 529 - #[no_mangle] 430 + #[unsafe(no_mangle)] 530 431 pub unsafe extern "C" fn strncat(s1: *mut c_char, s2: *const c_char, n: size_t) -> *mut c_char { 531 432 let len = strlen(s1.cast()); 532 433 let mut i = 0; ··· 545 446 } 546 447 547 448 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncmp.html>. 548 - #[no_mangle] 449 + #[unsafe(no_mangle)] 549 450 pub unsafe extern "C" fn strncmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int { 550 - let s1 = slice::from_raw_parts(s1 as *const c_uchar, n); 551 - let s2 = slice::from_raw_parts(s2 as *const c_uchar, n); 552 - 553 - for (&a, &b) in s1.iter().zip(s2.iter()) { 554 - let val = (a as c_int) - (b as c_int); 451 + for i in 0..n { 452 + // These must be cast as u8 to have correct comparisons 453 + let a = *s1.add(i) as u8; 454 + let b = *s2.add(i) as u8; 555 455 if a != b || a == 0 { 556 - return val; 456 + return (a as c_int) - (b as c_int); 557 457 } 558 458 } 559 459 ··· 561 461 } 562 462 563 463 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncpy.html>. 564 - #[no_mangle] 464 + #[unsafe(no_mangle)] 565 465 pub unsafe extern "C" fn strncpy(s1: *mut c_char, s2: *const c_char, n: size_t) -> *mut c_char { 566 466 stpncpy(s1, s2, n); 567 467 s1 568 468 } 569 469 570 470 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strdup.html>. 571 - #[no_mangle] 471 + #[unsafe(no_mangle)] 572 472 pub unsafe extern "C" fn strndup(s1: *const c_char, size: size_t) -> *mut c_char { 573 473 let len = strnlen(s1, size); 574 474 ··· 588 488 } 589 489 590 490 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strlen.html>. 591 - #[no_mangle] 491 + #[unsafe(no_mangle)] 592 492 pub unsafe extern "C" fn strnlen(s: *const c_char, size: size_t) -> size_t { 593 493 unsafe { NulTerminated::new(s).unwrap() }.take(size).count() 594 494 } 595 495 596 496 /// Non-POSIX, see <https://en.cppreference.com/w/c/string/byte/strlen>. 597 - #[no_mangle] 497 + #[unsafe(no_mangle)] 598 498 pub unsafe extern "C" fn strnlen_s(s: *const c_char, size: size_t) -> size_t { 599 - if s.is_null() { 600 - 0 601 - } else { 602 - strnlen(s, size) 603 - } 499 + if s.is_null() { 0 } else { strnlen(s, size) } 604 500 } 605 501 606 502 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strpbrk.html>. 607 - #[no_mangle] 503 + #[unsafe(no_mangle)] 608 504 pub unsafe extern "C" fn strpbrk(s1: *const c_char, s2: *const c_char) -> *mut c_char { 609 505 let p = s1.add(strcspn(s1, s2)); 610 506 if *p != 0 { ··· 615 511 } 616 512 617 513 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strrchr.html>. 618 - #[no_mangle] 514 + #[unsafe(no_mangle)] 619 515 pub unsafe extern "C" fn strrchr(s: *const c_char, c: c_int) -> *mut c_char { 620 516 let len = strlen(s) as isize; 621 517 let c = c as c_char; ··· 630 526 } 631 527 632 528 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strsignal.html>. 633 - #[no_mangle] 529 + #[unsafe(no_mangle)] 634 530 pub unsafe extern "C" fn strsignal(sig: c_int) -> *mut c_char { 635 531 signal::SIGNAL_STRINGS 636 532 .get(sig as usize) ··· 639 535 } 640 536 641 537 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strspn.html>. 642 - #[no_mangle] 538 + #[unsafe(no_mangle)] 643 539 pub unsafe extern "C" fn strspn(s1: *const c_char, s2: *const c_char) -> size_t { 644 540 inner_strspn(s1, s2, true) 645 541 } ··· 669 565 } 670 566 671 567 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strstr.html>. 672 - #[no_mangle] 568 + #[unsafe(no_mangle)] 673 569 pub unsafe extern "C" fn strstr(haystack: *const c_char, needle: *const c_char) -> *mut c_char { 674 570 inner_strstr(haystack, needle, !0) 675 571 } 676 572 677 573 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtok.html>. 678 - #[no_mangle] 574 + #[unsafe(no_mangle)] 679 575 pub unsafe extern "C" fn strtok(s1: *mut c_char, delimiter: *const c_char) -> *mut c_char { 680 576 static mut HAYSTACK: *mut c_char = ptr::null_mut(); 681 - strtok_r(s1, delimiter, &mut HAYSTACK) 577 + strtok_r(s1, delimiter, &raw mut HAYSTACK) 682 578 } 683 579 684 580 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtok.html>. 685 - #[no_mangle] 581 + #[unsafe(no_mangle)] 686 582 pub unsafe extern "C" fn strtok_r( 687 583 s: *mut c_char, 688 584 delimiter: *const c_char, ··· 719 615 } 720 616 721 617 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strxfrm.html>. 722 - #[no_mangle] 618 + #[unsafe(no_mangle)] 723 619 pub unsafe extern "C" fn strxfrm(s1: *mut c_char, s2: *const c_char, n: size_t) -> size_t { 724 620 // relibc has no locale stuff (yet) 725 621 let len = strlen(s2);
+13 -13
src/header/strings/mod.rs
··· 23 23 /// The `bcmp()` function was marked legacy in the Open Group Base 24 24 /// Specifications Issue 6, and removed in Issue 7. 25 25 #[deprecated] 26 - #[no_mangle] 26 + #[unsafe(no_mangle)] 27 27 pub unsafe extern "C" fn bcmp(first: *const c_void, second: *const c_void, n: size_t) -> c_int { 28 28 unsafe { string::memcmp(first, second, n) } 29 29 } ··· 34 34 /// The `bcopy()` function was marked legacy in the Open Group Base 35 35 /// Specifications Issue 6, and removed in Issue 7. 36 36 #[deprecated] 37 - #[no_mangle] 37 + #[unsafe(no_mangle)] 38 38 pub unsafe extern "C" fn bcopy(src: *const c_void, dst: *mut c_void, n: size_t) { 39 39 unsafe { 40 40 ptr::copy(src as *const u8, dst as *mut u8, n); ··· 47 47 /// The `bzero()` function was marked legacy in the Open Group Base 48 48 /// Specifications Issue 6, and removed in Issue 7. 49 49 #[deprecated] 50 - #[no_mangle] 50 + #[unsafe(no_mangle)] 51 51 pub unsafe extern "C" fn bzero(dst: *mut c_void, n: size_t) { 52 52 unsafe { 53 53 ptr::write_bytes(dst as *mut u8, 0, n); ··· 55 55 } 56 56 57 57 /// Non-POSIX, see <https://man7.org/linux/man-pages/man3/bzero.3.html>. 58 - #[no_mangle] 58 + #[unsafe(no_mangle)] 59 59 pub unsafe extern "C" fn explicit_bzero(s: *mut c_void, n: size_t) { 60 60 for i in 0..n { 61 61 unsafe { ··· 68 68 } 69 69 70 70 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ffs.html>. 71 - #[no_mangle] 71 + #[unsafe(no_mangle)] 72 72 pub extern "C" fn ffs(i: c_int) -> c_int { 73 73 if i == 0 { 74 74 return 0; ··· 77 77 } 78 78 79 79 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ffs.html>. 80 - #[no_mangle] 80 + #[unsafe(no_mangle)] 81 81 pub extern "C" fn ffsl(i: c_long) -> c_int { 82 82 if i == 0 { 83 83 return 0; ··· 86 86 } 87 87 88 88 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ffs.html>. 89 - #[no_mangle] 89 + #[unsafe(no_mangle)] 90 90 pub extern "C" fn ffsll(i: c_longlong) -> c_int { 91 91 if i == 0 { 92 92 return 0; ··· 100 100 /// The `index()` function was marked legacy in the Open Group Base 101 101 /// Specifications Issue 6, and removed in Issue 7. 102 102 #[deprecated] 103 - #[no_mangle] 103 + #[unsafe(no_mangle)] 104 104 pub unsafe extern "C" fn index(s: *const c_char, c: c_int) -> *mut c_char { 105 105 unsafe { string::strchr(s, c) } 106 106 } ··· 111 111 /// The `rindex()` function was marked legacy in the Open Group Base 112 112 /// Specifications Issue 6, and removed in Issue 7. 113 113 #[deprecated] 114 - #[no_mangle] 114 + #[unsafe(no_mangle)] 115 115 pub unsafe extern "C" fn rindex(s: *const c_char, c: c_int) -> *mut c_char { 116 116 unsafe { string::strrchr(s, c) } 117 117 } 118 118 119 119 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp.html>. 120 - #[no_mangle] 120 + #[unsafe(no_mangle)] 121 121 pub unsafe extern "C" fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int { 122 122 // SAFETY: the caller must ensure that s1 and s2 point to nul-terminated buffers. 123 123 let s1_iter = unsafe { NulTerminated::new(s1).unwrap() }.chain(once(&0)); ··· 129 129 130 130 // TODO: needs locale_t 131 131 // See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp.html>. 132 - // #[no_mangle] 132 + // #[unsafe(no_mangle)] 133 133 /*pub extern "C" fn strcasecmp_l(s1: *const c_char, s2: *const c_char, locale: locale_t) -> c_int { 134 134 unimplemented!(); 135 135 }*/ 136 136 137 137 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp.html>. 138 - #[no_mangle] 138 + #[unsafe(no_mangle)] 139 139 pub unsafe extern "C" fn strncasecmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int { 140 140 // SAFETY: the caller must ensure that s1 and s2 point to nul-terminated buffers. 141 141 let s1_iter = unsafe { NulTerminated::new(s1).unwrap() }.chain(once(&0)); ··· 147 147 148 148 // TODO: needs locale_t 149 149 // See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp.html>. 150 - // #[no_mangle] 150 + // #[unsafe(no_mangle)] 151 151 /*pub extern "C" fn strncasecmp_l(s1: *const c_char, s2: *const c_char, n: size_t, locale: locale_t) -> c_int { 152 152 unimplemented!(); 153 153 }*/
+1 -1
src/header/sys_auxv/mod.rs
··· 7 7 pub use crate::platform::auxv_defs::*; 8 8 9 9 /// See <https://www.man7.org/linux/man-pages/man3/getauxval.3.html>. 10 - #[no_mangle] 10 + #[unsafe(no_mangle)] 11 11 pub extern "C" fn getauxval(_t: c_ulong) -> c_ulong { 12 12 0 13 13 }
+6 -6
src/header/sys_epoll/mod.rs
··· 5 5 use crate::{ 6 6 error::ResultExt, 7 7 header::signal::sigset_t, 8 - platform::{types::*, PalEpoll, Sys}, 8 + platform::{PalEpoll, Sys, types::*}, 9 9 }; 10 10 11 11 pub use self::sys::*; ··· 58 58 pub data: epoll_data, 59 59 } 60 60 61 - #[no_mangle] 61 + #[unsafe(no_mangle)] 62 62 pub extern "C" fn epoll_create(_size: c_int) -> c_int { 63 63 epoll_create1(0) 64 64 } 65 65 66 - #[no_mangle] 66 + #[unsafe(no_mangle)] 67 67 pub extern "C" fn epoll_create1(flags: c_int) -> c_int { 68 68 trace_expr!( 69 69 Sys::epoll_create1(flags).or_minus_one_errno(), ··· 72 72 ) 73 73 } 74 74 75 - #[no_mangle] 75 + #[unsafe(no_mangle)] 76 76 pub unsafe extern "C" fn epoll_ctl( 77 77 epfd: c_int, 78 78 op: c_int, ··· 91 91 ) 92 92 } 93 93 94 - #[no_mangle] 94 + #[unsafe(no_mangle)] 95 95 pub unsafe extern "C" fn epoll_wait( 96 96 epfd: c_int, 97 97 events: *mut epoll_event, ··· 101 101 epoll_pwait(epfd, events, maxevents, timeout, ptr::null()) 102 102 } 103 103 104 - #[no_mangle] 104 + #[unsafe(no_mangle)] 105 105 pub unsafe extern "C" fn epoll_pwait( 106 106 epfd: c_int, 107 107 events: *mut epoll_event,
+2 -2
src/header/sys_file/mod.rs
··· 4 4 5 5 use crate::{ 6 6 error::ResultExt, 7 - platform::{types::*, Pal, Sys}, 7 + platform::{Pal, Sys, types::*}, 8 8 }; 9 9 10 10 pub const LOCK_SH: usize = 1; ··· 17 17 pub const L_XTND: usize = 2; 18 18 19 19 /// See <https://man7.org/linux/man-pages/man2/flock.2.html>. 20 - #[no_mangle] 20 + #[unsafe(no_mangle)] 21 21 pub extern "C" fn flock(fd: c_int, operation: c_int) -> c_int { 22 22 Sys::flock(fd, operation).map(|()| 0).or_minus_one_errno() 23 23 }
+2 -2
src/header/sys_ioctl/linux.rs
··· 1 1 use crate::{ 2 2 error::ResultExt, 3 - platform::{types::*, Sys}, 3 + platform::{Sys, types::*}, 4 4 }; 5 5 6 - #[no_mangle] 6 + #[unsafe(no_mangle)] 7 7 pub unsafe extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int { 8 8 // TODO: Somehow support varargs to syscall?? 9 9 Sys::ioctl(fd, request, out).or_minus_one_errno()
+2 -2
src/header/sys_ioctl/redox.rs
··· 8 8 errno::{self, EINVAL}, 9 9 fcntl, termios, 10 10 }, 11 - platform::{self, types::*, Pal, Sys}, 11 + platform::{self, Pal, Sys, types::*}, 12 12 }; 13 13 14 14 use super::winsize; ··· 132 132 Ok(0) 133 133 } 134 134 135 - #[no_mangle] 135 + #[unsafe(no_mangle)] 136 136 pub unsafe extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int { 137 137 ioctl_inner(fd, request, out).or_minus_one_errno() 138 138 }
+13 -13
src/header/sys_mman/mod.rs
··· 6 6 c_str::{CStr, CString}, 7 7 error::{Errno, ResultExt}, 8 8 header::{fcntl, unistd}, 9 - platform::{types::*, Pal, Sys, ERRNO}, 9 + platform::{ERRNO, Pal, Sys, types::*}, 10 10 }; 11 11 12 12 pub use self::sys::*; ··· 49 49 pub const POSIX_MADV_WONTNEED: c_int = 4; 50 50 51 51 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/madvise.2.html>. 52 - #[no_mangle] 52 + #[unsafe(no_mangle)] 53 53 pub unsafe extern "C" fn madvise(addr: *mut c_void, len: size_t, flags: c_int) -> c_int { 54 54 Sys::madvise(addr, len, flags) 55 55 .map(|()| 0) ··· 57 57 } 58 58 59 59 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlock.html>. 60 - #[no_mangle] 60 + #[unsafe(no_mangle)] 61 61 pub unsafe extern "C" fn mlock(addr: *const c_void, len: usize) -> c_int { 62 62 Sys::mlock(addr, len).map(|()| 0).or_minus_one_errno() 63 63 } 64 64 65 65 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlockall.html>. 66 - #[no_mangle] 66 + #[unsafe(no_mangle)] 67 67 pub unsafe extern "C" fn mlockall(flags: c_int) -> c_int { 68 68 Sys::mlockall(flags).map(|()| 0).or_minus_one_errno() 69 69 } 70 70 71 71 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mmap.html>. 72 - #[no_mangle] 72 + #[unsafe(no_mangle)] 73 73 pub unsafe extern "C" fn mmap( 74 74 addr: *mut c_void, 75 75 len: size_t, ··· 88 88 } 89 89 90 90 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mprotect.html>. 91 - #[no_mangle] 91 + #[unsafe(no_mangle)] 92 92 pub unsafe extern "C" fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int { 93 93 Sys::mprotect(addr, len, prot) 94 94 .map(|()| 0) ··· 96 96 } 97 97 98 98 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/mremap.2.html>. 99 - #[no_mangle] 99 + #[unsafe(no_mangle)] 100 100 pub unsafe extern "C" fn mremap( 101 101 old_address: *mut c_void, 102 102 old_size: usize, ··· 115 115 } 116 116 117 117 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/msync.html>. 118 - #[no_mangle] 118 + #[unsafe(no_mangle)] 119 119 pub unsafe extern "C" fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int { 120 120 Sys::msync(addr, len, flags) 121 121 .map(|()| 0) ··· 123 123 } 124 124 125 125 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlock.html>. 126 - #[no_mangle] 126 + #[unsafe(no_mangle)] 127 127 pub unsafe extern "C" fn munlock(addr: *const c_void, len: usize) -> c_int { 128 128 Sys::munlock(addr, len).map(|()| 0).or_minus_one_errno() 129 129 } 130 130 131 131 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlockall.html>. 132 - #[no_mangle] 132 + #[unsafe(no_mangle)] 133 133 pub unsafe extern "C" fn munlockall() -> c_int { 134 134 Sys::munlockall().map(|()| 0).or_minus_one_errno() 135 135 } 136 136 137 137 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/munmap.html>. 138 - #[no_mangle] 138 + #[unsafe(no_mangle)] 139 139 pub unsafe extern "C" fn munmap(addr: *mut c_void, len: size_t) -> c_int { 140 140 Sys::munmap(addr, len).map(|()| 0).or_minus_one_errno() 141 141 } ··· 167 167 } 168 168 169 169 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/shm_open.html>. 170 - #[no_mangle] 170 + #[unsafe(no_mangle)] 171 171 pub unsafe extern "C" fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t) -> c_int { 172 172 let path = shm_path(name); 173 173 fcntl::open(path.as_ptr(), oflag, mode) 174 174 } 175 175 176 176 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/shm_unlink.html>. 177 - #[no_mangle] 177 + #[unsafe(no_mangle)] 178 178 pub unsafe extern "C" fn shm_unlink(name: *const c_char) -> c_int { 179 179 let path = shm_path(name); 180 180 unistd::unlink(path.as_ptr())
+1 -1
src/header/sys_procfs/mod.rs
··· 63 63 pub type prstatus_t = elf_prstatus; 64 64 pub type prpsinfo_t = elf_prpsinfo; 65 65 66 - #[no_mangle] 66 + #[unsafe(no_mangle)] 67 67 pub extern "C" fn _cbindgen_export_procfs( 68 68 a: psaddr_t, 69 69 b: prgregset_t,
+2 -2
src/header/sys_ptrace/mod.rs
··· 2 2 3 3 use crate::{ 4 4 error::ResultExt, 5 - platform::{types::*, PalPtrace, Sys}, 5 + platform::{PalPtrace, Sys, types::*}, 6 6 }; 7 7 use core::ffi::VaList; 8 8 ··· 25 25 pub const PTRACE_SYSEMU_SINGLESTEP: c_int = 32; 26 26 27 27 // Can't use "params: ..." syntax, because... guess what? Cbingen again :( 28 - #[no_mangle] 28 + #[unsafe(no_mangle)] 29 29 pub unsafe extern "C" fn ptrace(request: c_int, mut __valist: ...) -> c_int { 30 30 // Musl also just grabs the arguments from the varargs... 31 31 Sys::ptrace(request, __valist.arg(), __valist.arg(), __valist.arg()).or_minus_one_errno()
+2 -2
src/header/sys_random/mod.rs
··· 6 6 7 7 use crate::{ 8 8 error::ResultExt, 9 - platform::{types::*, Pal, Sys}, 9 + platform::{Pal, Sys, types::*}, 10 10 }; 11 11 12 12 /// See <https://www.man7.org/linux/man-pages/man2/getrandom.2.html>. ··· 15 15 pub const GRND_RANDOM: c_uint = 2; 16 16 17 17 /// See <https://www.man7.org/linux/man-pages/man2/getrandom.2.html>. 18 - #[no_mangle] 18 + #[unsafe(no_mangle)] 19 19 pub unsafe extern "C" fn getrandom(buf: *mut c_void, buflen: size_t, flags: c_uint) -> ssize_t { 20 20 Sys::getrandom( 21 21 slice::from_raw_parts_mut(buf as *mut u8, buflen as usize),
+6 -6
src/header/sys_resource/mod.rs
··· 5 5 error::ResultExt, 6 6 header::sys_time::timeval, 7 7 out::Out, 8 - platform::{types::*, Pal, Sys}, 8 + platform::{Pal, Sys, types::*}, 9 9 }; 10 10 11 11 // Exported in bits file ··· 67 67 pub const PRIO_PGRP: c_int = 1; 68 68 pub const PRIO_USER: c_int = 2; 69 69 70 - #[no_mangle] 70 + #[unsafe(no_mangle)] 71 71 pub unsafe extern "C" fn getpriority(which: c_int, who: id_t) -> c_int { 72 72 let r = Sys::getpriority(which, who).or_minus_one_errno(); 73 73 if r < 0 { ··· 76 76 20 - r 77 77 } 78 78 79 - #[no_mangle] 79 + #[unsafe(no_mangle)] 80 80 pub unsafe extern "C" fn setpriority(which: c_int, who: id_t, nice: c_int) -> c_int { 81 81 Sys::setpriority(which, who, nice) 82 82 .map(|()| 0) 83 83 .or_minus_one_errno() 84 84 } 85 85 86 - #[no_mangle] 86 + #[unsafe(no_mangle)] 87 87 pub unsafe extern "C" fn getrlimit(resource: c_int, rlp: *mut rlimit) -> c_int { 88 88 let rlp = Out::nonnull(rlp); 89 89 ··· 92 92 .or_minus_one_errno() 93 93 } 94 94 95 - #[no_mangle] 95 + #[unsafe(no_mangle)] 96 96 pub unsafe extern "C" fn setrlimit(resource: c_int, rlp: *const rlimit) -> c_int { 97 97 Sys::setrlimit(resource, rlp) 98 98 .map(|()| 0) 99 99 .or_minus_one_errno() 100 100 } 101 101 102 - #[no_mangle] 102 + #[unsafe(no_mangle)] 103 103 pub unsafe extern "C" fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int { 104 104 Sys::getrusage(who, Out::nonnull(r_usage)) 105 105 .map(|()| 0)
+3 -3
src/header/sys_select/mod.rs
··· 9 9 header::{ 10 10 errno, 11 11 sys_epoll::{ 12 - epoll_create1, epoll_ctl, epoll_data, epoll_event, epoll_wait, EPOLLERR, EPOLLIN, 13 - EPOLLOUT, EPOLL_CLOEXEC, EPOLL_CTL_ADD, 12 + EPOLL_CLOEXEC, EPOLL_CTL_ADD, EPOLLERR, EPOLLIN, EPOLLOUT, epoll_create1, epoll_ctl, 13 + epoll_data, epoll_event, epoll_wait, 14 14 }, 15 15 sys_time::timeval, 16 16 }, ··· 161 161 count 162 162 } 163 163 164 - #[no_mangle] 164 + #[unsafe(no_mangle)] 165 165 pub unsafe extern "C" fn select( 166 166 nfds: c_int, 167 167 readfds: *mut fd_set,
+26 -26
src/header/sys_socket/mod.rs
··· 5 5 use crate::{ 6 6 error::ResultExt, 7 7 header::sys_uio::iovec, 8 - platform::{types::*, PalSocket, Sys}, 8 + platform::{PalSocket, Sys, types::*}, 9 9 }; 10 10 11 11 pub mod constants; ··· 20 20 pub l_linger: c_int, 21 21 } 22 22 23 - #[no_mangle] 23 + #[unsafe(no_mangle)] 24 24 pub extern "C" fn _cbindgen_export_linger(linger: linger) {} 25 25 26 26 #[repr(C)] ··· 51 51 pub gid: gid_t, 52 52 } 53 53 54 - #[no_mangle] 54 + #[unsafe(no_mangle)] 55 55 pub extern "C" fn _cbindgen_export_cmsghdr(cmsghdr: cmsghdr) {} 56 56 57 57 #[repr(C)] ··· 95 95 unsafe { ((*mhdr).msg_control as *mut c_uchar).offset((*mhdr).msg_controllen as isize) } 96 96 } 97 97 98 - #[no_mangle] 98 + #[unsafe(no_mangle)] 99 99 pub unsafe extern "C" fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { 100 100 unsafe { (cmsg as *mut c_uchar).offset(CMSG_ALIGN(mem::size_of::<cmsghdr>()) as isize) } 101 101 } 102 102 103 - #[no_mangle] 103 + #[unsafe(no_mangle)] 104 104 pub unsafe extern "C" fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { 105 105 if cmsg.is_null() { 106 106 return CMSG_FIRSTHDR(mhdr); ··· 119 119 } 120 120 } 121 121 122 - #[no_mangle] 122 + #[unsafe(no_mangle)] 123 123 pub unsafe extern "C" fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { 124 124 unsafe { 125 125 if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() { ··· 130 130 } 131 131 } 132 132 133 - #[no_mangle] 133 + #[unsafe(no_mangle)] 134 134 pub unsafe extern "C" fn CMSG_ALIGN(len: size_t) -> size_t { 135 135 (len + mem::size_of::<size_t>() - 1) & !(mem::size_of::<size_t>() - 1) 136 136 } 137 137 138 - #[no_mangle] 138 + #[unsafe(no_mangle)] 139 139 pub unsafe extern "C" fn CMSG_SPACE(len: c_uint) -> c_uint { 140 140 (CMSG_ALIGN(len as size_t) + CMSG_ALIGN(mem::size_of::<cmsghdr>())) as c_uint 141 141 } 142 142 143 - #[no_mangle] 143 + #[unsafe(no_mangle)] 144 144 pub unsafe extern "C" fn CMSG_LEN(length: c_uint) -> c_uint { 145 145 (CMSG_ALIGN(mem::size_of::<cmsghdr>()) + length as usize) as c_uint 146 146 } 147 147 // } These must match C macros in include/bits/sys/socket.h 148 148 149 - #[no_mangle] 149 + #[unsafe(no_mangle)] 150 150 pub unsafe extern "C" fn accept( 151 151 socket: c_int, 152 152 address: *mut sockaddr, ··· 161 161 ) 162 162 } 163 163 164 - #[no_mangle] 164 + #[unsafe(no_mangle)] 165 165 pub unsafe extern "C" fn bind( 166 166 socket: c_int, 167 167 address: *const sockaddr, ··· 178 178 ) 179 179 } 180 180 181 - #[no_mangle] 181 + #[unsafe(no_mangle)] 182 182 pub unsafe extern "C" fn connect( 183 183 socket: c_int, 184 184 address: *const sockaddr, ··· 193 193 ) 194 194 } 195 195 196 - #[no_mangle] 196 + #[unsafe(no_mangle)] 197 197 pub unsafe extern "C" fn getpeername( 198 198 socket: c_int, 199 199 address: *mut sockaddr, ··· 210 210 ) 211 211 } 212 212 213 - #[no_mangle] 213 + #[unsafe(no_mangle)] 214 214 pub unsafe extern "C" fn getsockname( 215 215 socket: c_int, 216 216 address: *mut sockaddr, ··· 227 227 ) 228 228 } 229 229 230 - #[no_mangle] 230 + #[unsafe(no_mangle)] 231 231 pub unsafe extern "C" fn getsockopt( 232 232 socket: c_int, 233 233 level: c_int, ··· 248 248 ) 249 249 } 250 250 251 - #[no_mangle] 251 + #[unsafe(no_mangle)] 252 252 pub unsafe extern "C" fn listen(socket: c_int, backlog: c_int) -> c_int { 253 253 Sys::listen(socket, backlog) 254 254 .map(|()| 0) 255 255 .or_minus_one_errno() 256 256 } 257 257 258 - #[no_mangle] 258 + #[unsafe(no_mangle)] 259 259 pub unsafe extern "C" fn recv( 260 260 socket: c_int, 261 261 buffer: *mut c_void, ··· 272 272 ) 273 273 } 274 274 275 - #[no_mangle] 275 + #[unsafe(no_mangle)] 276 276 pub unsafe extern "C" fn recvfrom( 277 277 socket: c_int, 278 278 buffer: *mut c_void, ··· 295 295 ) 296 296 } 297 297 298 - #[no_mangle] 298 + #[unsafe(no_mangle)] 299 299 pub unsafe extern "C" fn recvmsg(socket: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t { 300 300 Sys::recvmsg(socket, msg, flags) 301 301 .map(|r| r as ssize_t) 302 302 .or_minus_one_errno() 303 303 } 304 304 305 - #[no_mangle] 305 + #[unsafe(no_mangle)] 306 306 pub unsafe extern "C" fn send( 307 307 socket: c_int, 308 308 message: *const c_void, ··· 312 312 sendto(socket, message, length, flags, ptr::null(), 0) 313 313 } 314 314 315 - #[no_mangle] 315 + #[unsafe(no_mangle)] 316 316 pub unsafe extern "C" fn sendmsg(socket: c_int, msg: *const msghdr, flags: c_int) -> ssize_t { 317 317 Sys::sendmsg(socket, msg, flags) 318 318 .map(|w| w as ssize_t) 319 319 .or_minus_one_errno() 320 320 } 321 321 322 - #[no_mangle] 322 + #[unsafe(no_mangle)] 323 323 pub unsafe extern "C" fn sendto( 324 324 socket: c_int, 325 325 message: *const c_void, ··· 342 342 ) 343 343 } 344 344 345 - #[no_mangle] 345 + #[unsafe(no_mangle)] 346 346 pub unsafe extern "C" fn setsockopt( 347 347 socket: c_int, 348 348 level: c_int, ··· 363 363 ) 364 364 } 365 365 366 - #[no_mangle] 366 + #[unsafe(no_mangle)] 367 367 pub unsafe extern "C" fn shutdown(socket: c_int, how: c_int) -> c_int { 368 368 Sys::shutdown(socket, how).map(|()| 0).or_minus_one_errno() 369 369 } 370 370 371 - #[no_mangle] 371 + #[unsafe(no_mangle)] 372 372 pub unsafe extern "C" fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { 373 373 trace_expr!( 374 374 Sys::socket(domain, kind, protocol).or_minus_one_errno(), ··· 379 379 ) 380 380 } 381 381 382 - #[no_mangle] 382 + #[unsafe(no_mangle)] 383 383 pub unsafe extern "C" fn socketpair( 384 384 domain: c_int, 385 385 kind: c_int,
+15 -15
src/header/sys_stat/mod.rs
··· 8 8 time::timespec, 9 9 }, 10 10 out::Out, 11 - platform::{types::*, Pal, Sys}, 11 + platform::{Pal, Sys, types::*}, 12 12 }; 13 13 14 14 pub const S_IFMT: c_int = 0o0_170_000; ··· 71 71 pub _pad: [c_char; 24], 72 72 } 73 73 74 - #[no_mangle] 74 + #[unsafe(no_mangle)] 75 75 pub unsafe extern "C" fn chmod(path: *const c_char, mode: mode_t) -> c_int { 76 76 let path = CStr::from_ptr(path); 77 77 Sys::chmod(path, mode).map(|()| 0).or_minus_one_errno() 78 78 } 79 79 80 - #[no_mangle] 80 + #[unsafe(no_mangle)] 81 81 pub extern "C" fn fchmod(fildes: c_int, mode: mode_t) -> c_int { 82 82 Sys::fchmod(fildes, mode).map(|()| 0).or_minus_one_errno() 83 83 } 84 84 85 - #[no_mangle] 85 + #[unsafe(no_mangle)] 86 86 pub unsafe extern "C" fn fchmodat( 87 87 dirfd: c_int, 88 88 path: *const c_char, ··· 95 95 .or_minus_one_errno() 96 96 } 97 97 98 - #[no_mangle] 98 + #[unsafe(no_mangle)] 99 99 pub unsafe extern "C" fn fstat(fildes: c_int, buf: *mut stat) -> c_int { 100 100 let buf = Out::nonnull(buf); 101 101 Sys::fstat(fildes, buf).map(|()| 0).or_minus_one_errno() 102 102 } 103 103 104 - #[no_mangle] 104 + #[unsafe(no_mangle)] 105 105 pub unsafe extern "C" fn fstatat( 106 106 fildes: c_int, 107 107 path: *const c_char, ··· 115 115 .or_minus_one_errno() 116 116 } 117 117 118 - #[no_mangle] 118 + #[unsafe(no_mangle)] 119 119 pub unsafe extern "C" fn __fxstat(_ver: c_int, fildes: c_int, buf: *mut stat) -> c_int { 120 120 fstat(fildes, buf) 121 121 } 122 122 123 - #[no_mangle] 123 + #[unsafe(no_mangle)] 124 124 pub unsafe extern "C" fn futimens(fd: c_int, times: *const timespec) -> c_int { 125 125 Sys::futimens(fd, times).map(|()| 0).or_minus_one_errno() 126 126 } 127 127 128 - #[no_mangle] 128 + #[unsafe(no_mangle)] 129 129 pub unsafe extern "C" fn lstat(path: *const c_char, buf: *mut stat) -> c_int { 130 130 let path = CStr::from_ptr(path); 131 131 let buf = Out::nonnull(buf); ··· 144 144 res 145 145 } 146 146 147 - #[no_mangle] 147 + #[unsafe(no_mangle)] 148 148 pub unsafe extern "C" fn mkdir(path: *const c_char, mode: mode_t) -> c_int { 149 149 let path = CStr::from_ptr(path); 150 150 Sys::mkdir(path, mode).map(|()| 0).or_minus_one_errno() 151 151 } 152 152 153 - #[no_mangle] 153 + #[unsafe(no_mangle)] 154 154 pub unsafe extern "C" fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { 155 155 let path = CStr::from_ptr(path); 156 156 Sys::mkfifo(path, mode).map(|()| 0).or_minus_one_errno() 157 157 } 158 158 159 - #[no_mangle] 159 + #[unsafe(no_mangle)] 160 160 pub unsafe extern "C" fn mknod(path: *const c_char, mode: mode_t, dev: dev_t) -> c_int { 161 161 let path = CStr::from_ptr(path); 162 162 Sys::mknod(path, mode, dev).map(|()| 0).or_minus_one_errno() 163 163 } 164 164 165 - #[no_mangle] 165 + #[unsafe(no_mangle)] 166 166 pub unsafe extern "C" fn mknodat( 167 167 dirfd: c_int, 168 168 path: *const c_char, ··· 175 175 .or_minus_one_errno() 176 176 } 177 177 178 - #[no_mangle] 178 + #[unsafe(no_mangle)] 179 179 pub unsafe extern "C" fn stat(file: *const c_char, buf: *mut stat) -> c_int { 180 180 let file = CStr::from_ptr(file); 181 181 let buf = Out::nonnull(buf); ··· 194 194 res 195 195 } 196 196 197 - #[no_mangle] 197 + #[unsafe(no_mangle)] 198 198 pub extern "C" fn umask(mask: mode_t) -> mode_t { 199 199 Sys::umask(mask) 200 200 }
+3 -3
src/header/sys_statvfs/mod.rs
··· 5 5 error::ResultExt, 6 6 header::fcntl::O_PATH, 7 7 out::Out, 8 - platform::{types::*, Pal, Sys}, 8 + platform::{Pal, Sys, types::*}, 9 9 }; 10 10 11 11 //pub const ST_RDONLY ··· 27 27 pub f_namemax: c_ulong, 28 28 } 29 29 30 - #[no_mangle] 30 + #[unsafe(no_mangle)] 31 31 pub unsafe extern "C" fn fstatvfs(fildes: c_int, buf: *mut statvfs) -> c_int { 32 32 let buf = Out::nonnull(buf); 33 33 Sys::fstatvfs(fildes, buf).map(|()| 0).or_minus_one_errno() 34 34 } 35 35 36 - #[no_mangle] 36 + #[unsafe(no_mangle)] 37 37 pub unsafe extern "C" fn statvfs(file: *const c_char, buf: *mut statvfs) -> c_int { 38 38 let file = CStr::from_ptr(file); 39 39 let buf = Out::nonnull(buf);
+4 -4
src/header/sys_syslog/logger.rs
··· 18 18 sync::Mutex, 19 19 }; 20 20 21 - use bitflags::{bitflags, Flags}; 21 + use bitflags::{Flags, bitflags}; 22 22 use chrono::{DateTime, Utc}; 23 23 24 24 use super::{ 25 - sys::LogFile, LOG_ALERT, LOG_AUTH, LOG_AUTHPRIV, LOG_CONS, LOG_CRIT, LOG_CRON, LOG_DAEMON, 26 - LOG_DEBUG, LOG_EMERG, LOG_ERR, LOG_FTP, LOG_INFO, LOG_KERN, LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, 25 + LOG_ALERT, LOG_AUTH, LOG_AUTHPRIV, LOG_CONS, LOG_CRIT, LOG_CRON, LOG_DAEMON, LOG_DEBUG, 26 + LOG_EMERG, LOG_ERR, LOG_FTP, LOG_INFO, LOG_KERN, LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, 27 27 LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7, LOG_LPR, LOG_MAIL, LOG_MASK, 28 28 LOG_NDELAY, LOG_NEWS, LOG_NOTICE, LOG_NOWAIT, LOG_ODELAY, LOG_PERROR, LOG_PID, LOG_SYSLOG, 29 - LOG_UPTO, LOG_USER, LOG_UUCP, LOG_WARNING, 29 + LOG_UPTO, LOG_USER, LOG_UUCP, LOG_WARNING, sys::LogFile, 30 30 }; 31 31 32 32 pub(super) static LOGGER: Mutex<LogParams<LogFile>> = Mutex::new(LogParams::new(None));
+8 -8
src/header/sys_syslog/mod.rs
··· 14 14 use core::ffi::VaList; 15 15 16 16 use crate::{c_str::CStr, platform::types::*}; 17 - use logger::{Priority, LOGGER}; 17 + use logger::{LOGGER, Priority}; 18 18 19 19 /// Record the caller's PID in log messages. 20 20 pub const LOG_PID: c_int = 0x01; ··· 63 63 pub const LOG_DEBUG: c_int = 7; 64 64 65 65 /// Create a mask that includes all levels up to a certain priority. 66 - #[no_mangle] 66 + #[unsafe(no_mangle)] 67 67 pub const extern "C" fn LOG_UPTO(p: c_int) -> c_int { 68 68 (1 << (p + 1)) - 1 69 69 } 70 70 71 71 /// Create a mask that enables a single priority. 72 - #[no_mangle] 72 + #[unsafe(no_mangle)] 73 73 pub const extern "C" fn LOG_MASK(p: c_int) -> c_int { 74 74 1 << p 75 75 } 76 76 77 - #[no_mangle] 77 + #[unsafe(no_mangle)] 78 78 pub extern "C" fn setlogmask(mask: c_int) -> c_int { 79 79 let mut params = LOGGER.lock(); 80 80 let old = params.mask.bits(); ··· 86 86 old 87 87 } 88 88 89 - #[no_mangle] 89 + #[unsafe(no_mangle)] 90 90 pub unsafe extern "C" fn openlog(ident: *const c_char, opt: c_int, facility: c_int) { 91 91 let ident = unsafe { CStr::from_nullable_ptr(ident) }; 92 92 let conf = logger::Config::from_bits_truncate(opt); ··· 107 107 } 108 108 } 109 109 110 - #[no_mangle] 110 + #[unsafe(no_mangle)] 111 111 pub unsafe extern "C" fn vsyslog(priority: c_int, message: *const c_char, mut ap: VaList) { 112 112 let Some(message) = CStr::from_nullable_ptr(message) else { 113 113 return; ··· 122 122 } 123 123 } 124 124 125 - #[no_mangle] 125 + #[unsafe(no_mangle)] 126 126 pub unsafe extern "C" fn syslog(priority: c_int, message: *const c_char, mut __valist: ...) { 127 127 vsyslog(priority, message, __valist.as_va_list()); 128 128 } 129 129 130 - #[no_mangle] 130 + #[unsafe(no_mangle)] 131 131 pub extern "C" fn closelog() { 132 132 LOGGER.lock().close(); 133 133 }
+5 -5
src/header/sys_time/mod.rs
··· 7 7 error::ResultExt, 8 8 header::time::timespec, 9 9 out::Out, 10 - platform::{types::*, Pal, PalSignal, Sys}, 10 + platform::{Pal, PalSignal, Sys, types::*}, 11 11 }; 12 12 use core::ptr::null; 13 13 ··· 80 80 /// The `getitimer()` function was marked obsolescent in the Open Group Base 81 81 /// Specifications Issue 7, and removed in Issue 8. 82 82 #[deprecated] 83 - #[no_mangle] 83 + #[unsafe(no_mangle)] 84 84 pub unsafe extern "C" fn getitimer(which: c_int, value: *mut itimerval) -> c_int { 85 85 Sys::getitimer(which, &mut *value) 86 86 .map(|()| 0) ··· 96 96 /// The `gettimeofday()` function was marked obsolescent in the Open Group Base 97 97 /// Specifications Issue 7, and removed in Issue 8. 98 98 #[deprecated] 99 - #[no_mangle] 99 + #[unsafe(no_mangle)] 100 100 pub unsafe extern "C" fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int { 101 101 Sys::gettimeofday(Out::nonnull(tp), Out::nullable(tzp)) 102 102 .map(|()| 0) ··· 111 111 /// The `setitimer()` function was marked obsolescent in the Open Group Base 112 112 /// Specifications Issue 7, and removed in Issue 8. 113 113 #[deprecated] 114 - #[no_mangle] 114 + #[unsafe(no_mangle)] 115 115 pub unsafe extern "C" fn setitimer( 116 116 which: c_int, 117 117 value: *const itimerval, ··· 128 128 /// # Deprecation 129 129 /// The `utimes()` function was marked legacy in the Open Group Base 130 130 /// Specifications Issue 6, and then unmarked in Issue 7. 131 - #[no_mangle] 131 + #[unsafe(no_mangle)] 132 132 pub unsafe extern "C" fn utimes(path: *const c_char, times: *const timeval) -> c_int { 133 133 let path = CStr::from_ptr(path); 134 134 // Nullptr is valid here, it means "use current time"
+1 -1
src/header/sys_timeb/mod.rs
··· 32 32 /// # Safety 33 33 /// The caller must ensure that `tp` is convertible to a `&mut 34 34 /// MaybeUninit<timeb>`. 35 - #[no_mangle] 35 + #[unsafe(no_mangle)] 36 36 pub unsafe extern "C" fn ftime(tp: *mut timeb) -> c_int { 37 37 // SAFETY: the caller is required to ensure that the pointer is valid. 38 38 let tp_maybe_uninit = unsafe { NonNull::new_unchecked(tp).as_uninit_mut() };
+1 -1
src/header/sys_times/mod.rs
··· 12 12 tms_cstime: clock_t, 13 13 } 14 14 15 - #[no_mangle] 15 + #[unsafe(no_mangle)] 16 16 pub extern "C" fn times(out: *mut tms) -> clock_t { 17 17 Sys::times(out) 18 18 }
+4 -4
src/header/sys_uio/mod.rs
··· 40 40 } 41 41 } 42 42 43 - #[no_mangle] 43 + #[unsafe(no_mangle)] 44 44 pub unsafe extern "C" fn preadv( 45 45 fd: c_int, 46 46 iov: *const iovec, ··· 62 62 ret 63 63 } 64 64 65 - #[no_mangle] 65 + #[unsafe(no_mangle)] 66 66 pub unsafe extern "C" fn pwritev( 67 67 fd: c_int, 68 68 iov: *const iovec, ··· 80 80 unistd::pwrite(fd, vec.as_ptr() as *const c_void, vec.len(), offset) 81 81 } 82 82 83 - #[no_mangle] 83 + #[unsafe(no_mangle)] 84 84 pub unsafe extern "C" fn readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t { 85 85 if iovcnt < 0 || iovcnt > IOV_MAX { 86 86 platform::ERRNO.set(errno::EINVAL); ··· 97 97 ret 98 98 } 99 99 100 - #[no_mangle] 100 + #[unsafe(no_mangle)] 101 101 pub unsafe extern "C" fn writev(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t { 102 102 if iovcnt < 0 || iovcnt > IOV_MAX { 103 103 platform::ERRNO.set(errno::EINVAL);
+2 -2
src/header/sys_utsname/mod.rs
··· 2 2 3 3 use crate::{ 4 4 error::ResultExt, 5 - platform::{types::*, Pal, Sys}, 5 + platform::{Pal, Sys, types::*}, 6 6 }; 7 7 8 8 pub const UTSLENGTH: usize = 65; ··· 17 17 pub domainname: [c_char; UTSLENGTH], 18 18 } 19 19 20 - #[no_mangle] 20 + #[unsafe(no_mangle)] 21 21 pub unsafe extern "C" fn uname(uts: *mut utsname) -> c_int { 22 22 Sys::uname(uts).map(|()| 0).or_minus_one_errno() 23 23 }
+5 -5
src/header/sys_wait/mod.rs
··· 3 3 4 4 use crate::{error::ResultExt, out::Out}; 5 5 //use header::sys_resource::rusage; 6 - use crate::platform::{types::*, Pal, Sys}; 6 + use crate::platform::{Pal, Sys, types::*}; 7 7 8 8 pub const WNOHANG: c_int = 1; 9 9 pub const WUNTRACED: c_int = 2; ··· 18 18 #[allow(overflowing_literals)] 19 19 pub const __WCLONE: c_int = 0x8000_0000; 20 20 21 - #[no_mangle] 21 + #[unsafe(no_mangle)] 22 22 pub unsafe extern "C" fn wait(stat_loc: *mut c_int) -> pid_t { 23 23 waitpid(!0, stat_loc, 0) 24 24 } 25 25 26 - // #[no_mangle] 26 + // #[unsafe(no_mangle)] 27 27 // pub unsafe extern "C" fn wait3( 28 28 // stat_loc: *mut c_int, 29 29 // options: c_int, ··· 35 35 /* 36 36 * TODO: implement idtype_t, id_t, and siginfo_t 37 37 * 38 - * #[no_mangle] 38 + * #[unsafe(no_mangle)] 39 39 * pub unsafe extern "C" fn waitid( 40 40 * idtype: idtype_t, 41 41 * id: id_t, ··· 46 46 * } 47 47 */ 48 48 49 - #[no_mangle] 49 + #[unsafe(no_mangle)] 50 50 pub unsafe extern "C" fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t { 51 51 Sys::waitpid(pid, Out::nullable(stat_loc), options).or_minus_one_errno() 52 52 }
+17 -17
src/header/termios/mod.rs
··· 61 61 pub c_cc: [cc_t; NCCS], 62 62 } 63 63 64 - #[no_mangle] 64 + #[unsafe(no_mangle)] 65 65 pub unsafe extern "C" fn tcgetattr(fd: c_int, out: *mut termios) -> c_int { 66 66 sys_ioctl::ioctl(fd, sys_ioctl::TCGETS, out as *mut c_void) 67 67 } 68 68 69 - #[no_mangle] 69 + #[unsafe(no_mangle)] 70 70 pub unsafe extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *const termios) -> c_int { 71 71 if act < 0 || act > 2 { 72 72 platform::ERRNO.set(errno::EINVAL); ··· 77 77 } 78 78 79 79 #[cfg(target_os = "linux")] 80 - #[no_mangle] 80 + #[unsafe(no_mangle)] 81 81 pub unsafe extern "C" fn cfgetispeed(termios_p: *const termios) -> speed_t { 82 82 (*termios_p).__c_ispeed 83 83 } 84 84 85 85 #[cfg(target_os = "redox")] 86 - #[no_mangle] 86 + #[unsafe(no_mangle)] 87 87 pub unsafe extern "C" fn cfgetispeed(termios_p: *const termios) -> speed_t { 88 88 //TODO 89 89 0 90 90 } 91 91 92 92 #[cfg(target_os = "linux")] 93 - #[no_mangle] 93 + #[unsafe(no_mangle)] 94 94 pub unsafe extern "C" fn cfgetospeed(termios_p: *const termios) -> speed_t { 95 95 (*termios_p).__c_ospeed 96 96 } 97 97 98 98 #[cfg(target_os = "redox")] 99 - #[no_mangle] 99 + #[unsafe(no_mangle)] 100 100 pub unsafe extern "C" fn cfgetospeed(termios_p: *const termios) -> speed_t { 101 101 //TODO 102 102 0 103 103 } 104 104 105 105 #[cfg(target_os = "linux")] 106 - #[no_mangle] 106 + #[unsafe(no_mangle)] 107 107 pub unsafe extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) -> c_int { 108 108 match speed as usize { 109 109 B0..=B38400 | B57600..=B4000000 => { ··· 118 118 } 119 119 120 120 #[cfg(target_os = "redox")] 121 - #[no_mangle] 121 + #[unsafe(no_mangle)] 122 122 pub unsafe extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) -> c_int { 123 123 //TODO 124 124 platform::ERRNO.set(errno::EINVAL); ··· 126 126 } 127 127 128 128 #[cfg(target_os = "linux")] 129 - #[no_mangle] 129 + #[unsafe(no_mangle)] 130 130 pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) -> c_int { 131 131 match speed as usize { 132 132 B0..=B38400 | B57600..=B4000000 => { ··· 141 141 } 142 142 143 143 #[cfg(target_os = "redox")] 144 - #[no_mangle] 144 + #[unsafe(no_mangle)] 145 145 pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) -> c_int { 146 146 //TODO 147 147 platform::ERRNO.set(errno::EINVAL); 148 148 -1 149 149 } 150 150 151 - #[no_mangle] 151 + #[unsafe(no_mangle)] 152 152 pub unsafe extern "C" fn cfsetspeed(termios_p: *mut termios, speed: speed_t) -> c_int { 153 153 let r = cfsetispeed(termios_p, speed); 154 154 if r < 0 { ··· 157 157 cfsetospeed(termios_p, speed) 158 158 } 159 159 160 - #[no_mangle] 160 + #[unsafe(no_mangle)] 161 161 pub unsafe extern "C" fn tcflush(fd: c_int, queue: c_int) -> c_int { 162 162 sys_ioctl::ioctl(fd, sys_ioctl::TCFLSH, queue as *mut c_void) 163 163 } 164 164 165 - #[no_mangle] 165 + #[unsafe(no_mangle)] 166 166 pub unsafe extern "C" fn tcdrain(fd: c_int) -> c_int { 167 167 sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, 1 as *mut _) 168 168 } 169 169 170 - #[no_mangle] 170 + #[unsafe(no_mangle)] 171 171 pub unsafe extern "C" fn tcsendbreak(fd: c_int, _dur: c_int) -> c_int { 172 172 // non-zero duration is ignored by musl due to it being 173 173 // implementation-defined. we do the same. 174 174 sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, 0 as *mut _) 175 175 } 176 176 177 - #[no_mangle] 177 + #[unsafe(no_mangle)] 178 178 pub unsafe extern "C" fn tcsetwinsize(fd: c_int, mut sws: winsize) -> c_int { 179 179 sys_ioctl::ioctl(fd, sys_ioctl::TIOCSWINSZ, &mut sws as *mut _ as *mut c_void) 180 180 } 181 181 182 - #[no_mangle] 182 + #[unsafe(no_mangle)] 183 183 pub unsafe extern "C" fn tcflow(fd: c_int, action: c_int) -> c_int { 184 184 // non-zero duration is ignored by musl due to it being 185 185 // implementation-defined. we do the same. 186 186 sys_ioctl::ioctl(fd, sys_ioctl::TCXONC, action as *mut _) 187 187 } 188 188 189 - #[no_mangle] 189 + #[unsafe(no_mangle)] 190 190 pub unsafe extern "C" fn cfmakeraw(termios_p: *mut termios) { 191 191 (*termios_p).c_iflag &= 192 192 !(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) as u32;
+41 -45
src/header/time/mod.rs
··· 9 9 header::{errno::EOVERFLOW, fcntl::O_RDONLY, stdlib::getenv, unistd::readlink}, 10 10 io::Read, 11 11 out::Out, 12 - platform::{self, types::*, Pal, Sys}, 12 + platform::{self, Pal, Sys, types::*}, 13 13 sync::{Mutex, MutexGuard}, 14 14 }; 15 15 use alloc::{boxed::Box, collections::BTreeSet, string::String, vec::Vec}; 16 16 use chrono::{ 17 - format::ParseErrorKind, offset::MappedLocalTime, DateTime, Datelike, FixedOffset, NaiveDate, 18 - NaiveDateTime, Offset, ParseError, TimeZone, Timelike, Utc, 17 + DateTime, Datelike, FixedOffset, NaiveDate, NaiveDateTime, Offset, ParseError, TimeZone, 18 + Timelike, Utc, format::ParseErrorKind, offset::MappedLocalTime, 19 19 }; 20 20 use chrono_tz::{OffsetComponents, OffsetName, Tz}; 21 21 use core::{ ··· 113 113 114 114 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html>. 115 115 #[allow(non_upper_case_globals)] 116 - #[no_mangle] 116 + #[unsafe(no_mangle)] 117 117 pub static mut daylight: c_int = 0; 118 118 119 119 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html>. 120 120 #[allow(non_upper_case_globals)] 121 - #[no_mangle] 121 + #[unsafe(no_mangle)] 122 122 pub static mut timezone: c_long = 0; 123 123 124 124 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html>. 125 125 #[allow(non_upper_case_globals)] 126 - #[no_mangle] 126 + #[unsafe(no_mangle)] 127 127 pub static mut tzname: TzName = TzName([ptr::null_mut(); 2]); 128 128 129 129 #[allow(non_upper_case_globals)] 130 - #[no_mangle] 130 + #[unsafe(no_mangle)] 131 131 pub static mut getdate_err: c_int = 0; 132 132 133 133 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html>. ··· 146 146 /// The `asctime()` function was marked obsolescent in the Open Group Base 147 147 /// Specifications Issue 7. 148 148 #[deprecated] 149 - #[no_mangle] 149 + #[unsafe(no_mangle)] 150 150 pub unsafe extern "C" fn asctime(timeptr: *const tm) -> *mut c_char { 151 - asctime_r(timeptr, ASCTIME.as_mut_ptr().cast()) 151 + asctime_r(timeptr, &raw mut ASCTIME as *mut _) 152 152 } 153 153 154 154 /// See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/asctime.html>. ··· 157 157 /// The `asctime_r()` was marked obsolescent in the Open Group Base 158 158 /// Specifications Issue 7, and removed in Issue 8. 159 159 #[deprecated] 160 - #[no_mangle] 160 + #[unsafe(no_mangle)] 161 161 pub unsafe extern "C" fn asctime_r(tm: *const tm, buf: *mut c_char) -> *mut c_char { 162 162 let tm_sec = (*tm).tm_sec; 163 163 let tm_min = (*tm).tm_min; ··· 235 235 } 236 236 237 237 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/clock.html>. 238 - #[no_mangle] 238 + #[unsafe(no_mangle)] 239 239 pub extern "C" fn clock() -> clock_t { 240 240 let mut ts = mem::MaybeUninit::<timespec>::uninit(); 241 241 ··· 253 253 } 254 254 255 255 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/clock_getcpuclockid.html>. 256 - // #[no_mangle] 256 + // #[unsafe(no_mangle)] 257 257 pub extern "C" fn clock_getcpuclockid(pid: pid_t, clock_id: *mut clockid_t) -> c_int { 258 258 unimplemented!(); 259 259 } 260 260 261 261 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/clock_getres.html>. 262 - #[no_mangle] 262 + #[unsafe(no_mangle)] 263 263 pub unsafe extern "C" fn clock_getres(clock_id: clockid_t, res: *mut timespec) -> c_int { 264 264 Sys::clock_getres(clock_id, Out::nullable(res)) 265 265 .map(|()| 0) ··· 267 267 } 268 268 269 269 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/clock_getres.html>. 270 - #[no_mangle] 270 + #[unsafe(no_mangle)] 271 271 pub unsafe extern "C" fn clock_gettime(clock_id: clockid_t, tp: *mut timespec) -> c_int { 272 272 Sys::clock_gettime(clock_id, Out::nonnull(tp)) 273 273 .map(|()| 0) ··· 275 275 } 276 276 277 277 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/clock_nanosleep.html>. 278 - // #[no_mangle] 278 + // #[unsafe(no_mangle)] 279 279 pub extern "C" fn clock_nanosleep( 280 280 clock_id: clockid_t, 281 281 flags: c_int, ··· 286 286 } 287 287 288 288 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/clock_getres.html>. 289 - #[no_mangle] 289 + #[unsafe(no_mangle)] 290 290 pub unsafe extern "C" fn clock_settime(clock_id: clockid_t, tp: *const timespec) -> c_int { 291 291 Sys::clock_settime(clock_id, tp) 292 292 .map(|()| 0) ··· 299 299 /// The `ctime()` function was marked obsolescent in the Open Group Base 300 300 /// Specifications Issue 7. 301 301 #[deprecated] 302 - #[no_mangle] 302 + #[unsafe(no_mangle)] 303 303 pub unsafe extern "C" fn ctime(clock: *const time_t) -> *mut c_char { 304 304 asctime(localtime(clock)) 305 305 } ··· 310 310 /// The `ctime_r()` function was marked obsolescent in the Open Group Base 311 311 /// Specifications Issue 7, and removed in Issue 8. 312 312 #[deprecated] 313 - #[no_mangle] 313 + #[unsafe(no_mangle)] 314 314 pub unsafe extern "C" fn ctime_r(clock: *const time_t, buf: *mut c_char) -> *mut c_char { 315 315 // Using MaybeUninit<tm> seems to cause a panic during the build process 316 316 let mut tm1 = blank_tm(); ··· 319 319 } 320 320 321 321 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/difftime.html>. 322 - #[no_mangle] 322 + #[unsafe(no_mangle)] 323 323 pub unsafe extern "C" fn difftime(time1: time_t, time0: time_t) -> c_double { 324 324 (time1 - time0) as _ 325 325 } 326 326 327 327 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getdate.html>. 328 - // #[no_mangle] 328 + // #[unsafe(no_mangle)] 329 329 pub unsafe extern "C" fn getdate(string: *const c_char) -> *const tm { 330 330 unimplemented!(); 331 331 } 332 332 333 333 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/gmtime.html>. 334 - #[no_mangle] 334 + #[unsafe(no_mangle)] 335 335 pub unsafe extern "C" fn gmtime(timer: *const time_t) -> *mut tm { 336 - gmtime_r(timer, &mut TM) 336 + gmtime_r(timer, &raw mut TM) 337 337 } 338 338 339 339 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/gmtime.html>. 340 - #[no_mangle] 340 + #[unsafe(no_mangle)] 341 341 pub unsafe extern "C" fn gmtime_r(clock: *const time_t, result: *mut tm) -> *mut tm { 342 342 let _ = get_localtime(*clock, result); 343 343 result 344 344 } 345 345 346 346 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/localtime.html>. 347 - #[no_mangle] 347 + #[unsafe(no_mangle)] 348 348 pub unsafe extern "C" fn localtime(clock: *const time_t) -> *mut tm { 349 - localtime_r(clock, &mut TM) 349 + localtime_r(clock, &raw mut TM) 350 350 } 351 351 352 352 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/localtime.html>. 353 - #[no_mangle] 353 + #[unsafe(no_mangle)] 354 354 pub unsafe extern "C" fn localtime_r(clock: *const time_t, t: *mut tm) -> *mut tm { 355 355 let mut lock = TIMEZONE_LOCK.lock(); 356 356 clear_timezone(&mut lock); ··· 361 361 } 362 362 363 363 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mktime.html>. 364 - #[no_mangle] 364 + #[unsafe(no_mangle)] 365 365 pub unsafe extern "C" fn mktime(timeptr: *mut tm) -> time_t { 366 366 let mut lock = TIMEZONE_LOCK.lock(); 367 367 clear_timezone(&mut lock); ··· 414 414 } 415 415 416 416 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/nanosleep.html>. 417 - #[no_mangle] 417 + #[unsafe(no_mangle)] 418 418 pub unsafe extern "C" fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int { 419 419 Sys::nanosleep(rqtp, rmtp).map(|()| 0).or_minus_one_errno() 420 420 } 421 421 422 422 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strftime.html>. 423 - #[no_mangle] 423 + #[unsafe(no_mangle)] 424 424 pub unsafe extern "C" fn strftime( 425 425 s: *mut c_char, 426 426 maxsize: size_t, ··· 432 432 format, 433 433 timeptr, 434 434 ); 435 - if ret < maxsize { 436 - ret 437 - } else { 438 - 0 439 - } 435 + if ret < maxsize { ret } else { 0 } 440 436 } 441 437 442 438 // See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strftime.html>. 443 439 // TODO: needs locale_t 444 - // #[no_mangle] 440 + // #[unsafe(no_mangle)] 445 441 /*pub extern "C" fn strftime_l(s: *mut char, maxsize: size_t, format: *const c_char, timeptr: *const tm, locale: locale_t) -> size_t { 446 442 unimplemented!(); 447 443 }*/ 448 444 449 445 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/time.html>. 450 - #[no_mangle] 446 + #[unsafe(no_mangle)] 451 447 pub unsafe extern "C" fn time(tloc: *mut time_t) -> time_t { 452 448 let mut ts = timespec::default(); 453 449 Sys::clock_gettime(CLOCK_REALTIME, Out::from_mut(&mut ts)); ··· 458 454 } 459 455 460 456 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/timegm.3.html>. 461 - #[no_mangle] 457 + #[unsafe(no_mangle)] 462 458 pub unsafe extern "C" fn timegm(tm: *mut tm) -> time_t { 463 459 let tm_val = &mut *tm; 464 460 let dt = match convert_tm_generic(&Utc, tm_val) { ··· 477 473 478 474 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/timegm.3.html>. 479 475 #[deprecated] 480 - #[no_mangle] 476 + #[unsafe(no_mangle)] 481 477 pub unsafe extern "C" fn timelocal(tm: *mut tm) -> time_t { 482 478 let tm_val = &mut *tm; 483 479 let tz = time_zone(); ··· 497 493 } 498 494 499 495 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/timer_create.html>. 500 - // #[no_mangle] 496 + // #[unsafe(no_mangle)] 501 497 pub extern "C" fn timer_create( 502 498 clock_id: clockid_t, 503 499 evp: *mut sigevent, ··· 507 503 } 508 504 509 505 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/timer_delete.html>. 510 - // #[no_mangle] 506 + // #[unsafe(no_mangle)] 511 507 pub extern "C" fn timer_delete(timerid: timer_t) -> c_int { 512 508 unimplemented!(); 513 509 } 514 510 515 511 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/timer_getoverrun.html>. 516 - // #[no_mangle] 512 + // #[unsafe(no_mangle)] 517 513 pub extern "C" fn timer_getoverrun(timerid: timer_t) -> c_int { 518 514 unimplemented!(); 519 515 } 520 516 521 517 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/timer_getoverrun.html>. 522 - // #[no_mangle] 518 + // #[unsafe(no_mangle)] 523 519 pub extern "C" fn timer_gettime(timerid: timer_t, value: *mut itimerspec) -> c_int { 524 520 unimplemented!(); 525 521 } 526 522 527 523 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/timer_getoverrun.html>. 528 - // #[no_mangle] 524 + // #[unsafe(no_mangle)] 529 525 pub extern "C" fn timer_settime( 530 526 timerid: timer_t, 531 527 flags: c_int, ··· 536 532 } 537 533 538 534 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/timespec_get.html>. 539 - // #[no_mangle] 535 + // #[unsafe(no_mangle)] 540 536 pub extern "C" fn timespec_get(ts: *mut timespec, base: c_int) -> c_int { 541 537 unimplemented!(); 542 538 } 543 539 544 540 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tzset.html>. 545 - #[no_mangle] 541 + #[unsafe(no_mangle)] 546 542 pub unsafe extern "C" fn tzset() { 547 543 let mut lock = TIMEZONE_LOCK.lock(); 548 544 unsafe { clear_timezone(&mut lock) };
+4 -8
src/header/time/strftime.rs
··· 5 5 use super::{get_offset, tm}; 6 6 use crate::{ 7 7 c_str::CStr, 8 - platform::{self, types::*, WriteByte}, 8 + platform::{self, WriteByte, types::*}, 9 9 }; 10 10 11 11 // We use the langinfo constants 12 12 use crate::header::langinfo::{ 13 - nl_item, 14 - nl_langinfo, 15 13 ABDAY_1, 16 14 ABMON_1, 17 15 AM_STR, ··· 19 17 MON_1, 20 18 PM_STR, 21 19 // TODO : other constants if needed 20 + nl_item, 21 + nl_langinfo, 22 22 }; 23 23 24 24 /// A helper that calls `nl_langinfo(item)` and converts the returned pointer ··· 271 271 fn weeks_per_year(year: c_int) -> c_int { 272 272 let year = year as f64; 273 273 let p_y = (year + (year / 4.) - (year / 100.) + (year / 400.)) as c_int % 7; 274 - if p_y == 4 { 275 - 53 276 - } else { 277 - 52 278 - } 274 + if p_y == 4 { 53 } else { 52 } 279 275 } 280 276 281 277 /// Calculate the week of the year accounting for leap weeks (ISO 8601)
+3 -7
src/header/time/strptime.rs
··· 6 6 }; 7 7 use alloc::{string::String, vec::Vec}; 8 8 use core::{ 9 - ffi::{c_char, c_int, c_void, CStr}, 9 + ffi::{CStr, c_char, c_int, c_void}, 10 10 mem::MaybeUninit, 11 11 ptr, 12 12 ptr::NonNull, ··· 43 43 ]; 44 44 45 45 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strptime.html>. 46 - #[no_mangle] 46 + #[unsafe(no_mangle)] 47 47 pub unsafe extern "C" fn strptime( 48 48 buf: *const c_char, 49 49 format: *const c_char, ··· 502 502 } 503 503 } 504 504 505 - if count == 0 { 506 - None 507 - } else { 508 - Some((val, count)) 509 - } 505 + if count == 0 { None } else { Some((val, count)) } 510 506 } 511 507 512 508 /// Handle AM/PM. Returns (is_pm, length_consumed).
+3 -3
src/header/unistd/brk.rs
··· 3 3 use crate::{ 4 4 error::ResultExtPtrMut, 5 5 header::errno::ENOMEM, 6 - platform::{self, types::*, Pal, Sys}, 6 + platform::{self, Pal, Sys, types::*}, 7 7 }; 8 8 9 9 static mut BRK: *mut c_void = ptr::null_mut(); ··· 14 14 /// The `brk()` function was marked legacy in the System Interface & Headers 15 15 /// Issue 5, and removed in Issue 6. 16 16 #[deprecated] 17 - #[no_mangle] 17 + #[unsafe(no_mangle)] 18 18 pub unsafe extern "C" fn brk(addr: *mut c_void) -> c_int { 19 19 BRK = Sys::brk(addr).or_errno_null_mut(); 20 20 ··· 32 32 /// The `sbrk()` function was marked legacy in the System Interface & Headers 33 33 /// Issue 5, and removed in Issue 6. 34 34 #[deprecated] 35 - #[no_mangle] 35 + #[unsafe(no_mangle)] 36 36 pub unsafe extern "C" fn sbrk(incr: intptr_t) -> *mut c_void { 37 37 if BRK.is_null() { 38 38 BRK = Sys::brk(ptr::null_mut()).or_errno_null_mut();
+5 -5
src/header/unistd/getopt.rs
··· 6 6 7 7 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>. 8 8 #[allow(non_upper_case_globals)] 9 - #[no_mangle] 9 + #[unsafe(no_mangle)] 10 10 #[linkage = "weak"] // often redefined in GNU programs 11 11 pub static mut optarg: *mut c_char = ptr::null_mut(); 12 12 13 13 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>. 14 14 #[allow(non_upper_case_globals)] 15 - #[no_mangle] 15 + #[unsafe(no_mangle)] 16 16 #[linkage = "weak"] // often redefined in GNU programs 17 17 pub static mut opterr: c_int = 1; 18 18 19 19 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>. 20 20 #[allow(non_upper_case_globals)] 21 - #[no_mangle] 21 + #[unsafe(no_mangle)] 22 22 #[linkage = "weak"] // often redefined in GNU programs 23 23 pub static mut optind: c_int = 1; 24 24 25 25 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>. 26 26 #[allow(non_upper_case_globals)] 27 - #[no_mangle] 27 + #[unsafe(no_mangle)] 28 28 #[linkage = "weak"] // often redefined in GNU programs 29 29 pub static mut optopt: c_int = -1; 30 30 31 31 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>. 32 - #[no_mangle] 32 + #[unsafe(no_mangle)] 33 33 #[linkage = "weak"] // often redefined in GNU programs 34 34 pub unsafe extern "C" fn getopt( 35 35 argc: c_int,
+6 -3
src/header/unistd/getpass.rs
··· 9 9 termios, 10 10 }, 11 11 io::{self, Read, Write}, 12 + raw_cell::RawCell, 12 13 }; 13 14 14 15 use crate::platform::types::*; ··· 66 67 /// The `getpass()` function was marked legacy in the Open Group System 67 68 /// Interface & Headers Issue 5, and removed in Issue 6. 68 69 #[deprecated] 69 - #[no_mangle] 70 + #[unsafe(no_mangle)] 70 71 pub unsafe extern "C" fn getpass(prompt: *const c_char) -> *mut c_char { 71 - static mut PASSBUFF: [u8; PASS_MAX] = [0; PASS_MAX]; 72 + static PASSBUFF: RawCell<[u8; PASS_MAX]> = RawCell::new([0; PASS_MAX]); 72 73 73 - unsafe { getpass_rs(CStr::from_ptr(prompt), &mut PASSBUFF).unwrap_or(ptr::null_mut()) } 74 + unsafe { 75 + getpass_rs(CStr::from_ptr(prompt), &mut *PASSBUFF.as_mut_ptr()).unwrap_or(ptr::null_mut()) 76 + } 74 77 }
+104 -102
src/header/unistd/mod.rs
··· 21 21 time::timespec, 22 22 }, 23 23 out::Out, 24 - platform::{self, types::*, Pal, Sys, ERRNO}, 24 + platform::{self, ERRNO, Pal, Sys, types::*}, 25 25 }; 26 26 27 27 pub use self::{brk::*, getopt::*, getpass::getpass, pathconf::*, sysconf::*}; ··· 107 107 108 108 // Re-exported from pthread.h. `pthread_atfork` should be in pthread.h according to the 109 109 // standard, but glibc exports it here as well. We ONLY exported it in unistd.h till recently. 110 - extern "C" { 111 - #[no_mangle] 110 + unsafe extern "C" { 111 + #[unsafe(no_mangle)] 112 112 pub fn pthread_atfork( 113 113 prepare: Option<extern "C" fn()>, 114 114 parent: Option<extern "C" fn()>, ··· 117 117 } 118 118 119 119 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fork.html>. 120 - // #[no_mangle] 120 + // #[unsafe(no_mangle)] 121 121 pub unsafe extern "C" fn _Fork() -> pid_t { 122 122 unimplemented!(); 123 123 } 124 124 125 125 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/_Exit.html>. 126 - #[no_mangle] 126 + #[unsafe(no_mangle)] 127 127 pub extern "C" fn _exit(status: c_int) -> ! { 128 128 Sys::exit(status) 129 129 } 130 130 131 131 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/access.html>. 132 - #[no_mangle] 132 + #[unsafe(no_mangle)] 133 133 pub unsafe extern "C" fn access(path: *const c_char, mode: c_int) -> c_int { 134 134 let path = CStr::from_ptr(path); 135 135 Sys::access(path, mode).map(|()| 0).or_minus_one_errno() 136 136 } 137 137 138 138 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/alarm.html>. 139 - #[no_mangle] 139 + #[unsafe(no_mangle)] 140 140 pub extern "C" fn alarm(seconds: c_uint) -> c_uint { 141 141 // TODO setitimer is unimplemented on Redox and obsolete 142 142 let mut timer = sys_time::itimerval { ··· 160 160 } 161 161 162 162 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/chdir.html>. 163 - #[no_mangle] 163 + #[unsafe(no_mangle)] 164 164 pub unsafe extern "C" fn chdir(path: *const c_char) -> c_int { 165 165 let path = CStr::from_ptr(path); 166 166 Sys::chdir(path).map(|()| 0).or_minus_one_errno() 167 167 } 168 168 169 169 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/chown.html>. 170 - #[no_mangle] 170 + #[unsafe(no_mangle)] 171 171 pub unsafe extern "C" fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { 172 172 let path = CStr::from_ptr(path); 173 173 Sys::chown(path, owner, group) ··· 181 181 /// The `chroot()` function was marked legacy in the System Interface & Headers 182 182 /// Issue 5, and removed in Issue 6. 183 183 #[deprecated] 184 - #[no_mangle] 184 + #[unsafe(no_mangle)] 185 185 pub unsafe extern "C" fn chroot(path: *const c_char) -> c_int { 186 186 // TODO: Implement 187 187 platform::ERRNO.set(crate::header::errno::EPERM); ··· 190 190 } 191 191 192 192 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/close.html>. 193 - #[no_mangle] 193 + #[unsafe(no_mangle)] 194 194 pub extern "C" fn close(fildes: c_int) -> c_int { 195 195 Sys::close(fildes).map(|()| 0).or_minus_one_errno() 196 196 } 197 197 198 198 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/confstr.html>. 199 - #[no_mangle] 199 + #[unsafe(no_mangle)] 200 200 pub extern "C" fn confstr(name: c_int, buf: *mut c_char, len: size_t) -> size_t { 201 201 // confstr returns the number of bytes required to hold the string INCLUDING the NUL 202 202 // terminator. This is different from other C functions hence the + 1. ··· 219 219 } 220 220 221 221 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/crypt.html>. 222 - #[no_mangle] 222 + #[unsafe(no_mangle)] 223 223 pub unsafe extern "C" fn crypt(key: *const c_char, salt: *const c_char) -> *mut c_char { 224 224 let mut data = crypt_data::new(); 225 225 crypt_r(key, salt, &mut data as *mut _) 226 226 } 227 227 228 228 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/daemon.3.html>. 229 - #[no_mangle] 229 + #[unsafe(no_mangle)] 230 230 pub extern "C" fn daemon(nochdir: c_int, noclose: c_int) -> c_int { 231 231 if nochdir == 0 { 232 232 if Sys::chdir(c"/".into()).map(|()| 0).or_minus_one_errno() < 0 { ··· 262 262 } 263 263 264 264 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/dup.html>. 265 - #[no_mangle] 265 + #[unsafe(no_mangle)] 266 266 pub extern "C" fn dup(fildes: c_int) -> c_int { 267 267 Sys::dup(fildes).or_minus_one_errno() 268 268 } 269 269 270 270 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/dup.html>. 271 - #[no_mangle] 271 + #[unsafe(no_mangle)] 272 272 pub extern "C" fn dup2(fildes: c_int, fildes2: c_int) -> c_int { 273 273 Sys::dup2(fildes, fildes2).or_minus_one_errno() 274 274 } 275 275 276 276 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/dup.html>. 277 - // #[no_mangle] 277 + // #[unsafe(no_mangle)] 278 278 pub extern "C" fn dup3(fildes: c_int, fildes2: c_int, flag: c_int) -> c_int { 279 279 unimplemented!(); 280 280 } ··· 284 284 /// # Deprecation 285 285 /// The `encrypt()` function was marked obsolescent in the Open Group Base Specifications Issue 8. 286 286 #[deprecated] 287 - // #[no_mangle] 287 + // #[unsafe(no_mangle)] 288 288 pub extern "C" fn encrypt(block: [c_char; 64], edflag: c_int) { 289 289 unimplemented!(); 290 290 } 291 291 292 292 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exec.html>. 293 - #[no_mangle] 293 + #[unsafe(no_mangle)] 294 294 pub unsafe extern "C" fn execl( 295 295 path: *const c_char, 296 296 arg0: *const c_char, ··· 302 302 } 303 303 304 304 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exec.html>. 305 - #[no_mangle] 305 + #[unsafe(no_mangle)] 306 306 pub unsafe extern "C" fn execle( 307 307 path: *const c_char, 308 308 arg0: *const c_char, ··· 315 315 } 316 316 317 317 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exec.html>. 318 - #[no_mangle] 318 + #[unsafe(no_mangle)] 319 319 pub unsafe extern "C" fn execlp( 320 320 file: *const c_char, 321 321 arg0: *const c_char, ··· 327 327 } 328 328 329 329 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exec.html>. 330 - #[no_mangle] 330 + #[unsafe(no_mangle)] 331 331 pub unsafe extern "C" fn execv(path: *const c_char, argv: *const *mut c_char) -> c_int { 332 332 execve(path, argv, platform::environ) 333 333 } 334 334 335 335 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exec.html>. 336 - #[no_mangle] 336 + #[unsafe(no_mangle)] 337 337 pub unsafe extern "C" fn execve( 338 338 path: *const c_char, 339 339 argv: *const *mut c_char, ··· 346 346 } 347 347 348 348 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exec.html>. 349 - #[no_mangle] 349 + #[unsafe(no_mangle)] 350 350 pub unsafe extern "C" fn fexecve( 351 351 fd: c_int, 352 352 argv: *const *mut c_char, ··· 360 360 const PATH_SEPARATOR: u8 = b':'; 361 361 362 362 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/exec.html>. 363 - #[no_mangle] 363 + #[unsafe(no_mangle)] 364 364 pub unsafe extern "C" fn execvp(file: *const c_char, argv: *const *mut c_char) -> c_int { 365 365 let file = CStr::from_ptr(file); 366 366 ··· 399 399 } 400 400 401 401 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fchdir.html>. 402 - #[no_mangle] 402 + #[unsafe(no_mangle)] 403 403 pub extern "C" fn fchdir(fildes: c_int) -> c_int { 404 404 Sys::fchdir(fildes).map(|()| 0).or_minus_one_errno() 405 405 } 406 406 407 407 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fchown.html>. 408 - #[no_mangle] 408 + #[unsafe(no_mangle)] 409 409 pub extern "C" fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int { 410 410 Sys::fchown(fildes, owner, group) 411 411 .map(|()| 0) ··· 413 413 } 414 414 415 415 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fdatasync.html>. 416 - #[no_mangle] 416 + #[unsafe(no_mangle)] 417 417 pub extern "C" fn fdatasync(fildes: c_int) -> c_int { 418 418 Sys::fdatasync(fildes).map(|()| 0).or_minus_one_errno() 419 419 } 420 420 421 421 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fork.html>. 422 - #[no_mangle] 422 + #[unsafe(no_mangle)] 423 423 pub unsafe extern "C" fn fork() -> pid_t { 424 424 for prepare in &fork_hooks[0] { 425 425 prepare(); ··· 438 438 } 439 439 440 440 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fsync.html>. 441 - #[no_mangle] 441 + #[unsafe(no_mangle)] 442 442 pub extern "C" fn fsync(fildes: c_int) -> c_int { 443 443 Sys::fsync(fildes).map(|()| 0).or_minus_one_errno() 444 444 } 445 445 446 446 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ftruncate.html>. 447 - #[no_mangle] 447 + #[unsafe(no_mangle)] 448 448 pub extern "C" fn ftruncate(fildes: c_int, length: off_t) -> c_int { 449 449 Sys::ftruncate(fildes, length) 450 450 .map(|()| 0) ··· 452 452 } 453 453 454 454 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getcwd.html>. 455 - #[no_mangle] 455 + #[unsafe(no_mangle)] 456 456 pub unsafe extern "C" fn getcwd(mut buf: *mut c_char, mut size: size_t) -> *mut c_char { 457 457 let alloc = buf.is_null(); 458 458 let mut stack_buf = [0; limits::PATH_MAX]; ··· 493 493 /// The `getdtablesize()` function was marked legacy in the System Interface & 494 494 /// Headers Issue 5, and removed in Issue 6. 495 495 #[deprecated] 496 - #[no_mangle] 496 + #[unsafe(no_mangle)] 497 497 pub extern "C" fn getdtablesize() -> c_int { 498 498 let mut lim = mem::MaybeUninit::<sys_resource::rlimit>::uninit(); 499 499 let r = unsafe { ··· 513 513 } 514 514 515 515 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getegid.html>. 516 - #[no_mangle] 516 + #[unsafe(no_mangle)] 517 517 pub extern "C" fn getegid() -> gid_t { 518 518 Sys::getegid() 519 519 } 520 520 521 521 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getentropy.html>. 522 - // #[no_mangle] 522 + // #[unsafe(no_mangle)] 523 523 pub extern "C" fn getentropy(buffer: *mut c_void, length: size_t) -> c_int { 524 524 unimplemented!(); 525 525 } 526 526 527 527 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/geteuid.html>. 528 - #[no_mangle] 528 + #[unsafe(no_mangle)] 529 529 pub extern "C" fn geteuid() -> uid_t { 530 530 Sys::geteuid() 531 531 } 532 532 533 533 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getgid.html>. 534 - #[no_mangle] 534 + #[unsafe(no_mangle)] 535 535 pub extern "C" fn getgid() -> gid_t { 536 536 Sys::getgid() 537 537 } 538 538 539 539 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getgroups.html>. 540 - #[no_mangle] 540 + #[unsafe(no_mangle)] 541 541 pub unsafe extern "C" fn getgroups(size: c_int, list: *mut gid_t) -> c_int { 542 542 (|| { 543 543 let size = usize::try_from(size) ··· 553 553 } 554 554 555 555 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/gethostid.html>. 556 - // #[no_mangle] 556 + // #[unsafe(no_mangle)] 557 557 pub extern "C" fn gethostid() -> c_long { 558 558 unimplemented!(); 559 559 } 560 560 561 561 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/gethostname.html>. 562 - #[no_mangle] 562 + #[unsafe(no_mangle)] 563 563 pub unsafe extern "C" fn gethostname(mut name: *mut c_char, mut len: size_t) -> c_int { 564 564 let mut uts = mem::MaybeUninit::<sys_utsname::utsname>::uninit(); 565 565 // TODO ··· 589 589 } 590 590 591 591 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getlogin.html>. 592 - #[no_mangle] 592 + #[unsafe(no_mangle)] 593 593 pub unsafe extern "C" fn getlogin() -> *mut c_char { 594 - static mut LOGIN: [c_char; 256] = [0; 256]; 595 - if getlogin_r(LOGIN.as_mut_ptr(), LOGIN.len()) == 0 { 596 - LOGIN.as_mut_ptr() 594 + const LOGIN_LEN: usize = 256; 595 + static mut LOGIN: [c_char; LOGIN_LEN] = [0; LOGIN_LEN]; 596 + if getlogin_r(&raw mut LOGIN as *mut _, LOGIN_LEN) == 0 { 597 + &raw mut LOGIN as *mut _ 597 598 } else { 598 599 ptr::null_mut() 599 600 } 600 601 } 601 602 602 603 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getlogin.html>. 603 - #[no_mangle] 604 + #[unsafe(no_mangle)] 604 605 pub extern "C" fn getlogin_r(name: *mut c_char, namesize: size_t) -> c_int { 605 606 //TODO: Determine correct getlogin result on Redox 606 607 platform::ERRNO.set(errno::ENOENT); ··· 613 614 /// The `getpagesize()` function was marked legacy in the System Interface & 614 615 /// Headers Issue 5, and removed in Issue 6. 615 616 #[deprecated] 616 - #[no_mangle] 617 + #[unsafe(no_mangle)] 617 618 pub extern "C" fn getpagesize() -> c_int { 618 619 // Panic if we can't uphold the required behavior (no errors are specified for this function) 619 620 Sys::getpagesize() ··· 622 623 } 623 624 624 625 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpgid.html>. 625 - #[no_mangle] 626 + #[unsafe(no_mangle)] 626 627 pub extern "C" fn getpgid(pid: pid_t) -> pid_t { 627 628 Sys::getpgid(pid).or_minus_one_errno() 628 629 } 629 630 630 631 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpgrp.html>. 631 - #[no_mangle] 632 + #[unsafe(no_mangle)] 632 633 pub extern "C" fn getpgrp() -> pid_t { 633 634 Sys::getpgid(Sys::getpid()).or_minus_one_errno() 634 635 } 635 636 636 637 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getpid.html>. 637 - #[no_mangle] 638 + #[unsafe(no_mangle)] 638 639 pub extern "C" fn getpid() -> pid_t { 639 640 Sys::getpid() 640 641 } 641 642 642 643 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getppid.html>. 643 - #[no_mangle] 644 + #[unsafe(no_mangle)] 644 645 pub extern "C" fn getppid() -> pid_t { 645 646 Sys::getppid() 646 647 } 647 648 648 649 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getresgid.html>. 649 - #[no_mangle] 650 + #[unsafe(no_mangle)] 650 651 pub unsafe extern "C" fn getresgid(rgid: *mut gid_t, egid: *mut gid_t, sgid: *mut gid_t) -> c_int { 651 652 Sys::getresgid( 652 653 Out::nullable(rgid), ··· 658 659 } 659 660 660 661 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getresuid.html>. 661 - #[no_mangle] 662 + #[unsafe(no_mangle)] 662 663 pub unsafe extern "C" fn getresuid(ruid: *mut uid_t, euid: *mut uid_t, suid: *mut uid_t) -> c_int { 663 664 Sys::getresuid( 664 665 Out::nullable(ruid), ··· 670 671 } 671 672 672 673 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getsid.html>. 673 - #[no_mangle] 674 + #[unsafe(no_mangle)] 674 675 pub extern "C" fn getsid(pid: pid_t) -> pid_t { 675 676 Sys::getsid(pid).or_minus_one_errno() 676 677 } 677 678 678 679 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getuid.html>. 679 - #[no_mangle] 680 + #[unsafe(no_mangle)] 680 681 pub extern "C" fn getuid() -> uid_t { 681 682 Sys::getuid() 682 683 } ··· 687 688 /// The `getwd()` function was marked legacy in the Open Group Base 688 689 /// Specifications Issue 6, and removed in Issue 7. 689 690 #[deprecated] 690 - #[no_mangle] 691 + #[unsafe(no_mangle)] 691 692 pub unsafe extern "C" fn getwd(path_name: *mut c_char) -> *mut c_char { 692 693 unsafe { getcwd(path_name, limits::PATH_MAX) } 693 694 } 694 695 695 696 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isatty.html>. 696 - #[no_mangle] 697 + #[unsafe(no_mangle)] 697 698 pub extern "C" fn isatty(fd: c_int) -> c_int { 698 699 let mut t = termios::termios::default(); 699 700 if unsafe { termios::tcgetattr(fd, &mut t as *mut termios::termios) == 0 } { ··· 704 705 } 705 706 706 707 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/lchown.html>. 707 - #[no_mangle] 708 + #[unsafe(no_mangle)] 708 709 pub unsafe extern "C" fn lchown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int { 709 710 let path = CStr::from_ptr(path); 710 711 Sys::lchown(path, owner, group) ··· 713 714 } 714 715 715 716 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/link.html>. 716 - #[no_mangle] 717 + #[unsafe(no_mangle)] 717 718 pub unsafe extern "C" fn link(path1: *const c_char, path2: *const c_char) -> c_int { 718 719 let path1 = CStr::from_ptr(path1); 719 720 let path2 = CStr::from_ptr(path2); ··· 721 722 } 722 723 723 724 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/lockf.html>. 724 - #[no_mangle] 725 + #[unsafe(no_mangle)] 725 726 pub unsafe extern "C" fn lockf(fildes: c_int, function: c_int, size: off_t) -> c_int { 726 727 let mut fl = fcntl::flock { 727 728 l_type: fcntl::F_WRLCK as c_short, ··· 761 762 } 762 763 763 764 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/lseek.html>. 764 - #[no_mangle] 765 + #[unsafe(no_mangle)] 765 766 pub extern "C" fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t { 766 767 Sys::lseek(fildes, offset, whence).or_minus_one_errno() 767 768 } 768 769 769 770 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/nice.html>. 770 - // #[no_mangle] 771 + // #[unsafe(no_mangle)] 771 772 pub extern "C" fn nice(incr: c_int) -> c_int { 772 773 unimplemented!(); 773 774 } 774 775 775 776 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pause.html>. 776 - // #[no_mangle] 777 + // #[unsafe(no_mangle)] 777 778 pub extern "C" fn pause() -> c_int { 778 779 unimplemented!(); 779 780 } 780 781 781 782 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pipe.html>. 782 - #[no_mangle] 783 + #[unsafe(no_mangle)] 783 784 pub unsafe extern "C" fn pipe(fildes: *mut c_int) -> c_int { 784 785 pipe2(fildes, 0) 785 786 } 786 787 787 788 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pipe.html>. 788 - #[no_mangle] 789 + #[unsafe(no_mangle)] 789 790 pub unsafe extern "C" fn pipe2(fildes: *mut c_int, flags: c_int) -> c_int { 790 791 Sys::pipe2(Out::nonnull(fildes.cast::<[c_int; 2]>()), flags) 791 792 .map(|()| 0) ··· 793 794 } 794 795 795 796 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/close.html>. 796 - // #[no_mangle] 797 + // #[unsafe(no_mangle)] 797 798 pub extern "C" fn posix_close(fildes: c_int, flag: c_int) -> c_int { 798 799 unimplemented!(); 799 800 } 800 801 801 802 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/read.html>. 802 - #[no_mangle] 803 + #[unsafe(no_mangle)] 803 804 pub unsafe extern "C" fn pread( 804 805 fildes: c_int, 805 806 buf: *mut c_void, ··· 816 817 } 817 818 818 819 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/write.html>. 819 - #[no_mangle] 820 + #[unsafe(no_mangle)] 820 821 pub unsafe extern "C" fn pwrite( 821 822 fildes: c_int, 822 823 buf: *const c_void, ··· 833 834 } 834 835 835 836 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/read.html>. 836 - #[no_mangle] 837 + #[unsafe(no_mangle)] 837 838 pub unsafe extern "C" fn read(fildes: c_int, buf: *const c_void, nbyte: size_t) -> ssize_t { 838 839 let buf = unsafe { slice::from_raw_parts_mut(buf as *mut u8, nbyte as usize) }; 839 840 trace_expr!( ··· 848 849 } 849 850 850 851 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/readlink.html>. 851 - #[no_mangle] 852 + #[unsafe(no_mangle)] 852 853 pub unsafe extern "C" fn readlink( 853 854 path: *const c_char, 854 855 buf: *mut c_char, ··· 862 863 } 863 864 864 865 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/readlink.html>. 865 - #[no_mangle] 866 + #[unsafe(no_mangle)] 866 867 pub unsafe extern "C" fn readlinkat( 867 868 dirfd: c_int, 868 869 pathname: *const c_char, ··· 881 882 } 882 883 883 884 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rmdir.html>. 884 - #[no_mangle] 885 + #[unsafe(no_mangle)] 885 886 pub unsafe extern "C" fn rmdir(path: *const c_char) -> c_int { 886 887 let path = CStr::from_ptr(path); 887 888 Sys::rmdir(path).map(|()| 0).or_minus_one_errno() 888 889 } 889 890 890 - #[no_mangle] 891 + #[unsafe(no_mangle)] 891 892 pub unsafe extern "C" fn set_default_scheme(scheme: *const c_char) -> c_int { 892 893 let scheme = CStr::from_ptr(scheme); 893 894 Sys::set_default_scheme(scheme) ··· 896 897 } 897 898 898 899 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setegid.html>. 899 - #[no_mangle] 900 + #[unsafe(no_mangle)] 900 901 pub extern "C" fn setegid(gid: gid_t) -> c_int { 901 902 Sys::setresgid(-1, gid, -1).map(|()| 0).or_minus_one_errno() 902 903 } 903 904 904 905 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/seteuid.html>. 905 - #[no_mangle] 906 + #[unsafe(no_mangle)] 906 907 pub extern "C" fn seteuid(uid: uid_t) -> c_int { 907 908 Sys::setresuid(-1, uid, -1).map(|()| 0).or_minus_one_errno() 908 909 } 909 910 910 911 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setgid.html>. 911 - #[no_mangle] 912 + #[unsafe(no_mangle)] 912 913 pub extern "C" fn setgid(gid: gid_t) -> c_int { 913 914 Sys::setresgid(gid, gid, -1) 914 915 .map(|()| 0) ··· 918 919 /// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/setgroups.2.html>. 919 920 /// 920 921 /// TODO: specified in `grp.h`? 921 - #[no_mangle] 922 + #[unsafe(no_mangle)] 922 923 pub unsafe extern "C" fn setgroups(size: size_t, list: *const gid_t) -> c_int { 923 924 Sys::setgroups(size, list).map(|()| 0).or_minus_one_errno() 924 925 } 925 926 926 927 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setpgid.html>. 927 - #[no_mangle] 928 + #[unsafe(no_mangle)] 928 929 pub extern "C" fn setpgid(pid: pid_t, pgid: pid_t) -> c_int { 929 930 Sys::setpgid(pid, pgid).map(|()| 0).or_minus_one_errno() 930 931 } ··· 935 936 /// The `setpgrp()` function was marked obsolescent in the Open Group Base 936 937 /// Specifications Issue 7, and removed in Issue 8. 937 938 #[deprecated] 938 - #[no_mangle] 939 + #[unsafe(no_mangle)] 939 940 pub extern "C" fn setpgrp() -> pid_t { 940 941 setpgid(0, 0) 941 942 } 942 943 943 944 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setregid.html>. 944 - #[no_mangle] 945 + #[unsafe(no_mangle)] 945 946 pub extern "C" fn setregid(rgid: gid_t, egid: gid_t) -> c_int { 946 947 Sys::setresgid(rgid, egid, -1) 947 948 .map(|()| 0) ··· 949 950 } 950 951 951 952 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setresgid.html>. 952 - #[no_mangle] 953 + #[unsafe(no_mangle)] 953 954 pub extern "C" fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) -> c_int { 954 955 Sys::setresgid(rgid, egid, sgid) 955 956 .map(|()| 0) ··· 957 958 } 958 959 959 960 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setresuid.html>. 960 - #[no_mangle] 961 + #[unsafe(no_mangle)] 961 962 pub extern "C" fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) -> c_int { 962 963 Sys::setresuid(ruid, euid, suid) 963 964 .map(|()| 0) ··· 965 966 } 966 967 967 968 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setreuid.html>. 968 - #[no_mangle] 969 + #[unsafe(no_mangle)] 969 970 pub extern "C" fn setreuid(ruid: uid_t, euid: uid_t) -> c_int { 970 971 Sys::setresuid(ruid, euid, -1) 971 972 .map(|()| 0) ··· 973 974 } 974 975 975 976 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setsid.html>. 976 - #[no_mangle] 977 + #[unsafe(no_mangle)] 977 978 pub extern "C" fn setsid() -> pid_t { 978 979 Sys::setsid().or_minus_one_errno() 979 980 } 980 981 981 982 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setuid.html>. 982 - #[no_mangle] 983 + #[unsafe(no_mangle)] 983 984 pub extern "C" fn setuid(uid: uid_t) -> c_int { 984 985 Sys::setresuid(uid, uid, -1) 985 986 .map(|()| 0) ··· 987 988 } 988 989 989 990 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sleep.html>. 990 - #[no_mangle] 991 + #[unsafe(no_mangle)] 991 992 pub extern "C" fn sleep(seconds: c_uint) -> c_uint { 992 993 let rqtp = timespec { 993 994 tv_sec: seconds as time_t, ··· 1008 1009 } 1009 1010 1010 1011 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/swab.html>. 1011 - #[no_mangle] 1012 + #[unsafe(no_mangle)] 1012 1013 pub extern "C" fn swab(src: *const c_void, dest: *mut c_void, nbytes: ssize_t) { 1013 1014 if nbytes <= 0 { 1014 1015 return; ··· 1025 1026 } 1026 1027 1027 1028 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/symlink.html>. 1028 - #[no_mangle] 1029 + #[unsafe(no_mangle)] 1029 1030 pub unsafe extern "C" fn symlink(path1: *const c_char, path2: *const c_char) -> c_int { 1030 1031 let path1 = CStr::from_ptr(path1); 1031 1032 let path2 = CStr::from_ptr(path2); ··· 1033 1034 } 1034 1035 1035 1036 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sync.html>. 1036 - #[no_mangle] 1037 + #[unsafe(no_mangle)] 1037 1038 pub extern "C" fn sync() { 1038 1039 Sys::sync(); 1039 1040 } 1040 1041 1041 1042 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcgetpgrp.html>. 1042 - #[no_mangle] 1043 + #[unsafe(no_mangle)] 1043 1044 pub extern "C" fn tcgetpgrp(fd: c_int) -> pid_t { 1044 1045 let mut pgrp = 0; 1045 1046 if unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TIOCGPGRP, &mut pgrp as *mut pid_t as _) } < 0 { ··· 1049 1050 } 1050 1051 1051 1052 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcsetpgrp.html>. 1052 - #[no_mangle] 1053 + #[unsafe(no_mangle)] 1053 1054 pub extern "C" fn tcsetpgrp(fd: c_int, pgrp: pid_t) -> c_int { 1054 1055 if unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TIOCSPGRP, &pgrp as *const pid_t as _) } < 0 { 1055 1056 return -1; ··· 1058 1059 } 1059 1060 1060 1061 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/truncate.html>. 1061 - #[no_mangle] 1062 + #[unsafe(no_mangle)] 1062 1063 pub unsafe extern "C" fn truncate(path: *const c_char, length: off_t) -> c_int { 1063 1064 let file = unsafe { CStr::from_ptr(path) }; 1064 1065 // TODO: Rustify ··· 1075 1076 } 1076 1077 1077 1078 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ttyname.html>. 1078 - #[no_mangle] 1079 + #[unsafe(no_mangle)] 1079 1080 pub unsafe extern "C" fn ttyname(fildes: c_int) -> *mut c_char { 1080 - static mut TTYNAME: [c_char; 4096] = [0; 4096]; 1081 - if ttyname_r(fildes, TTYNAME.as_mut_ptr(), TTYNAME.len()) == 0 { 1082 - TTYNAME.as_mut_ptr() 1081 + const TTYNAME_LEN: usize = 4096; 1082 + static mut TTYNAME: [c_char; TTYNAME_LEN] = [0; TTYNAME_LEN]; 1083 + if ttyname_r(fildes, &raw mut TTYNAME as *mut _, TTYNAME_LEN) == 0 { 1084 + &raw mut TTYNAME as *mut _ 1083 1085 } else { 1084 1086 ptr::null_mut() 1085 1087 } 1086 1088 } 1087 1089 1088 1090 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/ttyname.html>. 1089 - #[no_mangle] 1091 + #[unsafe(no_mangle)] 1090 1092 pub extern "C" fn ttyname_r(fildes: c_int, name: *mut c_char, namesize: size_t) -> c_int { 1091 1093 let name = unsafe { slice::from_raw_parts_mut(name as *mut u8, namesize) }; 1092 1094 if name.is_empty() { ··· 1110 1112 /// The `ualarm()` function was marked obsolescent in the Open Group Base 1111 1113 /// Specifications Issue 6, and removed in Issue 7. 1112 1114 #[deprecated] 1113 - #[no_mangle] 1115 + #[unsafe(no_mangle)] 1114 1116 pub extern "C" fn ualarm(usecs: useconds_t, interval: useconds_t) -> useconds_t { 1115 1117 // TODO setitimer is unimplemented on Redox and obsolete 1116 1118 let mut timer = sys_time::itimerval { ··· 1135 1137 } 1136 1138 1137 1139 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/unlink.html>. 1138 - #[no_mangle] 1140 + #[unsafe(no_mangle)] 1139 1141 pub unsafe extern "C" fn unlink(path: *const c_char) -> c_int { 1140 1142 let path = CStr::from_ptr(path); 1141 1143 Sys::unlink(path).map(|()| 0).or_minus_one_errno() ··· 1147 1149 /// The `usleep()` function was marked obsolescent in the Open Group Base 1148 1150 /// Specifications Issue 6, and removed in Issue 7. 1149 1151 #[deprecated] 1150 - #[no_mangle] 1152 + #[unsafe(no_mangle)] 1151 1153 pub extern "C" fn usleep(useconds: useconds_t) -> c_int { 1152 1154 let rqtp = timespec { 1153 1155 tv_sec: (useconds / 1_000_000) as time_t, ··· 1165 1167 /// The `vfork()` function was marked obsolescent in the Open Group Base 1166 1168 /// Specifications Issue 6, and removed in Issue 7. 1167 1169 #[deprecated] 1168 - // #[no_mangle] 1170 + // #[unsafe(no_mangle)] 1169 1171 pub extern "C" fn vfork() -> pid_t { 1170 1172 unimplemented!(); 1171 1173 } ··· 1206 1208 // NULL 1207 1209 va.arg::<*const c_char>(); 1208 1210 1209 - f(MaybeUninit::slice_assume_init_ref(&*out), va); 1211 + f((&*out).assume_init_ref(), va); 1210 1212 1211 1213 // f only returns if it fails 1212 1214 if argc >= 32 { ··· 1216 1218 } 1217 1219 1218 1220 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/write.html>. 1219 - #[no_mangle] 1221 + #[unsafe(no_mangle)] 1220 1222 pub unsafe extern "C" fn write(fildes: c_int, buf: *const c_void, nbyte: size_t) -> ssize_t { 1221 1223 let buf = slice::from_raw_parts(buf as *const u8, nbyte as usize); 1222 1224 Sys::write(fildes, buf)
+2 -2
src/header/unistd/pathconf.rs
··· 58 58 } 59 59 60 60 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fpathconf.html>. 61 - #[no_mangle] 61 + #[unsafe(no_mangle)] 62 62 pub extern "C" fn fpathconf(_fildes: c_int, name: c_int) -> c_long { 63 63 pc(name) 64 64 } 65 65 66 66 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fpathconf.html>. 67 - #[no_mangle] 67 + #[unsafe(no_mangle)] 68 68 pub extern "C" fn pathconf(_path: *const c_char, name: c_int) -> c_long { 69 69 pc(name) 70 70 }
+1 -1
src/header/unistd/sysconf.rs
··· 12 12 13 13 use core::ffi::{c_int, c_long}; 14 14 15 - #[no_mangle] 15 + #[unsafe(no_mangle)] 16 16 pub unsafe extern "C" fn sysconf(name: c_int) -> c_long { 17 17 sysconf_impl(name) 18 18 }
+1 -1
src/header/unistd/sysconf/redox.rs
··· 7 7 fs::File, 8 8 header::{errno, fcntl, limits}, 9 9 io::Read, 10 - platform::{self, types::*, Pal, Sys}, 10 + platform::{self, Pal, Sys, types::*}, 11 11 }; 12 12 13 13 // POSIX.1 {
+2 -2
src/header/utime/mod.rs
··· 12 12 c_str::CStr, 13 13 error::ResultExt, 14 14 header::time::timespec, 15 - platform::{types::*, Pal, Sys}, 15 + platform::{Pal, Sys, types::*}, 16 16 }; 17 17 18 18 /// See <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/utime.h.html>. ··· 26 26 27 27 /// See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/utime.html>. 28 28 #[deprecated] 29 - #[no_mangle] 29 + #[unsafe(no_mangle)] 30 30 pub unsafe extern "C" fn utime(filename: *const c_char, times: *const utimbuf) -> c_int { 31 31 let filename_cstr = unsafe { CStr::from_ptr(filename) }; 32 32 let times_ref = unsafe { &*times };
+1 -1
src/header/utmp/mod.rs
··· 8 8 }; 9 9 10 10 /// See <https://www.man7.org/linux/man-pages/man3/openpty.3.html>. 11 - #[no_mangle] 11 + #[unsafe(no_mangle)] 12 12 pub unsafe extern "C" fn login_tty(fd: c_int) -> c_int { 13 13 // Create a new session 14 14 unistd::setsid();
+3 -3
src/header/wchar/lookaheadreader.rs
··· 1 - use super::{fseek_locked, ftell_locked, FILE, SEEK_SET}; 1 + use super::{FILE, SEEK_SET, fseek_locked, ftell_locked}; 2 2 use crate::{ 3 3 header::{ 4 4 errno::EILSEQ, 5 - wchar::{fgetwc, get_char_encoded_length, mbrtowc, MB_CUR_MAX}, 5 + wchar::{MB_CUR_MAX, fgetwc, get_char_encoded_length, mbrtowc}, 6 6 wctype::WEOF, 7 7 }, 8 8 io::Read, 9 9 platform::{ 10 - types::{c_char, off_t, wchar_t, wint_t}, 11 10 ERRNO, 11 + types::{c_char, off_t, wchar_t, wint_t}, 12 12 }, 13 13 }; 14 14 use core::ptr;
+77 -85
src/header/wchar/mod.rs
··· 7 7 ctype::isspace, 8 8 errno::{EILSEQ, ENOMEM, ERANGE}, 9 9 stdio::*, 10 - stdlib::{malloc, MB_CUR_MAX, MB_LEN_MAX}, 10 + stdlib::{MB_CUR_MAX, MB_LEN_MAX, malloc}, 11 11 string, 12 12 time::*, 13 13 wchar::{lookaheadreader::LookAheadReader, utf8::get_char_encoded_length}, 14 14 wctype::*, 15 15 }, 16 16 iter::{NulTerminated, NulTerminatedInclusive}, 17 - platform::{self, types::*, ERRNO}, 17 + platform::{self, ERRNO, types::*}, 18 18 }; 19 19 20 20 mod lookaheadreader; ··· 26 26 #[derive(Clone, Copy)] 27 27 pub struct mbstate_t; 28 28 29 - #[no_mangle] 29 + #[unsafe(no_mangle)] 30 30 pub unsafe extern "C" fn btowc(c: c_int) -> wint_t { 31 31 //Check for EOF 32 32 if c == EOF { ··· 46 46 wc as wint_t 47 47 } 48 48 49 - #[no_mangle] 49 + #[unsafe(no_mangle)] 50 50 pub unsafe extern "C" fn fgetwc(stream: *mut FILE) -> wint_t { 51 51 // TODO: Process locale 52 52 let mut buf: [c_uchar; MB_CUR_MAX as usize] = [0; MB_CUR_MAX as usize]; ··· 93 93 wc as wint_t 94 94 } 95 95 96 - #[no_mangle] 96 + #[unsafe(no_mangle)] 97 97 pub unsafe extern "C" fn fgetws(ws: *mut wchar_t, n: c_int, stream: *mut FILE) -> *mut wchar_t { 98 98 //TODO: lock 99 99 let mut i = 0; ··· 112 112 ws 113 113 } 114 114 115 - #[no_mangle] 115 + #[unsafe(no_mangle)] 116 116 pub unsafe extern "C" fn fputwc(wc: wchar_t, stream: *mut FILE) -> wint_t { 117 117 //Convert wchar_t to multibytes first 118 118 static mut INTERNAL: mbstate_t = mbstate_t; 119 119 let mut bytes: [c_char; MB_CUR_MAX as usize] = [0; MB_CUR_MAX as usize]; 120 120 121 - let amount = wcrtomb(bytes.as_mut_ptr(), wc, &mut INTERNAL); 121 + let amount = wcrtomb(bytes.as_mut_ptr(), wc, &raw mut INTERNAL); 122 122 123 123 for i in 0..amount { 124 124 fputc(bytes[i] as c_int, &mut *stream); ··· 127 127 wc as wint_t 128 128 } 129 129 130 - #[no_mangle] 130 + #[unsafe(no_mangle)] 131 131 pub unsafe extern "C" fn fputws(ws: *const wchar_t, stream: *mut FILE) -> c_int { 132 132 let mut i = 0; 133 133 loop { ··· 142 142 } 143 143 } 144 144 145 - #[no_mangle] 145 + #[unsafe(no_mangle)] 146 146 pub unsafe extern "C" fn fwide(stream: *mut FILE, mode: c_int) -> c_int { 147 147 (*stream).try_set_orientation(mode) 148 148 } 149 149 150 - #[no_mangle] 150 + #[unsafe(no_mangle)] 151 151 pub unsafe extern "C" fn getwc(stream: *mut FILE) -> wint_t { 152 152 fgetwc(stream) 153 153 } 154 154 155 - #[no_mangle] 155 + #[unsafe(no_mangle)] 156 156 pub unsafe extern "C" fn getwchar() -> wint_t { 157 157 fgetwc(stdin) 158 158 } 159 159 160 - #[no_mangle] 160 + #[unsafe(no_mangle)] 161 161 pub unsafe extern "C" fn mbsinit(ps: *const mbstate_t) -> c_int { 162 162 //Add a check for the state maybe 163 - if ps.is_null() { 164 - 1 165 - } else { 166 - 0 167 - } 163 + if ps.is_null() { 1 } else { 0 } 168 164 } 169 165 170 - #[no_mangle] 166 + #[unsafe(no_mangle)] 171 167 pub unsafe extern "C" fn mbrlen(s: *const c_char, n: size_t, ps: *mut mbstate_t) -> size_t { 172 168 static mut INTERNAL: mbstate_t = mbstate_t; 173 - mbrtowc(ptr::null_mut(), s, n, &mut INTERNAL) 169 + mbrtowc(ptr::null_mut(), s, n, &raw mut INTERNAL) 174 170 } 175 171 176 172 //Only works for UTF8 at the moment 177 - #[no_mangle] 173 + #[unsafe(no_mangle)] 178 174 pub unsafe extern "C" fn mbrtowc( 179 175 pwc: *mut wchar_t, 180 176 s: *const c_char, ··· 184 180 static mut INTERNAL: mbstate_t = mbstate_t; 185 181 186 182 if ps.is_null() { 187 - let ps = &mut INTERNAL; 183 + let ps = &raw mut INTERNAL; 188 184 } 189 185 if s.is_null() { 190 186 let xs: [c_char; 1] = [0]; ··· 196 192 197 193 //Convert a multibyte string to a wide string with a limited amount of bytes 198 194 //Required for in POSIX.1-2008 199 - #[no_mangle] 195 + #[unsafe(no_mangle)] 200 196 pub unsafe extern "C" fn mbsnrtowcs( 201 197 dst_ptr: *mut wchar_t, 202 198 src_ptr: *mut *const c_char, ··· 207 203 static mut INTERNAL: mbstate_t = mbstate_t; 208 204 209 205 if ps.is_null() { 210 - let ps = &mut INTERNAL; 206 + let ps = &raw mut INTERNAL; 211 207 } 212 208 213 209 let mut src = *src_ptr; ··· 255 251 } 256 252 257 253 //Convert a multibyte string to a wide string 258 - #[no_mangle] 254 + #[unsafe(no_mangle)] 259 255 pub unsafe extern "C" fn mbsrtowcs( 260 256 dst: *mut wchar_t, 261 257 src: *mut *const c_char, ··· 265 261 mbsnrtowcs(dst, src, size_t::max_value(), len, ps) 266 262 } 267 263 268 - #[no_mangle] 264 + #[unsafe(no_mangle)] 269 265 pub unsafe extern "C" fn putwc(wc: wchar_t, stream: *mut FILE) -> wint_t { 270 266 fputwc(wc, &mut *stream) 271 267 } 272 268 273 - #[no_mangle] 269 + #[unsafe(no_mangle)] 274 270 pub unsafe extern "C" fn putwchar(wc: wchar_t) -> wint_t { 275 271 fputwc(wc, &mut *stdout) 276 272 } 277 273 278 - #[no_mangle] 274 + #[unsafe(no_mangle)] 279 275 pub unsafe extern "C" fn vswscanf( 280 276 s: *const wchar_t, 281 277 format: *const wchar_t, ··· 285 281 wscanf::scanf(reader, format, __valist) 286 282 } 287 283 288 - #[no_mangle] 284 + #[unsafe(no_mangle)] 289 285 pub unsafe extern "C" fn swscanf( 290 286 s: *const wchar_t, 291 287 format: *const wchar_t, ··· 295 291 } 296 292 297 293 /// Push wide character `wc` back onto `stream` so it'll be read next 298 - #[no_mangle] 294 + #[unsafe(no_mangle)] 299 295 pub unsafe extern "C" fn ungetwc(wc: wint_t, stream: &mut FILE) -> wint_t { 300 296 if wc == WEOF { 301 297 return wc; ··· 303 299 static mut INTERNAL: mbstate_t = mbstate_t; 304 300 let mut bytes: [c_char; MB_CUR_MAX as usize] = [0; MB_CUR_MAX as usize]; 305 301 306 - let amount = wcrtomb(bytes.as_mut_ptr(), wc as wchar_t, &mut INTERNAL); 302 + let amount = wcrtomb(bytes.as_mut_ptr(), wc as wchar_t, &raw mut INTERNAL); 307 303 if amount == usize::MAX { 308 304 return WEOF; 309 305 } ··· 321 317 wc 322 318 } 323 319 324 - #[no_mangle] 320 + #[unsafe(no_mangle)] 325 321 pub unsafe extern "C" fn vfwprintf( 326 322 stream: *mut FILE, 327 323 format: *const wchar_t, ··· 334 330 335 331 wprintf::wprintf(&mut *stream, format, arg) 336 332 } 337 - #[no_mangle] 333 + #[unsafe(no_mangle)] 338 334 pub unsafe extern "C" fn fwprintf( 339 335 stream: *mut FILE, 340 336 format: *const wchar_t, ··· 343 339 vfwprintf(stream, format, __valist.as_va_list()) 344 340 } 345 341 346 - #[no_mangle] 342 + #[unsafe(no_mangle)] 347 343 pub unsafe extern "C" fn vwprintf(format: *const wchar_t, arg: va_list) -> c_int { 348 344 vfwprintf(&mut *stdout, format, arg) 349 345 } 350 - #[no_mangle] 346 + #[unsafe(no_mangle)] 351 347 pub unsafe extern "C" fn wprintf(format: *const wchar_t, mut __valist: ...) -> c_int { 352 348 vfwprintf(&mut *stdout, format, __valist.as_va_list()) 353 349 } 354 350 355 - #[no_mangle] 351 + #[unsafe(no_mangle)] 356 352 pub unsafe extern "C" fn vswprintf( 357 353 s: *mut wchar_t, 358 354 n: size_t, ··· 364 360 eprintln!("vswprintf not implemented"); 365 361 -1 366 362 } 367 - #[no_mangle] 363 + #[unsafe(no_mangle)] 368 364 pub unsafe extern "C" fn swprintf( 369 365 s: *mut wchar_t, 370 366 n: size_t, ··· 374 370 vswprintf(s, n, format, __valist.as_va_list()) 375 371 } 376 372 377 - #[no_mangle] 373 + #[unsafe(no_mangle)] 378 374 pub unsafe extern "C" fn wcpcpy(d: *mut wchar_t, s: *const wchar_t) -> *mut wchar_t { 379 375 return (wcscpy(d, s)).offset(wcslen(s) as isize); 380 376 } 381 377 382 - #[no_mangle] 378 + #[unsafe(no_mangle)] 383 379 pub unsafe extern "C" fn wcpncpy(d: *mut wchar_t, s: *const wchar_t, n: size_t) -> *mut wchar_t { 384 380 return (wcsncpy(d, s, n)).offset(wcsnlen(s, n) as isize); 385 381 } 386 382 387 383 //widechar to multibyte 388 - #[no_mangle] 384 + #[unsafe(no_mangle)] 389 385 pub unsafe extern "C" fn wcrtomb(s: *mut c_char, wc: wchar_t, ps: *mut mbstate_t) -> size_t { 390 386 let mut buffer: [c_char; MB_CUR_MAX as usize] = [0; MB_CUR_MAX as usize]; 391 387 let (s_cpy, wc_cpy) = if s.is_null() { ··· 397 393 utf8::wcrtomb(s_cpy, wc_cpy, ps) 398 394 } 399 395 400 - #[no_mangle] 396 + #[unsafe(no_mangle)] 401 397 pub unsafe extern "C" fn wcsdup(s: *const wchar_t) -> *mut wchar_t { 402 398 let l = wcslen(s); 403 399 ··· 411 407 wmemcpy(d, s, l + 1) 412 408 } 413 409 414 - #[no_mangle] 410 + #[unsafe(no_mangle)] 415 411 pub unsafe extern "C" fn wcsrtombs( 416 412 s: *mut c_char, 417 413 ws: *mut *const wchar_t, ··· 425 421 wcsnrtombs(s, ws, size_t::MAX, n, st) 426 422 } 427 423 428 - #[no_mangle] 424 + #[unsafe(no_mangle)] 429 425 pub unsafe extern "C" fn wcscat(ws1: *mut wchar_t, ws2: *const wchar_t) -> *mut wchar_t { 430 426 wcsncat(ws1, ws2, usize::MAX) 431 427 } ··· 436 432 /// The caller is required to ensure that `ws` is a valid pointer to a buffer 437 433 /// containing at least one nul value. The pointed-to buffer must not be 438 434 /// modified for the duration of the call. 439 - #[no_mangle] 435 + #[unsafe(no_mangle)] 440 436 pub unsafe extern "C" fn wcschr(ws: *const wchar_t, wc: wchar_t) -> *mut wchar_t { 441 437 // We iterate over non-mut references and thus need to coerce the 442 438 // resulting reference via a *const pointer before we can get our *mut. ··· 450 446 ptr.cast_mut() 451 447 } 452 448 453 - #[no_mangle] 449 + #[unsafe(no_mangle)] 454 450 pub unsafe extern "C" fn wcscmp(ws1: *const wchar_t, ws2: *const wchar_t) -> c_int { 455 451 wcsncmp(ws1, ws2, usize::MAX) 456 452 } 457 453 458 - #[no_mangle] 454 + #[unsafe(no_mangle)] 459 455 pub unsafe extern "C" fn wcscoll(ws1: *const wchar_t, ws2: *const wchar_t) -> c_int { 460 456 //TODO: locale comparison 461 457 wcscmp(ws1, ws2) 462 458 } 463 459 464 - #[no_mangle] 460 + #[unsafe(no_mangle)] 465 461 pub unsafe extern "C" fn wcscpy(ws1: *mut wchar_t, ws2: *const wchar_t) -> *mut wchar_t { 466 462 let mut i = 0; 467 463 loop { ··· 483 479 count 484 480 } 485 481 486 - #[no_mangle] 482 + #[unsafe(no_mangle)] 487 483 pub unsafe extern "C" fn wcscspn(wcs: *const wchar_t, set: *const wchar_t) -> size_t { 488 484 inner_wcsspn(wcs, set, true) 489 485 } 490 486 491 - // #[no_mangle] 487 + // #[unsafe(no_mangle)] 492 488 pub extern "C" fn wcsftime( 493 489 wcs: *mut wchar_t, 494 490 maxsize: size_t, ··· 498 494 unimplemented!(); 499 495 } 500 496 501 - #[no_mangle] 497 + #[unsafe(no_mangle)] 502 498 pub unsafe extern "C" fn wcslen(ws: *const wchar_t) -> size_t { 503 499 unsafe { NulTerminated::new(ws).unwrap() }.count() 504 500 } 505 501 506 - #[no_mangle] 502 + #[unsafe(no_mangle)] 507 503 pub unsafe extern "C" fn wcsncat( 508 504 ws1: *mut wchar_t, 509 505 ws2: *const wchar_t, ··· 524 520 ws1 525 521 } 526 522 527 - #[no_mangle] 523 + #[unsafe(no_mangle)] 528 524 pub unsafe extern "C" fn wcsncmp(ws1: *const wchar_t, ws2: *const wchar_t, n: size_t) -> c_int { 529 525 for i in 0..n { 530 526 let wc1 = *ws1.add(i); ··· 538 534 0 539 535 } 540 536 541 - #[no_mangle] 537 + #[unsafe(no_mangle)] 542 538 pub unsafe extern "C" fn wcsncpy( 543 539 ws1: *mut wchar_t, 544 540 ws2: *const wchar_t, ··· 560 556 ws1 561 557 } 562 558 563 - #[no_mangle] 559 + #[unsafe(no_mangle)] 564 560 pub unsafe extern "C" fn wcsnlen(mut s: *const wchar_t, maxlen: size_t) -> size_t { 565 561 let mut len = 0; 566 562 ··· 576 572 return len; 577 573 } 578 574 579 - #[no_mangle] 575 + #[unsafe(no_mangle)] 580 576 pub unsafe extern "C" fn wcsnrtombs( 581 577 mut dest: *mut c_char, 582 578 src: *mut *const wchar_t, ··· 624 620 written 625 621 } 626 622 627 - #[no_mangle] 623 + #[unsafe(no_mangle)] 628 624 pub unsafe extern "C" fn wcspbrk(mut wcs: *const wchar_t, set: *const wchar_t) -> *mut wchar_t { 629 625 wcs = wcs.add(wcscspn(wcs, set)); 630 626 if *wcs == 0 { ··· 636 632 } 637 633 } 638 634 639 - #[no_mangle] 635 + #[unsafe(no_mangle)] 640 636 pub unsafe extern "C" fn wcsrchr(ws1: *const wchar_t, wc: wchar_t) -> *mut wchar_t { 641 637 let mut last_matching_wc = 0 as *const wchar_t; 642 638 let mut i = 0; ··· 651 647 last_matching_wc as *mut wchar_t 652 648 } 653 649 654 - #[no_mangle] 650 + #[unsafe(no_mangle)] 655 651 pub unsafe extern "C" fn wcsspn(wcs: *const wchar_t, set: *const wchar_t) -> size_t { 656 652 inner_wcsspn(wcs, set, false) 657 653 } 658 654 659 - #[no_mangle] 655 + #[unsafe(no_mangle)] 660 656 pub unsafe extern "C" fn wcsstr(ws1: *const wchar_t, ws2: *const wchar_t) -> *mut wchar_t { 661 657 // Get length of ws2, not including null terminator 662 658 let ws2_len = wcslen(ws2); ··· 692 688 }; 693 689 } 694 690 695 - #[no_mangle] 691 + #[unsafe(no_mangle)] 696 692 pub unsafe extern "C" fn wcstod(mut ptr: *const wchar_t, end: *mut *mut wchar_t) -> c_double { 697 693 const RADIX: u32 = 10; 698 694 ··· 732 728 result 733 729 } 734 730 735 - #[no_mangle] 731 + #[unsafe(no_mangle)] 736 732 pub unsafe extern "C" fn wcstok( 737 733 mut wcs: *mut wchar_t, 738 734 delim: *const wchar_t, ··· 818 814 }}; 819 815 } 820 816 821 - #[no_mangle] 817 + #[unsafe(no_mangle)] 822 818 pub unsafe extern "C" fn wcstol( 823 819 mut ptr: *const wchar_t, 824 820 end: *mut *mut wchar_t, ··· 832 828 result 833 829 } 834 830 835 - #[no_mangle] 831 + #[unsafe(no_mangle)] 836 832 pub unsafe extern "C" fn wcstoll( 837 833 mut ptr: *const wchar_t, 838 834 end: *mut *mut wchar_t, ··· 846 842 result 847 843 } 848 844 849 - #[no_mangle] 845 + #[unsafe(no_mangle)] 850 846 pub unsafe extern "C" fn wcstoimax( 851 847 mut ptr: *const wchar_t, 852 848 end: *mut *mut wchar_t, ··· 860 856 result 861 857 } 862 858 863 - #[no_mangle] 859 + #[unsafe(no_mangle)] 864 860 pub unsafe extern "C" fn wcstoul( 865 861 mut ptr: *const wchar_t, 866 862 end: *mut *mut wchar_t, ··· 874 870 result 875 871 } 876 872 877 - #[no_mangle] 873 + #[unsafe(no_mangle)] 878 874 pub unsafe extern "C" fn wcstoull( 879 875 mut ptr: *const wchar_t, 880 876 end: *mut *mut wchar_t, ··· 888 884 result 889 885 } 890 886 891 - #[no_mangle] 887 + #[unsafe(no_mangle)] 892 888 pub unsafe extern "C" fn wcstoumax( 893 889 mut ptr: *const wchar_t, 894 890 end: *mut *mut wchar_t, ··· 902 898 result 903 899 } 904 900 905 - #[no_mangle] 901 + #[unsafe(no_mangle)] 906 902 pub unsafe extern "C" fn wcswcs(ws1: *const wchar_t, ws2: *const wchar_t) -> *mut wchar_t { 907 903 wcsstr(ws1, ws2) 908 904 } 909 905 910 - #[no_mangle] 906 + #[unsafe(no_mangle)] 911 907 pub unsafe extern "C" fn wcswidth(pwcs: *const wchar_t, n: size_t) -> c_int { 912 908 let mut total_width = 0; 913 909 for i in 0..n { ··· 920 916 total_width 921 917 } 922 918 923 - // #[no_mangle] 919 + // #[unsafe(no_mangle)] 924 920 pub extern "C" fn wcsxfrm(ws1: *mut wchar_t, ws2: *const wchar_t, n: size_t) -> size_t { 925 921 unimplemented!(); 926 922 } 927 923 928 - #[no_mangle] 924 + #[unsafe(no_mangle)] 929 925 pub extern "C" fn wctob(c: wint_t) -> c_int { 930 - if c <= 0x7F { 931 - c as c_int 932 - } else { 933 - EOF 934 - } 926 + if c <= 0x7F { c as c_int } else { EOF } 935 927 } 936 928 937 - #[no_mangle] 929 + #[unsafe(no_mangle)] 938 930 pub extern "C" fn wcwidth(wc: wchar_t) -> c_int { 939 931 match char::from_u32(wc as u32) { 940 932 Some(c) => match unicode_width::UnicodeWidthChar::width(c) { ··· 945 937 } 946 938 } 947 939 948 - #[no_mangle] 940 + #[unsafe(no_mangle)] 949 941 pub unsafe extern "C" fn wmemchr(ws: *const wchar_t, wc: wchar_t, n: size_t) -> *mut wchar_t { 950 942 for i in 0..n { 951 943 if *ws.add(i) == wc { ··· 955 947 ptr::null_mut() 956 948 } 957 949 958 - #[no_mangle] 950 + #[unsafe(no_mangle)] 959 951 pub unsafe extern "C" fn wmemcmp(ws1: *const wchar_t, ws2: *const wchar_t, n: size_t) -> c_int { 960 952 for i in 0..n { 961 953 let wc1 = *ws1.add(i); ··· 967 959 0 968 960 } 969 961 970 - #[no_mangle] 962 + #[unsafe(no_mangle)] 971 963 pub unsafe extern "C" fn wmemcpy( 972 964 ws1: *mut wchar_t, 973 965 ws2: *const wchar_t, ··· 980 972 ) as *mut wchar_t 981 973 } 982 974 983 - #[no_mangle] 975 + #[unsafe(no_mangle)] 984 976 pub unsafe extern "C" fn wmemmove( 985 977 ws1: *mut wchar_t, 986 978 ws2: *const wchar_t, ··· 993 985 ) as *mut wchar_t 994 986 } 995 987 996 - #[no_mangle] 988 + #[unsafe(no_mangle)] 997 989 pub unsafe extern "C" fn wmemset(ws: *mut wchar_t, wc: wchar_t, n: size_t) -> *mut wchar_t { 998 990 for i in 0..n { 999 991 *ws.add(i) = wc; ··· 1001 993 ws 1002 994 } 1003 995 1004 - #[no_mangle] 996 + #[unsafe(no_mangle)] 1005 997 pub unsafe extern "C" fn vwscanf(format: *const wchar_t, __valist: va_list) -> c_int { 1006 998 let mut file = (*stdin).lock(); 1007 999 if let Err(_) = file.try_set_byte_orientation_unlocked() { ··· 1013 1005 wscanf::scanf(reader, format, __valist) 1014 1006 } 1015 1007 1016 - #[no_mangle] 1008 + #[unsafe(no_mangle)] 1017 1009 pub unsafe extern "C" fn wscanf(format: *const wchar_t, mut __valist: ...) -> c_int { 1018 1010 vwscanf(format, __valist.as_va_list()) 1019 1011 } 1020 1012 1021 - #[no_mangle] 1013 + #[unsafe(no_mangle)] 1022 1014 pub extern "C" fn wcscasecmp(mut s1: *const wchar_t, mut s2: *const wchar_t) -> c_int { 1023 1015 unsafe { 1024 1016 while *s1 != 0 && *s2 != 0 { ··· 1033 1025 } 1034 1026 } 1035 1027 1036 - #[no_mangle] 1028 + #[unsafe(no_mangle)] 1037 1029 pub extern "C" fn wcsncasecmp(mut s1: *const wchar_t, mut s2: *const wchar_t, n: size_t) -> c_int { 1038 1030 if n == 0 { 1039 1031 return 0;
+1 -5
src/header/wchar/utf8.rs
··· 67 67 *pwc = result; 68 68 } 69 69 70 - if result != 0 { 71 - size 72 - } else { 73 - 0 74 - } 70 + if result != 0 { size } else { 0 } 75 71 } 76 72 77 73 //It's guaranteed that we don't have any nullpointers here
+6 -2
src/header/wchar/wprintf.rs
··· 109 109 110 110 (FmtKind::Char, _) 111 111 | (FmtKind::Unsigned, IntKind::Byte) 112 - | (FmtKind::Signed, IntKind::Byte) => VaArg::c_char(ap.arg::<c_char>()), 112 + | (FmtKind::Signed, IntKind::Byte) => { 113 + // c_int is passed but truncated to c_char 114 + VaArg::c_char(ap.arg::<c_int>() as c_char) 115 + } 113 116 (FmtKind::Unsigned, IntKind::Short) | (FmtKind::Signed, IntKind::Short) => { 114 - VaArg::c_short(ap.arg::<c_short>()) 117 + // c_int is passed but truncated to c_short 118 + VaArg::c_short(ap.arg::<c_int>() as c_short) 115 119 } 116 120 (FmtKind::Unsigned, IntKind::Int) | (FmtKind::Signed, IntKind::Int) => { 117 121 VaArg::c_int(ap.arg::<c_int>())
+1 -5
src/header/wchar/wscanf.rs
··· 25 25 unsafe fn next_char(string: &mut *const wchar_t) -> Result<wint_t, c_int> { 26 26 let c = **string as wint_t; 27 27 *string = string.offset(1); 28 - if c == 0 { 29 - Err(-1) 30 - } else { 31 - Ok(c) 32 - } 28 + if c == 0 { Err(-1) } else { Ok(c) } 33 29 } 34 30 35 31 macro_rules! wc_as_char {
+18 -18
src/header/wctype/mod.rs
··· 36 36 const WCTRANSLW: wctrans_t = 2 as wctrans_t; 37 37 38 38 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswalnum.html>. 39 - #[no_mangle] 39 + #[unsafe(no_mangle)] 40 40 pub extern "C" fn iswalnum(wc: wint_t) -> c_int { 41 41 c_int::from(iswdigit(wc) != 0 || iswalpha(wc) != 0) 42 42 } 43 43 44 44 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswalpha.html>. 45 - #[no_mangle] 45 + #[unsafe(no_mangle)] 46 46 pub extern "C" fn iswalpha(wc: wint_t) -> c_int { 47 47 c_int::from(alpha::is(wc as usize)) 48 48 } 49 49 50 50 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswblank.html>. 51 - #[no_mangle] 51 + #[unsafe(no_mangle)] 52 52 pub extern "C" fn iswblank(wc: wint_t) -> c_int { 53 53 ctype::isblank(wc as c_int) 54 54 } 55 55 56 56 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswcntrl.html>. 57 - #[no_mangle] 57 + #[unsafe(no_mangle)] 58 58 pub extern "C" fn iswcntrl(wc: wint_t) -> c_int { 59 59 c_int::from( 60 60 wc < 32 ··· 65 65 } 66 66 67 67 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswctype.html>. 68 - #[no_mangle] 68 + #[unsafe(no_mangle)] 69 69 pub extern "C" fn iswctype(wc: wint_t, desc: wctype_t) -> c_int { 70 70 match desc { 71 71 WCTYPE_ALNUM => iswalnum(wc), ··· 85 85 } 86 86 87 87 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswdigit.html>. 88 - #[no_mangle] 88 + #[unsafe(no_mangle)] 89 89 pub extern "C" fn iswdigit(wc: wint_t) -> c_int { 90 90 c_int::from(wc.wrapping_sub('0' as wint_t) < 10) 91 91 } 92 92 93 93 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswgraph.html>. 94 - #[no_mangle] 94 + #[unsafe(no_mangle)] 95 95 pub extern "C" fn iswgraph(wc: wint_t) -> c_int { 96 96 c_int::from(iswspace(wc) == 0 && iswprint(wc) != 0) 97 97 } 98 98 99 99 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswlower.html>. 100 - #[no_mangle] 100 + #[unsafe(no_mangle)] 101 101 pub extern "C" fn iswlower(wc: wint_t) -> c_int { 102 102 c_int::from(towupper(wc) != wc) 103 103 } 104 104 105 105 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswprint.html>. 106 - #[no_mangle] 106 + #[unsafe(no_mangle)] 107 107 pub extern "C" fn iswprint(wc: wint_t) -> c_int { 108 108 if wc < 0xff { 109 109 c_int::from((wc + 1 & 0x7f) >= 0x21) ··· 120 120 } 121 121 122 122 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswpunct.html>. 123 - #[no_mangle] 123 + #[unsafe(no_mangle)] 124 124 pub extern "C" fn iswpunct(wc: wint_t) -> c_int { 125 125 c_int::from(punct::is(wc as usize)) 126 126 } 127 127 128 128 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswspace.html>. 129 - #[no_mangle] 129 + #[unsafe(no_mangle)] 130 130 pub extern "C" fn iswspace(wc: wint_t) -> c_int { 131 131 c_int::from( 132 132 [ ··· 157 157 } 158 158 159 159 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswupper.html>. 160 - #[no_mangle] 160 + #[unsafe(no_mangle)] 161 161 pub extern "C" fn iswupper(wc: wint_t) -> c_int { 162 162 c_int::from(towlower(wc) != wc) 163 163 } 164 164 165 165 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iswxdigit.html>. 166 - #[no_mangle] 166 + #[unsafe(no_mangle)] 167 167 pub extern "C" fn iswxdigit(wc: wint_t) -> c_int { 168 168 c_int::from(wc.wrapping_sub('0' as wint_t) < 10 || (wc | 32).wrapping_sub('a' as wint_t) < 6) 169 169 } 170 170 171 171 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/towctrans.html>. 172 - #[no_mangle] 172 + #[unsafe(no_mangle)] 173 173 pub extern "C" fn towctrans(wc: wint_t, trans: wctrans_t) -> wint_t { 174 174 match trans { 175 175 WCTRANSUP => towupper(wc), ··· 179 179 } 180 180 181 181 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/towlower.html>. 182 - #[no_mangle] 182 + #[unsafe(no_mangle)] 183 183 pub extern "C" fn towlower(wc: wint_t) -> wint_t { 184 184 casemap(wc, 0) 185 185 } 186 186 187 187 /// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/towupper.html>. 188 - #[no_mangle] 188 + #[unsafe(no_mangle)] 189 189 pub extern "C" fn towupper(wc: wint_t) -> wint_t { 190 190 casemap(wc, 1) 191 191 } ··· 195 195 /// # Safety 196 196 /// The caller must ensure that `class` is convertible to a slice reference, up 197 197 /// to and including a terminating nul. 198 - #[no_mangle] 198 + #[unsafe(no_mangle)] 199 199 pub unsafe extern "C" fn wctrans(class: *const c_char) -> wctrans_t { 200 200 let class_cstr = unsafe { CStr::from_ptr(class) }; 201 201 match class_cstr.to_bytes() { ··· 210 210 /// # Safety 211 211 /// The caller must ensure that `name` is convertible to a slice reference, up 212 212 /// to and including a terminating nul. 213 - #[no_mangle] 213 + #[unsafe(no_mangle)] 214 214 pub unsafe extern "C" fn wctype(name: *const c_char) -> wctype_t { 215 215 let name_cstr = unsafe { CStr::from_ptr(name) }; 216 216 match name_cstr.to_bytes() {
+2 -2
src/io/buffered.rs
··· 13 13 use core::{cmp, fmt}; 14 14 15 15 use crate::io::{ 16 - self, prelude::*, Error, ErrorKind, Initializer, SeekFrom, Write, DEFAULT_BUF_SIZE, 16 + self, DEFAULT_BUF_SIZE, Error, ErrorKind, Initializer, SeekFrom, Write, prelude::*, 17 17 }; 18 18 19 19 /// The `BufReader` struct adds buffering to any reader. ··· 713 713 mod tests { 714 714 use alloc::string::String; 715 715 716 - use crate::io::{self, prelude::*, BufReader, BufWriter, LineWriter, SeekFrom}; 716 + use crate::io::{self, BufReader, BufWriter, LineWriter, SeekFrom, prelude::*}; 717 717 use test; 718 718 // use crate::sync::atomic::{AtomicUsize, Ordering}; 719 719
+2 -2
src/io/cursor.rs
··· 10 10 11 11 use core::cmp; 12 12 13 - use crate::io::{self, prelude::*, Error, ErrorKind, Initializer, SeekFrom}; 13 + use crate::io::{self, Error, ErrorKind, Initializer, SeekFrom, prelude::*}; 14 14 15 15 /// A `Cursor` wraps an in-memory buffer and provides it with a 16 16 /// [`Seek`] implementation. ··· 356 356 357 357 #[cfg(test)] 358 358 mod tests { 359 - use crate::io::{prelude::*, Cursor, SeekFrom}; 359 + use crate::io::{Cursor, SeekFrom, prelude::*}; 360 360 361 361 #[test] 362 362 fn test_vec_writer() {
+1 -1
src/io/impls.rs
··· 11 11 use alloc::string::String; 12 12 use core::{cmp, fmt, mem}; 13 13 14 - use crate::io::{self, prelude::*, Error, ErrorKind, Initializer, Seek, SeekFrom, Write}; 14 + use crate::io::{self, Error, ErrorKind, Initializer, Seek, SeekFrom, Write, prelude::*}; 15 15 16 16 impl<'a, R: Read + ?Sized> Read for &'a mut R { 17 17 #[inline]
+1 -1
src/io/mod.rs
··· 1753 1753 return Err(Error::new( 1754 1754 ErrorKind::WriteZero, 1755 1755 "failed to write whole buffer", 1756 - )) 1756 + )); 1757 1757 } 1758 1758 Ok(n) => buf = &buf[n..], 1759 1759 Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
+1 -1
src/ld_so/access.rs
··· 1 1 use crate::{ 2 2 c_str::{CStr, CString}, 3 3 error::Errno, 4 - platform::{types::*, Pal, Sys}, 4 + platform::{Pal, Sys, types::*}, 5 5 }; 6 6 7 7 pub fn accessible(path: &str, mode: c_int) -> Result<(), Errno> {
+2 -2
src/ld_so/debug.rs
··· 131 131 * break point there 132 132 */ 133 133 #[linkage = "weak"] 134 - #[no_mangle] 134 + #[unsafe(no_mangle)] 135 135 pub extern "C" fn _dl_debug_state() {} 136 136 137 - #[no_mangle] 137 + #[unsafe(no_mangle)] 138 138 pub static _r_debug: spin::Mutex<RTLDDebug> = spin::Mutex::new(RTLDDebug::NEW);
+6 -7
src/ld_so/dso.rs
··· 3 3 //! * <https://www.akkadia.org/drepper/dsohowto.pdf> 4 4 5 5 use object::{ 6 - elf, 6 + NativeEndian, Object, StringTable, SymbolIndex, elf, 7 7 read::elf::{ 8 8 Dyn as _, GnuHashTable, HashTable as SysVHashTable, ProgramHeader as _, Rel as _, 9 9 Rela as _, Sym as _, Version, VersionTable, 10 10 }, 11 - NativeEndian, Object, StringTable, SymbolIndex, 12 11 }; 13 12 14 13 use super::{ 15 - debug::{RTLDDebug, _r_debug}, 16 - linker::{Resolve, Scope, Symbol, __plt_resolve_trampoline, GLOBAL_SCOPE}, 14 + debug::{_r_debug, RTLDDebug}, 15 + linker::{__plt_resolve_trampoline, GLOBAL_SCOPE, Resolve, Scope, Symbol}, 17 16 tcb::Master, 18 17 }; 19 18 use crate::{ 20 19 header::sys_mman, 21 - platform::{types::c_void, Pal, Sys}, 20 + platform::{Pal, Sys, types::c_void}, 22 21 }; 23 22 use alloc::{ 24 23 string::{String, ToString}, ··· 37 36 38 37 #[cfg(target_pointer_width = "32")] 39 38 mod shim { 40 - use object::{elf::*, read::elf::ElfFile32, NativeEndian}; 39 + use object::{NativeEndian, elf::*, read::elf::ElfFile32}; 41 40 pub type Dyn = Dyn32<NativeEndian>; 42 41 pub type Rel = Rel32<NativeEndian>; 43 42 pub type Rela = Rela32<NativeEndian>; ··· 49 48 50 49 #[cfg(target_pointer_width = "64")] 51 50 mod shim { 52 - use object::{elf::*, read::elf::ElfFile64, NativeEndian}; 51 + use object::{NativeEndian, elf::*, read::elf::ElfFile64}; 53 52 pub type Dyn = Dyn64<NativeEndian>; 54 53 pub type Rel = Rel64<NativeEndian>; 55 54 pub type Rela = Rela64<NativeEndian>;
+9 -13
src/ld_so/linker.rs
··· 6 6 vec::Vec, 7 7 }; 8 8 use object::{ 9 - elf, 9 + NativeEndian, elf, 10 10 read::elf::{Rela as _, Sym}, 11 - NativeEndian, 12 11 }; 13 12 14 13 use core::{ ··· 24 23 fcntl, sys_mman, 25 24 unistd::F_OK, 26 25 }, 27 - ld_so::dso::{resolve_sym, SymbolBinding}, 26 + ld_so::dso::{SymbolBinding, resolve_sym}, 28 27 out::Out, 29 28 platform::{ 30 - types::{c_int, c_uint, c_void}, 31 29 Pal, Sys, 30 + types::{c_int, c_uint, c_void}, 32 31 }, 33 32 sync::rwlock::RwLock, 34 33 }; 35 34 36 35 use super::{ 36 + PATH_SEP, 37 37 access::accessible, 38 38 callbacks::LinkerCallbacks, 39 - debug::{RTLDState, _dl_debug_state, _r_debug}, 40 - dso::{ProgramHeader, Rela, DSO}, 39 + debug::{_dl_debug_state, _r_debug, RTLDState}, 40 + dso::{DSO, ProgramHeader, Rela}, 41 41 tcb::{Master, Tcb}, 42 - PATH_SEP, 43 42 }; 44 43 45 44 #[derive(Debug, Copy, Clone)] ··· 180 179 fn set_owner(&mut self, obj: Weak<DSO>) { 181 180 match self { 182 181 Self::Global { .. } => panic!("attempted to set global scope owner"), 183 - Self::Local { ref mut owner, .. } => { 182 + Self::Local { owner, .. } => { 184 183 assert!(owner.is_none(), "attempted to change local scope owner"); 185 184 *owner = Some(obj); 186 185 } ··· 436 435 ) -> Result<ObjectHandle> { 437 436 trace!( 438 437 "[ld.so] load_library(name={:?}, resolve={:#?}, scope={:#?}, noload={})", 439 - name, 440 - resolve, 441 - scope, 442 - noload 438 + name, resolve, scope, noload 443 439 ); 444 440 445 441 if noload && resolve == Resolve::Now { ··· 994 990 resolved 995 991 } 996 992 997 - extern "C" { 993 + unsafe extern "C" { 998 994 pub(super) fn __plt_resolve_trampoline() -> usize; 999 995 } 1000 996
+2 -2
src/ld_so/mod.rs
··· 6 6 7 7 use core::{mem, ptr}; 8 8 use object::{ 9 + Endianness, 9 10 elf::{self, ProgramHeader32, ProgramHeader64}, 10 11 read::elf::ProgramHeader, 11 - Endianness, 12 12 }; 13 13 14 14 use self::tcb::{Master, Tcb}; ··· 28 28 pub mod start; 29 29 pub mod tcb; 30 30 31 - pub use generic_rt::{panic_notls, ExpectTlsFree}; 31 + pub use generic_rt::{ExpectTlsFree, panic_notls}; 32 32 33 33 static mut STATIC_TCB_MASTER: Master = Master { 34 34 ptr: ptr::null_mut(),
+5 -5
src/ld_so/start.rs
··· 10 10 use generic_rt::ExpectTlsFree; 11 11 12 12 use crate::{ 13 + ALLOCATOR, 13 14 c_str::CStr, 14 15 header::unistd, 15 16 platform::{get_auxv, get_auxvs, types::c_char}, 16 17 start::Stack, 17 18 sync::mutex::Mutex, 18 - ALLOCATOR, 19 19 }; 20 20 21 21 use super::{ 22 + PATH_SEP, 22 23 access::accessible, 23 24 debug::_r_debug, 24 25 linker::{Config, Linker}, 25 26 tcb::Tcb, 26 - PATH_SEP, 27 27 }; 28 28 use crate::header::sys_auxv::{AT_ENTRY, AT_PHDR}; 29 29 ··· 145 145 None 146 146 } 147 147 148 - #[no_mangle] 148 + #[unsafe(no_mangle)] 149 149 pub unsafe extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) -> usize { 150 150 // Setup TCB for ourselves. 151 151 unsafe { ··· 182 182 }; 183 183 184 184 unsafe { 185 - crate::platform::OUR_ENVIRON = envs 185 + *crate::platform::OUR_ENVIRON.as_mut_ptr() = envs 186 186 .iter() 187 187 .map(|(k, v)| { 188 188 let mut var = Vec::with_capacity(k.len() + v.len() + 2); ··· 198 198 .chain(core::iter::once(core::ptr::null_mut())) 199 199 .collect::<Vec<_>>(); 200 200 201 - crate::platform::environ = crate::platform::OUR_ENVIRON.as_mut_ptr(); 201 + crate::platform::environ = crate::platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr(); 202 202 } 203 203 204 204 let is_manual = if let Some(img_entry) = get_auxv(&auxv, AT_ENTRY) {
+4 -6
src/lib.rs
··· 71 71 pub mod start; 72 72 pub mod sync; 73 73 74 - use crate::platform::{Allocator, Pal, Sys, NEWALLOCATOR}; 74 + use crate::platform::{Allocator, NEWALLOCATOR, Pal, Sys}; 75 75 76 76 #[global_allocator] 77 77 static ALLOCATOR: Allocator = NEWALLOCATOR; 78 78 79 - #[no_mangle] 79 + #[unsafe(no_mangle)] 80 80 pub extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! { 81 81 use core::fmt::Write; 82 82 ··· 89 89 #[cfg(not(test))] 90 90 #[panic_handler] 91 91 #[linkage = "weak"] 92 - #[no_mangle] 93 92 pub fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { 94 93 relibc_panic(pi) 95 94 } 96 95 97 96 #[cfg(not(test))] 98 97 #[lang = "eh_personality"] 99 - #[no_mangle] 100 98 #[linkage = "weak"] 101 99 pub extern "C" fn rust_eh_personality() {} 102 100 103 101 #[cfg(not(test))] 104 102 #[alloc_error_handler] 105 103 #[linkage = "weak"] 106 - #[no_mangle] 104 + #[unsafe(no_mangle)] 107 105 pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! { 108 106 use core::fmt::Write; 109 107 ··· 120 118 #[cfg(not(test))] 121 119 #[allow(non_snake_case)] 122 120 #[linkage = "weak"] 123 - #[no_mangle] 121 + #[unsafe(no_mangle)] 124 122 pub extern "C" fn _Unwind_Resume() -> ! { 125 123 use core::fmt::Write; 126 124
+1 -5
src/macros.rs
··· 200 200 let num = if overflow { 201 201 platform::ERRNO.set(ERANGE); 202 202 if CHECK_SIGN { 203 - if positive { 204 - MAX_VAL 205 - } else { 206 - MIN_VAL 207 - } 203 + if positive { MAX_VAL } else { MIN_VAL } 208 204 } else { 209 205 MAX_VAL 210 206 }
+1 -1
src/platform/allocator/mod.rs
··· 8 8 9 9 mod sys; 10 10 use super::types::*; 11 - use crate::{sync::Mutex, ALLOCATOR}; 11 + use crate::{ALLOCATOR, sync::Mutex}; 12 12 use dlmalloc::DlmallocCApi; 13 13 14 14 pub type Dlmalloc = DlmallocCApi<sys::System>;
+1 -1
src/platform/allocator/sys.rs
··· 3 3 sys_mman::{self, MAP_FAILED, MREMAP_MAYMOVE}, 4 4 unistd::pthread_atfork, 5 5 }, 6 - platform::{types::*, Pal, Sys}, 6 + platform::{Pal, Sys, types::*}, 7 7 sync::Mutex, 8 8 }; 9 9 use core::ptr;
+2 -2
src/platform/linux/epoll.rs
··· 1 - use super::{e_raw, Sys}; 1 + use super::{Sys, e_raw}; 2 2 use crate::{ 3 3 error::Result, 4 4 header::{signal::sigset_t, sys_epoll::epoll_event}, 5 - platform::{types::*, PalEpoll}, 5 + platform::{PalEpoll, types::*}, 6 6 }; 7 7 8 8 impl PalEpoll for Sys {
+2 -2
src/platform/linux/mod.rs
··· 1 1 use core::{arch::asm, ptr}; 2 2 3 - use super::{types::*, Pal, ERRNO}; 3 + use super::{ERRNO, Pal, types::*}; 4 4 use crate::{ 5 5 c_str::CStr, 6 6 header::{ ··· 9 9 fcntl::{AT_EMPTY_PATH, AT_FDCWD, AT_REMOVEDIR, AT_SYMLINK_NOFOLLOW}, 10 10 signal::SIGCHLD, 11 11 sys_resource::{rlimit, rusage}, 12 - sys_stat::{stat, S_IFIFO}, 12 + sys_stat::{S_IFIFO, stat}, 13 13 sys_statvfs::statvfs, 14 14 sys_time::{timeval, timezone}, 15 15 unistd::{SEEK_CUR, SEEK_SET},
+2 -2
src/platform/linux/ptrace.rs
··· 1 1 use super::{ 2 - super::{types::*, PalPtrace}, 3 - e_raw, Sys, 2 + super::{PalPtrace, types::*}, 3 + Sys, e_raw, 4 4 }; 5 5 use crate::error::Result; 6 6
+4 -4
src/platform/linux/signal.rs
··· 2 2 use core::{mem, ptr::addr_of}; 3 3 4 4 use super::{ 5 - super::{types::*, PalSignal}, 6 - e_raw, Sys, 5 + super::{PalSignal, types::*}, 6 + Sys, e_raw, 7 7 }; 8 8 use crate::{ 9 9 error::{Errno, Result}, 10 10 header::{ 11 - signal::{sigaction, siginfo_t, sigset_t, stack_t, NSIG, SA_RESTORER, SI_QUEUE}, 11 + signal::{NSIG, SA_RESTORER, SI_QUEUE, sigaction, siginfo_t, sigset_t, stack_t}, 12 12 sys_time::itimerval, 13 13 time::timespec, 14 14 }, ··· 68 68 act: Option<&sigaction>, 69 69 oact: Option<&mut sigaction>, 70 70 ) -> Result<(), Errno> { 71 - extern "C" { 71 + unsafe extern "C" { 72 72 fn __restore_rt(); 73 73 } 74 74 let act = act.map(|act| {
+2 -2
src/platform/linux/socket.rs
··· 1 - use super::{e_raw, Sys}; 1 + use super::{Sys, e_raw}; 2 2 use crate::{ 3 3 error::Result, 4 4 header::sys_socket::{msghdr, sockaddr, socklen_t}, 5 - platform::{types::*, PalSocket}, 5 + platform::{PalSocket, types::*}, 6 6 }; 7 7 8 8 impl PalSocket for Sys {
+4 -3
src/platform/mod.rs
··· 3 3 use crate::{ 4 4 error::{Errno, ResultExt}, 5 5 io::{self, Read, Write}, 6 + raw_cell::RawCell, 6 7 }; 7 8 use alloc::{boxed::Box, vec::Vec}; 8 9 use core::{cell::Cell, fmt, ptr}; ··· 48 49 #[allow(non_upper_case_globals)] 49 50 pub static mut argv: *mut *mut c_char = ptr::null_mut(); 50 51 #[allow(non_upper_case_globals)] 51 - pub static mut inner_argv: Vec<*mut c_char> = Vec::new(); 52 + pub static inner_argv: RawCell<Vec<*mut c_char>> = RawCell::new(Vec::new()); 52 53 #[allow(non_upper_case_globals)] 53 54 pub static mut program_invocation_name: *mut c_char = ptr::null_mut(); 54 55 #[allow(non_upper_case_globals)] 55 56 pub static mut program_invocation_short_name: *mut c_char = ptr::null_mut(); 56 57 57 58 #[allow(non_upper_case_globals)] 58 - #[no_mangle] 59 + #[unsafe(no_mangle)] 59 60 pub static mut environ: *mut *mut c_char = ptr::null_mut(); 60 61 61 - pub static mut OUR_ENVIRON: Vec<*mut c_char> = Vec::new(); 62 + pub static OUR_ENVIRON: RawCell<Vec<*mut c_char>> = RawCell::new(Vec::new()); 62 63 63 64 pub fn environ_iter() -> impl Iterator<Item = *mut c_char> + 'static { 64 65 unsafe {
+1 -1
src/platform/pal/epoll.rs
··· 1 1 use crate::{ 2 2 error::{Errno, Result}, 3 3 header::{signal::sigset_t, sys_epoll::epoll_event}, 4 - platform::{types::*, Pal}, 4 + platform::{Pal, types::*}, 5 5 }; 6 6 7 7 pub trait PalEpoll: Pal {
+1 -1
src/platform/pal/ptrace.rs
··· 1 1 use crate::{ 2 2 error::Result, 3 - platform::{types::*, Pal}, 3 + platform::{Pal, types::*}, 4 4 }; 5 5 6 6 pub trait PalPtrace: Pal {
+1 -1
src/platform/pal/signal.rs
··· 1 - use super::super::{types::*, Pal}; 1 + use super::super::{Pal, types::*}; 2 2 use crate::{ 3 3 error::{Errno, Result}, 4 4 header::{
+1 -1
src/platform/pal/socket.rs
··· 1 1 use crate::{ 2 2 error::Result, 3 3 header::sys_socket::{msghdr, sockaddr, socklen_t}, 4 - platform::{types::*, Pal}, 4 + platform::{Pal, types::*}, 5 5 }; 6 6 7 7 pub trait PalSocket: Pal {
+1 -1
src/platform/redox/clone.rs
··· 1 1 use core::mem::size_of; 2 2 3 3 use syscall::{ 4 + SetSighandlerData, 4 5 data::Map, 5 6 error::Result, 6 7 flag::{MapFlags, O_CLOEXEC}, 7 - SetSighandlerData, 8 8 }; 9 9 10 10 use redox_rt::{proc::FdGuard, signal::sighandler_function};
+1 -1
src/platform/redox/epoll.rs
··· 1 1 use super::{ 2 - super::{types::*, Pal, PalEpoll}, 2 + super::{Pal, PalEpoll, types::*}, 3 3 Sys, 4 4 }; 5 5
+5 -5
src/platform/redox/event.rs
··· 9 9 use super::libredox::RawResult; 10 10 11 11 use bitflags::Flags; 12 - use syscall::{Error, Result, EINVAL}; 12 + use syscall::{EINVAL, Error, Result}; 13 13 14 - #[no_mangle] 14 + #[unsafe(no_mangle)] 15 15 pub unsafe extern "C" fn redox_event_queue_create_v1(flags: u32) -> RawResult { 16 16 Error::mux((|| { 17 17 if flags != 0 { ··· 20 20 Ok(super::libredox::open("/scheme/event", O_CLOEXEC | O_CREAT | O_RDWR, 0o700)? as usize) 21 21 })()) 22 22 } 23 - #[no_mangle] 23 + #[unsafe(no_mangle)] 24 24 pub unsafe extern "C" fn redox_event_queue_get_events_v1( 25 25 queue: usize, 26 26 buf: *mut event::raw::RawEventV1, ··· 49 49 Ok(1) 50 50 })()) 51 51 } 52 - #[no_mangle] 52 + #[unsafe(no_mangle)] 53 53 pub unsafe extern "C" fn redox_event_queue_ctl_v1( 54 54 queue: usize, 55 55 fd: usize, ··· 75 75 Ok(0) 76 76 })()) 77 77 } 78 - #[no_mangle] 78 + #[unsafe(no_mangle)] 79 79 pub unsafe extern "C" fn redox_event_queue_destroy_v1(queue: usize) -> RawResult { 80 80 Error::mux(syscall::close(queue)) 81 81 }
+2 -2
src/platform/redox/exec.rs
··· 7 7 c_str::{CStr, CString}, 8 8 fs::File, 9 9 header::{limits::PATH_MAX, string::strlen}, 10 - io::{prelude::*, BufReader, SeekFrom}, 10 + io::{BufReader, SeekFrom, prelude::*}, 11 11 platform::{ 12 12 sys::{S_ISGID, S_ISUID}, 13 13 types::*, ··· 15 15 }; 16 16 17 17 use redox_rt::{ 18 + RtTcb, 18 19 proc::{ExtraInfo, FdGuard, FexecResult, InterpOverride}, 19 20 sys::Resugid, 20 - RtTcb, 21 21 }; 22 22 use syscall::{data::Stat, error::*, flag::*}; 23 23
+2 -2
src/platform/redox/extra.rs
··· 4 4 error::{Errno, ResultExt}, 5 5 platform::types::*, 6 6 }; 7 - use syscall::{error::*, F_SETFD, F_SETFL}; 7 + use syscall::{F_SETFD, F_SETFL, error::*}; 8 8 9 9 pub use redox_rt::proc::FdGuard; 10 10 11 - #[no_mangle] 11 + #[unsafe(no_mangle)] 12 12 pub unsafe extern "C" fn redox_fpath(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t { 13 13 syscall::fpath( 14 14 fd as usize,
+1 -1
src/platform/redox/libcscheme.rs
··· 1 1 use super::libredox; 2 2 use crate::{c_str::CStr, header::stdlib::getenv, platform::types::*}; 3 3 use core::{ptr, slice}; 4 - use syscall::{flag::*, Error, Result, EINVAL, EIO, ENOENT}; 4 + use syscall::{EINVAL, EIO, ENOENT, Error, Result, flag::*}; 5 5 6 6 pub const LIBC_SCHEME: &'static str = "libc:"; 7 7
+40 -40
src/platform/redox/libredox.rs
··· 2 2 3 3 use redox_rt::{ 4 4 protocol::{ProcKillTarget, SocketCall, WaitFlags}, 5 - sys::{posix_read, posix_write, WaitpidTarget}, 5 + sys::{WaitpidTarget, posix_read, posix_write}, 6 6 }; 7 - use syscall::{Error, Result, EMFILE}; 7 + use syscall::{EMFILE, Error, Result}; 8 8 9 9 use crate::{ 10 10 header::{ 11 11 errno::EINVAL, 12 - signal::{sigaction, SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK}, 12 + signal::{SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK, sigaction}, 13 13 sys_stat::UTIME_NOW, 14 14 sys_uio::iovec, 15 15 time::timespec, 16 16 }, 17 17 out::Out, 18 - platform::{types::*, PalSignal}, 18 + platform::{PalSignal, types::*}, 19 19 }; 20 20 21 21 use super::Sys; ··· 122 122 Ok(()) 123 123 } 124 124 125 - #[no_mangle] 125 + #[unsafe(no_mangle)] 126 126 pub unsafe extern "C" fn redox_open_v1( 127 127 path_base: *const u8, 128 128 path_len: usize, ··· 135 135 mode as mode_t, 136 136 )) 137 137 } 138 - #[no_mangle] 138 + #[unsafe(no_mangle)] 139 139 pub unsafe extern "C" fn redox_openat_v1( 140 140 fd: usize, 141 141 path_base: *const u8, ··· 148 148 flags as usize, 149 149 )) 150 150 } 151 - #[no_mangle] 151 + #[unsafe(no_mangle)] 152 152 pub unsafe extern "C" fn redox_dup_v1(fd: usize, buf: *const u8, len: usize) -> RawResult { 153 153 Error::mux(syscall::dup(fd, core::slice::from_raw_parts(buf, len))) 154 154 } 155 - #[no_mangle] 155 + #[unsafe(no_mangle)] 156 156 pub unsafe extern "C" fn redox_dup2_v1( 157 157 old_fd: usize, 158 158 new_fd: usize, ··· 165 165 core::slice::from_raw_parts(buf, len), 166 166 )) 167 167 } 168 - #[no_mangle] 168 + #[unsafe(no_mangle)] 169 169 pub unsafe extern "C" fn redox_read_v1(fd: usize, dst_base: *mut u8, dst_len: usize) -> RawResult { 170 170 Error::mux(posix_read(fd, slice::from_raw_parts_mut(dst_base, dst_len))) 171 171 } 172 - #[no_mangle] 172 + #[unsafe(no_mangle)] 173 173 pub unsafe extern "C" fn redox_write_v1( 174 174 fd: usize, 175 175 src_base: *const u8, ··· 177 177 ) -> RawResult { 178 178 Error::mux(posix_write(fd, slice::from_raw_parts(src_base, src_len))) 179 179 } 180 - #[no_mangle] 180 + #[unsafe(no_mangle)] 181 181 pub unsafe extern "C" fn redox_fsync_v1(fd: usize) -> RawResult { 182 182 Error::mux(syscall::fsync(fd)) 183 183 } 184 - #[no_mangle] 184 + #[unsafe(no_mangle)] 185 185 pub unsafe extern "C" fn redox_fdatasync_v1(fd: usize) -> RawResult { 186 186 // TODO 187 187 Error::mux(syscall::fsync(fd)) 188 188 } 189 - #[no_mangle] 189 + #[unsafe(no_mangle)] 190 190 pub unsafe extern "C" fn redox_fchmod_v1(fd: usize, new_mode: u16) -> RawResult { 191 191 Error::mux(syscall::fchmod(fd, new_mode)) 192 192 } 193 - #[no_mangle] 193 + #[unsafe(no_mangle)] 194 194 pub unsafe extern "C" fn redox_fchown_v1(fd: usize, new_uid: u32, new_gid: u32) -> RawResult { 195 195 Error::mux(syscall::fchown(fd, new_uid, new_gid)) 196 196 } 197 - #[no_mangle] 197 + #[unsafe(no_mangle)] 198 198 pub unsafe extern "C" fn redox_fpath_v1(fd: usize, dst_base: *mut u8, dst_len: usize) -> RawResult { 199 199 Error::mux(syscall::fpath( 200 200 fd, 201 201 core::slice::from_raw_parts_mut(dst_base, dst_len), 202 202 )) 203 203 } 204 - #[no_mangle] 204 + #[unsafe(no_mangle)] 205 205 pub unsafe extern "C" fn redox_fstat_v1( 206 206 fd: usize, 207 207 stat: *mut crate::header::sys_stat::stat, 208 208 ) -> RawResult { 209 209 Error::mux(fstat(fd, stat).map(|()| 0)) 210 210 } 211 - #[no_mangle] 211 + #[unsafe(no_mangle)] 212 212 pub unsafe extern "C" fn redox_fstatvfs_v1( 213 213 fd: usize, 214 214 stat: *mut crate::header::sys_statvfs::statvfs, 215 215 ) -> RawResult { 216 216 Error::mux(fstatvfs(fd, stat).map(|()| 0)) 217 217 } 218 - #[no_mangle] 218 + #[unsafe(no_mangle)] 219 219 pub unsafe extern "C" fn redox_futimens_v1(fd: usize, times: *const timespec) -> RawResult { 220 220 Error::mux(futimens(fd, times).map(|()| 0)) 221 221 } 222 - #[no_mangle] 222 + #[unsafe(no_mangle)] 223 223 pub unsafe extern "C" fn redox_close_v1(fd: usize) -> RawResult { 224 224 Error::mux(syscall::close(fd)) 225 225 } 226 226 227 - #[no_mangle] 227 + #[unsafe(no_mangle)] 228 228 pub unsafe extern "C" fn redox_get_pid_v1() -> RawResult { 229 229 redox_rt::sys::posix_getpid() as _ 230 230 } 231 231 232 - #[no_mangle] 232 + #[unsafe(no_mangle)] 233 233 pub unsafe extern "C" fn redox_get_euid_v1() -> RawResult { 234 234 redox_rt::sys::posix_getresugid().euid as _ 235 235 } 236 - #[no_mangle] 236 + #[unsafe(no_mangle)] 237 237 pub unsafe extern "C" fn redox_get_ruid_v1() -> RawResult { 238 238 redox_rt::sys::posix_getresugid().ruid as _ 239 239 } 240 - #[no_mangle] 240 + #[unsafe(no_mangle)] 241 241 pub unsafe extern "C" fn redox_get_egid_v1() -> RawResult { 242 242 redox_rt::sys::posix_getresugid().egid as _ 243 243 } 244 - #[no_mangle] 244 + #[unsafe(no_mangle)] 245 245 pub unsafe extern "C" fn redox_get_rgid_v1() -> RawResult { 246 246 redox_rt::sys::posix_getresugid().rgid as _ 247 247 } 248 - #[no_mangle] 248 + #[unsafe(no_mangle)] 249 249 pub unsafe extern "C" fn redox_get_ens_v0() -> RawResult { 250 250 Error::mux(redox_rt::sys::getens()) 251 251 } 252 - #[no_mangle] 252 + #[unsafe(no_mangle)] 253 253 pub unsafe extern "C" fn redox_get_proc_credentials_v1( 254 254 cap_fd: usize, 255 255 target_pid: usize, ··· 258 258 Error::mux(redox_rt::sys::get_proc_credentials(cap_fd, target_pid, buf)) 259 259 } 260 260 261 - #[no_mangle] 261 + #[unsafe(no_mangle)] 262 262 pub unsafe extern "C" fn redox_setrens_v1(rns: usize, ens: usize) -> RawResult { 263 263 Error::mux(redox_rt::sys::setrens(rns, ens).map(|()| 0)) 264 264 } 265 - #[no_mangle] 265 + #[unsafe(no_mangle)] 266 266 pub unsafe extern "C" fn redox_waitpid_v1(pid: usize, status: *mut i32, options: u32) -> RawResult { 267 267 let mut sts = 0_usize; 268 268 let res = Error::mux(redox_rt::sys::sys_waitpid( ··· 274 274 res 275 275 } 276 276 277 - #[no_mangle] 277 + #[unsafe(no_mangle)] 278 278 pub unsafe extern "C" fn redox_kill_v1(pid: usize, signal: u32) -> RawResult { 279 279 Error::mux( 280 280 redox_rt::sys::posix_kill(ProcKillTarget::from_raw(pid), signal as usize).map(|()| 0), 281 281 ) 282 282 } 283 283 284 - #[no_mangle] 284 + #[unsafe(no_mangle)] 285 285 pub unsafe extern "C" fn redox_sigaction_v1( 286 286 signal: u32, 287 287 new: *const sigaction, ··· 294 294 ) 295 295 } 296 296 297 - #[no_mangle] 297 + #[unsafe(no_mangle)] 298 298 pub unsafe extern "C" fn redox_sigprocmask_v1( 299 299 how: u32, 300 300 new: *const u64, ··· 306 306 .map_err(Into::into), 307 307 ) 308 308 } 309 - #[no_mangle] 309 + #[unsafe(no_mangle)] 310 310 pub unsafe extern "C" fn redox_mmap_v1( 311 311 addr: *mut (), 312 312 unaligned_len: usize, ··· 327 327 }, 328 328 )) 329 329 } 330 - #[no_mangle] 330 + #[unsafe(no_mangle)] 331 331 pub unsafe extern "C" fn redox_munmap_v1(addr: *mut (), unaligned_len: usize) -> RawResult { 332 332 Error::mux(syscall::funmap(addr as usize, unaligned_len)) 333 333 } 334 334 335 - #[no_mangle] 335 + #[unsafe(no_mangle)] 336 336 pub unsafe extern "C" fn redox_clock_gettime_v1(clock: usize, ts: *mut timespec) -> RawResult { 337 337 Error::mux(clock_gettime(clock, Out::nonnull(ts)).map(|()| 0)) 338 338 } 339 339 340 - #[no_mangle] 340 + #[unsafe(no_mangle)] 341 341 pub unsafe extern "C" fn redox_strerror_v1( 342 342 buf: *mut u8, 343 343 buflen: *mut usize, ··· 368 368 })()) 369 369 } 370 370 371 - #[no_mangle] 371 + #[unsafe(no_mangle)] 372 372 pub unsafe extern "C" fn redox_mkns_v1( 373 373 names: *const iovec, 374 374 num_names: usize, ··· 384 384 } 385 385 386 386 // ABI-UNSTABLE 387 - #[no_mangle] 387 + #[unsafe(no_mangle)] 388 388 pub unsafe extern "C" fn redox_cur_procfd_v0() -> usize { 389 389 **redox_rt::current_proc_fd() 390 390 } 391 391 392 - #[no_mangle] 392 + #[unsafe(no_mangle)] 393 393 pub unsafe extern "C" fn redox_cur_thrfd_v0() -> usize { 394 394 **redox_rt::RtTcb::current().thread_fd() 395 395 } 396 396 397 - #[no_mangle] 397 + #[unsafe(no_mangle)] 398 398 pub unsafe extern "C" fn redox_sys_call_v0( 399 399 fd: usize, 400 400 payload: *mut u8, ··· 411 411 )) 412 412 } 413 413 414 - #[no_mangle] 414 + #[unsafe(no_mangle)] 415 415 pub unsafe extern "C" fn redox_get_socket_token_v0( 416 416 fd: usize, 417 417 payload: *mut u8,
+18 -17
src/platform/redox/mod.rs
··· 4 4 ptr, slice, str, 5 5 }; 6 6 use redox_rt::{ 7 - protocol::{wifstopped, wstopsig, WaitFlags}, 8 - sys::{Resugid, WaitpidTarget}, 9 7 RtTcb, 8 + protocol::{WaitFlags, wifstopped, wstopsig}, 9 + sys::{Resugid, WaitpidTarget}, 10 10 }; 11 11 use syscall::{ 12 - self, 12 + self, EMFILE, Error, MODE_PERM, PtraceEvent, 13 13 data::{Map, Stat as redox_stat, StatVfs as redox_statvfs, TimeSpec as redox_timespec}, 14 14 dirent::{DirentHeader, DirentKind}, 15 - Error, PtraceEvent, EMFILE, MODE_PERM, 16 15 }; 17 16 18 17 use crate::{ ··· 29 28 limits, 30 29 sys_mman::{MAP_ANONYMOUS, MAP_FAILED, PROT_READ, PROT_WRITE}, 31 30 sys_random, 32 - sys_resource::{rlimit, rusage, RLIM_INFINITY}, 33 - sys_stat::{stat, S_ISGID, S_ISUID, S_ISVTX}, 31 + sys_resource::{RLIM_INFINITY, rlimit, rusage}, 32 + sys_stat::{S_ISGID, S_ISUID, S_ISVTX, stat}, 34 33 sys_statvfs::statvfs, 35 34 sys_time::{timeval, timezone}, 36 - sys_utsname::{utsname, UTSLENGTH}, 35 + sys_utsname::{UTSLENGTH, utsname}, 37 36 sys_wait, 38 37 time::timespec, 39 38 unistd::{F_OK, R_OK, SEEK_CUR, SEEK_SET, W_OK, X_OK}, 40 39 }, 41 - io::{self, prelude::*, BufReader}, 40 + io::{self, BufReader, prelude::*}, 42 41 out::Out, 43 42 sync::rwlock::RwLock, 44 43 }; 45 44 46 45 pub use redox_rt::proc::FdGuard; 47 46 48 - use super::{types::*, Pal, Read, ERRNO}; 47 + use super::{ERRNO, Pal, Read, types::*}; 49 48 50 49 static mut BRK_CUR: *mut c_void = ptr::null_mut(); 51 50 static mut BRK_END: *mut c_void = ptr::null_mut(); ··· 1134 1133 // normal: We still need to add WUNTRACED, but we only return 1135 1134 // it if (and only if) a ptrace traceme was activated during 1136 1135 // the wait. 1137 - let res = res.unwrap_or_else(|| loop { 1138 - let res = inner(&mut status, options | WaitFlags::WUNTRACED); 1136 + let res = res.unwrap_or_else(|| { 1137 + loop { 1138 + let res = inner(&mut status, options | WaitFlags::WUNTRACED); 1139 1139 1140 - // TODO: Also handle special PIDs here 1141 - if !wifstopped(status) 1142 - || options.contains(WaitFlags::WUNTRACED) 1143 - || ptrace::is_traceme(pid) 1144 - { 1145 - break res; 1140 + // TODO: Also handle special PIDs here 1141 + if !wifstopped(status) 1142 + || options.contains(WaitFlags::WUNTRACED) 1143 + || ptrace::is_traceme(pid) 1144 + { 1145 + break res; 1146 + } 1146 1147 } 1147 1148 }); 1148 1149
+2 -2
src/platform/redox/path.rs
··· 9 9 use redox_rt::signal::tmp_disable_signals; 10 10 use syscall::{data::Stat, error::*, flag::*}; 11 11 12 - use super::{libcscheme, FdGuard, Pal, Sys}; 12 + use super::{FdGuard, Pal, Sys, libcscheme}; 13 13 use crate::{ 14 14 error::Errno, 15 15 fs::File, ··· 18 18 sync::Mutex, 19 19 }; 20 20 21 - pub use redox_path::{canonicalize_using_cwd, RedoxPath}; 21 + pub use redox_path::{RedoxPath, canonicalize_using_cwd}; 22 22 23 23 // TODO: Define in syscall 24 24 const PATH_MAX: usize = 4096;
+9 -7
src/platform/redox/ptrace.rs
··· 4 4 //! we are NOT going to bend our API for the sake of 5 5 //! compatibility. So, this module will be a hellhole. 6 6 7 - use super::super::{types::*, Pal, PalPtrace, PalSignal, Sys, ERRNO}; 7 + use super::super::{ERRNO, Pal, PalPtrace, PalSignal, Sys, types::*}; 8 8 #[cfg(target_arch = "aarch64")] 9 9 use crate::header::arch_aarch64_user::user_regs_struct; 10 10 #[cfg(target_arch = "x86_64")] ··· 18 18 fcntl, signal, sys_ptrace, 19 19 }, 20 20 io::{self, prelude::*}, 21 + raw_cell::RawCell, 21 22 sync::Mutex, 22 23 }; 23 24 24 - use alloc::collections::{btree_map::Entry, BTreeMap}; 25 + use alloc::collections::{BTreeMap, btree_map::Entry}; 25 26 use core::mem; 26 27 use syscall; 27 28 ··· 44 45 } 45 46 46 47 #[thread_local] 47 - static mut STATE: Option<State> = None; 48 + static STATE: RawCell<Option<State>> = RawCell::new(None); 48 49 49 50 pub fn init_state() -> &'static State { 50 - // Safe due to STATE being thread_local 51 + // Safe due to STATE being thread_local (TODO: is it though?) 51 52 unsafe { 52 - if STATE.is_none() { 53 - STATE = Some(State::new()) 53 + if STATE.unsafe_ref().is_none() { 54 + *STATE.as_mut_ptr() = Some(State::new()) 54 55 } 55 - STATE.as_ref().unwrap() 56 + let state_ptr = STATE.unsafe_ref().as_ref().unwrap() as *const State; 57 + &*state_ptr 56 58 } 57 59 } 58 60 pub fn is_traceme(pid: pid_t) -> bool {
+4 -5
src/platform/redox/signal.rs
··· 1 1 use super::{ 2 - super::{types::*, Pal, PalSignal}, 2 + super::{Pal, PalSignal, types::*}, 3 3 Sys, 4 4 }; 5 5 use crate::{ ··· 7 7 header::{ 8 8 errno::{EINVAL, ENOSYS}, 9 9 signal::{ 10 - sigaction, siginfo_t, sigset_t, sigval, stack_t, ucontext_t, NSIG, SA_SIGINFO, 11 - SIGRTMIN, SIG_BLOCK, SIG_DFL, SIG_IGN, SIG_SETMASK, SIG_UNBLOCK, SS_DISABLE, 12 - SS_ONSTACK, 10 + NSIG, SA_SIGINFO, SIG_BLOCK, SIG_DFL, SIG_IGN, SIG_SETMASK, SIG_UNBLOCK, SIGRTMIN, 11 + SS_DISABLE, SS_ONSTACK, sigaction, siginfo_t, sigset_t, sigval, stack_t, ucontext_t, 13 12 }, 14 - sys_time::{itimerval, ITIMER_REAL}, 13 + sys_time::{ITIMER_REAL, itimerval}, 15 14 time::timespec, 16 15 }, 17 16 platform::ERRNO,
+8 -5
src/platform/redox/socket.rs
··· 7 7 use syscall::{self, flag::*}; 8 8 9 9 use super::{ 10 - super::{types::*, Pal, PalSocket, ERRNO}, 11 - path::dir_path_and_fd_path, 10 + super::{ERRNO, Pal, PalSocket, types::*}, 12 11 Sys, 12 + path::dir_path_and_fd_path, 13 13 }; 14 14 use crate::{ 15 15 error::{Errno, Result, ResultExt}, ··· 22 22 netinet_in::{in_addr, in_port_t, sockaddr_in}, 23 23 string::strnlen, 24 24 sys_socket::{ 25 - cmsghdr, constants::*, msghdr, sa_family_t, sockaddr, socklen_t, ucred, CMSG_ALIGN, 26 - CMSG_DATA, CMSG_FIRSTHDR, CMSG_LEN, CMSG_NXTHDR, CMSG_SPACE, 25 + CMSG_ALIGN, CMSG_DATA, CMSG_FIRSTHDR, CMSG_LEN, CMSG_NXTHDR, CMSG_SPACE, cmsghdr, 26 + constants::*, msghdr, sa_family_t, sockaddr, socklen_t, ucred, 27 27 }, 28 28 sys_time::timeval, 29 29 sys_uio::iovec, ··· 575 575 CallFlags::empty(), 576 576 &[SocketCall::Unbind as u64], 577 577 ) { 578 - eprintln!("bind: CRITICAL: failed to unbind socket after a failed transaction: {:?}", unbind_error); 578 + eprintln!( 579 + "bind: CRITICAL: failed to unbind socket after a failed transaction: {:?}", 580 + unbind_error 581 + ); 579 582 } 580 583 581 584 return Err(original_error);
+2 -2
src/platform/rlb.rs
··· 1 1 use alloc::vec::Vec; 2 2 3 - use crate::platform::{types::*, Pal, Sys}; 3 + use crate::platform::{Pal, Sys, types::*}; 4 4 5 5 use crate::{ 6 6 error::ResultExt, 7 - header::unistd::{lseek, SEEK_SET}, 7 + header::unistd::{SEEK_SET, lseek}, 8 8 }; 9 9 /// Implements an `Iterator` which returns on either newline or EOF. 10 10 #[derive(Clone)]
+1 -1
src/platform/test/mod.rs
··· 1 1 use crate::platform::{Pal, Sys}; 2 2 3 3 // Stub for call used in exit 4 - #[no_mangle] 4 + #[unsafe(no_mangle)] 5 5 pub extern "C" fn pthread_terminate() {} 6 6 7 7 mod epoll;
+5 -5
src/pthread/mod.rs
··· 2 2 3 3 use core::{ 4 4 cell::{Cell, UnsafeCell}, 5 - mem::{offset_of, MaybeUninit}, 6 - ptr::{self, addr_of, NonNull}, 5 + mem::{MaybeUninit, offset_of}, 6 + ptr::{self, NonNull, addr_of}, 7 7 sync::atomic::{AtomicBool, AtomicUsize, Ordering}, 8 8 }; 9 9 ··· 13 13 error::Errno, 14 14 header::{errno::*, pthread as header, sched::sched_param, sys_mman}, 15 15 ld_so::{ 16 + ExpectTlsFree, 16 17 linker::Linker, 17 18 tcb::{Master, Tcb}, 18 - ExpectTlsFree, 19 19 }, 20 - platform::{types::*, Pal, Sys}, 20 + platform::{Pal, Sys, types::*}, 21 21 }; 22 22 23 - use crate::sync::{waitval::Waitval, Mutex}; 23 + use crate::sync::{Mutex, waitval::Waitval}; 24 24 25 25 /// Called only by the main thread, as part of relibc_start. 26 26 pub unsafe fn init() {
+8 -8
src/raw_cell.rs
··· 14 14 } 15 15 } 16 16 #[inline] 17 - pub unsafe fn get(&self) -> T { 18 - self.inner.get().read() 19 - } 20 - #[inline] 21 - pub unsafe fn set(&self, t: T) { 22 - self.inner.get().write(t) 23 - } 24 - #[inline] 25 17 pub fn as_mut_ptr(&self) -> *mut T { 26 18 self.inner.get() 27 19 } ··· 32 24 #[inline] 33 25 pub fn into_inner(self) -> T { 34 26 self.inner.into_inner() 27 + } 28 + #[inline] 29 + pub unsafe fn unsafe_ref(&self) -> &T { 30 + &*self.inner.get() 31 + } 32 + #[inline] 33 + pub unsafe fn unsafe_mut(&self) -> &mut T { 34 + &mut *self.inner.get() 35 35 } 36 36 } 37 37
+13 -12
src/start.rs
··· 5 5 use generic_rt::ExpectTlsFree; 6 6 7 7 use crate::{ 8 + ALLOCATOR, 8 9 header::{libgen, stdio, stdlib}, 9 10 ld_so::{self, linker::Linker, tcb::Tcb}, 10 - platform::{self, get_auxvs, types::*, Pal, Sys}, 11 + platform::{self, Pal, Sys, get_auxvs, types::*}, 12 + raw_cell::RawCell, 11 13 sync::mutex::Mutex, 12 - ALLOCATOR, 13 14 }; 14 15 15 16 #[repr(C)] ··· 59 60 60 61 // Since Redox and Linux are so similar, it is easy to accidentally run a binary from one on the 61 62 // other. This will test that the current system is compatible with the current binary 62 - #[no_mangle] 63 + #[unsafe(no_mangle)] 63 64 pub unsafe fn relibc_verify_host() { 64 65 if !Sys::verify() { 65 66 intrinsics::abort(); 66 67 } 67 68 } 68 - #[link_section = ".init_array"] 69 + #[unsafe(link_section = ".init_array")] 69 70 #[used] 70 71 static INIT_ARRAY: [extern "C" fn(); 1] = [init_array]; 71 72 72 73 static mut init_complete: bool = false; 73 74 74 75 #[used] 75 - #[no_mangle] 76 + #[unsafe(no_mangle)] 76 77 static mut __relibc_init_environ: *mut *mut c_char = ptr::null_mut(); 77 78 78 79 fn alloc_init() { ··· 127 128 } 128 129 129 130 #[inline(never)] 130 - #[no_mangle] 131 + #[unsafe(no_mangle)] 131 132 pub unsafe extern "C" fn relibc_start_v1( 132 133 sp: &'static Stack, 133 134 main: unsafe extern "C" fn( ··· 136 137 envp: *mut *mut c_char, 137 138 ) -> c_int, 138 139 ) -> ! { 139 - extern "C" { 140 + unsafe extern "C" { 140 141 static __preinit_array_start: extern "C" fn(); 141 142 static __preinit_array_end: extern "C" fn(); 142 143 static __init_array_start: extern "C" fn(); ··· 183 184 // Set up argc and argv 184 185 let argc = sp.argc; 185 186 let argv = sp.argv(); 186 - platform::inner_argv = copy_string_array(argv, argc as usize); 187 - platform::argv = platform::inner_argv.as_mut_ptr(); 187 + *platform::inner_argv.as_mut_ptr() = copy_string_array(argv, argc as usize); 188 + platform::argv = platform::inner_argv.unsafe_mut().as_mut_ptr(); 188 189 // Special code for program_invocation_name and program_invocation_short_name 189 - if let Some(arg) = platform::inner_argv.get(0) { 190 + if let Some(arg) = platform::inner_argv.unsafe_ref().get(0) { 190 191 platform::program_invocation_name = *arg; 191 192 platform::program_invocation_short_name = libgen::basename(*arg); 192 193 } ··· 200 201 while !(*envp.add(len)).is_null() { 201 202 len += 1; 202 203 } 203 - platform::OUR_ENVIRON = copy_string_array(envp, len); 204 - platform::environ = platform::OUR_ENVIRON.as_mut_ptr(); 204 + *platform::OUR_ENVIRON.as_mut_ptr() = copy_string_array(envp, len); 205 + platform::environ = platform::OUR_ENVIRON.unsafe_mut().as_mut_ptr(); 205 206 } 206 207 207 208 let auxvs = get_auxvs(sp.auxv().cast());
+1 -1
src/sync/mod.rs
··· 27 27 time::timespec, 28 28 }, 29 29 out::Out, 30 - platform::{types::*, Pal, Sys}, 30 + platform::{Pal, Sys, types::*}, 31 31 }; 32 32 use core::{ 33 33 mem::MaybeUninit,
+1 -1
src/sync/pthread_mutex.rs
··· 9 9 pthread::*, 10 10 }; 11 11 12 - use crate::platform::{types::*, Pal, Sys}; 12 + use crate::platform::{Pal, Sys, types::*}; 13 13 14 14 use super::FutexWaitResult; 15 15
+1 -1
src/sync/semaphore.rs
··· 2 2 //TODO: improve implementation 3 3 4 4 use crate::{ 5 - header::time::{clock_gettime, timespec, CLOCK_MONOTONIC}, 5 + header::time::{CLOCK_MONOTONIC, clock_gettime, timespec}, 6 6 platform::types::*, 7 7 }; 8 8
+1 -1
tests/Cargo.toml
··· 2 2 name = "relibc-tests" 3 3 version = "0.1.0" 4 4 authors = ["Jeremy Soller <jeremy@system76.com>"] 5 - edition = "2018" 5 + edition = "2024" 6 6 7 7 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 8