diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_serenity.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_serenity.rs index 9dff331e0b4ff..b0ee9f10b687d 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_unknown_serenity.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_serenity.rs @@ -12,7 +12,7 @@ pub(crate) fn target() -> Target { description: Some("SerenityOS AArch64".into()), tier: Some(3), host_tools: Some(false), - std: Some(false), + std: Some(true), }, pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_serenity.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_serenity.rs index 7731a185c528c..be1bb2e976401 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_serenity.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_serenity.rs @@ -13,7 +13,7 @@ pub(crate) fn target() -> Target { description: Some("SerenityOS x86_64".into()), tier: Some(3), host_tools: Some(false), - std: Some(false), + std: Some(true), }, pointer_width: 64, data_layout: diff --git a/library/std/build.rs b/library/std/build.rs index 98856b58d890f..d8c97c0ab9f0f 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -58,6 +58,7 @@ fn main() { || target_os == "nuttx" || target_os == "cygwin" || target_os == "vexos" + || target_os == "serenity" // See src/bootstrap/src/core/build_steps/synthetic_targets.rs || env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok() diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index f95c6ac8dd76d..dcb37db287957 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -131,6 +131,8 @@ pub mod openbsd; pub mod redox; #[cfg(target_os = "rtems")] pub mod rtems; +#[cfg(target_os = "serenity")] +pub mod serenity; #[cfg(target_os = "solaris")] pub mod solaris; #[cfg(target_os = "solid_asp3")] diff --git a/library/std/src/os/serenity/fs.rs b/library/std/src/os/serenity/fs.rs new file mode 100644 index 0000000000000..09587bb9c8770 --- /dev/null +++ b/library/std/src/os/serenity/fs.rs @@ -0,0 +1,95 @@ +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use crate::fs::Metadata; +use crate::sys::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_atim.tv_sec as i64 + } + fn st_atime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_atim.tv_nsec as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtim.tv_sec as i64 + } + fn st_mtime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_mtim.tv_nsec as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctim.tv_sec as i64 + } + fn st_ctime_nsec(&self) -> i64 { + self.as_inner().as_inner().st_ctim.tv_nsec as i64 + } + 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 + } +} diff --git a/library/std/src/os/serenity/mod.rs b/library/std/src/os/serenity/mod.rs new file mode 100644 index 0000000000000..4e1531986e2f9 --- /dev/null +++ b/library/std/src/os/serenity/mod.rs @@ -0,0 +1,7 @@ +//! Serenity-specific definitions. + +#![stable(feature = "raw_ext", since = "1.1.0")] +#![forbid(unsafe_op_in_unsafe_fn)] + +pub mod fs; +pub mod raw; diff --git a/library/std/src/os/serenity/raw.rs b/library/std/src/os/serenity/raw.rs new file mode 100644 index 0000000000000..f42b80dc6abb0 --- /dev/null +++ b/library/std/src/os/serenity/raw.rs @@ -0,0 +1,15 @@ +#![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)] + +#[stable(feature = "pthread_t", since = "1.8.0")] +pub type pthread_t = i32; + +#[stable(feature = "raw_ext", since = "1.1.0")] +pub use libc::{blkcnt_t, blksize_t, dev_t, ino_t, mode_t, nlink_t, off_t, time_t}; diff --git a/library/std/src/os/unix/mod.rs b/library/std/src/os/unix/mod.rs index 436062cf0a4f2..3773aaf497623 100644 --- a/library/std/src/os/unix/mod.rs +++ b/library/std/src/os/unix/mod.rs @@ -80,6 +80,8 @@ mod platform { pub use crate::os::redox::*; #[cfg(target_os = "rtems")] pub use crate::os::rtems::*; + #[cfg(target_os = "serenity")] + pub use crate::os::serenity::*; #[cfg(target_os = "solaris")] pub use crate::os::solaris::*; #[cfg(target_os = "vita")] diff --git a/library/std/src/sys/args/unix.rs b/library/std/src/sys/args/unix.rs index 197931d8cc8d2..cd8d3703ff15d 100644 --- a/library/std/src/sys/args/unix.rs +++ b/library/std/src/sys/args/unix.rs @@ -85,6 +85,7 @@ pub fn args() -> Args { target_os = "hurd", target_os = "rtems", target_os = "nuttx", + target_os = "serenity", ))] mod imp { use crate::ffi::c_char; diff --git a/library/std/src/sys/fd/unix.rs b/library/std/src/sys/fd/unix.rs index 3166f8b7aacb7..1dc1b657d8fc2 100644 --- a/library/std/src/sys/fd/unix.rs +++ b/library/std/src/sys/fd/unix.rs @@ -82,6 +82,7 @@ const READ_LIMIT: usize = cfg_select! { target_os = "openbsd", target_vendor = "apple", target_os = "cygwin", + target_os = "serenity", ))] const fn max_iov() -> usize { libc::IOV_MAX as usize @@ -114,6 +115,7 @@ const fn max_iov() -> usize { target_os = "vita", target_vendor = "apple", target_os = "cygwin", + target_os = "serenity", )))] const fn max_iov() -> usize { 16 // The minimum value required by POSIX. @@ -239,6 +241,7 @@ impl FileDesc { target_os = "openbsd", // OpenBSD 2.7 target_os = "l4re", all(target_os = "macos", target_arch = "aarch64"), + target_os = "serenity", ))] pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result { let ret = cvt(unsafe { @@ -266,6 +269,7 @@ impl FileDesc { target_os = "openbsd", target_vendor = "apple", target_os = "l4re", + target_os = "serenity", )))] pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result { io::default_read_vectored(|b| self.read_at(b, offset), bufs) @@ -436,6 +440,7 @@ impl FileDesc { target_os = "netbsd", target_os = "openbsd", // OpenBSD 2.7 all(target_os = "macos", target_arch = "aarch64"), + target_os = "serenity", ))] pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result { let ret = cvt(unsafe { @@ -462,6 +467,7 @@ impl FileDesc { target_os = "netbsd", target_os = "openbsd", target_vendor = "apple", + target_os = "serenity", )))] pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result { io::default_write_vectored(|b| self.write_at(b, offset), bufs) diff --git a/library/std/src/sys/fs/unix.rs b/library/std/src/sys/fs/unix.rs index 4b384aee7bc24..929a0241c0fe6 100644 --- a/library/std/src/sys/fs/unix.rs +++ b/library/std/src/sys/fs/unix.rs @@ -315,7 +315,12 @@ fn debug_path_fd<'a, 'b>( } fn get_path_from_fd(fd: c_int) -> Option { - #[cfg(any(target_os = "linux", target_os = "illumos", target_os = "solaris"))] + #[cfg(any( + target_os = "linux", + target_os = "illumos", + target_os = "solaris", + target_os = "serenity" + ))] fn get_path(fd: c_int) -> Option { let mut p = PathBuf::from("/proc/self/fd"); p.push(&fd.to_string()); @@ -382,6 +387,7 @@ fn get_path_from_fd(fd: c_int) -> Option { target_os = "netbsd", target_os = "illumos", target_os = "solaris", + target_os = "serenity", target_vendor = "apple", )))] fn get_path(_fd: c_int) -> Option { @@ -563,7 +569,8 @@ impl FileAttr { target_os = "qnx", target_os = "aix", target_os = "wasi", - target_os = "l4re" + target_os = "l4re", + target_os = "serenity" )))] impl FileAttr { #[cfg(not(any( @@ -689,7 +696,13 @@ impl FileAttr { } } -#[cfg(any(target_os = "nto", target_os = "qnx", target_os = "wasi", target_os = "l4re"))] +#[cfg(any( + target_os = "nto", + target_os = "qnx", + target_os = "wasi", + target_os = "l4re", + target_os = "serenity" +))] impl FileAttr { pub fn modified(&self) -> io::Result { SystemTime::new(self.stat.st_mtim.tv_sec, self.stat.st_mtim.tv_nsec.into()) @@ -1337,6 +1350,7 @@ impl File { target_os = "haiku", target_os = "android", target_os = "redox", + target_os = "serenity", target_vendor = "apple", ) => { cvt(unsafe { libc::flock(self.as_raw_fd(), libc::LOCK_EX) })?; @@ -1361,6 +1375,7 @@ impl File { target_os = "haiku", target_os = "android", target_os = "redox", + target_os = "serenity", target_vendor = "apple", ) => { cvt(unsafe { libc::flock(self.as_raw_fd(), libc::LOCK_SH) })?; @@ -1385,6 +1400,7 @@ impl File { target_os = "haiku", target_os = "android", target_os = "redox", + target_os = "serenity", target_vendor = "apple", ) => { let result = @@ -1421,6 +1437,7 @@ impl File { target_os = "haiku", target_os = "android", target_os = "redox", + target_os = "serenity", target_vendor = "apple", ) => { let result = @@ -1457,6 +1474,7 @@ impl File { target_os = "haiku", target_os = "android", target_os = "redox", + target_os = "serenity", target_vendor = "apple", ) => { cvt(unsafe { libc::flock(self.as_raw_fd(), libc::LOCK_UN) })?; @@ -2000,7 +2018,8 @@ pub fn set_perm_nofollow(p: &CStr, perm: FilePermissions) -> io::Result<()> { target_os = "netbsd", target_os = "dragonfly", target_os = "nto", - target_os = "qnx" + target_os = "qnx", + target_os = "serenity", ))] { res = cvt_r(|| unsafe { diff --git a/library/std/src/sys/io/error/unix.rs b/library/std/src/sys/io/error/unix.rs index 5f60abf9d9528..275ab7cb15560 100644 --- a/library/std/src/sys/io/error/unix.rs +++ b/library/std/src/sys/io/error/unix.rs @@ -17,6 +17,7 @@ unsafe extern "C" { target_os = "fuchsia", target_os = "l4re", target_os = "hurd", + target_os = "serenity", target_os = "teeos", ), link_name = "__errno_location" diff --git a/library/std/src/sys/pal/unix/stack_overflow/handler_signal.rs b/library/std/src/sys/pal/unix/stack_overflow/handler_signal.rs index ba81ca1e15bf9..e8cb33704ea5b 100644 --- a/library/std/src/sys/pal/unix/stack_overflow/handler_signal.rs +++ b/library/std/src/sys/pal/unix/stack_overflow/handler_signal.rs @@ -156,6 +156,7 @@ fn get_stack() -> libc::stack_t { target_os = "netbsd", target_os = "linux", target_os = "dragonfly", + target_os = "serenity", ))] let flags = MAP_PRIVATE | MAP_ANON | libc::MAP_STACK; #[cfg(not(any( @@ -163,6 +164,7 @@ fn get_stack() -> libc::stack_t { target_os = "netbsd", target_os = "linux", target_os = "dragonfly", + target_os = "serenity", )))] let flags = MAP_PRIVATE | MAP_ANON; @@ -330,6 +332,17 @@ fn get_stack_start() -> Option<*mut libc::c_void> { Some(stack_ptr.with_addr(stackaddr)) } +#[cfg(target_os = "serenity")] +fn get_stack_start() -> Option<*mut libc::c_void> { + let mut user_stack_base: *mut libc::c_void = crate::ptr::null_mut(); + let mut user_stack_size: libc::size_t = 0; + // SAFETY: + // The pointers are valid for writing a `*mut libc::c_void` and a `size_t`. + assert_eq!(unsafe { libc::get_stack_bounds(&mut user_stack_base, &mut user_stack_size) }, 0); + + Some(user_stack_base) +} + #[cfg(any( target_os = "android", target_os = "freebsd", @@ -422,7 +435,7 @@ unsafe fn install_main_guard() -> Option> { // The FreeBSD code cannot be checked on non-BSDs. #[cfg(target_os = "freebsd")] install_main_guard_freebsd(page_size) - } else if cfg!(any(target_os = "netbsd", target_os = "openbsd")) { + } else if cfg!(any(target_os = "netbsd", target_os = "openbsd", target_os = "serenity")) { install_main_guard_bsds(page_size) } else { // SAFETY: guaranteed by caller. @@ -493,7 +506,7 @@ fn install_main_guard_bsds(page_size: usize) -> Option> { } // OpenBSD stack already includes a guard page, and stack is // immutable. - // NetBSD stack includes the guard page. + // NetBSD and SerenityOS stack includes the guard page. // // We'll just note where we expect rlimit to start // faulting, so our handler can report "stack overflow", and @@ -554,6 +567,7 @@ unsafe fn install_main_guard_default(page_size: usize) -> Option> { target_os = "openbsd", target_os = "solaris", target_os = "illumos", + target_os = "serenity", ))] fn current_guard() -> Option> { let stackptr = get_stack_start()?; diff --git a/library/std/src/sys/pal/unix/stack_overflow/mod.rs b/library/std/src/sys/pal/unix/stack_overflow/mod.rs index dfd9e006353d2..274a4c98f88ee 100644 --- a/library/std/src/sys/pal/unix/stack_overflow/mod.rs +++ b/library/std/src/sys/pal/unix/stack_overflow/mod.rs @@ -19,6 +19,7 @@ cfg_select! { target_os = "openbsd", target_os = "solaris", target_os = "illumos", + target_os = "serenity", ) => { mod handler_signal; mod thread_info; diff --git a/library/std/src/sys/paths/unix.rs b/library/std/src/sys/paths/unix.rs index 756c5ec26f127..d2f704f87d48e 100644 --- a/library/std/src/sys/paths/unix.rs +++ b/library/std/src/sys/paths/unix.rs @@ -269,7 +269,8 @@ pub fn current_exe() -> io::Result { target_os = "hurd", target_os = "android", target_os = "nuttx", - target_os = "emscripten" + target_os = "emscripten", + target_os = "serenity", ))] pub fn current_exe() -> io::Result { match crate::fs::read_link("/proc/self/exe") { diff --git a/library/std/src/sys/pipe/unix.rs b/library/std/src/sys/pipe/unix.rs index 86397ecd0badf..bbaeb9c4c7627 100644 --- a/library/std/src/sys/pipe/unix.rs +++ b/library/std/src/sys/pipe/unix.rs @@ -22,7 +22,8 @@ pub fn pipe() -> io::Result<(Pipe, Pipe)> { target_os = "netbsd", target_os = "openbsd", target_os = "cygwin", - target_os = "redox" + target_os = "redox", + target_os = "serenity", ) => unsafe { cvt(libc::pipe2(fds.as_mut_ptr(), libc::O_CLOEXEC))?; Ok((Pipe::from_raw_fd(fds[0]), Pipe::from_raw_fd(fds[1]))) diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index d1262ba3e2e6e..88840441d6279 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -1235,6 +1235,7 @@ fn signal_string(signal: i32) -> Option<&'static str> { target_os = "openbsd", target_os = "dragonfly", target_vendor = "apple", + target_os = "serenity", ))] libc::SIGINFO => "SIGINFO", #[cfg(target_os = "hurd")] diff --git a/library/std/src/sys/random/mod.rs b/library/std/src/sys/random/mod.rs index 23f6ce8d25eb4..c5d88a3798daa 100644 --- a/library/std/src/sys/random/mod.rs +++ b/library/std/src/sys/random/mod.rs @@ -21,6 +21,7 @@ cfg_select! { target_os = "netbsd", target_os = "openbsd", target_os = "rtems", + target_os = "serenity", target_os = "solaris", target_os = "vita", target_os = "nuttx", diff --git a/library/std/src/sys/thread/mod.rs b/library/std/src/sys/thread/mod.rs index dfbfc2bc8e0c2..1d120a273fbd2 100644 --- a/library/std/src/sys/thread/mod.rs +++ b/library/std/src/sys/thread/mod.rs @@ -73,6 +73,7 @@ cfg_select! { target_os = "wasi", target_vendor = "apple", target_os = "fuchsia", + target_os = "serenity", ))] pub use unix::sleep_until; pub use unix::{ @@ -150,6 +151,7 @@ cfg_select! { target_os = "motor", target_os = "vexos", target_os = "fuchsia", + target_os = "serenity", )))] pub fn sleep_until(deadline: crate::time::Instant) { use crate::time::Instant; diff --git a/library/std/src/sys/thread/unix.rs b/library/std/src/sys/thread/unix.rs index 400ee36466620..cd4366a5c5250 100644 --- a/library/std/src/sys/thread/unix.rs +++ b/library/std/src/sys/thread/unix.rs @@ -166,6 +166,7 @@ pub fn available_parallelism() -> io::Result> { target_vendor = "apple", target_os = "cygwin", target_os = "redox", + target_os = "serenity", target_os = "wasi", ) => { #[allow(unused_assignments)] @@ -368,7 +369,7 @@ pub fn current_os_id() -> Option { let id: libc::pid_t = unsafe { gettid() }; Some(id as u64) } - any(target_os = "nto", target_os = "qnx") => { + any(target_os = "nto", target_os = "qnx", target_os = "serenity") => { // SAFETY: FFI call with no preconditions. let id: libc::pid_t = unsafe { libc::gettid() }; Some(id as u64) @@ -446,7 +447,8 @@ pub fn set_name(name: &CStr) { target_os = "freebsd", target_os = "dragonfly", target_os = "nuttx", - target_os = "cygwin" + target_os = "cygwin", + target_os = "serenity", ))] pub fn set_name(name: &CStr) { unsafe { @@ -566,6 +568,7 @@ pub fn sleep(dur: Duration) { target_os = "hurd", target_os = "vxworks", target_os = "wasi", + target_os = "serenity", ) => { // POSIX specifies that `nanosleep` uses CLOCK_REALTIME, but is not // affected by clock adjustments. The timing of `sleep` however should @@ -669,6 +672,7 @@ pub fn sleep(dur: Duration) { target_os = "hurd", target_os = "vxworks", target_os = "wasi", + target_os = "serenity", ))] pub fn sleep_until(deadline: crate::time::Instant) { use crate::time::Instant; diff --git a/library/std/src/sys/thread_local/mod.rs b/library/std/src/sys/thread_local/mod.rs index 1c137e52d9319..ae021b2c6b4bf 100644 --- a/library/std/src/sys/thread_local/mod.rs +++ b/library/std/src/sys/thread_local/mod.rs @@ -77,7 +77,8 @@ pub(crate) mod destructors { target_os = "redox", target_os = "hurd", target_os = "netbsd", - target_os = "dragonfly" + target_os = "dragonfly", + target_os = "serenity", ) => { mod linux_like; mod list;