Skip to content

Commit

Permalink
Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubilee
Browse files Browse the repository at this point in the history
Add support for QNX Neutrino to standard library

This change:

- adds standard library support for QNX Neutrino (7.1).
- upgrades `libc` to version `0.2.139` which supports QNX Neutrino

`@gh-tr`

⚠️ Backtraces on QNX require rust-lang/backtrace-rs#507 which is not yet merged! (But everything else works without these changes) ⚠️

Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
  • Loading branch information
bors committed Mar 2, 2023
2 parents 0b4ba4c + a510715 commit 864b625
Show file tree
Hide file tree
Showing 43 changed files with 603 additions and 81 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2319,9 +2319,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"

[[package]]
name = "libc"
version = "0.2.138"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ mod c_char_definition {
)
),
all(target_os = "fuchsia", target_arch = "aarch64"),
all(target_os = "nto", target_arch = "aarch64"),
target_os = "horizon"
))] {
pub type c_char = u8;
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core" }
libc = { version = "0.2.138", default-features = false, features = ['rustc-dep-of-std'] }
libc = { version = "0.2.139", default-features = false, features = ['rustc-dep-of-std'] }
compiler_builtins = { version = "0.1.87" }
profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" }
Expand Down
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn main() {
|| target.contains("espidf")
|| target.contains("solid")
|| target.contains("nintendo-3ds")
|| target.contains("nto")
{
// These platforms don't have any special requirements.
} else {
Expand Down
5 changes: 4 additions & 1 deletion library/std/src/net/tcp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,10 @@ fn debug() {
// FIXME: re-enabled openbsd tests once their socket timeout code
// no longer has rounding errors.
// VxWorks ignores SO_SNDTIMEO.
#[cfg_attr(any(target_os = "netbsd", target_os = "openbsd", target_os = "vxworks"), ignore)]
#[cfg_attr(
any(target_os = "netbsd", target_os = "openbsd", target_os = "vxworks", target_os = "nto"),
ignore
)]
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
#[test]
fn timeouts() {
Expand Down
5 changes: 4 additions & 1 deletion library/std/src/net/udp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ fn debug() {
// FIXME: re-enabled openbsd/netbsd tests once their socket timeout code
// no longer has rounding errors.
// VxWorks ignores SO_SNDTIMEO.
#[cfg_attr(any(target_os = "netbsd", target_os = "openbsd", target_os = "vxworks"), ignore)]
#[cfg_attr(
any(target_os = "netbsd", target_os = "openbsd", target_os = "vxworks", target_os = "nto"),
ignore
)]
#[test]
fn timeouts() {
let addr = next_test_ip4();
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ pub mod l4re;
pub mod macos;
#[cfg(target_os = "netbsd")]
pub mod netbsd;
#[cfg(target_os = "nto")]
pub mod nto;
#[cfg(target_os = "openbsd")]
pub mod openbsd;
#[cfg(target_os = "redox")]
Expand Down
92 changes: 92 additions & 0 deletions library/std/src/os/nto/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sys_common::AsInner;

#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_dev(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ino(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mode(&self) -> u32;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_nlink(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_uid(&self) -> u32;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_gid(&self) -> u32;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_rdev(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_size(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime_nsec(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime_nsec(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime_nsec(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blksize(&self) -> u64;
#[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_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_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
}
}
4 changes: 4 additions & 0 deletions library/std/src/os/nto/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![stable(feature = "raw_ext", since = "1.1.0")]

pub mod fs;
pub(super) mod raw;
40 changes: 40 additions & 0 deletions library/std/src/os/nto/raw.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#![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_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::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, time_t};

mod arch {
use crate::os::raw::c_long;

#[stable(feature = "raw_ext", since = "1.1.0")]
pub type blkcnt_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 = 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 = i64;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type time_t = c_long;
}
5 changes: 4 additions & 1 deletion library/std/src/os/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ mod platform {
pub use crate::os::macos::*;
#[cfg(target_os = "netbsd")]
pub use crate::os::netbsd::*;
#[cfg(target_os = "nto")]
pub use crate::os::nto::*;
#[cfg(target_os = "openbsd")]
pub use crate::os::openbsd::*;
#[cfg(target_os = "redox")]
Expand Down Expand Up @@ -95,7 +97,8 @@ pub mod thread;
target_os = "watchos",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
target_os = "nto",
))]
pub mod ucred;

Expand Down
6 changes: 4 additions & 2 deletions library/std/src/os/unix/net/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use crate::{fmt, io};
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "haiku"
target_os = "haiku",
target_os = "nto",
))]
use libc::MSG_NOSIGNAL;
#[cfg(not(any(
Expand All @@ -29,7 +30,8 @@ use libc::MSG_NOSIGNAL;
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "haiku"
target_os = "haiku",
target_os = "nto",
)))]
const MSG_NOSIGNAL: libc::c_int = 0x0;

Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/unix/net/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ fn long_path() {
}

#[test]
#[cfg(not(target_os = "nto"))]
fn timeouts() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
Expand Down
26 changes: 17 additions & 9 deletions library/std/src/os/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ use crate::sealed::Sealed;
use crate::sys;
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};

#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
type UserId = u32;
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
type GroupId = u32;

#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
type UserId = u16;
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
type GroupId = u16;
use cfg_if::cfg_if;

cfg_if! {
if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] {
type UserId = u16;
type GroupId = u16;
} else if #[cfg(target_os = "nto")] {
// Both IDs are signed, see `sys/target_nto.h` of the QNX Neutrino SDP.
// Only positive values should be used, see e.g.
// https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/s/setuid.html
type UserId = i32;
type GroupId = i32;
} else {
type UserId = u32;
type GroupId = u32;
}
}

/// Unix-specific extensions to the [`process::Command`] builder.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/unix/ucred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ pub mod impl_linux {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "nto",
))]
pub mod impl_bsd {
use super::UCred;
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sys/unix/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ impl DoubleEndedIterator for Args {
target_os = "fuchsia",
target_os = "redox",
target_os = "vxworks",
target_os = "horizon"
target_os = "horizon",
target_os = "nto",
))]
mod imp {
use super::Args;
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/sys/unix/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ pub mod os {
pub const EXE_EXTENSION: &str = "";
}

#[cfg(target_os = "nto")]
pub mod os {
pub const FAMILY: &str = "unix";
pub const OS: &str = "nto";
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 = "redox")]
pub mod os {
pub const FAMILY: &str = "unix";
Expand Down
14 changes: 11 additions & 3 deletions library/std/src/sys/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ const fn max_iov() -> usize {
libc::IOV_MAX as usize
}

#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "nto",
))]
const fn max_iov() -> usize {
libc::UIO_MAXIOV as usize
}
Expand All @@ -67,6 +72,7 @@ const fn max_iov() -> usize {
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "nto",
target_os = "openbsd",
target_os = "horizon",
target_os = "watchos",
Expand Down Expand Up @@ -207,7 +213,8 @@ impl FileDesc {
target_os = "linux",
target_os = "haiku",
target_os = "redox",
target_os = "vxworks"
target_os = "vxworks",
target_os = "nto",
)))]
pub fn set_cloexec(&self) -> io::Result<()> {
unsafe {
Expand All @@ -225,7 +232,8 @@ impl FileDesc {
target_os = "linux",
target_os = "haiku",
target_os = "redox",
target_os = "vxworks"
target_os = "vxworks",
target_os = "nto",
))]
pub fn set_cloexec(&self) -> io::Result<()> {
unsafe {
Expand Down
Loading

0 comments on commit 864b625

Please sign in to comment.