added support for GNU/Hurd

This commit is contained in:
Samuel Thibault 2023-09-19 12:41:30 +02:00
parent ae9c330629
commit dcea7709f2
36 changed files with 626 additions and 35 deletions

View File

@ -21,8 +21,16 @@ pub fn new(p: &Path, wait: bool, create: bool, exclusive: bool) -> io::Result<Lo
let lock_type = if exclusive { libc::F_WRLCK } else { libc::F_RDLCK };
let mut flock: libc::flock = unsafe { mem::zeroed() };
#[cfg(not(all(target_os = "hurd", target_arch = "x86")))]
{
flock.l_type = lock_type as libc::c_short;
flock.l_whence = libc::SEEK_SET as libc::c_short;
}
#[cfg(all(target_os = "hurd", target_arch = "x86"))]
{
flock.l_type = lock_type as libc::c_int;
flock.l_whence = libc::SEEK_SET as libc::c_int;
}
flock.l_start = 0;
flock.l_len = 0;
@ -39,8 +47,16 @@ pub fn error_unsupported(err: &io::Error) -> bool {
impl Drop for Lock {
fn drop(&mut self) {
let mut flock: libc::flock = unsafe { mem::zeroed() };
#[cfg(not(all(target_os = "hurd", target_arch = "x86")))]
{
flock.l_type = libc::F_UNLCK as libc::c_short;
flock.l_whence = libc::SEEK_SET as libc::c_short;
}
#[cfg(all(target_os = "hurd", target_arch = "x86"))]
{
flock.l_type = libc::F_UNLCK as libc::c_int;
flock.l_whence = libc::SEEK_SET as libc::c_int;
}
flock.l_start = 0;
flock.l_len = 0;

View File

@ -0,0 +1,15 @@
use crate::spec::{cvs, RelroLevel, TargetOptions};
pub fn opts() -> TargetOptions {
TargetOptions {
os: "hurd".into(),
dynamic_linking: true,
families: cvs!["unix"],
has_rpath: true,
position_independent_executables: true,
relro_level: RelroLevel::Full,
has_thread_local: true,
crt_static_respected: true,
..Default::default()
}
}

View File

@ -0,0 +1,5 @@
use crate::spec::TargetOptions;
pub fn opts() -> TargetOptions {
TargetOptions { env: "gnu".into(), ..super::hurd_base::opts() }
}

View File

@ -0,0 +1,19 @@
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target};
pub fn target() -> Target {
let mut base = super::hurd_gnu_base::opts();
base.cpu = "pentiumpro".into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::InlineOrCall { min_llvm_version_for_inline: (11, 0, 1) };
Target {
llvm_target: "i686-unknown-hurd-gnu".into(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
f64:32:64-f80:32-n8:16:32-S128"
.into(),
arch: "x86".into(),
options: base,
}
}

View File

@ -71,6 +71,8 @@
mod fuchsia_base;
mod haiku_base;
mod hermit_base;
mod hurd_base;
mod hurd_gnu_base;
mod illumos_base;
mod l4re_base;
mod linux_base;
@ -1367,6 +1369,8 @@ fn $module() {
("i686-unknown-haiku", i686_unknown_haiku),
("x86_64-unknown-haiku", x86_64_unknown_haiku),
("i686-unknown-hurd-gnu", i686_unknown_hurd_gnu),
("aarch64-apple-darwin", aarch64_apple_darwin),
("x86_64-apple-darwin", x86_64_apple_darwin),
("x86_64h-apple-darwin", x86_64h_apple_darwin),

View File

@ -38,6 +38,7 @@ fn main() {
|| target.contains("vita")
|| target.contains("nto")
|| target.contains("xous")
|| target.contains("hurd")
// See src/bootstrap/synthetic_targets.rs
|| env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok()
{

View File

@ -0,0 +1,348 @@
//! Hurd-specific extensions to primitives in the [`std::fs`] module.
//!
//! [`std::fs`]: crate::fs
#![stable(feature = "metadata_ext", since = "1.1.0")]
use crate::fs::Metadata;
use crate::sys_common::AsInner;
/// OS-specific extensions to [`fs::Metadata`].
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
/// Returns the device ID on which this file resides.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_dev());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_dev(&self) -> u64;
/// Returns the inode number.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ino());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ino(&self) -> u64;
/// Returns the file type and mode.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mode());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mode(&self) -> u32;
/// Returns the number of hard links to file.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_nlink());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_nlink(&self) -> u64;
/// Returns the user ID of the file owner.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_uid());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_uid(&self) -> u32;
/// Returns the group ID of the file owner.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_gid());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_gid(&self) -> u32;
/// Returns the device ID that this file represents. Only relevant for special file.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_rdev());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_rdev(&self) -> u64;
/// Returns the size of the file (if it is a regular file or a symbolic link) in bytes.
///
/// The size of a symbolic link is the length of the pathname it contains,
/// without a terminating null byte.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_size());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_size(&self) -> u64;
/// Returns the last access time of the file, in seconds since Unix Epoch.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_atime());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime(&self) -> i64;
/// Returns the last access time of the file, in nanoseconds since [`st_atime`].
///
/// [`st_atime`]: Self::st_atime
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_atime_nsec());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime_nsec(&self) -> i64;
/// Returns the last modification time of the file, in seconds since Unix Epoch.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mtime());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime(&self) -> i64;
/// Returns the last modification time of the file, in nanoseconds since [`st_mtime`].
///
/// [`st_mtime`]: Self::st_mtime
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mtime_nsec());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime_nsec(&self) -> i64;
/// Returns the last status change time of the file, in seconds since Unix Epoch.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ctime());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime(&self) -> i64;
/// Returns the last status change time of the file, in nanoseconds since [`st_ctime`].
///
/// [`st_ctime`]: Self::st_ctime
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ctime_nsec());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime_nsec(&self) -> i64;
/// Returns the "preferred" block size for efficient filesystem I/O.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_blksize());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blksize(&self) -> u64;
/// Returns the number of blocks allocated to the file, 512-byte units.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::hurd::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_blocks());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blocks(&self) -> u64;
}
#[stable(feature = "metadata_ext", since = "1.1.0")]
impl MetadataExt for Metadata {
fn st_dev(&self) -> u64 {
self.as_inner().as_inner().st_fsid as u64
}
fn st_ino(&self) -> u64 {
self.as_inner().as_inner().st_ino as u64
}
fn st_mode(&self) -> u32 {
self.as_inner().as_inner().st_mode as u32
}
fn st_nlink(&self) -> u64 {
self.as_inner().as_inner().st_nlink as u64
}
fn st_uid(&self) -> u32 {
self.as_inner().as_inner().st_uid as u32
}
fn st_gid(&self) -> u32 {
self.as_inner().as_inner().st_gid as u32
}
fn st_rdev(&self) -> u64 {
self.as_inner().as_inner().st_rdev as u64
}
fn st_size(&self) -> u64 {
self.as_inner().as_inner().st_size as u64
}
fn st_atime(&self) -> i64 {
self.as_inner().as_inner().st_atim.tv_sec as i64
}
fn st_atime_nsec(&self) -> i64 {
self.as_inner().as_inner().st_atim.tv_nsec as i64
}
fn st_mtime(&self) -> i64 {
self.as_inner().as_inner().st_mtim.tv_sec as i64
}
fn st_mtime_nsec(&self) -> i64 {
self.as_inner().as_inner().st_mtim.tv_nsec as i64
}
fn st_ctime(&self) -> i64 {
self.as_inner().as_inner().st_ctim.tv_sec as i64
}
fn st_ctime_nsec(&self) -> i64 {
self.as_inner().as_inner().st_ctim.tv_nsec as i64
}
fn st_blksize(&self) -> u64 {
self.as_inner().as_inner().st_blksize as u64
}
fn st_blocks(&self) -> u64 {
self.as_inner().as_inner().st_blocks as u64
}
}

View File

@ -0,0 +1,6 @@
//! Hurd-specific definitions
#![stable(feature = "raw_ext", since = "1.1.0")]
pub mod fs;
pub mod raw;

View File

@ -0,0 +1,33 @@
//! Hurd-specific raw type definitions
#![stable(feature = "raw_ext", since = "1.1.0")]
#![deprecated(
since = "1.8.0",
note = "these type aliases are no longer supported by \
the standard library, the `libc` crate on \
crates.io should be used instead for the correct \
definitions"
)]
#![allow(deprecated)]
use crate::os::raw::{c_long, c_uint, c_ulong};
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type blkcnt_t = u64;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type blksize_t = c_long;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type dev_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type ino_t = u64;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type mode_t = c_uint;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type nlink_t = c_ulong;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type off_t = u64;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type time_t = c_long;
#[stable(feature = "pthread_t", since = "1.8.0")]
pub type pthread_t = c_long;

View File

@ -117,6 +117,8 @@ pub mod windows {}
pub mod hermit;
#[cfg(target_os = "horizon")]
pub mod horizon;
#[cfg(target_os = "hurd")]
pub mod hurd;
#[cfg(target_os = "illumos")]
pub mod illumos;
#[cfg(target_os = "ios")]

View File

@ -53,6 +53,8 @@ mod platform {
pub use crate::os::haiku::*;
#[cfg(target_os = "horizon")]
pub use crate::os::horizon::*;
#[cfg(target_os = "hurd")]
pub use crate::os::hurd::*;
#[cfg(target_os = "illumos")]
pub use crate::os::illumos::*;
#[cfg(target_os = "ios")]

View File

@ -71,6 +71,7 @@ fn next_back(&mut self) -> Option<OsString> {
target_os = "vxworks",
target_os = "horizon",
target_os = "nto",
target_os = "hurd",
))]
mod imp {
use super::Args;

View File

@ -152,6 +152,17 @@ pub mod os {
pub const EXE_EXTENSION: &str = "elf";
}
#[cfg(target_os = "hurd")]
pub mod os {
pub const FAMILY: &str = "unix";
pub const OS: &str = "hurd";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".so";
pub const DLL_EXTENSION: &str = "so";
pub const EXE_SUFFIX: &str = "";
pub const EXE_EXTENSION: &str = "";
}
#[cfg(target_os = "vita")]
pub mod os {
pub const FAMILY: &str = "unix";

View File

@ -13,14 +13,16 @@
target_os = "android",
target_os = "linux",
target_os = "emscripten",
target_os = "l4re"
target_os = "l4re",
target_os = "hurd",
))]
use libc::off64_t;
#[cfg(not(any(
target_os = "linux",
target_os = "emscripten",
target_os = "l4re",
target_os = "android"
target_os = "android",
target_os = "hurd",
)))]
use libc::off_t as off64_t;
@ -124,9 +126,9 @@ pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
}
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
#[cfg(not(any(target_os = "linux", target_os = "android")))]
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "hurd")))]
use libc::pread as pread64;
#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "hurd"))]
use libc::pread64;
unsafe {
@ -160,6 +162,7 @@ pub fn read_buf(&self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
@ -181,6 +184,7 @@ pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
target_os = "ios",
target_os = "tvos",
@ -281,9 +285,9 @@ pub fn is_write_vectored(&self) -> bool {
}
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
#[cfg(not(any(target_os = "linux", target_os = "android")))]
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "hurd")))]
use libc::pwrite as pwrite64;
#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "hurd"))]
use libc::pwrite64;
unsafe {
@ -301,6 +305,7 @@ pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
@ -322,6 +327,7 @@ pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
target_os = "ios",
target_os = "tvos",

View File

@ -39,9 +39,14 @@
all(target_os = "linux", target_env = "gnu")
))]
use libc::c_char;
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "android"))]
#[cfg(any(
target_os = "linux",
target_os = "emscripten",
target_os = "android",
target_os = "hurd",
))]
use libc::dirfd;
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "hurd"))]
use libc::fstatat64;
#[cfg(any(
target_os = "android",
@ -53,7 +58,7 @@
target_os = "vita",
))]
use libc::readdir as readdir64;
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "hurd"))]
use libc::readdir64;
#[cfg(any(target_os = "emscripten", target_os = "l4re"))]
use libc::readdir64_r;
@ -68,6 +73,7 @@
target_os = "redox",
target_os = "nto",
target_os = "vita",
target_os = "hurd",
)))]
use libc::readdir_r as readdir64_r;
#[cfg(target_os = "android")]
@ -79,13 +85,19 @@
target_os = "linux",
target_os = "emscripten",
target_os = "l4re",
target_os = "android"
target_os = "android",
target_os = "hurd",
)))]
use libc::{
dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
lstat as lstat64, off_t as off64_t, open as open64, stat as stat64,
};
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "l4re"))]
#[cfg(any(
target_os = "linux",
target_os = "emscripten",
target_os = "l4re",
target_os = "hurd"
))]
use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
pub use crate::sys_common::fs::try_exists;
@ -277,7 +289,8 @@ unsafe impl Sync for Dir {}
target_os = "fuchsia",
target_os = "redox",
target_os = "nto",
target_os = "vita"
target_os = "vita",
target_os = "hurd",
))]
pub struct DirEntry {
dir: Arc<InnerReadDir>,
@ -300,6 +313,7 @@ pub struct DirEntry {
target_os = "redox",
target_os = "nto",
target_os = "vita",
target_os = "hurd",
))]
struct dirent64_min {
d_ino: u64,
@ -321,6 +335,7 @@ struct dirent64_min {
target_os = "redox",
target_os = "nto",
target_os = "vita",
target_os = "hurd",
)))]
pub struct DirEntry {
dir: Arc<InnerReadDir>,
@ -455,7 +470,8 @@ impl FileAttr {
target_os = "vxworks",
target_os = "espidf",
target_os = "horizon",
target_os = "vita"
target_os = "vita",
target_os = "hurd",
)))]
pub fn modified(&self) -> io::Result<SystemTime> {
#[cfg(target_pointer_width = "32")]
@ -473,7 +489,7 @@ pub fn modified(&self) -> io::Result<SystemTime> {
Ok(SystemTime::new(self.stat.st_mtime as i64, 0))
}
#[cfg(target_os = "horizon")]
#[cfg(any(target_os = "horizon", target_os = "hurd"))]
pub fn modified(&self) -> io::Result<SystemTime> {
Ok(SystemTime::from(self.stat.st_mtim))
}
@ -482,7 +498,8 @@ pub fn modified(&self) -> io::Result<SystemTime> {
target_os = "vxworks",
target_os = "espidf",
target_os = "horizon",
target_os = "vita"
target_os = "vita",
target_os = "hurd",
)))]
pub fn accessed(&self) -> io::Result<SystemTime> {
#[cfg(target_pointer_width = "32")]
@ -500,7 +517,7 @@ pub fn accessed(&self) -> io::Result<SystemTime> {
Ok(SystemTime::new(self.stat.st_atime as i64, 0))
}
#[cfg(target_os = "horizon")]
#[cfg(any(target_os = "horizon", target_os = "hurd"))]
pub fn accessed(&self) -> io::Result<SystemTime> {
Ok(SystemTime::from(self.stat.st_atim))
}
@ -656,6 +673,7 @@ impl Iterator for ReadDir {
target_os = "illumos",
target_os = "nto",
target_os = "vita",
target_os = "hurd",
))]
fn next(&mut self) -> Option<io::Result<DirEntry>> {
if self.end_of_stream {
@ -756,6 +774,7 @@ macro_rules! offset_ptr {
target_os = "illumos",
target_os = "nto",
target_os = "vita",
target_os = "hurd",
)))]
fn next(&mut self) -> Option<io::Result<DirEntry>> {
if self.end_of_stream {
@ -809,7 +828,12 @@ pub fn file_name(&self) -> OsString {
}
#[cfg(all(
any(target_os = "linux", target_os = "emscripten", target_os = "android"),
any(
target_os = "linux",
target_os = "emscripten",
target_os = "android",
target_os = "hurd",
),
not(miri)
))]
pub fn metadata(&self) -> io::Result<FileAttr> {
@ -833,7 +857,12 @@ pub fn metadata(&self) -> io::Result<FileAttr> {
}
#[cfg(any(
not(any(target_os = "linux", target_os = "emscripten", target_os = "android")),
not(any(
target_os = "linux",
target_os = "emscripten",
target_os = "android",
target_os = "hurd",
)),
miri
))]
pub fn metadata(&self) -> io::Result<FileAttr> {
@ -892,6 +921,7 @@ pub fn file_type(&self) -> io::Result<FileType> {
target_os = "horizon",
target_os = "vita",
target_os = "nto",
target_os = "hurd",
))]
pub fn ino(&self) -> u64 {
self.entry.d_ino as u64
@ -949,6 +979,7 @@ fn name_bytes(&self) -> &[u8] {
target_os = "redox",
target_os = "nto",
target_os = "vita",
target_os = "hurd",
)))]
fn name_cstr(&self) -> &CStr {
unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()) }
@ -962,6 +993,7 @@ fn name_cstr(&self) -> &CStr {
target_os = "redox",
target_os = "nto",
target_os = "vita",
target_os = "hurd",
))]
fn name_cstr(&self) -> &CStr {
&self.name
@ -1131,6 +1163,7 @@ unsafe fn os_datasync(fd: c_int) -> c_int {
target_os = "netbsd",
target_os = "openbsd",
target_os = "nto",
target_os = "hurd",
))]
unsafe fn os_datasync(fd: c_int) -> c_int {
libc::fdatasync(fd)
@ -1146,6 +1179,7 @@ unsafe fn os_datasync(fd: c_int) -> c_int {
target_os = "openbsd",
target_os = "watchos",
target_os = "nto",
target_os = "hurd",
)))]
unsafe fn os_datasync(fd: c_int) -> c_int {
libc::fsync(fd)
@ -1456,6 +1490,7 @@ fn get_path(_fd: c_int) -> Option<PathBuf> {
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "hurd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "vxworks"
@ -1477,6 +1512,7 @@ fn get_mode(fd: c_int) -> Option<(bool, bool)> {
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "hurd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "vxworks"

View File

@ -59,9 +59,9 @@
use crate::sync::atomic::{AtomicBool, AtomicU8, Ordering};
use crate::sys::cvt;
use crate::sys::weak::syscall;
#[cfg(not(all(target_os = "linux", target_env = "gnu")))]
#[cfg(not(any(all(target_os = "linux", target_env = "gnu"), target_os = "hurd")))]
use libc::sendfile as sendfile64;
#[cfg(all(target_os = "linux", target_env = "gnu"))]
#[cfg(any(all(target_os = "linux", target_env = "gnu"), target_os = "hurd"))]
use libc::sendfile64;
use libc::{EBADF, EINVAL, ENOSYS, EOPNOTSUPP, EOVERFLOW, EPERM, EXDEV};

View File

@ -204,6 +204,10 @@ mod sigpipe {
}
if let Some(handler) = handler {
rtassert!(signal(libc::SIGPIPE, handler) != libc::SIG_ERR);
#[cfg(target_os = "hurd")]
{
rtassert!(signal(libc::SIGLOST, handler) != libc::SIG_ERR);
}
}
}
}

View File

@ -75,6 +75,7 @@ pub fn new_raw(fam: c_int, ty: c_int) -> io::Result<Socket> {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "illumos",
target_os = "hurd",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
@ -114,6 +115,7 @@ pub fn new_pair(fam: c_int, ty: c_int) -> io::Result<(Socket, Socket)> {
target_os = "freebsd",
target_os = "illumos",
target_os = "linux",
target_os = "hurd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "nto",
@ -220,6 +222,7 @@ pub fn accept(&self, storage: *mut sockaddr, len: *mut socklen_t) -> io::Result<
target_os = "freebsd",
target_os = "illumos",
target_os = "linux",
target_os = "hurd",
target_os = "netbsd",
target_os = "openbsd",
))] {

View File

@ -46,7 +46,8 @@
target_os = "linux",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "l4re"
target_os = "l4re",
target_os = "hurd",
),
link_name = "__errno_location"
)]
@ -121,7 +122,10 @@ pub fn set_errno(e: i32) {
pub fn error_string(errno: i32) -> String {
extern "C" {
#[cfg_attr(
all(any(target_os = "linux", target_env = "newlib"), not(target_env = "ohos")),
all(
any(target_os = "linux", target_os = "hurd", target_env = "newlib"),
not(target_env = "ohos")
),
link_name = "__xpg_strerror_r"
)]
fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: libc::size_t) -> c_int;
@ -359,7 +363,12 @@ pub fn current_exe() -> io::Result<PathBuf> {
}
}
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
#[cfg(any(
target_os = "linux",
target_os = "hurd",
target_os = "android",
target_os = "emscripten"
))]
pub fn current_exe() -> io::Result<PathBuf> {
match crate::fs::read_link("/proc/self/exe") {
Err(ref e) if e.kind() == io::ErrorKind::NotFound => Err(io::const_io_error!(

View File

@ -21,6 +21,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
if #[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "hurd",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",

View File

@ -374,6 +374,13 @@ unsafe fn do_exec(
return Err(io::Error::last_os_error());
}
}
#[cfg(target_os = "hurd")]
{
let ret = sys::signal(libc::SIGLOST, libc::SIG_DFL);
if ret == libc::SIG_ERR {
return Err(io::Error::last_os_error());
}
}
}
}
@ -620,6 +627,10 @@ fn drop(&mut self) {
let mut default_set = MaybeUninit::<libc::sigset_t>::uninit();
cvt(sigemptyset(default_set.as_mut_ptr()))?;
cvt(sigaddset(default_set.as_mut_ptr(), libc::SIGPIPE))?;
#[cfg(target_os = "hurd")]
{
cvt(sigaddset(default_set.as_mut_ptr(), libc::SIGLOST))?;
}
cvt_nz(libc::posix_spawnattr_setsigdefault(
attrs.0.as_mut_ptr(),
default_set.as_ptr(),
@ -993,6 +1004,8 @@ fn signal_string(signal: i32) -> &'static str {
target_os = "dragonfly"
))]
libc::SIGINFO => " (SIGINFO)",
#[cfg(target_os = "hurd")]
libc::SIGLOST => " (SIGLOST)",
_ => "",
}
}

View File

@ -32,6 +32,7 @@ fn drop(&mut self) {
target_os = "macos",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "hurd",
target_os = "solaris",
target_os = "illumos",
target_os = "netbsd",
@ -193,6 +194,7 @@ pub unsafe fn drop_handler(data: *mut libc::c_void) {
target_os = "macos",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "hurd",
target_os = "solaris",
target_os = "illumos",
target_os = "netbsd",

View File

@ -216,7 +216,8 @@ pub fn set_name(name: &CStr) {
target_os = "l4re",
target_os = "emscripten",
target_os = "redox",
target_os = "vxworks"
target_os = "vxworks",
target_os = "hurd",
))]
pub fn set_name(_name: &CStr) {
// Newlib, Emscripten, and VxWorks have no way to set a thread name.
@ -309,6 +310,7 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> {
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "hurd",
target_os = "ios",
target_os = "tvos",
target_os = "linux",
@ -690,6 +692,7 @@ fn find_mountpoint(group_path: &Path) -> Option<(Cow<'static, str>, &Path)> {
#[cfg(all(
not(target_os = "linux"),
not(target_os = "freebsd"),
not(target_os = "hurd"),
not(target_os = "macos"),
not(target_os = "netbsd"),
not(target_os = "openbsd"),
@ -710,6 +713,7 @@ pub unsafe fn init() -> Option<Guard> {
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "hurd",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
@ -766,6 +770,7 @@ unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
#[cfg(any(
target_os = "android",
target_os = "freebsd",
target_os = "hurd",
target_os = "linux",
target_os = "netbsd",
target_os = "l4re"
@ -903,6 +908,7 @@ pub unsafe fn current() -> Option<Guard> {
#[cfg(any(
target_os = "android",
target_os = "freebsd",
target_os = "hurd",
target_os = "linux",
target_os = "netbsd",
target_os = "l4re"
@ -934,7 +940,7 @@ pub unsafe fn current() -> Option<Guard> {
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackptr, &mut size), 0);
let stackaddr = stackptr.addr();
ret = if cfg!(any(target_os = "freebsd", target_os = "netbsd")) {
ret = if cfg!(any(target_os = "freebsd", target_os = "netbsd", target_os = "hurd")) {
Some(stackaddr - guardsize..stackaddr)
} else if cfg!(all(target_os = "linux", target_env = "musl")) {
Some(stackaddr - guardsize..stackaddr)

View File

@ -11,7 +11,7 @@
// Note, however, that we run on lots older linuxes, as well as cross
// compiling from a newer linux to an older linux, so we also have a
// fallback implementation to use as well.
#[cfg(any(target_os = "linux", target_os = "fuchsia", target_os = "redox"))]
#[cfg(any(target_os = "linux", target_os = "fuchsia", target_os = "redox", target_os = "hurd"))]
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
use crate::mem;
use crate::sys_common::thread_local_dtor::register_dtor_fallback;

View File

@ -35,7 +35,7 @@ pub(in crate::sys::unix) struct Timespec {
}
impl SystemTime {
#[cfg_attr(target_os = "horizon", allow(unused))]
#[cfg_attr(any(target_os = "horizon", target_os = "hurd"), allow(unused))]
pub fn new(tv_sec: i64, tv_nsec: i64) -> SystemTime {
SystemTime { t: Timespec::new(tv_sec, tv_nsec) }
}

View File

@ -32,6 +32,7 @@
cfg_if::cfg_if! {
if #[cfg(any(
target_os = "linux", target_os = "android",
target_os = "hurd",
target_os = "dragonfly", target_os = "freebsd",
target_os = "openbsd", target_os = "netbsd",
target_os = "haiku", target_os = "nto"))] {

View File

@ -148,3 +148,7 @@
#[cfg(target_os = "nto")]
#[link(name = "gcc_s")]
extern "C" {}
#[cfg(target_os = "hurd")]
#[link(name = "gcc_s")]
extern "C" {}

View File

@ -265,7 +265,8 @@ def default_build_triple(verbose):
'FreeBSD': 'unknown-freebsd',
'Haiku': 'unknown-haiku',
'NetBSD': 'unknown-netbsd',
'OpenBSD': 'unknown-openbsd'
'OpenBSD': 'unknown-openbsd',
'GNU': 'unknown-hurd',
}
# Consider the direct transformation first and then the special cases
@ -336,6 +337,7 @@ def default_build_triple(verbose):
'i386': 'i686',
'i486': 'i686',
'i686': 'i686',
'i686-AT386': 'i686',
'i786': 'i686',
'loongarch64': 'loongarch64',
'm68k': 'm68k',

View File

@ -133,7 +133,9 @@ pub unsafe fn setup(_build: &mut crate::Build) {}
// #[cfg(bootstrap)]
(Some(Mode::Std), "target_vendor", Some(&["unikraft"])),
(Some(Mode::Std), "target_env", Some(&["libnx"])),
(Some(Mode::Std), "target_os", Some(&["teeos"])),
// #[cfg(bootstrap)] hurd
(Some(Mode::Std), "target_os", Some(&["teeos", "hurd"])),
(Some(Mode::Rustc), "target_os", Some(&["hurd"])),
// #[cfg(bootstrap)] mips32r6, mips64r6
(
Some(Mode::Std),

View File

@ -28,6 +28,7 @@
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
- [\*-android and \*-androideabi](platform-support/android.md)
- [\*-linux-ohos](platform-support/openharmony.md)
- [\*-hurd-gnu](platform-support/hurd.md)
- [aarch64-unknown-teeos](platform-support/aarch64-unknown-teeos.md)
- [\*-esp-espidf](platform-support/esp-idf.md)
- [\*-unknown-fuchsia](platform-support/fuchsia.md)

View File

@ -269,6 +269,7 @@ target | std | host | notes
`i686-pc-windows-msvc` | * | | 32-bit Windows XP support
[`i686-pc-windows-gnullvm`](platform-support/pc-windows-gnullvm.md) | ✓ | ✓ |
`i686-unknown-haiku` | ✓ | ✓ | 32-bit Haiku
[`i686-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 32-bit GNU/Hurd
[`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 with SSE2
[`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD
`i686-uwp-windows-gnu` | ? | |

View File

@ -0,0 +1,35 @@
# `i686-unknown-hurd-gnu`
**Tier: 3**
[GNU/Hurd] is the GNU Hurd is the GNU project's replacement for the Unix kernel.
## Target maintainers
- Samuel Thibault, `samuel.thibault@ens-lyon.org`, https://github.com/sthibaul/
## Requirements
The target supports host tools.
The GNU/Hurd target supports `std` and uses the standard ELF file format.
## Building the target
This target can be built by adding `i686-unknown-hurd-gnu` as target in the rustc list.
## Building Rust programs
Rust does not yet ship pre-compiled artifacts for this target. To compile for
this target, you will either need to build Rust with the target enabled (see
"Building the target" above), or build your own copy of `core` by using
`build-std` or similar.
## Testing
Tests can be run in the same way as a regular binary.
## Cross-compilation toolchains and C code
The target supports C code, the GNU toolchain calls the target
`i686-unknown-gnu`.

View File

@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")]
| |
| help: there is a expected value with a similar name: `"linux"`
|
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `ericos`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `ericos`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
= note: `#[warn(unexpected_cfgs)]` on by default
warning: 1 warning emitted

View File

@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")]
| |
| help: there is a expected value with a similar name: `"linux"`
|
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
= note: `#[warn(unexpected_cfgs)]` on by default
warning: unexpected `cfg` condition value

View File

@ -16,6 +16,7 @@ mod rusti {
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
target_os = "linux",
target_os = "macos",

View File

@ -37,6 +37,7 @@ struct Outer {
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
target_os = "linux",
target_os = "macos",