Skip to content

Move sys::vxworks code to sys::unix #84119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions library/std/src/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -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)] {
11 changes: 11 additions & 0 deletions library/std/src/sys/unix/env.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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;
}
}

1 change: 1 addition & 0 deletions library/std/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
@@ -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",
11 changes: 3 additions & 8 deletions library/std/src/sys/unix/os.rs
Original file line number Diff line number Diff line change
@@ -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()) {
22 changes: 14 additions & 8 deletions library/std/src/sys/unix/process/mod.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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,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(),
@@ -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.
29 changes: 28 additions & 1 deletion library/std/src/sys/unix/rand.rs
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
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
@@ -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.

36 changes: 0 additions & 36 deletions library/std/src/sys/vxworks/rand.rs

This file was deleted.

7 changes: 0 additions & 7 deletions library/std/src/sys/vxworks/thread_local_dtor.rs

This file was deleted.