Horizon OS STD support

Co-authored-by: Ian Chamberlain <ian.h.chamberlain@gmail.com>
Co-authored-by: Mark Drobnak <mark.drobnak@gmail.com>
This commit is contained in:
Meziu 2021-10-19 17:59:59 +02:00 committed by Mark Drobnak
parent 3bdec3c8ab
commit 4e808f87cc
No known key found for this signature in database
GPG key ID: 47A133F3BF9D03D3
21 changed files with 288 additions and 67 deletions

View file

@ -143,7 +143,8 @@ mod c_char_definition {
target_arch = "powerpc"
)
),
all(target_os = "fuchsia", target_arch = "aarch64")
all(target_os = "fuchsia", target_arch = "aarch64"),
target_os = "horizon"
))] {
pub type c_char = u8;
pub type NonZero_c_char = crate::num::NonZeroU8;

View file

@ -29,6 +29,7 @@ fn main() {
|| target.contains("asmjs")
|| target.contains("espidf")
|| target.contains("solid")
|| target.contains("nintendo-3ds")
{
// These platforms don't have any special requirements.
} else {

View file

@ -0,0 +1,95 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]
use crate::fs::Metadata;
use crate::sys_common::AsInner;
/// OS-specific extensions to [`fs::Metadata`].
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_dev(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ino(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mode(&self) -> u32;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_nlink(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_uid(&self) -> u32;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_gid(&self) -> u32;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_rdev(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_size(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime_nsec(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime_nsec(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime_nsec(&self) -> i64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blksize(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blocks(&self) -> u64;
}
#[stable(feature = "metadata_ext", since = "1.1.0")]
impl MetadataExt for Metadata {
fn st_dev(&self) -> u64 {
self.as_inner().as_inner().st_dev as u64
}
fn st_ino(&self) -> u64 {
self.as_inner().as_inner().st_ino as u64
}
fn st_mode(&self) -> u32 {
self.as_inner().as_inner().st_mode as u32
}
fn st_nlink(&self) -> u64 {
self.as_inner().as_inner().st_nlink as u64
}
fn st_uid(&self) -> u32 {
self.as_inner().as_inner().st_uid as u32
}
fn st_gid(&self) -> u32 {
self.as_inner().as_inner().st_gid as u32
}
fn st_rdev(&self) -> u64 {
self.as_inner().as_inner().st_rdev as u64
}
fn st_size(&self) -> u64 {
self.as_inner().as_inner().st_size as u64
}
fn st_atime(&self) -> i64 {
self.as_inner().as_inner().st_atime as i64
}
fn st_atime_nsec(&self) -> i64 {
0
}
fn st_mtime(&self) -> i64 {
self.as_inner().as_inner().st_mtime as i64
}
fn st_mtime_nsec(&self) -> i64 {
0
}
fn st_ctime(&self) -> i64 {
self.as_inner().as_inner().st_ctime as i64
}
fn st_ctime_nsec(&self) -> i64 {
0
}
fn st_blksize(&self) -> u64 {
self.as_inner().as_inner().st_blksize as u64
}
fn st_blocks(&self) -> u64 {
self.as_inner().as_inner().st_blocks as u64
}
}

View file

@ -0,0 +1,6 @@
//! Definitions for Horizon OS
#![stable(feature = "raw_ext", since = "1.1.0")]
pub mod fs;
pub(crate) mod raw;

View file

@ -0,0 +1,70 @@
//! Horizon OS raw type definitions
#![stable(feature = "raw_ext", since = "1.1.0")]
#![deprecated(
since = "1.8.0",
note = "these type aliases are no longer supported by \
the standard library, the `libc` crate on \
crates.io should be used instead for the correct \
definitions"
)]
#![allow(deprecated)]
use crate::os::raw::c_long;
use crate::os::unix::raw::{gid_t, uid_t};
#[stable(feature = "pthread_t", since = "1.8.0")]
pub type pthread_t = libc::pthread_t;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type blkcnt_t = libc::blkcnt_t;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type blksize_t = libc::blksize_t;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type dev_t = libc::dev_t;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type ino_t = libc::ino_t;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type mode_t = libc::mode_t;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type nlink_t = libc::nlink_t;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type off_t = libc::off_t;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type time_t = libc::time_t;
#[repr(C)]
#[derive(Clone)]
#[stable(feature = "raw_ext", since = "1.1.0")]
pub struct stat {
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_dev: dev_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_ino: ino_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_mode: mode_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_nlink: nlink_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_uid: uid_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_gid: gid_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_rdev: dev_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_size: off_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_atime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_mtime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_ctime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_blksize: blksize_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_blocks: blkcnt_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_spare4: [c_long; 2usize],
}

View file

@ -123,6 +123,8 @@ pub mod windows {}
pub mod fuchsia;
#[cfg(target_os = "haiku")]
pub mod haiku;
#[cfg(target_os = "horizon")]
pub mod horizon;
#[cfg(target_os = "illumos")]
pub mod illumos;
#[cfg(target_os = "ios")]

View file

@ -51,6 +51,8 @@ mod platform {
pub use crate::os::fuchsia::*;
#[cfg(target_os = "haiku")]
pub use crate::os::haiku::*;
#[cfg(target_os = "horizon")]
pub use crate::os::horizon::*;
#[cfg(target_os = "illumos")]
pub use crate::os::illumos::*;
#[cfg(target_os = "ios")]

View file

@ -24,8 +24,9 @@ pub trait CommandExt: Sealed {
#[stable(feature = "rust1", since = "1.0.0")]
fn uid(
&mut self,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32,
#[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
id: u32,
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
) -> &mut process::Command;
/// Similar to `uid`, but sets the group ID of the child process. This has
@ -33,8 +34,9 @@ fn uid(
#[stable(feature = "rust1", since = "1.0.0")]
fn gid(
&mut self,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32,
#[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
id: u32,
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
) -> &mut process::Command;
/// Sets the supplementary group IDs for the calling process. Translates to
@ -42,8 +44,9 @@ fn gid(
#[unstable(feature = "setgroups", issue = "90747")]
fn groups(
&mut self,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] groups: &[u32],
#[cfg(any(target_os = "vxworks", target_os = "espidf"))] groups: &[u16],
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] groups: &[u32],
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
groups: &[u16],
) -> &mut process::Command;
/// Schedules a closure to be run just before the `exec` function is
@ -160,8 +163,9 @@ fn arg0<S>(&mut self, arg: S) -> &mut process::Command
impl CommandExt for process::Command {
fn uid(
&mut self,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32,
#[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
id: u32,
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
) -> &mut process::Command {
self.as_inner_mut().uid(id);
self
@ -169,8 +173,9 @@ fn uid(
fn gid(
&mut self,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32,
#[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
id: u32,
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] id: u16,
) -> &mut process::Command {
self.as_inner_mut().gid(id);
self
@ -178,8 +183,9 @@ fn gid(
fn groups(
&mut self,
#[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] groups: &[u32],
#[cfg(any(target_os = "vxworks", target_os = "espidf"))] groups: &[u16],
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] groups: &[u32],
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
groups: &[u16],
) -> &mut process::Command {
self.as_inner_mut().groups(groups);
self

View file

@ -58,7 +58,8 @@ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut
target_os = "illumos",
target_os = "redox",
target_os = "solaris",
target_os = "espidf"
target_os = "espidf",
target_os = "horizon"
))] {
#[inline]
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {

View file

@ -119,6 +119,17 @@ pub mod os {
pub const EXE_EXTENSION: &str = "";
}
#[cfg(target_os = "horizon")]
pub mod os {
pub const FAMILY: &str = "unix";
pub const OS: &str = "horizon";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".so";
pub const DLL_EXTENSION: &str = "so";
pub const EXE_SUFFIX: &str = ".elf";
pub const EXE_EXTENSION: &str = "elf";
}
#[cfg(all(target_os = "emscripten", target_arch = "asmjs"))]
pub mod os {
pub const FAMILY: &str = "unix";

View file

@ -9,8 +9,6 @@
use crate::sys::cvt;
use crate::sys_common::{AsInner, FromInner, IntoInner};
use libc::{c_int, c_void};
#[cfg(any(
target_os = "android",
target_os = "linux",
@ -38,7 +36,7 @@
// larger than or equal to INT_MAX. To handle both of these the read
// size is capped on both platforms.
#[cfg(target_os = "macos")]
const READ_LIMIT: usize = c_int::MAX as usize - 1;
const READ_LIMIT: usize = libc::c_int::MAX as usize - 1;
#[cfg(not(target_os = "macos"))]
const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
@ -69,6 +67,7 @@ const fn max_iov() -> usize {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "horizon"
)))]
const fn max_iov() -> usize {
16 // The minimum value required by POSIX.
@ -79,33 +78,33 @@ pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
let ret = cvt(unsafe {
libc::read(
self.as_raw_fd(),
buf.as_mut_ptr() as *mut c_void,
buf.as_mut_ptr() as *mut libc::c_void,
cmp::min(buf.len(), READ_LIMIT),
)
})?;
Ok(ret as usize)
}
#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
let ret = cvt(unsafe {
libc::readv(
self.as_raw_fd(),
bufs.as_ptr() as *const libc::iovec,
cmp::min(bufs.len(), max_iov()) as c_int,
cmp::min(bufs.len(), max_iov()) as libc::c_int,
)
})?;
Ok(ret as usize)
}
#[cfg(target_os = "espidf")]
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
return crate::io::default_read_vectored(|b| self.read(b), bufs);
}
#[inline]
pub fn is_read_vectored(&self) -> bool {
cfg!(not(target_os = "espidf"))
cfg!(not(any(target_os = "espidf", target_os = "horizon")))
}
pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
@ -122,7 +121,7 @@ pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
unsafe {
cvt(pread64(
self.as_raw_fd(),
buf.as_mut_ptr() as *mut c_void,
buf.as_mut_ptr() as *mut libc::c_void,
cmp::min(buf.len(), READ_LIMIT),
offset as off64_t,
))
@ -134,7 +133,7 @@ pub fn read_buf(&self, buf: &mut ReadBuf<'_>) -> io::Result<()> {
let ret = cvt(unsafe {
libc::read(
self.as_raw_fd(),
buf.unfilled_mut().as_mut_ptr() as *mut c_void,
buf.unfilled_mut().as_mut_ptr() as *mut libc::c_void,
cmp::min(buf.remaining(), READ_LIMIT),
)
})?;
@ -151,33 +150,33 @@ pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
let ret = cvt(unsafe {
libc::write(
self.as_raw_fd(),
buf.as_ptr() as *const c_void,
buf.as_ptr() as *const libc::c_void,
cmp::min(buf.len(), READ_LIMIT),
)
})?;
Ok(ret as usize)
}
#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let ret = cvt(unsafe {
libc::writev(
self.as_raw_fd(),
bufs.as_ptr() as *const libc::iovec,
cmp::min(bufs.len(), max_iov()) as c_int,
cmp::min(bufs.len(), max_iov()) as libc::c_int,
)
})?;
Ok(ret as usize)
}
#[cfg(target_os = "espidf")]
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
return crate::io::default_write_vectored(|b| self.write(b), bufs);
}
#[inline]
pub fn is_write_vectored(&self) -> bool {
cfg!(not(target_os = "espidf"))
cfg!(not(any(target_os = "espidf", target_os = "horizon")))
}
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
@ -189,7 +188,7 @@ pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
unsafe {
cvt(pwrite64(
self.as_raw_fd(),
buf.as_ptr() as *const c_void,
buf.as_ptr() as *const libc::c_void,
cmp::min(buf.len(), READ_LIMIT),
offset as off64_t,
))
@ -221,7 +220,7 @@ pub fn set_cloexec(&self) -> io::Result<()> {
}
}
#[cfg(any(
all(target_env = "newlib", not(target_os = "espidf")),
all(target_env = "newlib", not(any(target_os = "espidf", target_os = "horizon"))),
target_os = "solaris",
target_os = "illumos",
target_os = "emscripten",
@ -242,17 +241,17 @@ pub fn set_cloexec(&self) -> io::Result<()> {
Ok(())
}
}
#[cfg(target_os = "espidf")]
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
pub fn set_cloexec(&self) -> io::Result<()> {
// FD_CLOEXEC is not supported in ESP-IDF but there's no need to,
// because ESP-IDF does not support spawning processes either.
// FD_CLOEXEC is not supported in ESP-IDF and Horizon OS but there's no need to,
// because neither supports spawning processes.
Ok(())
}
#[cfg(target_os = "linux")]
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
unsafe {
let v = nonblocking as c_int;
let v = nonblocking as libc::c_int;
cvt(libc::ioctl(self.as_raw_fd(), libc::FIONBIO, &v))?;
Ok(())
}

View file

@ -395,7 +395,7 @@ pub fn created(&self) -> io::Result<SystemTime> {
#[cfg(not(target_os = "netbsd"))]
impl FileAttr {
#[cfg(all(not(target_os = "vxworks"), not(target_os = "espidf")))]
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
pub fn modified(&self) -> io::Result<SystemTime> {
#[cfg(target_pointer_width = "32")]
cfg_has_statx! {
@ -412,7 +412,12 @@ pub fn modified(&self) -> io::Result<SystemTime> {
Ok(SystemTime::new(self.stat.st_mtime as i64, 0))
}
#[cfg(all(not(target_os = "vxworks"), not(target_os = "espidf")))]
#[cfg(target_os = "horizon")]
pub fn modified(&self) -> io::Result<SystemTime> {
Ok(SystemTime::from(self.stat.st_mtim))
}
#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))]
pub fn accessed(&self) -> io::Result<SystemTime> {
#[cfg(target_pointer_width = "32")]
cfg_has_statx! {
@ -424,7 +429,7 @@ pub fn accessed(&self) -> io::Result<SystemTime> {
Ok(SystemTime::new(self.stat.st_atime as i64, self.stat.st_atime_nsec as i64))
}
#[cfg(any(target_os = "vxworks", target_os = "espidf"))]
#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))]
pub fn accessed(&self) -> io::Result<SystemTime> {
Ok(SystemTime::new(self.stat.st_atime as i64, 0))
}
@ -707,7 +712,8 @@ pub fn file_type(&self) -> io::Result<FileType> {
target_os = "fuchsia",
target_os = "redox",
target_os = "vxworks",
target_os = "espidf"
target_os = "espidf",
target_os = "horizon"
))]
pub fn ino(&self) -> u64 {
self.entry.d_ino as u64
@ -1251,7 +1257,7 @@ pub fn link(original: &Path, link: &Path) -> io::Result<()> {
let original = cstr(original)?;
let link = cstr(link)?;
cfg_if::cfg_if! {
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android", target_os = "espidf"))] {
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android", target_os = "espidf", target_os = "horizon"))] {
// VxWorks, Redox and ESP-IDF lack `linkat`, so use `link` instead. POSIX leaves
// it implementation-defined whether `link` follows symlinks, so rely on the
// `symlink_hard_link` test in library/std/src/fs/tests.rs to check the behavior.
@ -1549,14 +1555,14 @@ pub fn chroot(dir: &Path) -> io::Result<()> {
pub use remove_dir_impl::remove_dir_all;
// Fallback for REDOX and ESP-IDF (and Miri)
#[cfg(any(target_os = "redox", target_os = "espidf", miri))]
// Fallback for REDOX, ESP-ID, Horizon, and Miri
#[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon", miri))]
mod remove_dir_impl {
pub use crate::sys_common::fs::remove_dir_all;
}
// Modern implementation using openat(), unlinkat() and fdopendir()
#[cfg(not(any(target_os = "redox", target_os = "espidf", miri)))]
#[cfg(not(any(target_os = "redox", target_os = "espidf", target_os = "horizon", miri)))]
mod remove_dir_impl {
use super::{cstr, lstat, Dir, DirEntry, InnerReadDir, ReadDir};
use crate::ffi::CStr;

View file

@ -16,7 +16,11 @@ unsafe impl Sync for Condvar {}
libc::timespec { tv_sec: <libc::time_t>::MAX, tv_nsec: 1_000_000_000 - 1 };
fn saturating_cast_to_time_t(value: u64) -> libc::time_t {
if value > <libc::time_t>::MAX as u64 { <libc::time_t>::MAX } else { value as libc::time_t }
if value > <libc::time_t>::MAX as u64 {
<libc::time_t>::MAX
} else {
value as libc::time_t
}
}
impl LazyInit for Condvar {
@ -47,7 +51,7 @@ unsafe fn init(&mut self) {}
// So on that platform, init() should always be called
// Moreover, that platform does not have pthread_condattr_setclock support,
// hence that initialization should be skipped as well
#[cfg(target_os = "espidf")]
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
unsafe fn init(&mut self) {
let r = libc::pthread_cond_init(self.inner.get(), crate::ptr::null());
assert_eq!(r, 0);
@ -59,7 +63,8 @@ unsafe fn init(&mut self) {
target_os = "l4re",
target_os = "android",
target_os = "redox",
target_os = "espidf"
target_os = "espidf",
target_os = "horizon"
)))]
unsafe fn init(&mut self) {
use crate::mem::MaybeUninit;

View file

@ -43,10 +43,10 @@
pub mod thread_parker;
pub mod time;
#[cfg(target_os = "espidf")]
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
pub fn init(argc: isize, argv: *const *const u8) {}
#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
// SAFETY: must be called only once during runtime initialization.
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
pub unsafe fn init(argc: isize, argv: *const *const u8) {
@ -344,7 +344,7 @@ pub fn abort_internal() -> ! {
}
}
#[cfg(target_os = "espidf")]
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
mod unsupported {
use crate::io;

View file

@ -446,7 +446,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
path.canonicalize()
}
#[cfg(target_os = "espidf")]
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
pub fn current_exe() -> io::Result<PathBuf> {
super::unsupported::unsupported()
}
@ -601,7 +601,8 @@ pub fn home_dir() -> Option<PathBuf> {
target_os = "emscripten",
target_os = "redox",
target_os = "vxworks",
target_os = "espidf"
target_os = "espidf",
target_os = "horizon"
))]
unsafe fn fallback() -> Option<OsString> {
None
@ -612,7 +613,8 @@ unsafe fn fallback() -> Option<OsString> {
target_os = "emscripten",
target_os = "redox",
target_os = "vxworks",
target_os = "espidf"
target_os = "espidf",
target_os = "horizon"
)))]
unsafe fn fallback() -> Option<OsString> {
let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) {

View file

@ -3,6 +3,7 @@
pub use crate::ffi::OsString as EnvKey;
pub use crate::sys_common::process::CommandEnvs;
#[cfg_attr(any(target_os = "espidf", target_os = "horizon"), allow(unused))]
mod process_common;
cfg_if::cfg_if! {
@ -13,7 +14,7 @@
} else if #[cfg(target_os = "vxworks")] {
#[path = "process_vxworks.rs"]
mod process_inner;
} else if #[cfg(target_os = "espidf")] {
} else if #[cfg(any(target_os = "espidf", target_os = "horizon"))] {
#[path = "process_unsupported.rs"]
mod process_inner;
} else {

View file

@ -1,10 +1,6 @@
use crate::fmt;
use crate::io;
use crate::io::ErrorKind;
use crate::num::NonZeroI32;
use crate::sys;
use crate::sys::cvt;
use crate::sys::pipe::AnonPipe;
use crate::sys::process::process_common::*;
use crate::sys::unix::unsupported::*;
use core::ffi::NonZero_c_int;
@ -18,13 +14,13 @@
impl Command {
pub fn spawn(
&mut self,
default: Stdio,
needs_stdin: bool,
_default: Stdio,
_needs_stdin: bool,
) -> io::Result<(Process, StdioPipes)> {
unsupported()
}
pub fn exec(&mut self, default: Stdio) -> io::Error {
pub fn exec(&mut self, _default: Stdio) -> io::Error {
unsupported_err()
}
}
@ -34,7 +30,7 @@ pub fn exec(&mut self, default: Stdio) -> io::Error {
////////////////////////////////////////////////////////////////////////////////
pub struct Process {
handle: pid_t,
_handle: pid_t,
}
impl Process {
@ -59,6 +55,7 @@ pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
pub struct ExitStatus(c_int);
impl ExitStatus {
#[cfg_attr(target_os = "horizon", allow(unused))]
pub fn success(&self) -> bool {
self.code() == Some(0)
}

View file

@ -59,17 +59,27 @@ fn getrandom(
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) }
}
#[cfg(target_os = "espidf")]
#[cfg(any(target_os = "espidf", target_os = "horizon"))]
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
unsafe { libc::getrandom(buf.as_mut_ptr().cast(), buf.len(), 0) }
}
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "espidf")))]
#[cfg(not(any(
target_os = "linux",
target_os = "android",
target_os = "espidf",
target_os = "horizon"
)))]
fn getrandom_fill_bytes(_buf: &mut [u8]) -> bool {
false
}
#[cfg(any(target_os = "linux", target_os = "android", target_os = "espidf"))]
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "espidf",
target_os = "horizon"
))]
fn getrandom_fill_bytes(v: &mut [u8]) -> bool {
use crate::sync::atomic::{AtomicBool, Ordering};
use crate::sys::os::errno;

View file

@ -115,7 +115,7 @@ pub unsafe fn new(parker: *mut Parker) {
target_os = "redox"
))] {
addr_of_mut!((*parker).cvar).write(UnsafeCell::new(libc::PTHREAD_COND_INITIALIZER));
} else if #[cfg(target_os = "espidf")] {
} else if #[cfg(any(target_os = "espidf", target_os = "horizon"))] {
let r = libc::pthread_cond_init(addr_of_mut!((*parker).cvar).cast(), crate::ptr::null());
assert_eq!(r, 0);
} else {

View file

@ -18,6 +18,7 @@ pub(in crate::sys::unix) struct Timespec {
}
impl SystemTime {
#[cfg_attr(target_os = "horizon", allow(unused))]
pub fn new(tv_sec: i64, tv_nsec: i64) -> SystemTime {
SystemTime { t: Timespec::new(tv_sec, tv_nsec) }
}
@ -303,9 +304,9 @@ pub fn now() -> SystemTime {
}
}
#[cfg(not(any(target_os = "dragonfly", target_os = "espidf")))]
#[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "horizon")))]
pub type clock_t = libc::c_int;
#[cfg(any(target_os = "dragonfly", target_os = "espidf"))]
#[cfg(any(target_os = "dragonfly", target_os = "espidf", target_os = "horizon"))]
pub type clock_t = libc::c_ulong;
impl Timespec {

View file

@ -399,7 +399,12 @@ pub fn bind(addr: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
cvt(unsafe { c::bind(sock.as_raw(), addrp, len as _) })?;
// Start listening
#[cfg(not(target_os = "horizon"))]
cvt(unsafe { c::listen(sock.as_raw(), 128) })?;
// 40 is the maximum for Horizon OS
#[cfg(target_os = "horizon")]
cvt(unsafe { c::listen(sock.as_raw(), 40) })?;
Ok(TcpListener { inner: sock })
}