From 4b77eb7b3017f969c09ce6b338756a9aabf7abc0 Mon Sep 17 00:00:00 2001 From: rice7th Date: Sun, 25 Feb 2024 20:43:51 +0100 Subject: [PATCH 01/11] Renamed `invalid_mut` to `without_provenance_mut`. --- c-scape/src/brk.rs | 10 +++++----- c-scape/src/process_.rs | 4 ++-- c-scape/src/syscall.rs | 42 ++++++++++++++++++++--------------------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/c-scape/src/brk.rs b/c-scape/src/brk.rs index 43e221f..64a15af 100644 --- a/c-scape/src/brk.rs +++ b/c-scape/src/brk.rs @@ -1,5 +1,5 @@ use crate::convert_res; -use core::ptr::{invalid_mut, null_mut}; +use core::ptr::{without_provenance_mut, null_mut}; use errno::{set_errno, Errno}; use libc::{c_int, c_void, intptr_t}; @@ -35,7 +35,7 @@ unsafe extern "C" fn sbrk(increment: intptr_t) -> *mut c_void { // Read the current value from the OS. old = match convert_res(rustix::runtime::brk(null_mut())) { Some(old) => old, - None => return invalid_mut(!0), + None => return without_provenance_mut(!0), }; } @@ -57,7 +57,7 @@ unsafe extern "C" fn sbrk(increment: intptr_t) -> *mut c_void { if !ok { CURRENT = old; set_errno(Errno(libc::ENOMEM)); - return invalid_mut(!0); + return without_provenance_mut(!0); } // Install the new address. @@ -65,7 +65,7 @@ unsafe extern "C" fn sbrk(increment: intptr_t) -> *mut c_void { Some(new) => new, None => { CURRENT = old; - return invalid_mut(!0); + return without_provenance_mut(!0); } }; @@ -74,7 +74,7 @@ unsafe extern "C" fn sbrk(increment: intptr_t) -> *mut c_void { // The `brk` syscall returns the old value if it failed. if new != want { set_errno(Errno(libc::ENOMEM)); - return invalid_mut(!0); + return without_provenance_mut(!0); } old diff --git a/c-scape/src/process_.rs b/c-scape/src/process_.rs index fcf9338..0f871de 100644 --- a/c-scape/src/process_.rs +++ b/c-scape/src/process_.rs @@ -189,8 +189,8 @@ unsafe extern "C" fn __getauxval(type_: c_ulong) -> *mut c_void { #[cfg(feature = "take-charge")] fn _getauxval(type_: c_ulong) -> *mut c_void { match type_ { - libc::AT_HWCAP => ptr::invalid_mut(rustix::param::linux_hwcap().0), - libc::AT_HWCAP2 => ptr::invalid_mut(rustix::param::linux_hwcap().1), + libc::AT_HWCAP => ptr::without_provenance_mut(rustix::param::linux_hwcap().0), + libc::AT_HWCAP2 => ptr::without_provenance_mut(rustix::param::linux_hwcap().1), _ => todo!("unrecognized __getauxval {}", type_), } } diff --git a/c-scape/src/syscall.rs b/c-scape/src/syscall.rs index c994782..a6bfa43 100644 --- a/c-scape/src/syscall.rs +++ b/c-scape/src/syscall.rs @@ -2,7 +2,7 @@ use crate::convert_res; #[cfg(feature = "thread")] use core::mem::zeroed; -use core::ptr::invalid_mut; +use core::ptr::without_provenance_mut; #[cfg(feature = "thread")] use core::ptr::null; use errno::{set_errno, Errno}; @@ -23,14 +23,14 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { let fd = args.arg::(); let buf = args.arg::<*mut c_void>(); let count = args.arg::(); - invalid_mut(libc::read(fd, buf, count) as _) + without_provenance_mut(libc::read(fd, buf, count) as _) } #[cfg(feature = "syscall-write")] libc::SYS_write => { let fd = args.arg::(); let buf = args.arg::<*const c_void>(); let count = args.arg::(); - invalid_mut(libc::write(fd, buf, count) as _) + without_provenance_mut(libc::write(fd, buf, count) as _) } #[cfg(feature = "syscall-open")] #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] @@ -45,7 +45,7 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { } else { libc::open(path, flags) }; - invalid_mut(fd as _) + without_provenance_mut(fd as _) } #[cfg(feature = "syscall-openat")] libc::SYS_openat => { @@ -60,15 +60,15 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { } else { libc::openat(dirfd, path, flags) }; - invalid_mut(fd as _) + without_provenance_mut(fd as _) } #[cfg(feature = "syscall-close")] libc::SYS_close => { let fd = args.arg::(); - invalid_mut(libc::close(fd) as _) + without_provenance_mut(libc::close(fd) as _) } #[cfg(feature = "syscall-getpid")] - libc::SYS_getpid => invalid_mut(rustix::process::getpid().as_raw_nonzero().get() as _), + libc::SYS_getpid => without_provenance_mut(rustix::process::getpid().as_raw_nonzero().get() as _), #[cfg(feature = "syscall-statx")] libc::SYS_statx => { let dirfd = args.arg::(); @@ -76,13 +76,13 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { let flags = args.arg::(); let mask = args.arg::(); let statxbuf = args.arg::<*mut libc::statx>(); - invalid_mut(libc::statx(dirfd, path, flags, mask, statxbuf) as _) + without_provenance_mut(libc::statx(dirfd, path, flags, mask, statxbuf) as _) } libc::SYS_getrandom => { let buf = args.arg::<*mut c_void>(); let len = args.arg::(); let flags = args.arg::(); - invalid_mut(libc::getrandom(buf, len, flags) as _) + without_provenance_mut(libc::getrandom(buf, len, flags) as _) } #[cfg(feature = "thread")] libc::SYS_futex => { @@ -92,23 +92,23 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { let timeout = args.arg::<*const libc::timespec>(); let uaddr2 = args.arg::<*mut u32>(); let val3 = args.arg::(); - invalid_mut(futex(uaddr, futex_op, val, timeout, uaddr2, val3) as isize as usize) + without_provenance_mut(futex(uaddr, futex_op, val, timeout, uaddr2, val3) as isize as usize) } libc::SYS_clone3 => { // ensure std::process uses fork as fallback code on linux set_errno(Errno(libc::ENOSYS)); - invalid_mut(!0) + without_provenance_mut(!0) } #[cfg(feature = "syscall-epoll_create1")] libc::SYS_epoll_create1 => { let flags = args.arg::(); - invalid_mut(libc::epoll_create(flags) as isize as usize) + without_provenance_mut(libc::epoll_create(flags) as isize as usize) } #[cfg(feature = "syscall-timerfd_create")] libc::SYS_timerfd_create => { let clockid = args.arg::(); let flags = args.arg::(); - invalid_mut(libc::timerfd_create(clockid, flags) as isize as usize) + without_provenance_mut(libc::timerfd_create(clockid, flags) as isize as usize) } #[cfg(feature = "syscall-timerfd_settime")] libc::SYS_timerfd_settime => { @@ -116,7 +116,7 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { let flags = args.arg::(); let new_value = args.arg::<*const libc::itimerspec>(); let old_value = args.arg::<*mut libc::itimerspec>(); - invalid_mut(libc::timerfd_settime(fd, flags, new_value, old_value) as isize as usize) + without_provenance_mut(libc::timerfd_settime(fd, flags, new_value, old_value) as isize as usize) } #[cfg(feature = "syscall-utimensat")] libc::SYS_utimensat => { @@ -129,34 +129,34 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { if path.is_null() { if flags != 0 { set_errno(Errno(libc::EINVAL)); - invalid_mut(-1 as isize as usize) + without_provenance_mut(-1 as isize as usize) } else { - invalid_mut(libc::futimens(fd, times) as isize as usize) + without_provenance_mut(libc::futimens(fd, times) as isize as usize) } } else { - invalid_mut(libc::utimensat(fd, path, times, flags) as isize as usize) + without_provenance_mut(libc::utimensat(fd, path, times, flags) as isize as usize) } } #[cfg(feature = "syscall-fdatasync")] libc::SYS_fdatasync => { let fd = args.arg::(); - invalid_mut(libc::fdatasync(fd) as isize as usize) + without_provenance_mut(libc::fdatasync(fd) as isize as usize) } #[cfg(feature = "syscall-syncfs")] libc::SYS_syncfs => { let fd = args.arg::(); - invalid_mut(libc::syncfs(fd) as isize as usize) + without_provenance_mut(libc::syncfs(fd) as isize as usize) } #[cfg(feature = "syscall-sync")] libc::SYS_sync => { libc::sync(); - invalid_mut(0) + without_provenance_mut(0) } #[cfg(feature = "syscall-pipe2")] libc::SYS_pipe2 => { let pipefd = args.arg::<*mut c_int>(); let flags = args.arg::(); - invalid_mut(libc::pipe2(pipefd, flags) as isize as usize) + without_provenance_mut(libc::pipe2(pipefd, flags) as isize as usize) } _ => unimplemented!( "syscall({:?}); maybe try enabling the \"extra-syscalls\" feature", From 09f0195a34d6cce6fc109cfbba9ba6be276691ff Mon Sep 17 00:00:00 2001 From: rice7th Date: Mon, 26 Feb 2024 16:24:49 +0100 Subject: [PATCH 02/11] Bump nightly version --- c-scape/src/brk.rs | 2 +- c-scape/src/syscall.rs | 14 ++++++++++---- rust-toolchain.toml | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/c-scape/src/brk.rs b/c-scape/src/brk.rs index 64a15af..156076a 100644 --- a/c-scape/src/brk.rs +++ b/c-scape/src/brk.rs @@ -1,5 +1,5 @@ use crate::convert_res; -use core::ptr::{without_provenance_mut, null_mut}; +use core::ptr::{null_mut, without_provenance_mut}; use errno::{set_errno, Errno}; use libc::{c_int, c_void, intptr_t}; diff --git a/c-scape/src/syscall.rs b/c-scape/src/syscall.rs index a6bfa43..15c09e9 100644 --- a/c-scape/src/syscall.rs +++ b/c-scape/src/syscall.rs @@ -2,9 +2,9 @@ use crate::convert_res; #[cfg(feature = "thread")] use core::mem::zeroed; -use core::ptr::without_provenance_mut; #[cfg(feature = "thread")] use core::ptr::null; +use core::ptr::without_provenance_mut; use errno::{set_errno, Errno}; #[cfg(feature = "extra-syscalls")] use libc::{c_char, size_t}; @@ -68,7 +68,9 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { without_provenance_mut(libc::close(fd) as _) } #[cfg(feature = "syscall-getpid")] - libc::SYS_getpid => without_provenance_mut(rustix::process::getpid().as_raw_nonzero().get() as _), + libc::SYS_getpid => { + without_provenance_mut(rustix::process::getpid().as_raw_nonzero().get() as _) + } #[cfg(feature = "syscall-statx")] libc::SYS_statx => { let dirfd = args.arg::(); @@ -92,7 +94,9 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { let timeout = args.arg::<*const libc::timespec>(); let uaddr2 = args.arg::<*mut u32>(); let val3 = args.arg::(); - without_provenance_mut(futex(uaddr, futex_op, val, timeout, uaddr2, val3) as isize as usize) + without_provenance_mut( + futex(uaddr, futex_op, val, timeout, uaddr2, val3) as isize as usize + ) } libc::SYS_clone3 => { // ensure std::process uses fork as fallback code on linux @@ -116,7 +120,9 @@ unsafe extern "C" fn syscall(number: c_long, mut args: ...) -> *mut c_void { let flags = args.arg::(); let new_value = args.arg::<*const libc::itimerspec>(); let old_value = args.arg::<*mut libc::itimerspec>(); - without_provenance_mut(libc::timerfd_settime(fd, flags, new_value, old_value) as isize as usize) + without_provenance_mut( + libc::timerfd_settime(fd, flags, new_value, old_value) as isize as usize, + ) } #[cfg(feature = "syscall-utimensat")] libc::SYS_utimensat => { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 04f37c3..c9a29fc 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-12-19" +channel = "nightly-2024-02-26" components = ["rustc", "cargo", "rust-std", "rust-src", "rustfmt"] From 57424e38973f7215ad20c754db212db0326d0072 Mon Sep 17 00:00:00 2001 From: rice7th Date: Tue, 27 Feb 2024 17:46:52 +0100 Subject: [PATCH 03/11] Use `addr_of_mut!()` instead of `&mut STATIC` --- c-scape/src/fs/xattr.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/c-scape/src/fs/xattr.rs b/c-scape/src/fs/xattr.rs index 99720be..49b49c7 100644 --- a/c-scape/src/fs/xattr.rs +++ b/c-scape/src/fs/xattr.rs @@ -26,7 +26,7 @@ unsafe extern "C" fn getxattr( match convert_res(rustix::fs::getxattr( path, name, - &mut READ_BUFFER[..min(len, READ_BUFFER.len())], + addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -56,7 +56,7 @@ unsafe extern "C" fn lgetxattr( match convert_res(rustix::fs::lgetxattr( path, name, - &mut READ_BUFFER[..min(len, READ_BUFFER.len())], + addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -86,7 +86,7 @@ unsafe extern "C" fn fgetxattr( match convert_res(rustix::fs::fgetxattr( fd, name, - &mut READ_BUFFER[..min(len, READ_BUFFER.len())], + addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -169,7 +169,7 @@ unsafe extern "C" fn listxattr(path: *const c_char, list: *mut c_char, len: size // a slice, use a temporary copy. match convert_res(rustix::fs::listxattr( path, - &mut READ_BUFFER[..min(len, READ_BUFFER.len())], + addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -192,7 +192,7 @@ unsafe extern "C" fn llistxattr(path: *const c_char, list: *mut c_char, len: siz // a slice, use a temporary copy. match convert_res(rustix::fs::llistxattr( path, - &mut READ_BUFFER[..min(len, READ_BUFFER.len())], + addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -215,7 +215,7 @@ unsafe extern "C" fn flistxattr(fd: c_int, list: *mut c_char, len: size_t) -> ss // a slice, use a temporary copy. match convert_res(rustix::fs::flistxattr( fd, - &mut READ_BUFFER[..min(len, READ_BUFFER.len())], + addr_of_mut!([..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. From 9f4905814f4bec9b9adac3879ff5cf6c28a375f1 Mon Sep 17 00:00:00 2001 From: rice7th Date: Tue, 27 Feb 2024 18:27:46 +0100 Subject: [PATCH 04/11] Bump c-ward, c-scape and c-gull version to `0.15.50` to make obvious the various feature changes introduced by origin `0.18.x` --- Cargo.toml | 2 +- c-gull/Cargo.toml | 4 ++-- c-scape/Cargo.toml | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3e1688f..d29c3d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c-ward" -version = "0.15.40" +version = "0.15.50" authors = [ "Dan Gohman ", ] diff --git a/c-gull/Cargo.toml b/c-gull/Cargo.toml index 644122a..77e3158 100644 --- a/c-gull/Cargo.toml +++ b/c-gull/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c-gull" -version = "0.15.40" +version = "0.15.50" authors = [ "Dan Gohman ", ] @@ -15,7 +15,7 @@ keywords = ["linux", "libc"] # We use the libc crate for C ABI types and constants, but we don't depend on # the actual platform libc. libc = { version = "0.2.138", default-features = false } -c-scape = { path = "../c-scape", version = "0.15.40", default-features = false } +c-scape = { path = "../c-scape", version = "0.15.50", default-features = false } errno = { version = "0.3.3", default-features = false, optional = true } tz-rs = { version = "0.6.11", default-features = false, optional = true } rustix = { version = "0.38.31", default-features = false, optional = true, features = ["fs", "itoa", "net", "param", "process", "procfs", "rand", "termios", "thread", "time"] } diff --git a/c-scape/Cargo.toml b/c-scape/Cargo.toml index 26b5787..5cf565f 100644 --- a/c-scape/Cargo.toml +++ b/c-scape/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c-scape" -version = "0.15.40" +version = "0.15.50" authors = [ "Dan Gohman ", ] @@ -23,7 +23,7 @@ rustix = { version = "0.38.31", default-features = false, features = ["event", " rustix-futex-sync = { version = "0.2.1", features = ["atomic_usize"] } memoffset = "0.9.0" realpath-ext = { version = "0.1.0", default-features = false } -origin = { version = "0.17.0", default-features = false, features = ["thread", "init-fini-arrays", "alloc"] } +origin = { version = "0.18.1", default-features = false, features = ["thread", "init-fini-arrays", "alloc"] } # We use the libc crate for C ABI types and constants, but we don't depend on # the actual platform libc. libc = { version = "0.2.138", default-features = false } @@ -64,7 +64,7 @@ static_assertions = "1.1.0" [features] default = ["thread", "std", "coexist-with-libc", "threadsafe-setenv", "use-compiler-builtins"] -thread = ["origin/set_thread_id"] +thread = [] # set_thread_id is not behind a feature anymore. std = ["rustix/std", "printf-compat/std"] # In "take-charge" mode, this enables code in c-scape to define the From 3464394df4491a596b9a3d08dfe31fcedb12be93 Mon Sep 17 00:00:00 2001 From: rice7th Date: Tue, 27 Feb 2024 18:38:49 +0100 Subject: [PATCH 05/11] Fixed references to `static mut`s, removed stabilized features' gates. --- c-scape/src/errno_.rs | 4 ++-- c-scape/src/fs/xattr.rs | 14 +++++++------- c-scape/src/lib.rs | 1 - tests/example_crates.rs | 1 - 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/c-scape/src/errno_.rs b/c-scape/src/errno_.rs index 99a754d..f5fb970 100644 --- a/c-scape/src/errno_.rs +++ b/c-scape/src/errno_.rs @@ -1,7 +1,7 @@ use alloc::borrow::ToOwned; use alloc::format; use core::cell::SyncUnsafeCell; -use core::ptr::{copy_nonoverlapping, null_mut}; +use core::ptr::{addr_of_mut, copy_nonoverlapping, null_mut}; use libc::{c_char, c_int}; /// Return the address of the thread-local `errno` state. @@ -15,7 +15,7 @@ unsafe extern "C" fn __errno_location() -> *mut c_int { #[cfg_attr(feature = "thread", thread_local)] static mut ERRNO: i32 = 0; - &mut ERRNO + addr_of_mut!(ERRNO) } #[no_mangle] diff --git a/c-scape/src/fs/xattr.rs b/c-scape/src/fs/xattr.rs index 49b49c7..f174e33 100644 --- a/c-scape/src/fs/xattr.rs +++ b/c-scape/src/fs/xattr.rs @@ -3,7 +3,7 @@ use crate::{convert_res, READ_BUFFER}; use core::cmp::min; use core::ffi::CStr; -use core::ptr::copy_nonoverlapping; +use core::ptr::{addr_of_mut, copy_nonoverlapping}; use core::slice; use libc::{c_char, c_int, c_void, size_t, ssize_t}; use rustix::fd::BorrowedFd; @@ -26,7 +26,7 @@ unsafe extern "C" fn getxattr( match convert_res(rustix::fs::getxattr( path, name, - addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), + &mut *addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -56,7 +56,7 @@ unsafe extern "C" fn lgetxattr( match convert_res(rustix::fs::lgetxattr( path, name, - addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), + &mut *addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -86,7 +86,7 @@ unsafe extern "C" fn fgetxattr( match convert_res(rustix::fs::fgetxattr( fd, name, - addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), + &mut *addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -169,7 +169,7 @@ unsafe extern "C" fn listxattr(path: *const c_char, list: *mut c_char, len: size // a slice, use a temporary copy. match convert_res(rustix::fs::listxattr( path, - addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), + &mut *addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -192,7 +192,7 @@ unsafe extern "C" fn llistxattr(path: *const c_char, list: *mut c_char, len: siz // a slice, use a temporary copy. match convert_res(rustix::fs::llistxattr( path, - addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), + &mut *addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. @@ -215,7 +215,7 @@ unsafe extern "C" fn flistxattr(fd: c_int, list: *mut c_char, len: size_t) -> ss // a slice, use a temporary copy. match convert_res(rustix::fs::flistxattr( fd, - addr_of_mut!([..min(len, READ_BUFFER.len())]), + &mut *addr_of_mut!(READ_BUFFER[..min(len, READ_BUFFER.len())]), )) { Some(size) => { // If `size` is 0, `value` could be null. diff --git a/c-scape/src/lib.rs b/c-scape/src/lib.rs index 5492585..2aba49b 100644 --- a/c-scape/src/lib.rs +++ b/c-scape/src/lib.rs @@ -7,7 +7,6 @@ #![feature(exposed_provenance)] #![feature(inline_const)] #![feature(sync_unsafe_cell)] -#![feature(ip_in_core)] #![feature(linkage)] #![deny(fuzzy_provenance_casts, lossy_provenance_casts)] diff --git a/tests/example_crates.rs b/tests/example_crates.rs index 1a7e746..f77a8b9 100644 --- a/tests/example_crates.rs +++ b/tests/example_crates.rs @@ -1,7 +1,6 @@ //! Run the programs in the `example-crates` directory and compare their //! outputs with expected outputs. -#![feature(cfg_target_abi)] use std::sync::OnceLock; From 773d81e546275cf33259b04ffde4398fa3791825 Mon Sep 17 00:00:00 2001 From: rice7th Date: Tue, 27 Feb 2024 18:45:28 +0100 Subject: [PATCH 06/11] Removed `std::convert::TryInto` imports since they were redundant. --- c-scape/src/fs/dir/readdir.rs | 1 - c-scape/src/fs/lseek.rs | 1 - c-scape/src/fs/stat.rs | 1 - c-scape/src/io/mod.rs | 1 - c-scape/src/io/poll.rs | 1 - c-scape/src/net/mod.rs | 1 - c-scape/src/thread/mod.rs | 1 - c-scape/src/time/mod.rs | 2 -- 8 files changed, 9 deletions(-) diff --git a/c-scape/src/fs/dir/readdir.rs b/c-scape/src/fs/dir/readdir.rs index 9fe4990..8557da3 100644 --- a/c-scape/src/fs/dir/readdir.rs +++ b/c-scape/src/fs/dir/readdir.rs @@ -1,4 +1,3 @@ -use core::convert::TryInto; use core::mem::transmute; use core::ptr::null_mut; diff --git a/c-scape/src/fs/lseek.rs b/c-scape/src/fs/lseek.rs index 7aadffb..b37e53d 100644 --- a/c-scape/src/fs/lseek.rs +++ b/c-scape/src/fs/lseek.rs @@ -1,5 +1,4 @@ use crate::convert_res; -use core::convert::TryInto; use errno::{set_errno, Errno}; use libc::{c_int, off64_t, off_t}; use rustix::fd::BorrowedFd; diff --git a/c-scape/src/fs/stat.rs b/c-scape/src/fs/stat.rs index db2e916..ac4b972 100644 --- a/c-scape/src/fs/stat.rs +++ b/c-scape/src/fs/stat.rs @@ -1,4 +1,3 @@ -use core::convert::TryInto; use core::ffi::CStr; use core::mem::size_of_val; use core::ptr::{addr_of, addr_of_mut, copy_nonoverlapping}; diff --git a/c-scape/src/io/mod.rs b/c-scape/src/io/mod.rs index 979faa1..f2ada4b 100644 --- a/c-scape/src/io/mod.rs +++ b/c-scape/src/io/mod.rs @@ -15,7 +15,6 @@ mod write; use rustix::event::EventfdFlags; use rustix::fd::{BorrowedFd, IntoRawFd}; -use core::convert::TryInto; use libc::{c_int, c_long, c_uint}; use crate::convert_res; diff --git a/c-scape/src/io/poll.rs b/c-scape/src/io/poll.rs index 733ebac..e6dba1e 100644 --- a/c-scape/src/io/poll.rs +++ b/c-scape/src/io/poll.rs @@ -1,4 +1,3 @@ -use core::convert::TryInto; use core::slice; use libc::c_int; diff --git a/c-scape/src/net/mod.rs b/c-scape/src/net/mod.rs index 6a1a499..a2bd387 100644 --- a/c-scape/src/net/mod.rs +++ b/c-scape/src/net/mod.rs @@ -1,7 +1,6 @@ mod inet; use core::cmp::min; -use core::convert::TryInto; use core::ffi::c_void; #[cfg(not(target_os = "wasi"))] use core::mem::size_of; diff --git a/c-scape/src/thread/mod.rs b/c-scape/src/thread/mod.rs index 4076546..56f9737 100644 --- a/c-scape/src/thread/mod.rs +++ b/c-scape/src/thread/mod.rs @@ -3,7 +3,6 @@ mod key; use crate::GetThreadId; use alloc::boxed::Box; use alloc::format; -use core::convert::TryInto; use core::ffi::c_void; use core::mem::{align_of, size_of, transmute, zeroed, ManuallyDrop, MaybeUninit}; use core::ptr::{self, copy_nonoverlapping, null_mut, NonNull}; diff --git a/c-scape/src/time/mod.rs b/c-scape/src/time/mod.rs index 9e626be..8ee06e1 100644 --- a/c-scape/src/time/mod.rs +++ b/c-scape/src/time/mod.rs @@ -1,5 +1,3 @@ -use core::convert::TryInto; - use errno::{set_errno, Errno}; use libc::{c_int, c_uint}; From e62cecff2a9b681ab9b614e165dfdb40e1161fae Mon Sep 17 00:00:00 2001 From: rice7th Date: Tue, 27 Feb 2024 18:49:29 +0100 Subject: [PATCH 07/11] Fixed more references to `static mut`s by replacing them with `addr_of_mut!()` --- c-gull/src/nss.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/c-gull/src/nss.rs b/c-gull/src/nss.rs index 7eb6ae5..cf83e2c 100644 --- a/c-gull/src/nss.rs +++ b/c-gull/src/nss.rs @@ -9,7 +9,7 @@ use core::ffi::CStr; use core::mem::{align_of, zeroed}; -use core::ptr::{copy_nonoverlapping, null, null_mut, write}; +use core::ptr::{addr_of_mut, copy_nonoverlapping, null, null_mut, write}; use core::str; use core::str::FromStr; use errno::{set_errno, Errno}; @@ -677,7 +677,7 @@ unsafe fn getserv_r( // musl returns just the protocol name as the alias list. The intersection // of these two that portable code is obliged to assume is an empty list. static mut STATIC_SERVENT_ALIASES: *mut c_char = null_mut(); - let s_aliases = &mut STATIC_SERVENT_ALIASES; + let s_aliases = &mut *addr_of_mut!(STATIC_SERVENT_ALIASES); let mut command = command; let output = match command.output() { @@ -806,7 +806,7 @@ unsafe extern "C" fn getservbyname( libc!(libc::getservbyname(name, proto)); let mut result = null_mut(); - if getservbyname_r(name, proto, &mut STATIC_SERVENT, null_mut(), 0, &mut result) == 0 { + if getservbyname_r(name, proto, addr_of_mut!(STATIC_SERVENT), null_mut(), 0, &mut result) == 0 { result } else { null_mut() @@ -822,7 +822,7 @@ unsafe extern "C" fn getservbyport(port: c_int, proto: *const c_char) -> *mut li if getservbyport_r( port, proto, - &mut STATIC_SERVENT, + addr_of_mut!(STATIC_SERVENT), buf.as_mut_ptr(), buf.len(), &mut result, From 251cc9b4c8f9f1a87860c89bff4706d97022e2ae Mon Sep 17 00:00:00 2001 From: rice7th Date: Tue, 27 Feb 2024 18:50:23 +0100 Subject: [PATCH 08/11] Fix last import warning to pass all tests. --- c-gull/src/termios_.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/c-gull/src/termios_.rs b/c-gull/src/termios_.rs index fbf90d9..1c0dbc9 100644 --- a/c-gull/src/termios_.rs +++ b/c-gull/src/termios_.rs @@ -6,7 +6,6 @@ use crate::convert_res; use alloc::ffi::CString; -use alloc::vec::Vec; use core::cell::SyncUnsafeCell; use core::ptr::{copy_nonoverlapping, null_mut}; use libc::{c_char, c_int, size_t}; From 83193dec9703e958222ed3ce87a758812eae1d3a Mon Sep 17 00:00:00 2001 From: rice7th Date: Tue, 27 Feb 2024 18:54:20 +0100 Subject: [PATCH 09/11] Run `cargo fmt`. --- c-gull/src/nss.rs | 10 +++++++++- tests/example_crates.rs | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/c-gull/src/nss.rs b/c-gull/src/nss.rs index cf83e2c..01b13c3 100644 --- a/c-gull/src/nss.rs +++ b/c-gull/src/nss.rs @@ -806,7 +806,15 @@ unsafe extern "C" fn getservbyname( libc!(libc::getservbyname(name, proto)); let mut result = null_mut(); - if getservbyname_r(name, proto, addr_of_mut!(STATIC_SERVENT), null_mut(), 0, &mut result) == 0 { + if getservbyname_r( + name, + proto, + addr_of_mut!(STATIC_SERVENT), + null_mut(), + 0, + &mut result, + ) == 0 + { result } else { null_mut() diff --git a/tests/example_crates.rs b/tests/example_crates.rs index f77a8b9..d369767 100644 --- a/tests/example_crates.rs +++ b/tests/example_crates.rs @@ -1,7 +1,6 @@ //! Run the programs in the `example-crates` directory and compare their //! outputs with expected outputs. - use std::sync::OnceLock; fn test_crate( From 6fa48971711c40fbbbe4dc45cab10adc574682d5 Mon Sep 17 00:00:00 2001 From: rice7th Date: Wed, 28 Feb 2024 23:44:31 +0100 Subject: [PATCH 10/11] De-bumped version number and removed ambiguous comment. --- Cargo.toml | 2 +- c-gull/Cargo.toml | 2 +- c-scape/Cargo.toml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d29c3d1..3e1688f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c-ward" -version = "0.15.50" +version = "0.15.40" authors = [ "Dan Gohman ", ] diff --git a/c-gull/Cargo.toml b/c-gull/Cargo.toml index 77e3158..1f11c8d 100644 --- a/c-gull/Cargo.toml +++ b/c-gull/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c-gull" -version = "0.15.50" +version = "0.15.40" authors = [ "Dan Gohman ", ] diff --git a/c-scape/Cargo.toml b/c-scape/Cargo.toml index 5cf565f..05e0e1e 100644 --- a/c-scape/Cargo.toml +++ b/c-scape/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c-scape" -version = "0.15.50" +version = "0.15.40" authors = [ "Dan Gohman ", ] @@ -64,7 +64,7 @@ static_assertions = "1.1.0" [features] default = ["thread", "std", "coexist-with-libc", "threadsafe-setenv", "use-compiler-builtins"] -thread = [] # set_thread_id is not behind a feature anymore. +thread = [] std = ["rustix/std", "printf-compat/std"] # In "take-charge" mode, this enables code in c-scape to define the From 836a97772bb397f9036a02752c2dcaa96167a6b2 Mon Sep 17 00:00:00 2001 From: rice7th Date: Wed, 28 Feb 2024 23:46:09 +0100 Subject: [PATCH 11/11] Fix wrong version number. --- c-gull/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c-gull/Cargo.toml b/c-gull/Cargo.toml index 1f11c8d..644122a 100644 --- a/c-gull/Cargo.toml +++ b/c-gull/Cargo.toml @@ -15,7 +15,7 @@ keywords = ["linux", "libc"] # We use the libc crate for C ABI types and constants, but we don't depend on # the actual platform libc. libc = { version = "0.2.138", default-features = false } -c-scape = { path = "../c-scape", version = "0.15.50", default-features = false } +c-scape = { path = "../c-scape", version = "0.15.40", default-features = false } errno = { version = "0.3.3", default-features = false, optional = true } tz-rs = { version = "0.6.11", default-features = false, optional = true } rustix = { version = "0.38.31", default-features = false, optional = true, features = ["fs", "itoa", "net", "param", "process", "procfs", "rand", "termios", "thread", "time"] }