Skip to content

Commit 75bf7c6

Browse files
authored
Merge branch 'bytecodealliance:main' into bind_device
2 parents 59e976d + e5b793b commit 75bf7c6

File tree

138 files changed

+2378
-1236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+2378
-1236
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
cargo update --package=half --precise=2.2.1
5757
cargo update --package=flate2 --precise=1.0.35
5858
cargo update --package=textwrap --precise=0.16.1
59+
cargo update --package=once_cell --precise=1.20.3
5960
6061
- run: >
6162
rustup target add
@@ -221,18 +222,20 @@ jobs:
221222
- run: cargo check -Z build-std --target armv7-unknown-freebsd --all-targets --features=all-apis
222223
- run: cargo check -Z build-std --target aarch64-unknown-linux-gnu_ilp32 --all-targets --features=all-apis
223224
- run: cargo check -Z build-std --target x86_64-unknown-haiku --all-targets --features=all-apis
224-
- run: cargo check -Z build-std --target x86_64-uwp-windows-msvc --all-targets --features=all-apis
225+
# Temporarily disable due to build errors on nightly.
226+
# - run: cargo check -Z build-std --target x86_64-uwp-windows-msvc --all-targets --features=all-apis
225227
- run: cargo check -Z build-std --target=riscv32imc-esp-espidf --features=all-apis
226228
- run: cargo check -Z build-std --target=aarch64-unknown-nto-qnx710 --features=all-apis
227229
- run: cargo check -Z build-std --target=x86_64-pc-nto-qnx710 --features=all-apis
228230
- run: cargo check -Z build-std --target=armv6k-nintendo-3ds --all-features
229-
# Temporarily disable armv7-sony-vita-newlibeabihf, as it gets build errors.
230-
# - run: cargo check -Z build-std --target=armv7-sony-vita-newlibeabihf --features=all-apis
231-
- run: cargo check -Z build-std --target=powerpc64-ibm-aix --features=all-apis
231+
- run: cargo check -Z build-std --target=armv7-sony-vita-newlibeabihf --features=all-apis
232+
# Temporarily disable due to build errors on nightly.
233+
# - run: cargo check -Z build-std --target=powerpc64-ibm-aix --features=all-apis
232234
- run: cargo check -Z build-std --target=mipsel-unknown-linux-gnu --features=all-apis
233235
- run: cargo check -Z build-std --target=mips64el-unknown-linux-gnuabi64 --features=all-apis
234236
- run: cargo check -Z build-std --target=powerpc-unknown-linux-musl --features=all-apis
235237
- run: cargo check -Z build-std --target=powerpc64le-unknown-linux-musl --features=all-apis
238+
- run: cargo check -Z build-std --target=armv7k-apple-watchos --features=all-apis
236239

237240

238241
test:
@@ -244,13 +247,13 @@ jobs:
244247
RUSTFLAGS: --cfg rustix_use_experimental_features
245248
strategy:
246249
matrix:
247-
build: [ubuntu, ubuntu-20.04, i686-linux, aarch64-linux, powerpc-linux, powerpc64le-linux, riscv64-linux, s390x-linux, arm-linux, ubuntu-stable, i686-linux-stable, aarch64-linux-stable, riscv64-linux-stable, s390x-linux-stable, powerpc-linux-stable, powerpc64le-linux-stable, arm-linux-stable, ubuntu-1.63, i686-linux-1.63, aarch64-linux-1.63, riscv64-linux-1.63, s390x-linux-1.63, powerpc64le-linux, powerpc64le-linux-1.63, arm-linux-1.63, macos-latest, macos-13, windows, windows-2019, musl]
250+
build: [ubuntu, ubuntu-22.04, i686-linux, aarch64-linux, powerpc-linux, powerpc64le-linux, riscv64-linux, s390x-linux, arm-linux, ubuntu-stable, i686-linux-stable, aarch64-linux-stable, riscv64-linux-stable, s390x-linux-stable, powerpc-linux-stable, powerpc64le-linux-stable, arm-linux-stable, ubuntu-1.63, i686-linux-1.63, aarch64-linux-1.63, riscv64-linux-1.63, s390x-linux-1.63, powerpc64le-linux, powerpc64le-linux-1.63, arm-linux-1.63, macos-latest, macos-13, windows, windows-2019, musl]
248251
include:
249252
- build: ubuntu
250253
os: ubuntu-latest
251254
rust: nightly
252-
- build: ubuntu-20.04
253-
os: ubuntu-20.04
255+
- build: ubuntu-22.04
256+
os: ubuntu-22.04
254257
rust: nightly
255258
- build: i686-linux
256259
os: ubuntu-latest
@@ -533,6 +536,7 @@ jobs:
533536
cargo update --package=half --precise=2.2.1
534537
cargo update --package=flate2 --precise=1.0.35
535538
cargo update --package=textwrap --precise=0.16.1
539+
cargo update --package=once_cell --precise=1.20.3
536540
537541
- run: |
538542
cargo test --verbose --features=all-apis --release --workspace -- --nocapture

CHANGES.md

Lines changed: 111 additions & 107 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ cargo test --features=all-apis
1414
```
1515

1616
And, rustix has two backends, linux_raw and libc, and only one is used in
17-
any given build. To test with the libc backend explicitly, additionally
18-
enable the `use-libc` feature:
17+
any given build. To test on Linux with the libc backend explicitly,
18+
additionally enable the `use-libc` feature:
1919

2020
```console
2121
cargo test --features=all-apis,use-libc

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustix"
3-
version = "1.0.1"
3+
version = "1.0.6"
44
authors = [
55
"Dan Gohman <dev@sunfishcode.online>",
66
"Jakub Konka <kubkon@jakubkonka.com>",
@@ -32,15 +32,15 @@ compiler_builtins = { version = '0.1.49', optional = true }
3232
[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies]
3333
linux-raw-sys = { version = "0.9.2", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
3434
libc_errno = { package = "errno", version = "0.3.10", default-features = false, optional = true }
35-
libc = { version = "0.2.168", default-features = false, optional = true }
35+
libc = { version = "0.2.171", default-features = false, optional = true }
3636

3737
# Dependencies for platforms where only libc is supported:
3838
#
3939
# On all other Unix-family platforms, and under Miri, we always use the libc
4040
# backend, so enable its dependencies unconditionally.
4141
[target.'cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
4242
libc_errno = { package = "errno", version = "0.3.10", default-features = false }
43-
libc = { version = "0.2.168", default-features = false }
43+
libc = { version = "0.2.171", default-features = false }
4444

4545
# Additional dependencies for Linux with the libc backend:
4646
#
@@ -66,7 +66,7 @@ default-features = false
6666

6767
[dev-dependencies]
6868
tempfile = "3.5.0"
69-
libc = "0.2.168"
69+
libc = "0.2.171"
7070
libc_errno = { package = "errno", version = "0.3.10", default-features = false }
7171
serial_test = "2.0.0"
7272
memoffset = "0.9.0"
@@ -269,4 +269,5 @@ check-cfg = [
269269
'cfg(wasi_ext)',
270270
'cfg(wasip2)',
271271
'cfg(target_arch, values("xtensa"))',
272+
'cfg(target_os, values("cygwin"))',
272273
]

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ building.
5252

5353
## Cargo features
5454

55-
The modules [`rustix::io`], [`rustix::fd`], [`rustix::ffi`], and
56-
[`rustix::ioctl`] are enabled by default. The rest of the API modules are
57-
conditional with cargo feature flags.
55+
The modules [`rustix::io`], [`rustix::buffer`], [`rustix::fd`],
56+
[`rustix::ffi`], and [`rustix::ioctl`] are enabled by default. The rest of the
57+
API modules are conditional with cargo feature flags.
5858

5959
| Name | Description |
6060
| ---------- | -------------------------------------------------------------- |
@@ -88,6 +88,7 @@ conditional with cargo feature flags.
8888
| `std` | On by default; disable to activate `#![no_std]`. |
8989
| `alloc` | On by default; enables features that depend on [`alloc`]. |
9090

91+
[`rustix::buffer`]: https://docs.rs/rustix/*/rustix/buffer/index.html
9192
[`rustix::event`]: https://docs.rs/rustix/*/rustix/event/index.html
9293
[`rustix::fs`]: https://docs.rs/rustix/*/rustix/fs/index.html
9394
[`rustix::io_uring`]: https://docs.rs/rustix/*/rustix/io_uring/index.html

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ fn main() {
159159
|| (arch == "aarch64" && os == "linux" && abi == Ok("ilp32".to_string())))
160160
&& (apple
161161
|| os == "android"
162+
|| (os == "freebsd" && arch == "x86")
162163
|| os == "haiku"
163164
|| env == "gnu"
164165
|| (env == "musl" && arch == "x86")

examples/process.rs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,62 @@ fn main() -> rustix::io::Result<()> {
5050
println!("Stack Limit: {:?}", getrlimit(Resource::Stack));
5151
#[cfg(not(target_os = "haiku"))]
5252
println!("Core Limit: {:?}", getrlimit(Resource::Core));
53-
#[cfg(not(any(solarish, target_os = "haiku")))]
53+
#[cfg(not(any(solarish, target_os = "cygwin", target_os = "haiku")))]
5454
println!("Rss Limit: {:?}", getrlimit(Resource::Rss));
55-
#[cfg(not(any(solarish, target_os = "haiku")))]
55+
#[cfg(not(any(solarish, target_os = "cygwin", target_os = "haiku")))]
5656
println!("Nproc Limit: {:?}", getrlimit(Resource::Nproc));
5757
#[cfg(not(target_os = "solaris"))]
5858
println!("Nofile Limit: {:?}", getrlimit(Resource::Nofile));
59-
#[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))]
59+
#[cfg(not(any(solarish, target_os = "aix", target_os = "cygwin", target_os = "haiku")))]
6060
println!("Memlock Limit: {:?}", getrlimit(Resource::Memlock));
6161
#[cfg(not(target_os = "openbsd"))]
6262
println!("As Limit: {:?}", getrlimit(Resource::As));
63-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
63+
#[cfg(not(any(
64+
bsd,
65+
solarish,
66+
target_os = "aix",
67+
target_os = "cygwin",
68+
target_os = "haiku",
69+
)))]
6470
println!("Locks Limit: {:?}", getrlimit(Resource::Locks));
65-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
71+
#[cfg(not(any(
72+
bsd,
73+
solarish,
74+
target_os = "aix",
75+
target_os = "cygwin",
76+
target_os = "haiku",
77+
)))]
6678
println!("Sigpending Limit: {:?}", getrlimit(Resource::Sigpending));
67-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
79+
#[cfg(not(any(
80+
bsd,
81+
solarish,
82+
target_os = "aix",
83+
target_os = "cygwin",
84+
target_os = "haiku",
85+
)))]
6886
println!("Msgqueue Limit: {:?}", getrlimit(Resource::Msgqueue));
69-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
87+
#[cfg(not(any(
88+
bsd,
89+
solarish,
90+
target_os = "aix",
91+
target_os = "cygwin",
92+
target_os = "haiku",
93+
)))]
7094
println!("Nice Limit: {:?}", getrlimit(Resource::Nice));
71-
#[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
95+
#[cfg(not(any(
96+
bsd,
97+
solarish,
98+
target_os = "aix",
99+
target_os = "cygwin",
100+
target_os = "haiku",
101+
)))]
72102
println!("Rtprio Limit: {:?}", getrlimit(Resource::Rtprio));
73103
#[cfg(not(any(
74104
bsd,
75105
solarish,
76106
target_os = "aix",
77107
target_os = "android",
108+
target_os = "cygwin",
78109
target_os = "emscripten",
79110
target_os = "haiku",
80111
)))]

examples/stdio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
258258
if term.local_modes.contains(LocalModes::ECHOCTL) {
259259
print!(" ECHOCTL");
260260
}
261-
#[cfg(not(any(target_os = "redox")))]
261+
#[cfg(not(any(target_os = "cygwin", target_os = "redox")))]
262262
if term.local_modes.contains(LocalModes::ECHOPRT) {
263263
print!(" ECHOPRT");
264264
}
@@ -276,7 +276,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
276276
if term.local_modes.contains(LocalModes::TOSTOP) {
277277
print!(" TOSTOP");
278278
}
279-
#[cfg(not(any(target_os = "redox")))]
279+
#[cfg(not(any(target_os = "cygwin", target_os = "redox")))]
280280
if term.local_modes.contains(LocalModes::PENDIN) {
281281
print!(" PENDIN");
282282
}

src/backend/libc/c.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,70 @@ pub(crate) use __fsid_t as fsid_t;
518518
#[cfg(feature = "mm")]
519519
#[cfg(target_os = "android")]
520520
pub(crate) const MAP_DROPPABLE: c_int = bitcast!(linux_raw_sys::general::MAP_DROPPABLE);
521+
522+
// FreeBSD added `timerfd_*` in FreeBSD 14. NetBSD added then in NetBSD 10.
523+
#[cfg(all(feature = "time", any(target_os = "freebsd", target_os = "netbsd")))]
524+
syscall!(pub(crate) fn timerfd_create(
525+
clockid: c_int,
526+
flags: c_int
527+
) via SYS_timerfd_create -> c_int);
528+
#[cfg(all(feature = "time", any(target_os = "freebsd", target_os = "netbsd")))]
529+
syscall!(pub(crate) fn timerfd_gettime(
530+
fd: c_int,
531+
curr_value: *mut itimerspec
532+
) via SYS_timerfd_gettime -> c_int);
533+
#[cfg(all(feature = "time", any(target_os = "freebsd", target_os = "netbsd")))]
534+
syscall!(pub(crate) fn timerfd_settime(
535+
fd: c_int,
536+
flags: c_int,
537+
new_value: *const itimerspec,
538+
old_value: *mut itimerspec
539+
) via SYS_timerfd_settime -> c_int);
540+
541+
#[cfg(all(feature = "time", target_os = "illumos"))]
542+
extern "C" {
543+
pub(crate) fn timerfd_create(clockid: c_int, flags: c_int) -> c_int;
544+
pub(crate) fn timerfd_gettime(fd: c_int, curr_value: *mut itimerspec) -> c_int;
545+
pub(crate) fn timerfd_settime(
546+
fd: c_int,
547+
flags: c_int,
548+
new_value: *const itimerspec,
549+
old_value: *mut itimerspec,
550+
) -> c_int;
551+
}
552+
553+
// illumos and NetBSD timerfd support.
554+
// Submitted upstream in <https://github.com/rust-lang/libc/pull/4333>.
555+
556+
// <https://code.illumos.org/plugins/gitiles/illumos-gate/+/refs/heads/master/usr/src/uts/common/sys/timerfd.h#34>
557+
#[cfg(all(feature = "time", target_os = "illumos"))]
558+
pub(crate) const TFD_CLOEXEC: i32 = 0o2000000;
559+
#[cfg(all(feature = "time", target_os = "illumos"))]
560+
pub(crate) const TFD_NONBLOCK: i32 = 0o4000;
561+
#[cfg(all(feature = "time", target_os = "illumos"))]
562+
pub(crate) const TFD_TIMER_ABSTIME: i32 = 1 << 0;
563+
#[cfg(all(feature = "time", target_os = "illumos"))]
564+
pub(crate) const TFD_TIMER_CANCEL_ON_SET: i32 = 1 << 1;
565+
566+
// <https://nxr.netbsd.org/xref/src/sys/sys/timerfd.h#44>
567+
#[cfg(all(feature = "time", target_os = "netbsd"))]
568+
pub(crate) const TFD_CLOEXEC: i32 = O_CLOEXEC;
569+
#[cfg(all(feature = "time", target_os = "netbsd"))]
570+
pub(crate) const TFD_NONBLOCK: i32 = O_NONBLOCK;
571+
#[cfg(all(feature = "time", target_os = "netbsd"))]
572+
pub(crate) const TFD_TIMER_ABSTIME: i32 = O_WRONLY;
573+
#[cfg(all(feature = "time", target_os = "netbsd"))]
574+
pub(crate) const TFD_TIMER_CANCEL_ON_SET: i32 = O_RDWR;
575+
576+
#[cfg(test)]
577+
mod tests {
578+
use super::*;
579+
580+
#[test]
581+
#[cfg(linux_kernel)]
582+
fn test_flags() {
583+
// libc may publicly define `O_LARGEFILE` to 0, but we want the real
584+
// non-zero value.
585+
assert_ne!(O_LARGEFILE, 0);
586+
}
587+
}

src/backend/libc/event/epoll.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ bitflags! {
6666
const WAKEUP = bitcast!(c::EPOLLWAKEUP);
6767

6868
/// `EPOLLEXCLUSIVE`
69-
#[cfg(not(target_os = "android"))]
7069
const EXCLUSIVE = bitcast!(c::EPOLLEXCLUSIVE);
7170

7271
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>

src/backend/libc/event/syscalls.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::backend::conv::ret;
66
use crate::backend::conv::ret_c_int;
77
#[cfg(any(linux_kernel, target_os = "illumos", target_os = "redox"))]
88
use crate::backend::conv::ret_u32;
9+
#[cfg(bsd)]
10+
use crate::event::kqueue::Event;
911
#[cfg(solarish)]
1012
use crate::event::port::Event;
1113
#[cfg(any(
@@ -47,8 +49,6 @@ use {crate::backend::conv::borrowed_fd, crate::fd::BorrowedFd};
4749
target_os = "redox"
4850
))]
4951
use {crate::backend::conv::ret_owned_fd, crate::fd::OwnedFd};
50-
#[cfg(bsd)]
51-
use {crate::event::kqueue::Event, crate::utils::as_ptr};
5252

5353
#[cfg(any(
5454
linux_kernel,
@@ -96,8 +96,28 @@ pub(crate) unsafe fn kevent(
9696
kq: BorrowedFd<'_>,
9797
changelist: &[Event],
9898
eventlist: (*mut Event, usize),
99-
timeout: Option<&c::timespec>,
99+
timeout: Option<&Timespec>,
100100
) -> io::Result<c::c_int> {
101+
// If we don't have to fix y2038 on this platform, `Timespec` is the same
102+
// as `c::timespec` and it's easy.
103+
#[cfg(not(fix_y2038))]
104+
let timeout = crate::timespec::option_as_libc_timespec_ptr(timeout);
105+
106+
// If we do have to fix y2038 on this platform, convert to `c::timespec`.
107+
#[cfg(fix_y2038)]
108+
let converted_timeout;
109+
#[cfg(fix_y2038)]
110+
let timeout = match timeout {
111+
None => null(),
112+
Some(timeout) => {
113+
converted_timeout = c::timespec {
114+
tv_sec: timeout.tv_sec.try_into().map_err(|_| io::Errno::OVERFLOW)?,
115+
tv_nsec: timeout.tv_nsec as _,
116+
};
117+
&converted_timeout
118+
}
119+
};
120+
101121
ret_c_int(c::kevent(
102122
borrowed_fd(kq),
103123
changelist.as_ptr().cast(),
@@ -107,7 +127,7 @@ pub(crate) unsafe fn kevent(
107127
.map_err(|_| io::Errno::OVERFLOW)?,
108128
eventlist.0.cast(),
109129
eventlist.1.try_into().map_err(|_| io::Errno::OVERFLOW)?,
110-
timeout.map_or(null(), as_ptr),
130+
timeout,
111131
))
112132
}
113133

@@ -229,7 +249,7 @@ pub(crate) unsafe fn select(
229249
Some(timeout) => {
230250
// Convert from `Timespec` to `c::timeval`.
231251
timeout_data = c::timeval {
232-
tv_sec: timeout.tv_sec.try_into().map_err(|_| io::Errno::OVERFLOW)?,
252+
tv_sec: timeout.tv_sec.try_into().map_err(|_| io::Errno::INVAL)?,
233253
tv_usec: ((timeout.tv_nsec + 999) / 1000) as _,
234254
};
235255
&timeout_data
@@ -306,7 +326,7 @@ pub(crate) unsafe fn select(
306326
Some(timeout) => {
307327
// Convert from `Timespec` to `c::timeval`.
308328
timeout_data = c::timeval {
309-
tv_sec: timeout.tv_sec.try_into().map_err(|_| io::Errno::OVERFLOW)?,
329+
tv_sec: timeout.tv_sec.try_into().map_err(|_| io::Errno::INVAL)?,
310330
tv_usec: ((timeout.tv_nsec + 999) / 1000) as _,
311331
};
312332
&timeout_data

0 commit comments

Comments
 (0)