Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
95 changes: 95 additions & 0 deletions library/std/src/os/serenity/fs.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 7 additions & 0 deletions library/std/src/os/serenity/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 15 additions & 0 deletions library/std/src/os/serenity/raw.rs
Original file line number Diff line number Diff line change
@@ -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};
2 changes: 2 additions & 0 deletions library/std/src/os/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/args/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/sys/fd/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<usize> {
let ret = cvt(unsafe {
Expand Down Expand Up @@ -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<usize> {
io::default_read_vectored(|b| self.read_at(b, offset), bufs)
Expand Down Expand Up @@ -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<usize> {
let ret = cvt(unsafe {
Expand All @@ -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<usize> {
io::default_write_vectored(|b| self.write_at(b, offset), bufs)
Expand Down
27 changes: 23 additions & 4 deletions library/std/src/sys/fs/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,12 @@ fn debug_path_fd<'a, 'b>(
}

fn get_path_from_fd(fd: c_int) -> Option<PathBuf> {
#[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<PathBuf> {
let mut p = PathBuf::from("/proc/self/fd");
p.push(&fd.to_string());
Expand Down Expand Up @@ -382,6 +387,7 @@ fn get_path_from_fd(fd: c_int) -> Option<PathBuf> {
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris",
target_os = "serenity",
target_vendor = "apple",
)))]
fn get_path(_fd: c_int) -> Option<PathBuf> {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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> {
SystemTime::new(self.stat.st_mtim.tv_sec, self.stat.st_mtim.tv_nsec.into())
Expand Down Expand Up @@ -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) })?;
Expand All @@ -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) })?;
Expand All @@ -1385,6 +1400,7 @@ impl File {
target_os = "haiku",
target_os = "android",
target_os = "redox",
target_os = "serenity",
target_vendor = "apple",
) => {
let result =
Expand Down Expand Up @@ -1421,6 +1437,7 @@ impl File {
target_os = "haiku",
target_os = "android",
target_os = "redox",
target_os = "serenity",
target_vendor = "apple",
) => {
let result =
Expand Down Expand Up @@ -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) })?;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/io/error/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 16 additions & 2 deletions library/std/src/sys/pal/unix/stack_overflow/handler_signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ 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(
target_os = "openbsd",
target_os = "netbsd",
target_os = "linux",
target_os = "dragonfly",
target_os = "serenity",
)))]
let flags = MAP_PRIVATE | MAP_ANON;

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -422,7 +435,7 @@ unsafe fn install_main_guard() -> Option<Range<usize>> {
// 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.
Expand Down Expand Up @@ -493,7 +506,7 @@ fn install_main_guard_bsds(page_size: usize) -> Option<Range<usize>> {
}
// 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
Expand Down Expand Up @@ -554,6 +567,7 @@ unsafe fn install_main_guard_default(page_size: usize) -> Option<Range<usize>> {
target_os = "openbsd",
target_os = "solaris",
target_os = "illumos",
target_os = "serenity",
))]
fn current_guard() -> Option<Range<usize>> {
let stackptr = get_stack_start()?;
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/pal/unix/stack_overflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cfg_select! {
target_os = "openbsd",
target_os = "solaris",
target_os = "illumos",
target_os = "serenity",
) => {
mod handler_signal;
mod thread_info;
Expand Down
Loading
Loading