Rollup merge of #84119 - CDirkx:vxworks, r=m-ou-se
Move `sys::vxworks` code to `sys::unix`
Follow-up to #77666, `sys::vxworks` is almost identical to `sys::unix`, the only differences are the `rand`, `thread_local_dtor`, and `process` implementation. Since `vxworks` is `target_family = unix` anyway, there is no reason for the code not to live inside of `sys::unix` like all the other unix-OSes.
e41f378f82/compiler/rustc_target/src/spec/vxworks_base.rs (L12)
``@rustbot`` label: +T-libs-impl
This commit is contained in:
commit
3897ad1128
14 changed files with 88 additions and 222 deletions
|
@ -25,10 +25,7 @@
|
|||
mod common;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "vxworks")] {
|
||||
mod vxworks;
|
||||
pub use self::vxworks::*;
|
||||
} else if #[cfg(unix)] {
|
||||
if #[cfg(unix)] {
|
||||
mod unix;
|
||||
pub use self::unix::*;
|
||||
} else if #[cfg(windows)] {
|
||||
|
|
|
@ -173,3 +173,14 @@ pub mod os {
|
|||
pub const EXE_SUFFIX: &str = "";
|
||||
pub const EXE_EXTENSION: &str = "";
|
||||
}
|
||||
|
||||
#[cfg(target_os = "vxworks")]
|
||||
pub mod os {
|
||||
pub const FAMILY: &str = "unix";
|
||||
pub const OS: &str = "vxworks";
|
||||
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 = "";
|
||||
}
|
||||
|
|
|
@ -62,6 +62,8 @@ cfg_if::cfg_if! {
|
|||
use crate::os::redox as platform;
|
||||
#[cfg(target_os = "solaris")]
|
||||
use crate::os::solaris as platform;
|
||||
#[cfg(target_os = "vxworks")]
|
||||
use crate::os::vxworks as platform;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ pub fn init() {
|
|||
} else if #[cfg(not(any(
|
||||
target_os = "emscripten",
|
||||
target_os = "fuchsia",
|
||||
target_os = "vxworks",
|
||||
// The poll on Darwin doesn't set POLLNVAL for closed fds.
|
||||
target_os = "macos",
|
||||
target_os = "ios",
|
||||
|
|
|
@ -85,11 +85,6 @@ pub fn errno() -> i32 {
|
|||
unsafe { libc::errnoGet() }
|
||||
}
|
||||
|
||||
#[cfg(target_os = "vxworks")]
|
||||
pub fn set_errno(e: i32) {
|
||||
unsafe { libc::errnoSet(e as c_int) };
|
||||
}
|
||||
|
||||
#[cfg(target_os = "dragonfly")]
|
||||
pub fn errno() -> i32 {
|
||||
extern "C" {
|
||||
|
@ -642,7 +637,7 @@ pub fn getppid() -> u32 {
|
|||
unsafe { libc::getppid() as u32 }
|
||||
}
|
||||
|
||||
#[cfg(target_env = "gnu")]
|
||||
#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
|
||||
pub fn glibc_version() -> Option<(usize, usize)> {
|
||||
if let Some(Ok(version_str)) = glibc_version_cstr().map(CStr::to_str) {
|
||||
parse_glibc_version(version_str)
|
||||
|
@ -651,7 +646,7 @@ pub fn glibc_version() -> Option<(usize, usize)> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_env = "gnu")]
|
||||
#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
|
||||
fn glibc_version_cstr() -> Option<&'static CStr> {
|
||||
weak! {
|
||||
fn gnu_get_libc_version() -> *const libc::c_char
|
||||
|
@ -665,7 +660,7 @@ fn glibc_version_cstr() -> Option<&'static CStr> {
|
|||
|
||||
// Returns Some((major, minor)) if the string is a valid "x.y" version,
|
||||
// ignoring any extra dot-separated parts. Otherwise return None.
|
||||
#[cfg(target_env = "gnu")]
|
||||
#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
|
||||
fn parse_glibc_version(version: &str) -> Option<(usize, usize)> {
|
||||
let mut parsed_ints = version.split('.').map(str::parse::<usize>).fuse();
|
||||
match (parsed_ints.next(), parsed_ints.next()) {
|
||||
|
|
|
@ -4,11 +4,17 @@ pub use crate::ffi::OsString as EnvKey;
|
|||
pub use crate::sys_common::process::CommandEnvs;
|
||||
|
||||
mod process_common;
|
||||
#[cfg(not(target_os = "fuchsia"))]
|
||||
#[path = "process_unix.rs"]
|
||||
mod process_inner;
|
||||
#[cfg(target_os = "fuchsia")]
|
||||
#[path = "process_fuchsia.rs"]
|
||||
mod process_inner;
|
||||
#[cfg(target_os = "fuchsia")]
|
||||
mod zircon;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "fuchsia")] {
|
||||
#[path = "process_fuchsia.rs"]
|
||||
mod process_inner;
|
||||
mod zircon;
|
||||
} else if #[cfg(target_os = "vxworks")] {
|
||||
#[path = "process_vxworks.rs"]
|
||||
mod process_inner;
|
||||
} else {
|
||||
#[path = "process_unix.rs"]
|
||||
mod process_inner;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ impl Command {
|
|||
needs_stdin: bool,
|
||||
) -> io::Result<(Process, StdioPipes)> {
|
||||
use crate::sys::cvt_r;
|
||||
const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX";
|
||||
let envp = self.capture_env();
|
||||
|
||||
if self.saw_nul() {
|
||||
|
@ -61,6 +60,9 @@ impl Command {
|
|||
t!(cvt(libc::chdir(cwd.as_ptr())));
|
||||
}
|
||||
|
||||
// pre_exec closures are ignored on VxWorks
|
||||
let _ = self.get_closures();
|
||||
|
||||
let c_envp = envp
|
||||
.as_ref()
|
||||
.map(|c| c.as_ptr())
|
||||
|
@ -68,7 +70,7 @@ impl Command {
|
|||
let stack_size = thread::min_stack();
|
||||
|
||||
// ensure that access to the environment is synchronized
|
||||
let _lock = sys::os::env_lock();
|
||||
let _lock = sys::os::env_read_lock();
|
||||
|
||||
let ret = libc::rtpSpawn(
|
||||
self.get_program_cstr().as_ptr(),
|
||||
|
@ -196,6 +198,24 @@ impl ExitStatus {
|
|||
pub fn signal(&self) -> Option<i32> {
|
||||
if !self.exited() { Some(libc::WTERMSIG(self.0)) } else { None }
|
||||
}
|
||||
|
||||
pub fn core_dumped(&self) -> bool {
|
||||
// This method is not yet properly implemented on VxWorks
|
||||
false
|
||||
}
|
||||
|
||||
pub fn stopped_signal(&self) -> Option<i32> {
|
||||
if libc::WIFSTOPPED(self.0) { Some(libc::WSTOPSIG(self.0)) } else { None }
|
||||
}
|
||||
|
||||
pub fn continued(&self) -> bool {
|
||||
// This method is not yet properly implemented on VxWorks
|
||||
false
|
||||
}
|
||||
|
||||
pub fn into_raw(&self) -> c_int {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying.
|
|
@ -18,7 +18,8 @@ pub fn hashmap_random_keys() -> (u64, u64) {
|
|||
not(target_os = "freebsd"),
|
||||
not(target_os = "netbsd"),
|
||||
not(target_os = "fuchsia"),
|
||||
not(target_os = "redox")
|
||||
not(target_os = "redox"),
|
||||
not(target_os = "vxworks")
|
||||
))]
|
||||
mod imp {
|
||||
use crate::fs::File;
|
||||
|
@ -237,3 +238,29 @@ mod imp {
|
|||
file.read_exact(v).expect("failed to read rand:")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "vxworks")]
|
||||
mod imp {
|
||||
use crate::io;
|
||||
use core::sync::atomic::{AtomicBool, Ordering::Relaxed};
|
||||
|
||||
pub fn fill_bytes(v: &mut [u8]) {
|
||||
static RNG_INIT: AtomicBool = AtomicBool::new(false);
|
||||
while !RNG_INIT.load(Relaxed) {
|
||||
let ret = unsafe { libc::randSecure() };
|
||||
if ret < 0 {
|
||||
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
|
||||
} else if ret > 0 {
|
||||
RNG_INIT.store(true, Relaxed);
|
||||
break;
|
||||
}
|
||||
unsafe { libc::usleep(10) };
|
||||
}
|
||||
let ret = unsafe {
|
||||
libc::randABytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
|
||||
};
|
||||
if ret < 0 {
|
||||
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,3 +92,9 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "vxworks")]
|
||||
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
|
||||
use crate::sys_common::thread_local_dtor::register_dtor_fallback;
|
||||
register_dtor_fallback(t, dtor);
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
pub mod os {
|
||||
pub const FAMILY: &str = "vxworks";
|
||||
pub const OS: &str = "vxworks";
|
||||
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 = "";
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
#![allow(dead_code)]
|
||||
#![allow(missing_docs, nonstandard_style)]
|
||||
|
||||
use crate::io::ErrorKind;
|
||||
|
||||
pub use self::rand::hashmap_random_keys;
|
||||
pub use crate::os::vxworks as platform;
|
||||
pub use libc::strlen;
|
||||
|
||||
#[macro_use]
|
||||
#[path = "../unix/weak.rs"]
|
||||
pub mod weak;
|
||||
|
||||
#[path = "../unix/alloc.rs"]
|
||||
pub mod alloc;
|
||||
#[path = "../unix/args.rs"]
|
||||
pub mod args;
|
||||
#[path = "../unix/cmath.rs"]
|
||||
pub mod cmath;
|
||||
#[path = "../unix/condvar.rs"]
|
||||
pub mod condvar;
|
||||
pub mod env;
|
||||
#[path = "../unix/ext/mod.rs"]
|
||||
pub mod ext;
|
||||
#[path = "../unix/fd.rs"]
|
||||
pub mod fd;
|
||||
#[path = "../unix/fs.rs"]
|
||||
pub mod fs;
|
||||
#[path = "../unix/io.rs"]
|
||||
pub mod io;
|
||||
#[path = "../unix/memchr.rs"]
|
||||
pub mod memchr;
|
||||
#[path = "../unix/mutex.rs"]
|
||||
pub mod mutex;
|
||||
#[path = "../unix/net.rs"]
|
||||
pub mod net;
|
||||
#[path = "../unix/os.rs"]
|
||||
pub mod os;
|
||||
#[path = "../unix/path.rs"]
|
||||
pub mod path;
|
||||
#[path = "../unix/pipe.rs"]
|
||||
pub mod pipe;
|
||||
pub mod process;
|
||||
pub mod rand;
|
||||
#[path = "../unix/rwlock.rs"]
|
||||
pub mod rwlock;
|
||||
#[path = "../unix/stack_overflow.rs"]
|
||||
pub mod stack_overflow;
|
||||
#[path = "../unix/stdio.rs"]
|
||||
pub mod stdio;
|
||||
#[path = "../unix/thread.rs"]
|
||||
pub mod thread;
|
||||
pub mod thread_local_dtor;
|
||||
#[path = "../unix/thread_local_key.rs"]
|
||||
pub mod thread_local_key;
|
||||
#[path = "../unix/time.rs"]
|
||||
pub mod time;
|
||||
|
||||
pub use crate::sys_common::os_str_bytes as os_str;
|
||||
|
||||
#[cfg(not(test))]
|
||||
pub fn init() {
|
||||
// ignore SIGPIPE
|
||||
unsafe {
|
||||
assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
pub use libc::signal;
|
||||
|
||||
pub fn decode_error_kind(errno: i32) -> ErrorKind {
|
||||
match errno as libc::c_int {
|
||||
libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
|
||||
libc::ECONNRESET => ErrorKind::ConnectionReset,
|
||||
libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
|
||||
libc::EPIPE => ErrorKind::BrokenPipe,
|
||||
libc::ENOTCONN => ErrorKind::NotConnected,
|
||||
libc::ECONNABORTED => ErrorKind::ConnectionAborted,
|
||||
libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
|
||||
libc::EADDRINUSE => ErrorKind::AddrInUse,
|
||||
libc::ENOENT => ErrorKind::NotFound,
|
||||
libc::EINTR => ErrorKind::Interrupted,
|
||||
libc::EINVAL => ErrorKind::InvalidInput,
|
||||
libc::ETIMEDOUT => ErrorKind::TimedOut,
|
||||
libc::EEXIST => ErrorKind::AlreadyExists,
|
||||
libc::ENOSYS => ErrorKind::Unsupported,
|
||||
|
||||
// These two constants can have the same value on some systems,
|
||||
// but different values on others, so we can't use a match
|
||||
// clause
|
||||
x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => ErrorKind::WouldBlock,
|
||||
|
||||
_ => ErrorKind::Other,
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub trait IsMinusOne {
|
||||
fn is_minus_one(&self) -> bool;
|
||||
}
|
||||
|
||||
macro_rules! impl_is_minus_one {
|
||||
($($t:ident)*) => ($(impl IsMinusOne for $t {
|
||||
fn is_minus_one(&self) -> bool {
|
||||
*self == -1
|
||||
}
|
||||
})*)
|
||||
}
|
||||
|
||||
impl_is_minus_one! { i8 i16 i32 i64 isize }
|
||||
|
||||
pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
|
||||
if t.is_minus_one() { Err(crate::io::Error::last_os_error()) } else { Ok(t) }
|
||||
}
|
||||
|
||||
pub fn cvt_r<T, F>(mut f: F) -> crate::io::Result<T>
|
||||
where
|
||||
T: IsMinusOne,
|
||||
F: FnMut() -> T,
|
||||
{
|
||||
loop {
|
||||
match cvt(f()) {
|
||||
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
|
||||
other => return other,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On Unix-like platforms, libc::abort will unregister signal handlers
|
||||
// including the SIGABRT handler, preventing the abort from being blocked, and
|
||||
// fclose streams, with the side effect of flushing them so libc buffered
|
||||
// output will be printed. Additionally the shell will generally print a more
|
||||
// understandable error message like "Abort trap" rather than "Illegal
|
||||
// instruction" that intrinsics::abort would cause, as intrinsics::abort is
|
||||
// implemented as an illegal instruction.
|
||||
pub fn abort_internal() -> ! {
|
||||
unsafe { libc::abort() }
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
pub use self::process_common::{Command, CommandArgs, ExitCode, Stdio, StdioPipes};
|
||||
pub use self::process_inner::{ExitStatus, Process};
|
||||
pub use crate::ffi::OsString as EnvKey;
|
||||
pub use crate::sys_common::process::CommandEnvs;
|
||||
|
||||
#[path = "../../unix/process/process_common.rs"]
|
||||
mod process_common;
|
||||
#[path = "process_vxworks.rs"]
|
||||
mod process_inner;
|
|
@ -1,36 +0,0 @@
|
|||
use crate::mem;
|
||||
use crate::slice;
|
||||
|
||||
pub fn hashmap_random_keys() -> (u64, u64) {
|
||||
let mut v = (0, 0);
|
||||
unsafe {
|
||||
let view = slice::from_raw_parts_mut(&mut v as *mut _ as *mut u8, mem::size_of_val(&v));
|
||||
imp::fill_bytes(view);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
mod imp {
|
||||
use crate::io;
|
||||
use core::sync::atomic::{AtomicBool, Ordering::Relaxed};
|
||||
|
||||
pub fn fill_bytes(v: &mut [u8]) {
|
||||
static RNG_INIT: AtomicBool = AtomicBool::new(false);
|
||||
while !RNG_INIT.load(Relaxed) {
|
||||
let ret = unsafe { libc::randSecure() };
|
||||
if ret < 0 {
|
||||
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
|
||||
} else if ret > 0 {
|
||||
RNG_INIT.store(true, Relaxed);
|
||||
break;
|
||||
}
|
||||
unsafe { libc::usleep(10) };
|
||||
}
|
||||
let ret = unsafe {
|
||||
libc::randABytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
|
||||
};
|
||||
if ret < 0 {
|
||||
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#![cfg(target_thread_local)]
|
||||
#![unstable(feature = "thread_local_internals", issue = "none")]
|
||||
|
||||
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
|
||||
use crate::sys_common::thread_local_dtor::register_dtor_fallback;
|
||||
register_dtor_fallback(t, dtor);
|
||||
}
|
Loading…
Add table
Reference in a new issue