Skip to content

Commit 3897ad1

Browse files
authored
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. https://github.com/rust-lang/rust/blob/e41f378f825488a537b024fc3ed599d9c12fda96/compiler/rustc_target/src/spec/vxworks_base.rs#L12 ``@rustbot`` label: +T-libs-impl
2 parents a7a7737 + aa46f08 commit 3897ad1

File tree

14 files changed

+88
-222
lines changed

14 files changed

+88
-222
lines changed

library/std/src/sys/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
mod common;
2626

2727
cfg_if::cfg_if! {
28-
if #[cfg(target_os = "vxworks")] {
29-
mod vxworks;
30-
pub use self::vxworks::*;
31-
} else if #[cfg(unix)] {
28+
if #[cfg(unix)] {
3229
mod unix;
3330
pub use self::unix::*;
3431
} else if #[cfg(windows)] {

library/std/src/sys/unix/env.rs

+11
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,14 @@ pub mod os {
173173
pub const EXE_SUFFIX: &str = "";
174174
pub const EXE_EXTENSION: &str = "";
175175
}
176+
177+
#[cfg(target_os = "vxworks")]
178+
pub mod os {
179+
pub const FAMILY: &str = "unix";
180+
pub const OS: &str = "vxworks";
181+
pub const DLL_PREFIX: &str = "lib";
182+
pub const DLL_SUFFIX: &str = ".so";
183+
pub const DLL_EXTENSION: &str = "so";
184+
pub const EXE_SUFFIX: &str = "";
185+
pub const EXE_EXTENSION: &str = "";
186+
}

library/std/src/sys/unix/ext/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ cfg_if::cfg_if! {
6262
use crate::os::redox as platform;
6363
#[cfg(target_os = "solaris")]
6464
use crate::os::solaris as platform;
65+
#[cfg(target_os = "vxworks")]
66+
use crate::os::vxworks as platform;
6567
}
6668
}
6769

library/std/src/sys/unix/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub fn init() {
7171
} else if #[cfg(not(any(
7272
target_os = "emscripten",
7373
target_os = "fuchsia",
74+
target_os = "vxworks",
7475
// The poll on Darwin doesn't set POLLNVAL for closed fds.
7576
target_os = "macos",
7677
target_os = "ios",

library/std/src/sys/unix/os.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ pub fn errno() -> i32 {
8585
unsafe { libc::errnoGet() }
8686
}
8787

88-
#[cfg(target_os = "vxworks")]
89-
pub fn set_errno(e: i32) {
90-
unsafe { libc::errnoSet(e as c_int) };
91-
}
92-
9388
#[cfg(target_os = "dragonfly")]
9489
pub fn errno() -> i32 {
9590
extern "C" {
@@ -642,7 +637,7 @@ pub fn getppid() -> u32 {
642637
unsafe { libc::getppid() as u32 }
643638
}
644639

645-
#[cfg(target_env = "gnu")]
640+
#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
646641
pub fn glibc_version() -> Option<(usize, usize)> {
647642
if let Some(Ok(version_str)) = glibc_version_cstr().map(CStr::to_str) {
648643
parse_glibc_version(version_str)
@@ -651,7 +646,7 @@ pub fn glibc_version() -> Option<(usize, usize)> {
651646
}
652647
}
653648

654-
#[cfg(target_env = "gnu")]
649+
#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
655650
fn glibc_version_cstr() -> Option<&'static CStr> {
656651
weak! {
657652
fn gnu_get_libc_version() -> *const libc::c_char
@@ -665,7 +660,7 @@ fn glibc_version_cstr() -> Option<&'static CStr> {
665660

666661
// Returns Some((major, minor)) if the string is a valid "x.y" version,
667662
// ignoring any extra dot-separated parts. Otherwise return None.
668-
#[cfg(target_env = "gnu")]
663+
#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
669664
fn parse_glibc_version(version: &str) -> Option<(usize, usize)> {
670665
let mut parsed_ints = version.split('.').map(str::parse::<usize>).fuse();
671666
match (parsed_ints.next(), parsed_ints.next()) {

library/std/src/sys/unix/process/mod.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ pub use crate::ffi::OsString as EnvKey;
44
pub use crate::sys_common::process::CommandEnvs;
55

66
mod process_common;
7-
#[cfg(not(target_os = "fuchsia"))]
8-
#[path = "process_unix.rs"]
9-
mod process_inner;
10-
#[cfg(target_os = "fuchsia")]
11-
#[path = "process_fuchsia.rs"]
12-
mod process_inner;
13-
#[cfg(target_os = "fuchsia")]
14-
mod zircon;
7+
8+
cfg_if::cfg_if! {
9+
if #[cfg(target_os = "fuchsia")] {
10+
#[path = "process_fuchsia.rs"]
11+
mod process_inner;
12+
mod zircon;
13+
} else if #[cfg(target_os = "vxworks")] {
14+
#[path = "process_vxworks.rs"]
15+
mod process_inner;
16+
} else {
17+
#[path = "process_unix.rs"]
18+
mod process_inner;
19+
}
20+
}

library/std/src/sys/vxworks/process/process_vxworks.rs library/std/src/sys/unix/process/process_vxworks.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ impl Command {
1818
needs_stdin: bool,
1919
) -> io::Result<(Process, StdioPipes)> {
2020
use crate::sys::cvt_r;
21-
const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX";
2221
let envp = self.capture_env();
2322

2423
if self.saw_nul() {
@@ -61,14 +60,17 @@ impl Command {
6160
t!(cvt(libc::chdir(cwd.as_ptr())));
6261
}
6362

63+
// pre_exec closures are ignored on VxWorks
64+
let _ = self.get_closures();
65+
6466
let c_envp = envp
6567
.as_ref()
6668
.map(|c| c.as_ptr())
6769
.unwrap_or_else(|| *sys::os::environ() as *const _);
6870
let stack_size = thread::min_stack();
6971

7072
// ensure that access to the environment is synchronized
71-
let _lock = sys::os::env_lock();
73+
let _lock = sys::os::env_read_lock();
7274

7375
let ret = libc::rtpSpawn(
7476
self.get_program_cstr().as_ptr(),
@@ -196,6 +198,24 @@ impl ExitStatus {
196198
pub fn signal(&self) -> Option<i32> {
197199
if !self.exited() { Some(libc::WTERMSIG(self.0)) } else { None }
198200
}
201+
202+
pub fn core_dumped(&self) -> bool {
203+
// This method is not yet properly implemented on VxWorks
204+
false
205+
}
206+
207+
pub fn stopped_signal(&self) -> Option<i32> {
208+
if libc::WIFSTOPPED(self.0) { Some(libc::WSTOPSIG(self.0)) } else { None }
209+
}
210+
211+
pub fn continued(&self) -> bool {
212+
// This method is not yet properly implemented on VxWorks
213+
false
214+
}
215+
216+
pub fn into_raw(&self) -> c_int {
217+
self.0
218+
}
199219
}
200220

201221
/// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying.

library/std/src/sys/unix/rand.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pub fn hashmap_random_keys() -> (u64, u64) {
1818
not(target_os = "freebsd"),
1919
not(target_os = "netbsd"),
2020
not(target_os = "fuchsia"),
21-
not(target_os = "redox")
21+
not(target_os = "redox"),
22+
not(target_os = "vxworks")
2223
))]
2324
mod imp {
2425
use crate::fs::File;
@@ -237,3 +238,29 @@ mod imp {
237238
file.read_exact(v).expect("failed to read rand:")
238239
}
239240
}
241+
242+
#[cfg(target_os = "vxworks")]
243+
mod imp {
244+
use crate::io;
245+
use core::sync::atomic::{AtomicBool, Ordering::Relaxed};
246+
247+
pub fn fill_bytes(v: &mut [u8]) {
248+
static RNG_INIT: AtomicBool = AtomicBool::new(false);
249+
while !RNG_INIT.load(Relaxed) {
250+
let ret = unsafe { libc::randSecure() };
251+
if ret < 0 {
252+
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
253+
} else if ret > 0 {
254+
RNG_INIT.store(true, Relaxed);
255+
break;
256+
}
257+
unsafe { libc::usleep(10) };
258+
}
259+
let ret = unsafe {
260+
libc::randABytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
261+
};
262+
if ret < 0 {
263+
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
264+
}
265+
}
266+
}

library/std/src/sys/unix/thread_local_dtor.rs

+6
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
9292
}
9393
}
9494
}
95+
96+
#[cfg(target_os = "vxworks")]
97+
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
98+
use crate::sys_common::thread_local_dtor::register_dtor_fallback;
99+
register_dtor_fallback(t, dtor);
100+
}

library/std/src/sys/vxworks/env.rs

-9
This file was deleted.

library/std/src/sys/vxworks/mod.rs

-138
This file was deleted.

library/std/src/sys/vxworks/process/mod.rs

-9
This file was deleted.

0 commit comments

Comments
 (0)