From 538d7f524f025045fd8460b188ea0e4b1b3e5210 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 16 Oct 2026 23:00:40 -0400 Subject: [PATCH 1/2] compiler: Add `{x86_64,aarch64}-unknown-serenity` targets Co-Authored-By: Daniel Bertalan --- compiler/rustc_target/src/spec/base/mod.rs | 1 + .../rustc_target/src/spec/base/serenity.rs | 21 +++++++ compiler/rustc_target/src/spec/mod.rs | 4 ++ .../spec/targets/aarch64_unknown_serenity.rs | 22 +++++++ .../spec/targets/x86_64_unknown_serenity.rs | 24 ++++++++ src/bootstrap/src/core/sanity.rs | 1 + src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 2 + .../rustc/src/platform-support/serenity.md | 59 +++++++++++++++++++ src/librustdoc/clean/cfg.rs | 1 + tests/assembly-llvm/targets/targets-elf.rs | 6 ++ tests/ui/check-cfg/cfg-crate-features.stderr | 2 +- tests/ui/check-cfg/well-known-values.stderr | 4 +- 13 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 compiler/rustc_target/src/spec/base/serenity.rs create mode 100644 compiler/rustc_target/src/spec/targets/aarch64_unknown_serenity.rs create mode 100644 compiler/rustc_target/src/spec/targets/x86_64_unknown_serenity.rs create mode 100644 src/doc/rustc/src/platform-support/serenity.md diff --git a/compiler/rustc_target/src/spec/base/mod.rs b/compiler/rustc_target/src/spec/base/mod.rs index 726ec2c228596..5ce44806626f0 100644 --- a/compiler/rustc_target/src/spec/base/mod.rs +++ b/compiler/rustc_target/src/spec/base/mod.rs @@ -31,6 +31,7 @@ pub(crate) mod openbsd; pub(crate) mod qnx_sdp; pub(crate) mod qtee; pub(crate) mod redox; +pub(crate) mod serenity; pub(crate) mod solaris; pub(crate) mod solid; pub(crate) mod teeos; diff --git a/compiler/rustc_target/src/spec/base/serenity.rs b/compiler/rustc_target/src/spec/base/serenity.rs new file mode 100644 index 0000000000000..2be7849193e30 --- /dev/null +++ b/compiler/rustc_target/src/spec/base/serenity.rs @@ -0,0 +1,21 @@ +use crate::spec::{FramePointer, Os, PanicStrategy, RelroLevel, TargetOptions, cvs}; + +pub(crate) fn opts() -> TargetOptions { + TargetOptions { + os: Os::Serenity, + dynamic_linking: true, + frame_pointer: FramePointer::Always, + families: cvs!["unix"], + default_dwarf_version: 5, + has_rpath: true, + no_default_libraries: false, + position_independent_executables: true, + static_position_independent_executables: false, + relro_level: RelroLevel::Full, + has_thread_local: true, + panic_strategy: PanicStrategy::Abort, + crt_static_default: false, + crt_static_respected: false, + ..Default::default() + } +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index ae17e37e29f86..aa12afef7021a 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1708,6 +1708,9 @@ supported_targets! { ("aarch64-unknown-hyperlight", aarch64_unknown_hyperlight), ("x86_64-unknown-hyperlight", x86_64_unknown_hyperlight), + + ("aarch64-unknown-serenity", aarch64_unknown_serenity), + ("x86_64-unknown-serenity", x86_64_unknown_serenity), } /// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]> @@ -1885,6 +1888,7 @@ crate::target_spec_enum! { Qurt = "qurt", Redox = "redox", Rtems = "rtems", + Serenity = "serenity", Solaris = "solaris", SolidAsp3 = "solid_asp3", TeeOs = "teeos", diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_serenity.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_serenity.rs new file mode 100644 index 0000000000000..9dff331e0b4ff --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_serenity.rs @@ -0,0 +1,22 @@ +use crate::spec::{Arch, StackProbeType, Target, base}; + +pub(crate) fn target() -> Target { + let mut base = base::serenity::opts(); + base.max_atomic_width = Some(128); + base.stack_probes = StackProbeType::Inline; + base.features = "+v8a".into(); + + Target { + llvm_target: "aarch64-unknown-serenity".into(), + metadata: crate::spec::TargetMetadata { + description: Some("SerenityOS AArch64".into()), + tier: Some(3), + host_tools: Some(false), + std: Some(false), + }, + 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(), + arch: Arch::AArch64, + options: base + } +} 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 new file mode 100644 index 0000000000000..7731a185c528c --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_serenity.rs @@ -0,0 +1,24 @@ +use crate::spec::{Arch, Cc, LinkerFlavor, Lld, StackProbeType, Target, base}; + +pub(crate) fn target() -> Target { + let mut base = base::serenity::opts(); + base.cpu = "x86-64".into(); + base.max_atomic_width = Some(64); + base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); + base.stack_probes = StackProbeType::Inline; + + Target { + llvm_target: "x86_64-unknown-serenity".into(), + metadata: crate::spec::TargetMetadata { + description: Some("SerenityOS x86_64".into()), + tier: Some(3), + host_tools: Some(false), + std: Some(false), + }, + pointer_width: 64, + data_layout: + "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(), + arch: Arch::X86_64, + options: base, + } +} diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index ac44a4dfca9b1..ba181220a7fb0 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -35,6 +35,7 @@ pub struct Finder { /// Targets can be removed from this list during the usual release process bootstrap compiler bumps, /// when the newly-bumped stage 0 compiler now knows about the formerly-missing targets. const STAGE0_MISSING_TARGETS: &[&str] = &[ + "aarch64-unknown-serenity", // just a dummy comment so the list doesn't get onelined "aarch64-unknown-qtee", ]; diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index abd2bb11104b0..ff073e6ccdb1a 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -141,6 +141,7 @@ - [\*-unknown-netbsd\*](platform-support/netbsd.md) - [\*-unknown-openbsd](platform-support/openbsd.md) - [\*-unknown-redox](platform-support/redox.md) + - [\*-unknown-serenity](platform-support/serenity.md) - [\*-unknown-uefi](platform-support/unknown-uefi.md) - [\*-pc-windows-msvc](platform-support/windows-msvc.md) - [\*-uwp-windows-msvc](platform-support/uwp-windows-msvc.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index f81a7a54a6b44..6fc487e7e92ad 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -287,6 +287,7 @@ target | std | host | notes [`aarch64-unknown-nuttx`](platform-support/nuttx.md) | ✓ | | ARM64 with NuttX [`aarch64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | ARM64 OpenBSD [`aarch64-unknown-redox`](platform-support/redox.md) | ✓ | | ARM64 Redox OS +[`aarch64-unknown-serenity`](platform-support/serenity.md) | ? | | | ARM64 SerenityOS | [`aarch64-unknown-teeos`](platform-support/aarch64-unknown-teeos.md) | ? | | ARM64 TEEOS | [`aarch64-unknown-qtee`](platform-support/aarch64-unknown-qtee.md) | ? | | ARM64 QTEE | [`aarch64-unknown-trusty`](platform-support/trusty.md) | ✓ | | @@ -471,6 +472,7 @@ target | std | host | notes [`x86_64-unknown-managarm-mlibc`](platform-support/managarm.md) | ? | | x86_64 Managarm [`x86_64-unknown-motor`](platform-support/motor.md) | ✓ | | x86_64 Motor OS [`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD +[`x86_64-unknown-serenity`](platform-support/serenity.md) | ? | | | x86_64 SerenityOS | [`x86_64-unknown-trusty`](platform-support/trusty.md) | ✓ | | `x86_64-uwp-windows-gnu` | ✓ | | [`x86_64-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | | diff --git a/src/doc/rustc/src/platform-support/serenity.md b/src/doc/rustc/src/platform-support/serenity.md new file mode 100644 index 0000000000000..d195b0f393d86 --- /dev/null +++ b/src/doc/rustc/src/platform-support/serenity.md @@ -0,0 +1,59 @@ +# `*-unknown-serenity` + +**Tier: 3** + +SerenityOS is a graphical Unix-like operating system for 64-bit x86, Arm, and RISC-V computers. + +## Target maintainers + +[@ADKaster](https://github.com/ADKaster) +[@nico](https://github.com/nico) + +## Requirements + +Host tools are not supported. `std` is not yet supported. There are no releases, as +SerenityOS is a hobbyist OS. + +A checkout of [`serenity`](https://github.com/SerenityOS/serenity) is required to build +the operating system image. The simplest cross-compilation environment is the +serenity [Ports tree](https://github.com/SerenityOS/serenity/tree/master/Ports#readme). +Out-of-tree cross-compilation has been shown to work, but is not a typical developer +workflow. + +Target binaries are in the ELF format and are expected to call into the Kernel +via libc. Direct syscalls are not supported due to an [`msyscall` mitigation] +(https://man.serenityos.org/man7/Mitigations.html#syscall-call-from-verification). + +## Building the target + +The targets can be built by enabling them for a `rustc` build, for example: + +```toml +[build] +build-stage = 1 +target = ["aarch64-unknown-serenity", "x86_64-unknown-serenity"] +``` + +## Building Rust programs + +Rust does not yet ship pre-compiled artifacts for this target. To compile for +this target, you will either need to build Rust with the target enabled (see +"Building the target" above), or build your own copy of `core` by using +`build-std` or similar. + +## Testing + +Target binaries can be included in a default developer QEMU image by copying +the binary and any required runtime dependencies into a subfolder under +`Build//Root` or `Build/clang/Root`, depending on the cross-compilation +toolchain used when building. + +Alternatively, a [`sync-local.sh`](https://github.com/SerenityOS/serenity/blob/master/Documentation/AdvancedBuildInstructions.md#customizing-the-disk-image) +script can be used to modify the disk image during an image build. + +Running the rust test suite is not yet supported. + +## Cross-compilation toolchains and C code + +The operating system is written in C++, so a C/C++ compiler is required. +The target triples are as expected, `$ARCH-unknown-serenity`. diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index de240d8f87092..1255da9d48d39 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -692,6 +692,7 @@ fn human_readable_target_os(os: Symbol) -> Option<&'static str> { Qurt => "QuRT", Redox => "Redox OS", Rtems => "RTEMS OS", + Serenity => "SerenityOS", Solaris => "Solaris", SolidAsp3 => "SOLID ASP3", TeeOs => "TEEOS", diff --git a/tests/assembly-llvm/targets/targets-elf.rs b/tests/assembly-llvm/targets/targets-elf.rs index 2908c659f9f02..96b43f4fe1f59 100644 --- a/tests/assembly-llvm/targets/targets-elf.rs +++ b/tests/assembly-llvm/targets/targets-elf.rs @@ -112,6 +112,9 @@ //@ revisions: aarch64_unknown_nuttx //@ [aarch64_unknown_nuttx] compile-flags: --target aarch64-unknown-nuttx //@ [aarch64_unknown_nuttx] needs-llvm-components: aarch64 +//@ revisions: aarch64_unknown_serenity +//@ [aarch64_unknown_serenity] compile-flags: --target aarch64-unknown-serenity +//@ [aarch64_unknown_serenity] needs-llvm-components: aarch64 //@ revisions: aarch64_unknown_trusty //@ [aarch64_unknown_trusty] compile-flags: --target aarch64-unknown-trusty //@ [aarch64_unknown_trusty] needs-llvm-components: aarch64 @@ -784,6 +787,9 @@ //@ revisions: x86_64_unknown_redox //@ [x86_64_unknown_redox] compile-flags: --target x86_64-unknown-redox //@ [x86_64_unknown_redox] needs-llvm-components: x86 +//@ revisions: x86_64_unknown_serenity +//@ [x86_64_unknown_serenity] compile-flags: --target x86_64-unknown-serenity +//@ [x86_64_unknown_serenity] needs-llvm-components: x86 //@ revisions: x86_64_unknown_trusty //@ [x86_64_unknown_trusty] compile-flags: --target x86_64-unknown-trusty //@ [x86_64_unknown_trusty] needs-llvm-components: x86 diff --git a/tests/ui/check-cfg/cfg-crate-features.stderr b/tests/ui/check-cfg/cfg-crate-features.stderr index f2f7a235c2a0a..19666a8e57611 100644 --- a/tests/ui/check-cfg/cfg-crate-features.stderr +++ b/tests/ui/check-cfg/cfg-crate-features.stderr @@ -24,7 +24,7 @@ warning: unexpected `cfg` condition value: `does_not_exist` LL | #![cfg(not(target(os = "does_not_exist")))] | ^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `helenos`, `hermit`, `horizon`, `hurd`, `hyperlight`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `ps3`, `psp`, `psx`, `qnx`, `qtee`, and `qurt` and 18 more + = note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `helenos`, `hermit`, `horizon`, `hurd`, `hyperlight`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `ps3`, `psp`, `psx`, `qnx`, `qtee`, and `qurt` and 19 more = note: see for more information about checking conditional configuration = note: `#[warn(unexpected_cfgs)]` on by default diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index e2f8f8cfb571f..0600b0c33025b 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -232,7 +232,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_os = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `helenos`, `hermit`, `horizon`, `hurd`, `hyperlight`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `ps3`, `psp`, `psx`, `qnx`, `qtee`, `qurt`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `vexos`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` + = note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `helenos`, `hermit`, `horizon`, `hurd`, `hyperlight`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `ps3`, `psp`, `psx`, `qnx`, `qtee`, `qurt`, `redox`, `rtems`, `serenity`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `vexos`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` @@ -305,7 +305,7 @@ LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux` | | | help: there is a expected value with a similar name: `"linux"` | - = note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `helenos`, `hermit`, `horizon`, `hurd`, `hyperlight`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `ps3`, `psp`, `psx`, `qnx`, `qtee`, `qurt`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `vexos`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` + = note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `helenos`, `hermit`, `horizon`, `hurd`, `hyperlight`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `ps3`, `psp`, `psx`, `qnx`, `qtee`, `qurt`, `redox`, `rtems`, `serenity`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `vexos`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm` = note: see for more information about checking conditional configuration warning: 31 warnings emitted From 1100bf0dbbd22bcc2a0d40ef2444981db82f1fd0 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 31 Oct 2026 20:21:16 -0400 Subject: [PATCH 2/2] serenity: Add std support --- .../spec/targets/aarch64_unknown_serenity.rs | 2 +- .../spec/targets/x86_64_unknown_serenity.rs | 2 +- library/std/build.rs | 1 + library/std/src/os/mod.rs | 2 + library/std/src/os/serenity/fs.rs | 95 +++++++++++++++++++ library/std/src/os/serenity/mod.rs | 7 ++ library/std/src/os/serenity/raw.rs | 15 +++ library/std/src/os/unix/mod.rs | 2 + library/std/src/sys/args/unix.rs | 1 + library/std/src/sys/fd/unix.rs | 6 ++ library/std/src/sys/fs/unix.rs | 28 +++++- library/std/src/sys/io/error/unix.rs | 1 + .../pal/unix/stack_overflow/handler_signal.rs | 18 +++- .../src/sys/pal/unix/stack_overflow/mod.rs | 1 + library/std/src/sys/paths/unix.rs | 3 +- library/std/src/sys/pipe/unix.rs | 3 +- library/std/src/sys/process/unix/unix.rs | 1 + library/std/src/sys/random/mod.rs | 1 + library/std/src/sys/thread/mod.rs | 2 + library/std/src/sys/thread/unix.rs | 8 +- library/std/src/sys/thread_local/mod.rs | 3 +- 21 files changed, 189 insertions(+), 13 deletions(-) create mode 100644 library/std/src/os/serenity/fs.rs create mode 100644 library/std/src/os/serenity/mod.rs create mode 100644 library/std/src/os/serenity/raw.rs 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 6ebbc6afc1661..01f8c56684644 100644 --- a/library/std/src/sys/fd/unix.rs +++ b/library/std/src/sys/fd/unix.rs @@ -91,6 +91,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 @@ -123,6 +124,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. @@ -247,6 +249,7 @@ impl FileDesc { target_os = "netbsd", target_os = "openbsd", // OpenBSD 2.7 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 { @@ -273,6 +276,7 @@ impl FileDesc { target_os = "netbsd", target_os = "openbsd", target_vendor = "apple", + 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) @@ -443,6 +447,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 { @@ -469,6 +474,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 76560a8e2eeae..a4bd21b49ac4a 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()) @@ -1086,6 +1099,7 @@ impl DirEntry { target_os = "qnx", target_os = "vita", target_os = "l4re", + target_os = "serenity", )))] match self.entry.d_type { libc::DT_CHR => return Ok(FileType { mode: libc::S_IFCHR }), @@ -1336,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) })?; @@ -1360,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) })?; @@ -1384,6 +1400,7 @@ impl File { target_os = "haiku", target_os = "android", target_os = "redox", + target_os = "serenity", target_vendor = "apple", ) => { let result = @@ -1420,6 +1437,7 @@ impl File { target_os = "haiku", target_os = "android", target_os = "redox", + target_os = "serenity", target_vendor = "apple", ) => { let result = @@ -1456,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) })?; @@ -1999,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 cee799c36c79b..dff8718613357 100644 --- a/library/std/src/sys/paths/unix.rs +++ b/library/std/src/sys/paths/unix.rs @@ -292,7 +292,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 b7908dea2b5de..f2a72b4d0b659 100644 --- a/library/std/src/sys/thread/unix.rs +++ b/library/std/src/sys/thread/unix.rs @@ -165,6 +165,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)] @@ -367,7 +368,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) @@ -445,7 +446,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 { @@ -565,6 +567,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 @@ -668,6 +671,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 5d3c23ce04678..9b759f7b73766 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;