Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GNU/Hurd support #844

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
target_os = "aix",
target_os = "emscripten",
target_os = "haiku",
target_os = "hurd",
target_os = "redox",
)))]
if term.input_modes.contains(InputModes::IUTF8) {
Expand Down Expand Up @@ -217,6 +218,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
solarish,
target_os = "emscripten",
target_os = "haiku",
target_os = "hurd",
target_os = "redox",
)))]
if term.control_modes.contains(ControlModes::CMSPAR) {
Expand Down Expand Up @@ -297,6 +299,7 @@ fn show<Fd: AsFd>(fd: Fd) -> io::Result<()> {
solarish,
target_os = "aix",
target_os = "haiku",
target_os = "hurd",
target_os = "nto",
)))]
println!(
Expand Down
20 changes: 15 additions & 5 deletions src/backend/libc/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ pub(super) use libc::fallocate64 as fallocate;
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
#[cfg(any(linux_like, target_os = "aix"))]
pub(super) use libc::open64 as open;
#[cfg(any(linux_kernel, target_os = "aix", target_os = "l4re"))]
#[cfg(any(
linux_kernel,
target_os = "aix",
target_os = "hurd",
target_os = "l4re"
))]
pub(super) use libc::posix_fallocate64 as posix_fallocate;
#[cfg(any(all(linux_like, not(target_os = "android")), target_os = "aix"))]
pub(super) use libc::{blkcnt64_t as blkcnt_t, rlim64_t as rlim_t};
Expand All @@ -123,7 +128,7 @@ pub(super) use libc::{
rlimit64 as rlimit, setrlimit64 as setrlimit, statfs64 as statfs, statvfs64 as statvfs,
RLIM_INFINITY,
};
#[cfg(linux_like)]
#[cfg(any(linux_like, target_os = "hurd"))]
pub(super) use libc::{
fstat64 as fstat, fstatat64 as fstatat, fstatfs64 as fstatfs, fstatvfs64 as fstatvfs,
ftruncate64 as ftruncate, getrlimit64 as getrlimit, ino64_t as ino_t, lseek64 as lseek,
Expand All @@ -144,11 +149,16 @@ pub(super) use libc::{
target_arch = "mips64r6"
)
)))]
#[cfg(any(linux_like, target_os = "aix"))]
#[cfg(any(linux_like, target_os = "aix", target_os = "hurd"))]
pub(super) use libc::{lstat64 as lstat, stat64 as stat};
#[cfg(any(linux_kernel, target_os = "aix", target_os = "emscripten"))]
#[cfg(any(
linux_kernel,
target_os = "aix",
target_os = "hurd",
target_os = "emscripten"
))]
pub(super) use libc::{pread64 as pread, pwrite64 as pwrite};
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
#[cfg(any(target_os = "linux", target_os = "hurd", target_os = "emscripten"))]
pub(super) use libc::{preadv64 as preadv, pwritev64 as pwritev};

#[cfg(all(target_os = "linux", target_env = "gnu"))]
Expand Down
4 changes: 2 additions & 2 deletions src/backend/libc/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use crate::io;
#[cfg(feature = "process")]
use crate::process::fchdir;
use alloc::borrow::ToOwned;
#[cfg(not(linux_like))]
#[cfg(not(any(linux_like, target_os = "hurd")))]
use c::readdir as libc_readdir;
#[cfg(linux_like)]
#[cfg(any(linux_like, target_os = "hurd"))]
use c::readdir64 as libc_readdir;
use core::fmt;
use core::ptr::NonNull;
Expand Down
6 changes: 3 additions & 3 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<Owned
pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedFd> {
// Work around <https://sourceware.org/bugzilla/show_bug.cgi?id=17523>.
// glibc versions before 2.25 don't handle `O_TMPFILE` correctly.
#[cfg(all(unix, target_env = "gnu"))]
#[cfg(all(unix, target_env = "gnu", not(target_os = "hurd")))]
if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() {
return open_via_syscall(path, oflags, mode);
}
Expand Down Expand Up @@ -153,7 +153,7 @@ pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedF
/// Use a direct syscall (via libc) for `openat`.
///
/// This is only currently necessary as a workaround for old glibc; see below.
#[cfg(all(unix, target_env = "gnu"))]
#[cfg(all(unix, target_env = "gnu", not(target_os = "hurd")))]
fn openat_via_syscall(
dirfd: BorrowedFd<'_>,
path: &CStr,
Expand Down Expand Up @@ -188,7 +188,7 @@ pub(crate) fn openat(
) -> io::Result<OwnedFd> {
// Work around <https://sourceware.org/bugzilla/show_bug.cgi?id=17523>.
// glibc versions before 2.25 don't handle `O_TMPFILE` correctly.
#[cfg(all(unix, target_env = "gnu"))]
#[cfg(all(unix, target_env = "gnu", not(target_os = "hurd")))]
if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() {
return openat_via_syscall(dirfd, path, oflags, mode);
}
Expand Down
10 changes: 9 additions & 1 deletion src/backend/libc/fs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ bitflags! {
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "hurd",
target_os = "wasi",
)))]
const KEEP_SIZE = bitcast!(c::FALLOC_FL_KEEP_SIZE);
Expand All @@ -805,6 +806,7 @@ bitflags! {
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "hurd",
target_os = "wasi",
)))]
const PUNCH_HOLE = bitcast!(c::FALLOC_FL_PUNCH_HOLE);
Expand All @@ -815,6 +817,7 @@ bitflags! {
target_os = "emscripten",
target_os = "fuchsia",
target_os = "haiku",
target_os = "hurd",
target_os = "l4re",
target_os = "linux",
target_os = "wasi",
Expand All @@ -825,6 +828,7 @@ bitflags! {
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "hurd",
target_os = "emscripten",
target_os = "wasi",
)))]
Expand All @@ -834,6 +838,7 @@ bitflags! {
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "hurd",
target_os = "emscripten",
target_os = "wasi",
)))]
Expand All @@ -843,6 +848,7 @@ bitflags! {
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "hurd",
target_os = "emscripten",
target_os = "wasi",
)))]
Expand All @@ -852,6 +858,7 @@ bitflags! {
bsd,
target_os = "aix",
target_os = "haiku",
target_os = "hurd",
target_os = "emscripten",
target_os = "wasi",
)))]
Expand Down Expand Up @@ -940,7 +947,7 @@ pub enum FlockOperation {
///
/// [`statat`]: crate::fs::statat
/// [`fstat`]: crate::fs::fstat
#[cfg(not(linux_like))]
#[cfg(not(any(linux_like, target_os = "hurd")))]
pub type Stat = c::stat;

/// `struct stat` for use with [`statat`] and [`fstat`].
Expand All @@ -949,6 +956,7 @@ pub type Stat = c::stat;
/// [`fstat`]: crate::fs::fstat
#[cfg(any(
all(linux_kernel, target_pointer_width = "64"),
target_os = "hurd",
target_os = "emscripten",
target_os = "l4re",
))]
Expand Down