Skip to content

Commit ac1e47f

Browse files
authored
Update to rustix 1.0. (#159)
* Update to rustix 1.0.
1 parent 5172254 commit ac1e47f

33 files changed

Lines changed: 916 additions & 399 deletions

File tree

c-gull/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ libc = { version = "0.2.155", default-features = false }
1818
c-scape = { path = "../c-scape", version = "0.21.0", default-features = false }
1919
errno = { version = "0.3.3", default-features = false, optional = true }
2020
tz-rs = { version = "0.7.0", default-features = false, optional = true }
21-
rustix = { version = "0.38.31", default-features = false, optional = true, features = ["fs", "itoa", "net", "param", "process", "procfs", "rand", "termios", "thread", "time"] }
21+
rustix = { version = "1.0.0", default-features = false, optional = true, features = ["fs", "net", "param", "process", "rand", "termios", "thread", "time"] }
2222

2323
[features]
2424
default = ["thread", "std", "coexist-with-libc", "threadsafe-setenv"]

c-gull/src/resolve.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use std::process::Command;
1111
use errno::{errno, set_errno, Errno};
1212
use libc::{c_char, c_int, size_t};
1313
use rustix::net::{
14-
IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrAny, SocketAddrStorage, SocketAddrV4,
15-
SocketAddrV6,
14+
addr::SocketAddrArg, addr::SocketAddrStorage, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr,
15+
SocketAddrV4, SocketAddrV6,
1616
};
1717

1818
// TODO: Upstream this.
@@ -141,21 +141,20 @@ unsafe extern "C" fn getaddrinfo(
141141
} else {
142142
Ipv4Addr::LOCALHOST
143143
};
144-
SocketAddrAny::V4(SocketAddrV4::new(addr, port))
144+
SocketAddrV4::new(addr, port).write_sockaddr(storage)
145145
}
146146
libc::AF_INET6 => {
147147
let addr = if is_passive {
148148
Ipv6Addr::UNSPECIFIED
149149
} else {
150150
Ipv6Addr::LOCALHOST
151151
};
152-
SocketAddrAny::V6(SocketAddrV6::new(addr, port, 0, 0))
152+
SocketAddrV6::new(addr, port, 0, 0).write_sockaddr(storage)
153153
}
154154
_ => unreachable!(),
155-
}
156-
.write(storage);
155+
};
157156
info.ai_addr = storage.cast();
158-
info.ai_addrlen = len.try_into().unwrap();
157+
info.ai_addrlen = len;
159158

160159
if !prev.is_null() {
161160
(*prev).ai_next = ptr;
@@ -215,9 +214,9 @@ unsafe extern "C" fn getaddrinfo(
215214
let info = &mut *ptr;
216215

217216
let storage = alloc::alloc::alloc(addr_layout).cast::<SocketAddrStorage>();
218-
let len = SocketAddrAny::from(SocketAddr::new(addr, port)).write(storage);
217+
let len = SocketAddr::new(addr, port).write_sockaddr(storage);
219218
info.ai_addr = storage.cast();
220-
info.ai_addrlen = len.try_into().unwrap();
219+
info.ai_addrlen = len;
221220
*res = ptr;
222221
return 0;
223222
}
@@ -237,9 +236,9 @@ unsafe extern "C" fn getaddrinfo(
237236
{
238237
let storage =
239238
alloc::alloc::alloc(addr_layout).cast::<SocketAddrStorage>();
240-
let len = SocketAddrAny::V4(SocketAddrV4::new(v4, port)).write(storage);
239+
let len = SocketAddrV4::new(v4, port).write_sockaddr(storage);
241240
info.ai_addr = storage.cast();
242-
info.ai_addrlen = len.try_into().unwrap();
241+
info.ai_addrlen = len;
243242
info.ai_family = libc::AF_INET;
244243
}
245244
}
@@ -249,8 +248,7 @@ unsafe extern "C" fn getaddrinfo(
249248
{
250249
let storage =
251250
alloc::alloc::alloc(addr_layout).cast::<SocketAddrStorage>();
252-
let len =
253-
SocketAddrAny::V6(SocketAddrV6::new(v6, port, 0, 0)).write(storage);
251+
let len = SocketAddrV6::new(v6, port, 0, 0).write_sockaddr(storage);
254252
info.ai_addr = storage.cast();
255253
info.ai_addrlen = len.try_into().unwrap();
256254
info.ai_family = libc::AF_INET6;

c-scape/Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ cc = { version = "1.0.68", optional = true }
1919

2020
[dependencies]
2121
libm = "0.2.1"
22-
rustix = { version = "0.38.35", default-features = false, features = ["event", "fs", "itoa", "mm", "net", "param", "pipe", "process", "rand", "runtime", "shm", "stdio", "system", "termios", "thread", "time"] }
23-
rustix-futex-sync = { version = "0.2.1", features = ["atomic_usize"] }
22+
rustix = { version = "1.0.0", default-features = false, features = ["event", "fs", "mm", "net", "param", "pipe", "process", "pty", "rand", "runtime", "shm", "stdio", "system", "termios", "thread", "time"] }
23+
rustix-futex-sync = { version = "0.3.0", features = ["atomic_usize"] }
2424
memoffset = "0.9.0"
2525
realpath-ext = { version = "0.1.0", default-features = false }
26-
origin = { version = "0.24.0", default-features = false, features = ["init-fini-arrays", "program-at-exit", "thread-at-exit", "nightly", "getauxval"] }
26+
origin = { version = "0.25.0", default-features = false, features = ["init-fini-arrays", "program-at-exit", "thread-at-exit", "nightly", "getauxval"] }
2727
# We use the libc crate for C ABI types and constants, but we don't depend on
2828
# the actual platform libc.
2929
libc = { version = "0.2.155", default-features = false }
3030
errno = { version = "0.3.3", default-features = false }
31-
rand_pcg = "0.3.1"
32-
rand_core = { version = "0.6.4", features = ["getrandom"] }
33-
rand = { version = "0.8.5", default-features = false }
34-
rustix-dlmalloc = { version = "0.1.0", optional = true }
35-
rustix-openpty = "0.1.1"
31+
rand_pcg = "0.9.0"
32+
rand_core = { version = "0.9.3", features = ["os_rng"] }
33+
rand = { version = "0.9.0", default-features = false }
34+
rustix-dlmalloc = { version = "0.2.1", optional = true }
35+
rustix-openpty = "0.2.0"
3636
bitflags = { version = "2.4.1", default-features = false }
3737
printf-compat = { version = "0.1.1", default-features = false }
3838
num-complex = { version = "0.4.4", default-features = false, features = ["libm"] }

c-scape/build.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ fn main() {
1616
link_in_empty(name);
1717
}
1818
}
19+
20+
let os = var("CARGO_CFG_TARGET_OS").unwrap();
21+
22+
if os == "linux" || os == "l4re" || os == "android" || os == "emscripten" {
23+
use_feature("linux_like");
24+
}
25+
26+
// Add some additional common target combinations.
27+
28+
// Android and "regular" Linux both use the Linux kernel.
29+
if os == "android" || os == "linux" {
30+
use_feature("linux_kernel");
31+
}
1932
}
2033

2134
fn link_in_empty(name: &str) {
@@ -63,3 +76,7 @@ fn link_in_empty(name: &str) {
6376
);
6477
}
6578
}
79+
80+
fn use_feature(feature: &str) {
81+
println!("cargo:rustc-cfg={}", feature);
82+
}

c-scape/src/at_fork.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ pub(crate) fn at_fork(
4949
///
5050
/// # Safety
5151
///
52-
/// Wildly unsafe. See the documentation comment for [`rustix::runtime::fork`].
53-
/// On top of that, this calls the unsafe functions registered with
54-
/// [`at_fork`].
52+
/// Wildly unsafe. See the documentation comment for
53+
/// [`rustix::runtime::kernel_fork`]. On top of that, this calls the unsafe
54+
/// functions registered with [`at_fork`].
5555
pub(crate) unsafe fn fork() -> rustix::io::Result<Option<rustix::process::Pid>> {
5656
let funcs = FORK_FUNCS.lock();
5757

5858
// Callbacks before calling `fork`.
5959
funcs.prepare.iter().rev().for_each(|func| func());
6060

6161
// Call `fork`.
62-
match rustix::runtime::fork()? {
62+
match rustix::runtime::kernel_fork()? {
6363
rustix::runtime::Fork::Child(pid) => {
6464
// The child's thread record is copied from the parent;
6565
// update it with the child's current-thread-id.
@@ -72,7 +72,7 @@ pub(crate) unsafe fn fork() -> rustix::io::Result<Option<rustix::process::Pid>>
7272
funcs.child.iter().for_each(|func| func());
7373
Ok(None)
7474
}
75-
rustix::runtime::Fork::Parent(child_pid) => {
75+
rustix::runtime::Fork::ParentOf(child_pid) => {
7676
// Callbacks after calling `fork`, in the parent.
7777
funcs.parent.iter().for_each(|func| func());
7878
Ok(Some(child_pid))

c-scape/src/brk.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static mut CURRENT: *mut c_void = null_mut();
99
unsafe extern "C" fn brk(ptr: *mut c_void) -> c_int {
1010
libc!(libc::brk(ptr));
1111

12-
let new = match convert_res(rustix::runtime::brk(ptr)) {
12+
let new = match convert_res(rustix::runtime::kernel_brk(ptr)) {
1313
Some(new) => new,
1414
None => return -1,
1515
};
@@ -33,7 +33,7 @@ unsafe extern "C" fn sbrk(increment: intptr_t) -> *mut c_void {
3333

3434
if old.is_null() {
3535
// Read the current value from the OS.
36-
old = match convert_res(rustix::runtime::brk(null_mut())) {
36+
old = match convert_res(rustix::runtime::kernel_brk(null_mut())) {
3737
Some(old) => old,
3838
None => return without_provenance_mut(!0),
3939
};
@@ -61,7 +61,7 @@ unsafe extern "C" fn sbrk(increment: intptr_t) -> *mut c_void {
6161
}
6262

6363
// Install the new address.
64-
let new = match convert_res(rustix::runtime::brk(want)) {
64+
let new = match convert_res(rustix::runtime::kernel_brk(want)) {
6565
Some(new) => new,
6666
None => {
6767
CURRENT = old;

c-scape/src/exit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ unsafe extern "C" fn exit(status: c_int) -> ! {
5353
#[no_mangle]
5454
unsafe extern "C" fn _Exit(status: c_int) -> ! {
5555
//libc!(libc::_Exit(status));
56-
origin::program::exit_immediately(status)
56+
origin::program::immediate_exit(status)
5757
}
5858

5959
/// POSIX-compatible `_exit`.

c-scape/src/fs/fadvise.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::convert_res;
2+
use core::num::NonZeroU64;
23
use errno::{set_errno, Errno};
34
use libc::{c_int, off64_t, off_t};
45
use rustix::fd::BorrowedFd;
@@ -28,7 +29,7 @@ unsafe extern "C" fn posix_fadvise64(
2829
match convert_res(rustix::fs::fadvise(
2930
BorrowedFd::borrow_raw(fd),
3031
offset as u64,
31-
len as u64,
32+
NonZeroU64::new(len as u64),
3233
advice,
3334
)) {
3435
Some(()) => 0,

c-scape/src/fs/fcntl.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use core::ffi::VaList;
22
use errno::{set_errno, Errno};
33
use rustix::fd::{BorrowedFd, IntoRawFd};
4-
use rustix::fs::{FdFlags, FlockOperation, OFlags};
4+
use rustix::fs::{FlockOperation, OFlags};
5+
use rustix::io::FdFlags;
56

67
use libc::c_int;
78

@@ -44,7 +45,7 @@ unsafe fn _fcntl<FlockTy: Flock>(fd: c_int, cmd: c_int, mut args: VaList<'_, '_>
4445
libc::F_GETFD => {
4546
libc!(libc::fcntl(fd, libc::F_GETFD));
4647
let fd = BorrowedFd::borrow_raw(fd);
47-
match convert_res(rustix::fs::fcntl_getfd(fd)) {
48+
match convert_res(rustix::io::fcntl_getfd(fd)) {
4849
Some(flags) => flags.bits() as _,
4950
None => -1,
5051
}
@@ -53,7 +54,7 @@ unsafe fn _fcntl<FlockTy: Flock>(fd: c_int, cmd: c_int, mut args: VaList<'_, '_>
5354
let flags = args.arg::<c_int>();
5455
libc!(libc::fcntl(fd, libc::F_SETFD, flags));
5556
let fd = BorrowedFd::borrow_raw(fd);
56-
match convert_res(rustix::fs::fcntl_setfd(
57+
match convert_res(rustix::io::fcntl_setfd(
5758
fd,
5859
FdFlags::from_bits(flags as _).unwrap(),
5960
)) {
@@ -100,7 +101,7 @@ unsafe fn _fcntl<FlockTy: Flock>(fd: c_int, cmd: c_int, mut args: VaList<'_, '_>
100101
let arg = args.arg::<c_int>();
101102
libc!(libc::fcntl(fd, libc::F_DUPFD_CLOEXEC, arg));
102103
let fd = BorrowedFd::borrow_raw(fd);
103-
match convert_res(rustix::fs::fcntl_dupfd_cloexec(fd, arg)) {
104+
match convert_res(rustix::io::fcntl_dupfd_cloexec(fd, arg)) {
104105
Some(fd) => fd.into_raw_fd(),
105106
None => -1,
106107
}

c-scape/src/fs/inotify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ unsafe extern "C" fn inotify_init1(flags: c_int) -> c_int {
1515
libc!(libc::inotify_init1(flags));
1616

1717
let flags = CreateFlags::from_bits(flags as _).unwrap();
18-
match convert_res(inotify::inotify_init(flags)) {
18+
match convert_res(inotify::init(flags)) {
1919
Some(fd) => fd.into_raw_fd(),
2020
None => -1,
2121
}
@@ -28,7 +28,7 @@ unsafe extern "C" fn inotify_add_watch(fd: c_int, pathname: *const c_char, mask:
2828
let fd = BorrowedFd::borrow_raw(fd);
2929
let pathname = CStr::from_ptr(pathname);
3030
let mask = WatchFlags::from_bits(mask).unwrap();
31-
match convert_res(inotify::inotify_add_watch(fd, pathname, mask)) {
31+
match convert_res(inotify::add_watch(fd, pathname, mask)) {
3232
Some(wd) => wd,
3333
None => -1,
3434
}
@@ -39,7 +39,7 @@ unsafe extern "C" fn inotify_rm_watch(fd: c_int, wd: c_int) -> c_int {
3939
libc!(libc::inotify_rm_watch(fd, wd));
4040

4141
let fd = BorrowedFd::borrow_raw(fd);
42-
match convert_res(inotify::inotify_remove_watch(fd, wd)) {
42+
match convert_res(inotify::remove_watch(fd, wd)) {
4343
Some(()) => 0,
4444
None => -1,
4545
}

0 commit comments

Comments
 (0)