Skip to content

Commit

Permalink
Rollup merge of rust-lang#127480 - biabbas:vxworks, r=workingjubilee
Browse files Browse the repository at this point in the history
Fix build failure on vxworks rust-lang#127084

PR to address issue rust-lang#127084 .
1. Skip `reset_segpipe` for vxworks
2. Return unimplemented error for vxworks from settimes and lchown
3. Temporarily skip dirfd for vxworks
4. Add allow unused unsafe on read_at and write_at functions in unix/fs.rs
5. Using cfg disable ON_BROKEN_PIPE_FLAG_USED and on_broken_pipe_flag_used() for vxworks
6. Remove old crate::syscommon::thread::min_stack() reference from process_vxworks.rs and update to set stack size of rtpthread

Thank you.
  • Loading branch information
matthiaskrgr authored Jul 24, 2024
2 parents 122b0b2 + 0ea5694 commit ce523d6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion library/std/src/os/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ pub fn lchown<P: AsRef<Path>>(dir: P, uid: Option<u32>, gid: Option<u32>) -> io:
/// }
/// ```
#[stable(feature = "unix_chroot", since = "1.56.0")]
#[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))]
#[cfg(not(target_os = "fuchsia"))]
pub fn chroot<P: AsRef<Path>>(dir: P) -> io::Result<()> {
sys::fs::chroot(dir.as_ref())
}
2 changes: 2 additions & 0 deletions library/std/src/sys/pal/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl FileDesc {
(&mut me).read_to_end(buf)
}

#[cfg_attr(target_os = "vxworks", allow(unused_unsafe))]
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
#[cfg(not(any(
all(target_os = "linux", not(target_env = "musl")),
Expand Down Expand Up @@ -318,6 +319,7 @@ impl FileDesc {
cfg!(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))
}

#[cfg_attr(target_os = "vxworks", allow(unused_unsafe))]
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
#[cfg(not(any(
all(target_os = "linux", not(target_env = "musl")),
Expand Down
24 changes: 22 additions & 2 deletions library/std/src/sys/pal/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ impl Drop for Dir {
target_os = "espidf",
target_os = "fuchsia",
target_os = "horizon",
target_os = "vxworks",
)))]
{
let fd = unsafe { libc::dirfd(self.0) };
Expand Down Expand Up @@ -1313,7 +1314,12 @@ impl File {
}

pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
#[cfg(not(any(target_os = "redox", target_os = "espidf", target_os = "horizon")))]
#[cfg(not(any(
target_os = "redox",
target_os = "espidf",
target_os = "horizon",
target_os = "vxworks"
)))]
let to_timespec = |time: Option<SystemTime>| match time {
Some(time) if let Some(ts) = time.t.to_timespec() => Ok(ts),
Some(time) if time > crate::sys::time::UNIX_EPOCH => Err(io::const_io_error!(
Expand All @@ -1327,10 +1333,11 @@ impl File {
None => Ok(libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }),
};
cfg_if::cfg_if! {
if #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon"))] {
if #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon", target_os = "vxworks"))] {
// Redox doesn't appear to support `UTIME_OMIT`.
// ESP-IDF and HorizonOS do not support `futimens` at all and the behavior for those OS is therefore
// the same as for Redox.
// `futimens` and `UTIME_OMIT` are a work in progress for vxworks.
let _ = times;
Err(io::const_io_error!(
io::ErrorKind::Unsupported,
Expand Down Expand Up @@ -1962,18 +1969,31 @@ pub fn fchown(fd: c_int, uid: u32, gid: u32) -> io::Result<()> {
Ok(())
}

#[cfg(not(target_os = "vxworks"))]
pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> {
run_path_with_cstr(path, &|path| {
cvt(unsafe { libc::lchown(path.as_ptr(), uid as libc::uid_t, gid as libc::gid_t) })
.map(|_| ())
})
}

#[cfg(target_os = "vxworks")]
pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> {
let (_, _, _) = (path, uid, gid);
Err(io::const_io_error!(io::ErrorKind::Unsupported, "lchown not supported by vxworks"))
}

#[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))]
pub fn chroot(dir: &Path) -> io::Result<()> {
run_path_with_cstr(dir, &|dir| cvt(unsafe { libc::chroot(dir.as_ptr()) }).map(|_| ()))
}

#[cfg(target_os = "vxworks")]
pub fn chroot(dir: &Path) -> io::Result<()> {
let _ = dir;
Err(io::const_io_error!(io::ErrorKind::Unsupported, "chroot not supported by vxworks"))
}

pub use remove_dir_impl::remove_dir_all;

// Fallback for REDOX, ESP-ID, Horizon, Vita, Vxworks and Miri
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/sys/pal/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
target_os = "emscripten",
target_os = "fuchsia",
target_os = "horizon",
target_os = "vxworks",
// Unikraft's `signal` implementation is currently broken:
// https://github.com/unikraft/lib-musl/issues/57
target_vendor = "unikraft",
Expand Down Expand Up @@ -209,6 +210,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
target_os = "emscripten",
target_os = "fuchsia",
target_os = "horizon",
target_os = "vxworks",
)))]
static ON_BROKEN_PIPE_FLAG_USED: crate::sync::atomic::AtomicBool =
crate::sync::atomic::AtomicBool::new(false);
Expand All @@ -218,6 +220,7 @@ static ON_BROKEN_PIPE_FLAG_USED: crate::sync::atomic::AtomicBool =
target_os = "emscripten",
target_os = "fuchsia",
target_os = "horizon",
target_os = "vxworks",
)))]
pub(crate) fn on_broken_pipe_flag_used() -> bool {
ON_BROKEN_PIPE_FLAG_USED.load(crate::sync::atomic::Ordering::Relaxed)
Expand Down
9 changes: 7 additions & 2 deletions library/std/src/sys/pal/unix/process/process_vxworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::io::{self, ErrorKind};
use crate::num::NonZero;
use crate::sys;
use crate::sys::cvt;
use crate::sys::pal::unix::thread;
use crate::sys::process::process_common::*;
use crate::sys_common::thread;
use libc::RTP_ID;
use libc::{self, c_char, c_int};

Expand Down Expand Up @@ -68,7 +68,12 @@ impl Command {
.as_ref()
.map(|c| c.as_ptr())
.unwrap_or_else(|| *sys::os::environ() as *const _);
let stack_size = thread::min_stack();
let stack_size = crate::cmp::max(
crate::env::var_os("RUST_MIN_STACK")
.and_then(|s| s.to_str().and_then(|s| s.parse().ok()))
.unwrap_or(thread::DEFAULT_MIN_STACK_SIZE),
libc::PTHREAD_STACK_MIN,
);

// ensure that access to the environment is synchronized
let _lock = sys::os::env_read_lock();
Expand Down

0 comments on commit ce523d6

Please sign in to comment.