Auto merge of #115230 - Vtewari2311:mod-hurd-latest, r=b-naber

added support for GNU/Hurd

adding support for i686-unknown-hurd-gnu
This commit is contained in:
bors 2023-09-21 19:24:01 +00:00
commit f73d376fb6
36 changed files with 626 additions and 35 deletions

View file

@ -71,6 +71,7 @@ impl DoubleEndedIterator for Args {
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 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
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 @@ impl FileDesc {
}
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 @@ impl FileDesc {
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 @@ impl FileDesc {
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 @@ impl FileDesc {
}
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 @@ impl FileDesc {
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 @@ impl FileDesc {
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 @@ use libc::{c_int, mode_t};
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 @@ use libc::fstatat64;
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 @@ use libc::readdir64_r;
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 @@ use libc::{
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 @@ impl FileAttr {
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 @@ impl FileAttr {
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 @@ impl FileAttr {
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 @@ 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 {
@ -809,7 +828,12 @@ impl DirEntry {
}
#[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 @@ impl DirEntry {
}
#[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 @@ impl DirEntry {
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 @@ impl DirEntry {
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 @@ impl DirEntry {
target_os = "redox",
target_os = "nto",
target_os = "vita",
target_os = "hurd",
))]
fn name_cstr(&self) -> &CStr {
&self.name
@ -1131,6 +1163,7 @@ impl File {
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 @@ impl File {
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 @@ impl fmt::Debug for File {
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 @@ impl fmt::Debug for File {
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::ptr;
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 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
}
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 @@ impl 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 @@ impl 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 @@ impl Socket {
target_os = "freebsd",
target_os = "illumos",
target_os = "linux",
target_os = "hurd",
target_os = "netbsd",
target_os = "openbsd",
))] {

View file

@ -46,7 +46,8 @@ extern "C" {
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 @@ impl Command {
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 @@ impl Command {
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 @@ impl Drop for Handler {
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 @@ mod imp {
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 @@ impl Thread {
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",
@ -692,6 +694,7 @@ mod cgroups {
#[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"),
@ -712,6 +715,7 @@ pub mod guard {
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "hurd",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
@ -768,6 +772,7 @@ pub mod guard {
#[cfg(any(
target_os = "android",
target_os = "freebsd",
target_os = "hurd",
target_os = "linux",
target_os = "netbsd",
target_os = "l4re"
@ -905,6 +910,7 @@ pub mod guard {
#[cfg(any(
target_os = "android",
target_os = "freebsd",
target_os = "hurd",
target_os = "linux",
target_os = "netbsd",
target_os = "l4re"
@ -936,7 +942,7 @@ pub mod 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) }
}