Skip to content

Commit 06aeb5c

Browse files
committed
Adding Support for vxworks in rustix
1 parent c4caf5c commit 06aeb5c

35 files changed

+229
-83
lines changed

src/backend/libc/fs/dir.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::fs::{fstat, Stat};
2424
target_os = "wasi",
2525
)))]
2626
use crate::fs::{fstatfs, StatFs};
27-
#[cfg(not(any(solarish, target_os = "vita", target_os = "wasi")))]
27+
#[cfg(not(any(solarish, target_os = "vita", target_os = "wasi", target_os = "vxworks")))]
2828
use crate::fs::{fstatvfs, StatVfs};
2929
use crate::io;
3030
#[cfg(not(any(target_os = "fuchsia", target_os = "vita", target_os = "wasi")))]
@@ -159,6 +159,7 @@ impl Dir {
159159
///
160160
/// [`libc::seekdir`]: https://docs.rs/libc/*/arm-unknown-linux-gnueabihf/libc/fn.seekdir.html
161161
#[cfg(target_pointer_width = "64")]
162+
#[cfg(not(target_os = "vxworks"))]
162163
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
163164
#[doc(alias = "seekdir")]
164165
#[inline]
@@ -260,7 +261,8 @@ impl Dir {
260261
solarish,
261262
target_os = "horizon",
262263
target_os = "vita",
263-
target_os = "wasi"
264+
target_os = "wasi",
265+
target_os = "vxworks",
264266
)))]
265267
#[inline]
266268
pub fn statvfs(&self) -> io::Result<StatVfs> {

src/backend/libc/fs/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ pub mod inotify;
77
target_os = "haiku",
88
target_os = "horizon",
99
target_os = "vita",
10-
target_os = "wasi"
10+
target_os = "wasi",
11+
target_os = "vxworks",
1112
)))]
1213
pub(crate) mod makedev;
1314
#[cfg(not(windows))]

src/backend/libc/fs/syscalls.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::fs::AtFlags;
2222
target_os = "nto",
2323
target_os = "redox",
2424
target_os = "vita",
25+
target_os = "vxworks",
2526
)))]
2627
use crate::fs::FallocateFlags;
2728
#[cfg(not(any(
@@ -60,7 +61,7 @@ use crate::fs::Timestamps;
6061
)))]
6162
use crate::fs::{Dev, FileType};
6263
use crate::fs::{Mode, OFlags, SeekFrom, Stat};
63-
#[cfg(not(target_os = "wasi"))]
64+
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
6465
use crate::fs::{StatVfs, StatVfsMountFlags};
6566
use crate::io;
6667
#[cfg(all(target_env = "gnu", fix_y2038))]
@@ -85,6 +86,7 @@ use {
8586
target_os = "redox",
8687
target_os = "solaris",
8788
target_os = "vita",
89+
target_os = "vxworks",
8890
)))]
8991
use {crate::fs::Advice, core::num::NonZeroU64};
9092
#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
@@ -103,7 +105,7 @@ weak!(fn __futimens64(c::c_int, *const LibcTimespec) -> c::c_int);
103105
/// Use a direct syscall (via libc) for `open`.
104106
///
105107
/// This is only currently necessary as a workaround for old glibc; see below.
106-
#[cfg(all(unix, target_env = "gnu"))]
108+
#[cfg(all(not(target_os = "vxworks"), unix, target_env = "gnu"))]
107109
fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedFd> {
108110
// Linux on aarch64, loongarch64 and riscv64 has no `open` syscall so use
109111
// `openat`.
@@ -150,7 +152,8 @@ pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedF
150152
unix,
151153
target_env = "gnu",
152154
not(target_os = "hurd"),
153-
not(target_os = "freebsd")
155+
not(target_os = "freebsd"),
156+
not(target_os = "vxworks"),
154157
))]
155158
if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() {
156159
return open_via_syscall(path, oflags, mode);
@@ -218,7 +221,8 @@ pub(crate) fn openat(
218221
unix,
219222
target_env = "gnu",
220223
not(target_os = "hurd"),
221-
not(target_os = "freebsd")
224+
not(target_os = "freebsd"),
225+
not(target_os = "vxworks")
222226
))]
223227
if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() {
224228
return openat_via_syscall(dirfd, path, oflags, mode);
@@ -271,7 +275,7 @@ pub(crate) fn statfs(filename: &CStr) -> io::Result<StatFs> {
271275
}
272276
}
273277

274-
#[cfg(not(target_os = "wasi"))]
278+
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
275279
#[inline]
276280
pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> {
277281
unsafe {
@@ -448,6 +452,7 @@ pub(crate) fn rename(old_path: &CStr, new_path: &CStr) -> io::Result<()> {
448452
unsafe { ret(c::rename(c_str(old_path), c_str(new_path))) }
449453
}
450454

455+
#[cfg(not(target_os = "vxworks"))]
451456
pub(crate) fn renameat(
452457
old_dirfd: BorrowedFd<'_>,
453458
old_path: &CStr,
@@ -481,7 +486,7 @@ pub(crate) fn renameat(
481486
ret(c::rename(c_str(old_path), c_str(new_path)))
482487
}
483488

484-
#[cfg(not(target_os = "macos"))]
489+
#[cfg(not(any(target_os = "macos", target_os = "vxworks")))]
485490
unsafe {
486491
ret(c::renameat(
487492
borrowed_fd(old_dirfd),
@@ -729,7 +734,7 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
729734
}
730735
}
731736

732-
#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
737+
#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "vxworks")))]
733738
pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
734739
// See the comments in `fstat` about using `crate::fs::statx` here.
735740
#[cfg(all(
@@ -812,7 +817,8 @@ pub(crate) fn access(path: &CStr, access: Access) -> io::Result<()> {
812817
target_os = "espidf",
813818
target_os = "horizon",
814819
target_os = "redox",
815-
target_os = "vita"
820+
target_os = "vita",
821+
target_os = "vxworks",
816822
)))]
817823
pub(crate) fn accessat(
818824
dirfd: BorrowedFd<'_>,
@@ -1096,7 +1102,8 @@ pub(crate) fn chmod(path: &CStr, mode: Mode) -> io::Result<()> {
10961102
linux_kernel,
10971103
target_os = "espidf",
10981104
target_os = "redox",
1099-
target_os = "wasi"
1105+
target_os = "wasi",
1106+
target_os = "vxworks",
11001107
)))]
11011108
pub(crate) fn chmodat(
11021109
dirfd: BorrowedFd<'_>,
@@ -1175,7 +1182,7 @@ pub(crate) fn fclonefileat(
11751182
}
11761183
}
11771184

1178-
#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "wasi")))]
1185+
#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "wasi", target_os = "vxworks")))]
11791186
pub(crate) fn chownat(
11801187
dirfd: BorrowedFd<'_>,
11811188
path: &CStr,
@@ -1201,7 +1208,8 @@ pub(crate) fn chownat(
12011208
target_os = "horizon",
12021209
target_os = "redox",
12031210
target_os = "vita",
1204-
target_os = "wasi"
1211+
target_os = "wasi",
1212+
target_os = "vxworks",
12051213
)))]
12061214
pub(crate) fn mknodat(
12071215
dirfd: BorrowedFd<'_>,
@@ -1283,6 +1291,7 @@ pub(crate) fn copy_file_range(
12831291
target_os = "redox",
12841292
target_os = "solaris",
12851293
target_os = "vita",
1294+
target_os = "vxworks",
12861295
)))]
12871296
pub(crate) fn fadvise(
12881297
fd: BorrowedFd<'_>,
@@ -1494,7 +1503,8 @@ pub(crate) fn fchown(fd: BorrowedFd<'_>, owner: Option<Uid>, group: Option<Gid>)
14941503
target_os = "horizon",
14951504
target_os = "solaris",
14961505
target_os = "vita",
1497-
target_os = "wasi"
1506+
target_os = "wasi",
1507+
target_os = "vxworks",
14981508
)))]
14991509
pub(crate) fn flock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::Result<()> {
15001510
unsafe { ret(c::flock(borrowed_fd(fd), operation as c::c_int)) }
@@ -1522,7 +1532,8 @@ pub(crate) fn syncfs(fd: BorrowedFd<'_>) -> io::Result<()> {
15221532
target_os = "horizon",
15231533
target_os = "redox",
15241534
target_os = "vita",
1525-
target_os = "wasi"
1535+
target_os = "wasi",
1536+
target_os = "vxworks",
15261537
)))]
15271538
pub(crate) fn sync() {
15281539
unsafe { c::sync() }
@@ -1609,7 +1620,7 @@ pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result<StatFs> {
16091620
}
16101621
}
16111622

1612-
#[cfg(not(target_os = "wasi"))]
1623+
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
16131624
pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result<StatVfs> {
16141625
let mut statvfs = MaybeUninit::<c::statvfs>::uninit();
16151626
unsafe {
@@ -1618,7 +1629,7 @@ pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result<StatVfs> {
16181629
}
16191630
}
16201631

1621-
#[cfg(not(target_os = "wasi"))]
1632+
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
16221633
fn libc_statvfs_to_statvfs(from: c::statvfs) -> StatVfs {
16231634
StatVfs {
16241635
f_bsize: from.f_bsize as u64,
@@ -1744,6 +1755,7 @@ fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> {
17441755
target_os = "nto",
17451756
target_os = "redox",
17461757
target_os = "vita",
1758+
target_os = "vxworks",
17471759
)))]
17481760
pub(crate) fn fallocate(
17491761
fd: BorrowedFd<'_>,

src/backend/libc/fs/types.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bitflags! {
4141
const SYMLINK_NOFOLLOW = bitcast!(c::AT_SYMLINK_NOFOLLOW);
4242

4343
/// `AT_EACCESS`
44-
#[cfg(not(target_os = "android"))]
44+
#[cfg(not(any(target_os = "android", target_os = "vxworks")))]
4545
const EACCESS = bitcast!(c::AT_EACCESS);
4646

4747
/// `AT_REMOVEDIR`
@@ -259,7 +259,7 @@ bitflags! {
259259
const CREATE = bitcast!(c::O_CREAT);
260260

261261
/// `O_DIRECTORY`
262-
#[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
262+
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vxworks")))]
263263
const DIRECTORY = bitcast!(c::O_DIRECTORY);
264264

265265
/// `O_DSYNC`
@@ -277,7 +277,7 @@ bitflags! {
277277
const FSYNC = bitcast!(c::O_FSYNC);
278278

279279
/// `O_NOFOLLOW`
280-
#[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
280+
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vxworks")))]
281281
const NOFOLLOW = bitcast!(c::O_NOFOLLOW);
282282

283283
/// `O_NONBLOCK`
@@ -295,7 +295,7 @@ bitflags! {
295295
const RDWR = bitcast!(c::O_RDWR);
296296

297297
/// `O_NOCTTY`
298-
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "l4re", target_os = "redox", target_os = "vita")))]
298+
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "l4re", target_os = "redox", target_os = "vita", target_os = "vxworks")))]
299299
const NOCTTY = bitcast!(c::O_NOCTTY);
300300

301301
/// `O_RSYNC`
@@ -654,6 +654,7 @@ impl FileType {
654654
target_os = "redox",
655655
target_os = "solaris",
656656
target_os = "vita",
657+
target_os = "vxworks",
657658
)))]
658659
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
659660
#[repr(u32)]
@@ -767,7 +768,8 @@ bitflags! {
767768
target_os = "horizon",
768769
target_os = "nto",
769770
target_os = "redox",
770-
target_os = "vita"
771+
target_os = "vita",
772+
target_os = "vxworks",
771773
)))]
772774
bitflags! {
773775
/// `FALLOC_FL_*` constants for use with [`fallocate`].
@@ -861,7 +863,7 @@ bitflags! {
861863
}
862864
}
863865

864-
#[cfg(not(target_os = "wasi"))]
866+
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
865867
bitflags! {
866868
/// `ST_*` constants for use with [`StatVfs`].
867869
#[repr(transparent)]
@@ -924,7 +926,8 @@ bitflags! {
924926
target_os = "espidf",
925927
target_os = "horizon",
926928
target_os = "vita",
927-
target_os = "wasi"
929+
target_os = "wasi",
930+
target_os = "vxworks",
928931
)))]
929932
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
930933
#[repr(u32)]
@@ -967,6 +970,26 @@ pub enum FlockOperation {
967970
NonBlockingUnlock = bitcast!(8 | 4),
968971
}
969972

973+
/// On Vxworks, we do not have flock or the flock enum.
974+
/// So here, we create the enum ourselves
975+
#[cfg(target_os = "vxworks")]
976+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
977+
#[repr(i32)]
978+
pub enum FlockOperation {
979+
/// `LOCK_SH`
980+
LockShared = 1,
981+
/// `LOCK_EX`
982+
LockExclusive = 2,
983+
/// `LOCK_UN`
984+
Unlock = 4,
985+
/// `LOCK_SH | LOCK_NB`
986+
NonBlockingLockShared = 1 | 8,
987+
/// `LOCK_EX | LOCK_NB`
988+
NonBlockingLockExclusive = 2 | 8,
989+
/// `LOCK_UN | LOCK_NB`
990+
NonBlockingUnlock = 4 | 8,
991+
}
992+
970993
/// `struct stat` for use with [`statat`] and [`fstat`].
971994
///
972995
/// [`statat`]: crate::fs::statat
@@ -1093,7 +1116,7 @@ pub type Fsid = c::fsid_t;
10931116
///
10941117
/// [`statvfs`]: crate::fs::statvfs
10951118
/// [`fstatvfs`]: crate::fs::fstatvfs
1096-
#[cfg(not(target_os = "wasi"))]
1119+
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
10971120
#[allow(missing_docs)]
10981121
pub struct StatVfs {
10991122
pub f_bsize: u64,

0 commit comments

Comments
 (0)