--- /dev/null +++ b/src/librustc_target/spec/gnu_base.rs @@ -0,0 +1,43 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use spec::{LinkArgs, LinkerFlavor, TargetOptions, RelroLevel}; +use std::default::Default; + +pub fn opts() -> TargetOptions { + let mut args = LinkArgs::new(); + args.insert(LinkerFlavor::Gcc, vec![ + // We want to be able to strip as much executable code as possible + // from the linker command line, and this flag indicates to the + // linker that it can avoid linking in dynamic libraries that don't + // actually satisfy any symbols up to that point (as with many other + // resolutions the linker does). This option only applies to all + // following libraries so we're sure to pass it as one of the first + // arguments. + "-Wl,--as-needed".to_string(), + + // Always enable NX protection when it is available + "-Wl,-z,noexecstack".to_string(), + ]); + + TargetOptions { + dynamic_linking: true, + executables: true, + target_family: Some("unix".to_string()), + linker_is_gnu: true, + has_rpath: true, + pre_link_args: args, + position_independent_executables: true, + relro_level: RelroLevel::Full, + exe_allocation_crate: super::maybe_jemalloc(), + has_elf_tls: true, + .. Default::default() + } +} --- /dev/null +++ b/src/librustc_target/spec/i686_unknown_gnu.rs @@ -0,0 +1,34 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use spec::{LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::gnu_base::opts(); + base.cpu = "pentiumpro".to_string(); + base.max_atomic_width = Some(64); + base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string()); + base.stack_probes = true; + + Ok(Target { + llvm_target: "i686-unknown-hurd-gnu".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), + arch: "x86".to_string(), + target_os: "gnu".to_string(), + target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), + //linker_flavor: LinkerFlavor::Gcc, + linker_flavor: LinkerFlavor::Ld, + options: base, + }) +} --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -61,6 +61,7 @@ mod bitrig_base; mod cloudabi_base; mod dragonfly_base; mod freebsd_base; +mod gnu_base; mod haiku_base; mod linux_base; mod linux_musl_base; @@ -373,6 +374,8 @@ supported_targets! { ("armv7-unknown-cloudabi-eabihf", armv7_unknown_cloudabi_eabihf), ("i686-unknown-cloudabi", i686_unknown_cloudabi), ("x86_64-unknown-cloudabi", x86_64_unknown_cloudabi), + + ("i686-unknown-gnu", i686_unknown_gnu), } /// Everything `rustc` knows about how to compile for a specific target. --- /dev/null +++ b/src/libstd/os/gnu/fs.rs @@ -0,0 +1,389 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use libc; + +use fs::Metadata; +use sys_common::AsInner; + +#[allow(deprecated)] +use os::gnu::raw; + +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned [`stat`] are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + /// + /// [`stat`]: ../../../../std/os/gnu/raw/struct.stat.html + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::gnu::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// let stat = meta.as_raw_stat(); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", + reason = "deprecated in favor of the accessor \ + methods of this trait")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + /// Returns the device ID on which this file resides. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::gnu::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::gnu::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::gnu::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::gnu::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::gnu::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::gnu::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::gnu::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::gnu::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. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::gnu::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, nano seconds part. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::gnu::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. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::gnu::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, nano seconds part. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::gnu::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. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::gnu::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, nano seconds part. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::gnu::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" blocksize for efficient filesystem I/O. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::gnu::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::gnu::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 { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat + as *const raw::stat) + } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev 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_atime as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atime_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtime_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctime_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 + } +} --- /dev/null +++ b/src/libstd/os/gnu/mod.rs @@ -0,0 +1,16 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Linux-specific definitions + +#![stable(feature = "raw_ext", since = "1.1.0")] + +pub mod raw; +pub mod fs; --- /dev/null +++ b/src/libstd/os/gnu/raw.rs @@ -0,0 +1,91 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Linux-specific raw type definitions + +#![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "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)] +#![allow(missing_debug_implementations)] + +use os::raw::c_int; + +#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; + +#[stable(feature = "pthread_t", since = "1.8.0")] +pub type pthread_t = c_int; + +#[doc(inline)] +#[stable(feature = "raw_ext", since = "1.1.0")] +pub use self::arch::{off_t, off64_t, ino_t, ino64_t, nlink_t, blksize_t, blkcnt_t, blkcnt64_t, stat, time_t}; + +#[cfg(any(target_arch = "x86"))] +mod arch { + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt64_t = i64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type ino64_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i32; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type off64_t = i64; + #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_fstype: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gen: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_author: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_flags: u32, + } +} --- a/src/libstd/os/mod.rs +++ b/src/libstd/os/mod.rs @@ -40,6 +40,7 @@ cfg_if! { #[cfg(target_os = "dragonfly")] pub mod dragonfly; #[cfg(target_os = "freebsd")] pub mod freebsd; #[cfg(target_os = "haiku")] pub mod haiku; + #[cfg(target_os = "gnu")] pub mod gnu; #[cfg(target_os = "ios")] pub mod ios; #[cfg(target_os = "macos")] pub mod macos; #[cfg(target_os = "netbsd")] pub mod netbsd; --- a/src/liblibc/src/unix/bsd/mod.rs +++ b/src/liblibc/src/unix/bsd/mod.rs @@ -548,7 +548,7 @@ cfg_if! { target_os = "bitrig"))] { mod netbsdlike; pub use self::netbsdlike::*; - } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { + } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "gnu"))] { mod freebsdlike; pub use self::freebsdlike::*; } else { --- a/src/liblibc/src/unix/mod.rs +++ b/src/liblibc/src/unix/mod.rs @@ -959,7 +959,8 @@ cfg_if! { target_os = "dragonfly", target_os = "openbsd", target_os = "netbsd", - target_os = "bitrig"))] { + target_os = "bitrig", + target_os = "gnu"))] { mod bsd; pub use self::bsd::*; } else if #[cfg(target_os = "solaris")] { --- a/src/vendor/libc/src/unix/bsd/mod.rs +++ b/src/vendor/libc/src/unix/bsd/mod.rs @@ -548,7 +548,7 @@ cfg_if! { target_os = "bitrig"))] { mod netbsdlike; pub use self::netbsdlike::*; - } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { + } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "gnu"))] { mod freebsdlike; pub use self::freebsdlike::*; } else { --- a/src/vendor/libc/src/unix/mod.rs +++ b/src/vendor/libc/src/unix/mod.rs @@ -944,7 +944,8 @@ cfg_if! { target_os = "dragonfly", target_os = "openbsd", target_os = "netbsd", - target_os = "bitrig"))] { + target_os = "bitrig", + target_os = "gnu"))] { mod bsd; pub use self::bsd::*; } else if #[cfg(target_os = "solaris")] { --- /dev/null +++ b/src/liblibc/src/unix/bsd/freebsdlike/gnu/mod.rs @@ -0,0 +1,168 @@ +pub type clock_t = ::c_long; +pub type ino_t = ::c_ulong; +pub type ino64_t = u64; +pub type off64_t = i64; +pub type nlink_t = ::c_uint; +pub type blksize_t = ::c_long; +pub type blkcnt64_t = i64; +pub type clockid_t = i32; +pub type sem_t = _sem; + +pub type fsblkcnt_t = ::c_ulong; +pub type fsfilcnt_t = ::c_ulong; + +pub type time_t = ::c_long; +pub type suseconds_t = ::c_long; +pub type fsid_t = u64; + +s! { + pub struct exit_status { + pub e_termination: ::c_short, + pub e_exit: ::c_short, + } + + pub struct utmpx { + pub ut_type: ::c_short, + pub ut_pid: ::pid_t, + pub ut_line: [::c_char; 32], + pub ut_id: [::c_char; 4], + pub ut_user: [::c_char; 32], + pub ut_host: [::c_char; 256], + pub ut_exit: ::exit_status, + pub ut_session: ::c_long, + pub ut_tv: ::timeval, + pub ut_addr_v6: ::int32_t, + pub __glibc_reserved: [::c_char; 20], + } + + pub struct aiocb { + pub aio_fildes: ::c_int, + pub aio_lio_opcode: ::c_int, + pub aio_reqprio: ::c_int, + pub aio_buf: *mut ::c_void, + pub aio_nbytes: ::size_t, + pub aio_sigevent: sigevent, + pub __next_prio: *mut aiocb, + pub __abs_prio: ::c_int, + pub __policy: ::c_int, + pub __error_code: ::c_int, + pub __return_value: ::ssize_t, + pub aio_offset: ::off_t, + #[cfg(all(not(target_arch = "x86_64"), target_pointer_width = "32"))] + __pad: [::c_char; 4], + __glibc_reserved: [::c_char; 32], + } + + pub struct dirent { + pub d_ino: ino_t, + pub d_reclen: ::c_ushort, + pub d_type: u8, + pub d_namlen: u8, + pub d_name: [::c_char; 256], + } + + pub struct mq_attr { + pub mq_flags: ::c_long, + pub mq_maxmsg: ::c_long, + pub mq_msgsize: ::c_long, + pub mq_curmsgs: ::c_long, + } + + pub struct sigevent { + pub sigev_value: ::sigval, + pub sigev_signo: ::c_int, + pub sigev_notify: ::c_int, + pub sigev_notify_function: *mut ::c_void, + pub sigev_notify_attributes: *mut ::c_void, + } + + pub struct stat { + pub st_fstype: ::c_int, + pub st_dev: u64, + pub st_ino: ::ino_t, + pub st_gen: ::c_uint, + pub st_rdev: ::dev_t, + pub st_mode: ::mode_t, + pub st_nlink: ::nlink_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_size: ::off_t, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_ulong, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_ulong, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_ulong, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt_t, + pub st_author: ::uid_t, + pub st_flags: ::c_uint, + __st_spare: [u8; 11], + } + + pub struct stat64 { + pub st_fstype: ::c_int, + pub st_dev: u64, + pub st_ino: ::ino64_t, + pub st_gen: ::c_uint, + pub st_rdev: ::dev_t, + pub st_mode: ::mode_t, + pub st_nlink: ::nlink_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_size: ::off64_t, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_ulong, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_ulong, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_ulong, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt64_t, + pub st_author: ::uid_t, + pub st_flags: ::c_uint, + __st_spare: [u8; 8], + } + + pub struct statvfs { + pub __f_type: ::c_uint, + pub f_bsize: ::c_ulong, + pub f_blocks: ::fsblkcnt_t, + pub f_bfree: ::fsblkcnt_t, + pub f_bavail: ::fsblkcnt_t, + pub f_files: ::fsfilcnt_t, + pub f_ffree: ::fsfilcnt_t, + pub f_fsid: ::fsid_t, + pub f_namemax: ::c_ulong, + pub f_favail: ::fsfilcnt_t, + pub f_frsize: ::c_ulong, + pub f_flag: ::c_ulong, + pub f_spare: [::c_uint; 3], + } + + pub struct _sem { + __lock: ::c_int, + __queue: *mut ::c_void, + __pshared: ::c_int, + __value: ::c_int, + __data: *mut ::c_void, + } +} + +pub const O_CLOEXEC: ::c_int = 0x00400000; + +pub const CLOCK_REALTIME: ::clockid_t = 0; +pub const CLOCK_MONOTONIC: ::clockid_t = 1; + +extern { + pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; +} + +cfg_if! { + if #[cfg(target_arch = "x86")] { + mod x86; + pub use self::x86::*; + } else { + // Unknown target_arch + } +} --- /dev/null +++ b/src/liblibc/src/unix/bsd/freebsdlike/gnu/x86.rs @@ -0,0 +1,2 @@ +pub type c_long = i32; +pub type c_ulong = u32; --- a/src/liblibc/src/unix/bsd/freebsdlike/mod.rs +++ b/src/liblibc/src/unix/bsd/freebsdlike/mod.rs @@ -1211,6 +1211,9 @@ cfg_if! { } else if #[cfg(target_os = "dragonfly")] { mod dragonfly; pub use self::dragonfly::*; + } else if #[cfg(target_os = "gnu")] { + mod gnu; + pub use self::gnu::*; } else { // ... } --- a/src/liblibc/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/liblibc/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -32,18 +32,18 @@ s! { pub struct aiocb { pub aio_fildes: ::c_int, - pub aio_offset: ::off_t, - pub aio_buf: *mut ::c_void, - pub aio_nbytes: ::size_t, - __unused1: [::c_int; 2], - __unused2: *mut ::c_void, pub aio_lio_opcode: ::c_int, pub aio_reqprio: ::c_int, - // unused 3 through 5 are the __aiocb_private structure - __unused3: ::c_long, - __unused4: ::c_long, - __unused5: *mut ::c_void, + pub aio_buf: *mut ::c_void, + pub aio_nbytes: ::size_t, pub aio_sigevent: sigevent + pub __next_prio: *mut ::c_void, + pub __abs_prio: ::c_int; + pub __policy: ::c_int; + pub __error_code: ::c_int; + pub __return_value: ::ssize_t, + pub aio_offset: ::off_t, + __glibc_reserved: [::c_char; 32], } pub struct dirent { --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -24,22 +24,26 @@ use time::Duration; #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd", target_os = "netbsd", - target_os = "solaris", target_os = "haiku", target_os = "l4re"))] + target_os = "solaris", target_os = "haiku", target_os = "l4re", + target_os = "gnu"))] use sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP; #[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd", target_os = "netbsd", - target_os = "solaris", target_os = "haiku", target_os = "l4re")))] + target_os = "solaris", target_os = "haiku", target_os = "l4re", + target_os = "gnu")))] use sys::net::netc::IPV6_ADD_MEMBERSHIP; #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd", target_os = "netbsd", - target_os = "solaris", target_os = "haiku", target_os = "l4re"))] + target_os = "solaris", target_os = "haiku", target_os = "l4re", + target_os = "gnu"))] use sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP; #[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "openbsd", target_os = "netbsd", - target_os = "solaris", target_os = "haiku", target_os = "l4re")))] + target_os = "solaris", target_os = "haiku", target_os = "l4re", + target_os = "gnu")))] use sys::net::netc::IPV6_DROP_MEMBERSHIP; #[cfg(any(target_os = "linux", target_os = "android", --- a/src/libstd/sys/unix/env.rs +++ b/src/libstd/sys/unix/env.rs @@ -172,3 +172,14 @@ pub mod os { pub const EXE_SUFFIX: &'static str = ""; pub const EXE_EXTENSION: &'static str = ""; } + +#[cfg(target_os = "gnu")] +pub mod os { + pub const FAMILY: &'static str = "unix"; + pub const OS: &'static str = "gnu"; + pub const DLL_PREFIX: &'static str = "lib"; + pub const DLL_SUFFIX: &'static str = ".so"; + pub const DLL_EXTENSION: &'static str = "so"; + pub const EXE_SUFFIX: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; +} --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -28,6 +28,7 @@ use libc; #[cfg(all(not(dox), target_os = "emscripten"))] pub use os::emscripten as platform; #[cfg(all(not(dox), target_os = "fuchsia"))] pub use os::fuchsia as platform; #[cfg(all(not(dox), target_os = "l4re"))] pub use os::linux as platform; +#[cfg(all(not(dox), target_os = "gnu"))] pub use os::gnu as platform; pub use self::rand::hashmap_random_keys; pub use libc::strlen; --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -138,9 +138,10 @@ impl Thread { target_os = "solaris", target_os = "haiku", target_os = "l4re", - target_os = "emscripten"))] + target_os = "emscripten", + target_os = "gnu"))] pub fn set_name(_name: &CStr) { - // Newlib, Illumos, Haiku, and Emscripten have no way to set a thread name. + // Newlib, Illumos, Haiku, Emscripten and GNU have no way to set a thread name. } #[cfg(target_os = "fuchsia")] pub fn set_name(_name: &CStr) { @@ -446,7 +447,8 @@ fn min_stack_size(attr: *const libc::pth // No point in looking up __pthread_get_minstack() on non-glibc // platforms. #[cfg(all(not(target_os = "linux"), - not(target_os = "netbsd")))] + not(target_os = "netbsd"), + not(target_os = "gnu")))] fn min_stack_size(_: *const libc::pthread_attr_t) -> usize { libc::PTHREAD_STACK_MIN } @@ -455,3 +457,8 @@ fn min_stack_size(_: *const libc::pthrea fn min_stack_size(_: *const libc::pthread_attr_t) -> usize { 2048 // just a guess } + +#[cfg(target_os = "gnu")] +fn min_stack_size(_: *const libc::pthread_attr_t) -> usize { + 2048 // just a reasonable value +} --- a/src/libstd/sys/unix/args.rs +++ b/src/libstd/sys/unix/args.rs @@ -66,7 +66,8 @@ impl DoubleEndedIterator for Args { target_os = "emscripten", target_os = "haiku", target_os = "l4re", - target_os = "fuchsia"))] + target_os = "fuchsia", + target_os = "gnu"))] mod imp { use os::unix::prelude::*; use ptr; --- a/src/libstd/sys/unix/fast_thread_local.rs +++ b/src/libstd/sys/unix/fast_thread_local.rs @@ -20,7 +20,7 @@ // fallback implementation to use as well. // // Due to rust-lang/rust#18804, make sure this is not generic! -#[cfg(any(target_os = "linux", target_os = "fuchsia"))] +#[cfg(any(target_os = "linux", target_os = "fuchsia", target_os = "gnu"))] pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { use libc; use mem; --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -352,7 +352,8 @@ impl DirEntry { target_os = "solaris", target_os = "haiku", target_os = "l4re", - target_os = "fuchsia"))] + target_os = "fuchsia", + target_os = "gnu"))] pub fn ino(&self) -> u64 { self.entry.d_ino as u64 } @@ -372,7 +373,8 @@ impl DirEntry { target_os = "openbsd", target_os = "freebsd", target_os = "dragonfly", - target_os = "bitrig"))] + target_os = "bitrig", + target_os = "gnu"))] fn name_bytes(&self) -> &[u8] { unsafe { ::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8, --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -281,7 +281,7 @@ pub fn current_exe() -> io::Result io::Result { let selfexe = PathBuf::from("/proc/self/exe"); if selfexe.exists() {