Skip to content

Commit

Permalink
Rollup merge of rust-lang#84119 - CDirkx:vxworks, r=m-ou-se
Browse files Browse the repository at this point in the history
Move `sys::vxworks` code to `sys::unix`

Follow-up to rust-lang#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.

https://github.com/rust-lang/rust/blob/e41f378f825488a537b024fc3ed599d9c12fda96/compiler/rustc_target/src/spec/vxworks_base.rs#L12

`@rustbot` label: +T-libs-impl
  • Loading branch information
m-ou-se authored Apr 21, 2021
2 parents 865a213 + aa46f08 commit 641cec3
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 222 deletions.
5 changes: 1 addition & 4 deletions library/std/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)] {
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 @@ -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 = "";
}
2 changes: 2 additions & 0 deletions library/std/src/sys/unix/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 3 additions & 8 deletions library/std/src/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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()) {
Expand Down
22 changes: 14 additions & 8 deletions library/std/src/sys/unix/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -61,14 +60,17 @@ 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())
.unwrap_or_else(|| *sys::os::environ() as *const _);
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(),
Expand Down Expand Up @@ -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.
Expand Down
29 changes: 28 additions & 1 deletion library/std/src/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
6 changes: 6 additions & 0 deletions library/std/src/sys/unix/thread_local_dtor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
9 changes: 0 additions & 9 deletions library/std/src/sys/vxworks/env.rs

This file was deleted.

138 changes: 0 additions & 138 deletions library/std/src/sys/vxworks/mod.rs

This file was deleted.

9 changes: 0 additions & 9 deletions library/std/src/sys/vxworks/process/mod.rs

This file was deleted.

Loading

0 comments on commit 641cec3

Please sign in to comment.