Skip to content

Commit 95b4a4f

Browse files
committed
Auto merge of #77666 - fusion-engineering-forks:vxworks-cleanup, r=dtolnay
Vxworks / Unix deduplication `sys/vxworks` was almost entirely an (outdated) copy of `sys/unix`. I went through every file to check the differences and tried to figure out if they were simply outdated or intentional differences between `unix` and `vxworks`. Most of them did not have any `vxworks`-specific changes, so are deleted. I've added some minor `cfg(target_os = "vxworks")`-specific things to `sys/unix` to allow for deduplication. Before this change, the vxworks target didn't compile because its outdated process implementation did not match the expected interface anymore. This also fixes that: `std` compiles again for `x86_64-wrs-vxworks`. It's probably good to merge `sys/vxworks` entirely into `sys/unix`, but it might be better to to that in a follow-up PR. `@rustbot` modify labels: +T-libs +C-cleanup
2 parents 8e6f69a + 0f0257b commit 95b4a4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+226
-4476
lines changed

library/std/src/os/vxworks/fs.rs

+15
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ pub trait MetadataExt {
2626
#[stable(feature = "metadata_ext2", since = "1.8.0")]
2727
fn st_atime(&self) -> i64;
2828
#[stable(feature = "metadata_ext2", since = "1.8.0")]
29+
fn st_atime_nsec(&self) -> i64;
30+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
2931
fn st_mtime(&self) -> i64;
3032
#[stable(feature = "metadata_ext2", since = "1.8.0")]
33+
fn st_mtime_nsec(&self) -> i64;
34+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
3135
fn st_ctime(&self) -> i64;
3236
#[stable(feature = "metadata_ext2", since = "1.8.0")]
37+
fn st_ctime_nsec(&self) -> i64;
38+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
3339
fn st_blksize(&self) -> u64;
3440
#[stable(feature = "metadata_ext2", since = "1.8.0")]
3541
fn st_blocks(&self) -> u64;
@@ -66,12 +72,21 @@ impl MetadataExt for Metadata {
6672
fn st_atime(&self) -> i64 {
6773
self.as_inner().as_inner().st_atime as i64
6874
}
75+
fn st_atime_nsec(&self) -> i64 {
76+
0
77+
}
6978
fn st_mtime(&self) -> i64 {
7079
self.as_inner().as_inner().st_mtime as i64
7180
}
81+
fn st_mtime_nsec(&self) -> i64 {
82+
0
83+
}
7284
fn st_ctime(&self) -> i64 {
7385
self.as_inner().as_inner().st_ctime as i64
7486
}
87+
fn st_ctime_nsec(&self) -> i64 {
88+
0
89+
}
7590
fn st_blksize(&self) -> u64 {
7691
self.as_inner().as_inner().st_blksize as u64
7792
}

library/std/src/os/vxworks/raw.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ use crate::os::raw::c_ulong;
55

66
#[stable(feature = "pthread_t", since = "1.8.0")]
77
pub type pthread_t = c_ulong;
8+
9+
#[stable(feature = "raw_ext", since = "1.1.0")]
10+
pub use libc::{blkcnt_t, blksize_t, dev_t, ino_t, mode_t, nlink_t, off_t, time_t};

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ impl DoubleEndedIterator for Args {
7070
target_os = "haiku",
7171
target_os = "l4re",
7272
target_os = "fuchsia",
73-
target_os = "redox"
73+
target_os = "redox",
74+
target_os = "vxworks"
7475
))]
7576
mod imp {
7677
use super::Args;

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

+7
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,9 @@ pub trait MetadataExt {
650650
/// ```
651651
#[stable(feature = "metadata_ext", since = "1.1.0")]
652652
fn blocks(&self) -> u64;
653+
#[cfg(target_os = "vxworks")]
654+
#[stable(feature = "metadata_ext", since = "1.1.0")]
655+
fn attrib(&self) -> u8;
653656
}
654657

655658
#[stable(feature = "metadata_ext", since = "1.1.0")]
@@ -702,6 +705,10 @@ impl MetadataExt for fs::Metadata {
702705
fn blocks(&self) -> u64 {
703706
self.st_blocks()
704707
}
708+
#[cfg(target_os = "vxworks")]
709+
fn attrib(&self) -> u8 {
710+
self.st_attrib()
711+
}
705712
}
706713

707714
/// Unix-specific extensions for [`fs::FileType`].

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

+20-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@ pub trait CommandExt {
1616
/// `setuid` call in the child process. Failure in the `setuid`
1717
/// call will cause the spawn to fail.
1818
#[stable(feature = "rust1", since = "1.0.0")]
19-
fn uid(&mut self, id: u32) -> &mut process::Command;
19+
fn uid(
20+
&mut self,
21+
#[cfg(not(target_os = "vxworks"))] id: u32,
22+
#[cfg(target_os = "vxworks")] id: u16,
23+
) -> &mut process::Command;
2024

2125
/// Similar to `uid`, but sets the group ID of the child process. This has
2226
/// the same semantics as the `uid` field.
2327
#[stable(feature = "rust1", since = "1.0.0")]
24-
fn gid(&mut self, id: u32) -> &mut process::Command;
28+
fn gid(
29+
&mut self,
30+
#[cfg(not(target_os = "vxworks"))] id: u32,
31+
#[cfg(target_os = "vxworks")] id: u16,
32+
) -> &mut process::Command;
2533

2634
/// Schedules a closure to be run just before the `exec` function is
2735
/// invoked.
@@ -115,12 +123,20 @@ pub trait CommandExt {
115123

116124
#[stable(feature = "rust1", since = "1.0.0")]
117125
impl CommandExt for process::Command {
118-
fn uid(&mut self, id: u32) -> &mut process::Command {
126+
fn uid(
127+
&mut self,
128+
#[cfg(not(target_os = "vxworks"))] id: u32,
129+
#[cfg(target_os = "vxworks")] id: u16,
130+
) -> &mut process::Command {
119131
self.as_inner_mut().uid(id);
120132
self
121133
}
122134

123-
fn gid(&mut self, id: u32) -> &mut process::Command {
135+
fn gid(
136+
&mut self,
137+
#[cfg(not(target_os = "vxworks"))] id: u32,
138+
#[cfg(target_os = "vxworks")] id: u16,
139+
) -> &mut process::Command {
124140
self.as_inner_mut().gid(id);
125141
self
126142
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ impl FileDesc {
200200
target_os = "l4re",
201201
target_os = "linux",
202202
target_os = "haiku",
203-
target_os = "redox"
203+
target_os = "redox",
204+
target_os = "vxworks"
204205
)))]
205206
pub fn set_cloexec(&self) -> io::Result<()> {
206207
unsafe {
@@ -217,7 +218,8 @@ impl FileDesc {
217218
target_os = "l4re",
218219
target_os = "linux",
219220
target_os = "haiku",
220-
target_os = "redox"
221+
target_os = "redox",
222+
target_os = "vxworks"
221223
))]
222224
pub fn set_cloexec(&self) -> io::Result<()> {
223225
unsafe {

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

+49-7
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,38 @@ impl FileAttr {
297297

298298
#[cfg(not(target_os = "netbsd"))]
299299
impl FileAttr {
300+
#[cfg(not(target_os = "vxworks"))]
300301
pub fn modified(&self) -> io::Result<SystemTime> {
301302
Ok(SystemTime::from(libc::timespec {
302303
tv_sec: self.stat.st_mtime as libc::time_t,
303304
tv_nsec: self.stat.st_mtime_nsec as _,
304305
}))
305306
}
306307

308+
#[cfg(target_os = "vxworks")]
309+
pub fn modified(&self) -> io::Result<SystemTime> {
310+
Ok(SystemTime::from(libc::timespec {
311+
tv_sec: self.stat.st_mtime as libc::time_t,
312+
tv_nsec: 0,
313+
}))
314+
}
315+
316+
#[cfg(not(target_os = "vxworks"))]
307317
pub fn accessed(&self) -> io::Result<SystemTime> {
308318
Ok(SystemTime::from(libc::timespec {
309319
tv_sec: self.stat.st_atime as libc::time_t,
310320
tv_nsec: self.stat.st_atime_nsec as _,
311321
}))
312322
}
313323

324+
#[cfg(target_os = "vxworks")]
325+
pub fn accessed(&self) -> io::Result<SystemTime> {
326+
Ok(SystemTime::from(libc::timespec {
327+
tv_sec: self.stat.st_atime as libc::time_t,
328+
tv_nsec: 0,
329+
}))
330+
}
331+
314332
#[cfg(any(
315333
target_os = "freebsd",
316334
target_os = "openbsd",
@@ -535,12 +553,22 @@ impl DirEntry {
535553
lstat(&self.path())
536554
}
537555

538-
#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "haiku"))]
556+
#[cfg(any(
557+
target_os = "solaris",
558+
target_os = "illumos",
559+
target_os = "haiku",
560+
target_os = "vxworks"
561+
))]
539562
pub fn file_type(&self) -> io::Result<FileType> {
540563
lstat(&self.path()).map(|m| m.file_type())
541564
}
542565

543-
#[cfg(not(any(target_os = "solaris", target_os = "illumos", target_os = "haiku")))]
566+
#[cfg(not(any(
567+
target_os = "solaris",
568+
target_os = "illumos",
569+
target_os = "haiku",
570+
target_os = "vxworks"
571+
)))]
544572
pub fn file_type(&self) -> io::Result<FileType> {
545573
match self.entry.d_type {
546574
libc::DT_CHR => Ok(FileType { mode: libc::S_IFCHR }),
@@ -565,7 +593,8 @@ impl DirEntry {
565593
target_os = "haiku",
566594
target_os = "l4re",
567595
target_os = "fuchsia",
568-
target_os = "redox"
596+
target_os = "redox",
597+
target_os = "vxworks"
569598
))]
570599
pub fn ino(&self) -> u64 {
571600
self.entry.d_ino as u64
@@ -603,7 +632,8 @@ impl DirEntry {
603632
target_os = "linux",
604633
target_os = "emscripten",
605634
target_os = "l4re",
606-
target_os = "haiku"
635+
target_os = "haiku",
636+
target_os = "vxworks"
607637
))]
608638
fn name_bytes(&self) -> &[u8] {
609639
unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes() }
@@ -901,13 +931,25 @@ impl fmt::Debug for File {
901931
Some(PathBuf::from(OsString::from_vec(buf)))
902932
}
903933

904-
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
934+
#[cfg(target_os = "vxworks")]
935+
fn get_path(fd: c_int) -> Option<PathBuf> {
936+
let mut buf = vec![0; libc::PATH_MAX as usize];
937+
let n = unsafe { libc::ioctl(fd, libc::FIOGETNAME, buf.as_ptr()) };
938+
if n == -1 {
939+
return None;
940+
}
941+
let l = buf.iter().position(|&c| c == 0).unwrap();
942+
buf.truncate(l as usize);
943+
Some(PathBuf::from(OsString::from_vec(buf)))
944+
}
945+
946+
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "vxworks")))]
905947
fn get_path(_fd: c_int) -> Option<PathBuf> {
906948
// FIXME(#24570): implement this for other Unix platforms
907949
None
908950
}
909951

910-
#[cfg(any(target_os = "linux", target_os = "macos"))]
952+
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "vxworks"))]
911953
fn get_mode(fd: c_int) -> Option<(bool, bool)> {
912954
let mode = unsafe { libc::fcntl(fd, libc::F_GETFL) };
913955
if mode == -1 {
@@ -921,7 +963,7 @@ impl fmt::Debug for File {
921963
}
922964
}
923965

924-
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
966+
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "vxworks")))]
925967
fn get_mode(_fd: c_int) -> Option<(bool, bool)> {
926968
// FIXME(#24570): implement this for other Unix platforms
927969
None

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl Socket {
7777
}
7878
}
7979

80+
#[cfg(not(target_os = "vxworks"))]
8081
pub fn new_pair(fam: c_int, ty: c_int) -> io::Result<(Socket, Socket)> {
8182
unsafe {
8283
let mut fds = [0, 0];
@@ -98,6 +99,11 @@ impl Socket {
9899
}
99100
}
100101

102+
#[cfg(target_os = "vxworks")]
103+
pub fn new_pair(_fam: c_int, _ty: c_int) -> io::Result<(Socket, Socket)> {
104+
unimplemented!()
105+
}
106+
101107
pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
102108
self.set_nonblocking(true)?;
103109
let r = unsafe {
@@ -366,7 +372,7 @@ impl IntoInner<c_int> for Socket {
366372
// res_init unconditionally, we call it only when we detect we're linking
367373
// against glibc version < 2.26. (That is, when we both know its needed and
368374
// believe it's thread-safe).
369-
#[cfg(target_env = "gnu")]
375+
#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
370376
fn on_resolver_failure() {
371377
use crate::sys;
372378

@@ -378,5 +384,5 @@ fn on_resolver_failure() {
378384
}
379385
}
380386

381-
#[cfg(not(target_env = "gnu"))]
387+
#[cfg(any(not(target_env = "gnu"), target_os = "vxworks"))]
382388
fn on_resolver_failure() {}

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

+30-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cfg_if::cfg_if! {
3737
}
3838

3939
extern "C" {
40-
#[cfg(not(target_os = "dragonfly"))]
40+
#[cfg(not(any(target_os = "dragonfly", target_os = "vxworks")))]
4141
#[cfg_attr(
4242
any(
4343
target_os = "linux",
@@ -67,18 +67,28 @@ extern "C" {
6767
}
6868

6969
/// Returns the platform-specific value of errno
70-
#[cfg(not(target_os = "dragonfly"))]
70+
#[cfg(not(any(target_os = "dragonfly", target_os = "vxworks")))]
7171
pub fn errno() -> i32 {
7272
unsafe { (*errno_location()) as i32 }
7373
}
7474

7575
/// Sets the platform-specific value of errno
76-
#[cfg(all(not(target_os = "linux"), not(target_os = "dragonfly")))] // needed for readdir and syscall!
76+
#[cfg(all(not(target_os = "linux"), not(target_os = "dragonfly"), not(target_os = "vxworks")))] // needed for readdir and syscall!
7777
#[allow(dead_code)] // but not all target cfgs actually end up using it
7878
pub fn set_errno(e: i32) {
7979
unsafe { *errno_location() = e as c_int }
8080
}
8181

82+
#[cfg(target_os = "vxworks")]
83+
pub fn errno() -> i32 {
84+
unsafe { libc::errnoGet() }
85+
}
86+
87+
#[cfg(target_os = "vxworks")]
88+
pub fn set_errno(e: i32) {
89+
unsafe { libc::errnoSet(e as c_int) };
90+
}
91+
8292
#[cfg(target_os = "dragonfly")]
8393
pub fn errno() -> i32 {
8494
extern "C" {
@@ -439,6 +449,19 @@ pub fn current_exe() -> io::Result<PathBuf> {
439449
Err(io::Error::new(ErrorKind::Other, "Not yet implemented!"))
440450
}
441451

452+
#[cfg(target_os = "vxworks")]
453+
pub fn current_exe() -> io::Result<PathBuf> {
454+
#[cfg(test)]
455+
use realstd::env;
456+
457+
#[cfg(not(test))]
458+
use crate::env;
459+
460+
let exe_path = env::args().next().unwrap();
461+
let path = path::Path::new(&exe_path);
462+
path.canonicalize()
463+
}
464+
442465
pub struct Env {
443466
iter: vec::IntoIter<(OsString, OsString)>,
444467
_dont_send_or_sync_me: PhantomData<*mut ()>,
@@ -568,7 +591,8 @@ pub fn home_dir() -> Option<PathBuf> {
568591
target_os = "android",
569592
target_os = "ios",
570593
target_os = "emscripten",
571-
target_os = "redox"
594+
target_os = "redox",
595+
target_os = "vxworks"
572596
))]
573597
unsafe fn fallback() -> Option<OsString> {
574598
None
@@ -577,7 +601,8 @@ pub fn home_dir() -> Option<PathBuf> {
577601
target_os = "android",
578602
target_os = "ios",
579603
target_os = "emscripten",
580-
target_os = "redox"
604+
target_os = "redox",
605+
target_os = "vxworks"
581606
)))]
582607
unsafe fn fallback() -> Option<OsString> {
583608
let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ cfg_if::cfg_if! {
2424
// fuchsia doesn't have /dev/null
2525
} else if #[cfg(target_os = "redox")] {
2626
const DEV_NULL: &str = "null:\0";
27+
} else if #[cfg(target_os = "vxworks")] {
28+
const DEV_NULL: &str = "/null\0";
2729
} else {
2830
const DEV_NULL: &str = "/dev/null\0";
2931
}
@@ -48,7 +50,7 @@ cfg_if::cfg_if! {
4850
raw[bit / 8] |= 1 << (bit % 8);
4951
return 0;
5052
}
51-
} else {
53+
} else if #[cfg(not(target_os = "vxworks"))] {
5254
pub use libc::{sigemptyset, sigaddset};
5355
}
5456
}

0 commit comments

Comments
 (0)