Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b809a21
wip: port some old std work
lewisfm Aug 22, 2025
3317cd7
vexos: move fs and stdio into respective modules
Tropix126 Aug 24, 2025
2fdd96d
vexos: implement global dlmalloc fallback
Tropix126 Aug 24, 2025
a141abf
vexos: finish bringing modules up to date
Tropix126 Aug 26, 2025
36d71f1
vexos: provide `dlmalloc::Allocator` implementation
Tropix126 Aug 26, 2025
3989b2c
vexos: block on stdout writes with size>2048
Tropix126 Aug 26, 2025
0163635
format, tidy
Tropix126 Aug 26, 2025
ba08497
bump to vex-sdk 0.27.0
Tropix126 Aug 26, 2025
bed0127
vexos: simplify logic by casting `count` to usize early
Tropix126 Aug 26, 2025
64a440f
vexos: remove accidental semicolon
Tropix126 Aug 26, 2025
85025ad
vexos: fix file opening logic
Tropix126 Aug 28, 2025
7e66bd1
vexos: improve error message when opening files in RW mode
Tropix126 Aug 28, 2025
4be4d68
vexos: fix logic regarding `create` and `create_new`
Tropix126 Aug 28, 2025
21ef17d
update `armv7a-vex-v5` target documentation
Tropix126 Aug 28, 2025
6b85cc9
clarify details regarding system ABI, fix typos
Tropix126 Aug 28, 2025
70804e4
simplify `vexFileStatus` check in `fs::exists`
Tropix126 Aug 28, 2025
c3a6373
remove unnecessary allocator lock on VEXos
Tropix126 Aug 28, 2025
7eb898e
fmt
Tropix126 Aug 28, 2025
7f8cb7d
switch to `run_path_with_cstr` for path conversion
Tropix126 Aug 29, 2025
76b70ba
vexos: refactor `FileAttr`, clean up `open` logic
Tropix126 Aug 30, 2025
4cc8721
vexos: improve unsafe hygiene in alloc and PAL, fix fs issues
Tropix126 Aug 30, 2025
9f67126
re-export relevant items from `unsupported` in vexos modules
Tropix126 Aug 30, 2025
fb1b204
fix type incompatibilities from `unsupported` re-exports
Tropix126 Aug 30, 2025
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
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/targets/armv7a_vex_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) fn target() -> Target {
description: Some("ARMv7-A Cortex-A9 VEX V5 Brain".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(false),
std: Some(true),
},
pointer_width: 32,
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
Expand Down
10 changes: 10 additions & 0 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ dependencies = [
"unwind",
"wasi 0.11.1+wasi-snapshot-preview1",
"wasi 0.14.3+wasi-0.2.4",
"vex-sdk",
"windows-targets 0.0.0",
]

Expand Down Expand Up @@ -390,6 +391,15 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "vex-sdk"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89f74fce61d7a7ba1589da9634c6305a72befb7cc9150c1f872d87d8060f32b9"
dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
Expand Down
7 changes: 6 additions & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ path = "../windows_targets"
rand = { version = "0.9.0", default-features = false, features = ["alloc"] }
rand_xorshift = "0.4.0"

[target.'cfg(any(all(target_family = "wasm", target_os = "unknown"), target_os = "xous", all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
[target.'cfg(any(all(target_family = "wasm", target_os = "unknown"), target_os = "xous", target_os = "vexos", all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
dlmalloc = { version = "0.2.10", features = ['rustc-dep-of-std'] }

[target.x86_64-fortanix-unknown-sgx.dependencies]
Expand All @@ -89,6 +89,11 @@ wasip2 = { version = '0.14.3', features = [
r-efi = { version = "5.2.0", features = ['rustc-dep-of-std'] }
r-efi-alloc = { version = "2.0.0", features = ['rustc-dep-of-std'] }

[target.'cfg(target_os = "vexos")'.dependencies]
vex-sdk = { version = "0.27.0", features = [
'rustc-dep-of-std',
], default-features = false }

[features]
backtrace = [
'addr2line/rustc-dep-of-std',
Expand Down
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn main() {
|| target_os == "rtems"
|| target_os == "nuttx"
|| target_os == "cygwin"
|| target_os == "vexos"

// 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/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ pub mod consts {
/// * `"redox"`
/// * `"solaris"`
/// * `"solid_asp3`
/// * `"vexos"`
/// * `"vita"`
/// * `"vxworks"`
/// * `"xous"`
Expand Down Expand Up @@ -1148,6 +1149,7 @@ pub mod consts {
///
/// <details><summary>Full list of possible values</summary>
///
/// * `"bin"`
/// * `"exe"`
/// * `"efi"`
/// * `"js"`
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/sys/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ cfg_select! {
target_os = "uefi" => {
mod uefi;
}
target_os = "vexos" => {
mod vexos;
}
target_family = "wasm" => {
mod wasm;
}
Expand Down
96 changes: 96 additions & 0 deletions library/std/src/sys/alloc/vexos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use crate::alloc::{GlobalAlloc, Layout, System};
use crate::ptr;
use crate::sync::atomic::{AtomicBool, Ordering};

// Symbols for heap section boundaries defined in the target's linkerscript
unsafe extern "C" {
static mut __heap_start: u8;
static mut __heap_end: u8;
}

static mut DLMALLOC: dlmalloc::Dlmalloc<Vexos> = dlmalloc::Dlmalloc::new_with_allocator(Vexos);

struct Vexos;

unsafe impl dlmalloc::Allocator for Vexos {
/// Allocs system resources
fn alloc(&self, _size: usize) -> (*mut u8, usize, u32) {
static INIT: AtomicBool = AtomicBool::new(false);

if !INIT.swap(true, Ordering::Relaxed) {
// This target has no growable heap, as user memory has a fixed
// size/location and VEXos does not manage allocation for us.
unsafe {
(
(&raw mut __heap_start).cast::<u8>(),
(&raw const __heap_end).offset_from_unsigned(&raw const __heap_start),
0,
)
}
} else {
(ptr::null_mut(), 0, 0)
}
}

fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
ptr::null_mut()
}

fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}

fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
return false;
}

fn can_release_part(&self, _flags: u32) -> bool {
false
}

fn allocates_zeros(&self) -> bool {
false
}

fn page_size(&self) -> usize {
0x1000
}
}

#[stable(feature = "alloc_system_type", since = "1.28.0")]
unsafe impl GlobalAlloc for System {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
// SAFETY: DLMALLOC access is guaranteed to be safe because we are a single-threaded target, which
// guarantees unique and non-reentrant access to the allocator. As such, no allocator lock is used.
// Calling malloc() is safe because preconditions on this function match the trait method preconditions.
unsafe { DLMALLOC.malloc(layout.size(), layout.align()) }
}

#[inline]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
// SAFETY: DLMALLOC access is guaranteed to be safe because we are a single-threaded target, which
// guarantees unique and non-reentrant access to the allocator. As such, no allocator lock is used.
// Calling calloc() is safe because preconditions on this function match the trait method preconditions.
unsafe { DLMALLOC.calloc(layout.size(), layout.align()) }
}

#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
// SAFETY: DLMALLOC access is guaranteed to be safe because we are a single-threaded target, which
// guarantees unique and non-reentrant access to the allocator. As such, no allocator lock is used.
// Calling free() is safe because preconditions on this function match the trait method preconditions.
unsafe { DLMALLOC.free(ptr, layout.size(), layout.align()) }
}

#[inline]
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
// SAFETY: DLMALLOC access is guaranteed to be safe because we are a single-threaded target, which
// guarantees unique and non-reentrant access to the allocator. As such, no allocator lock is used.
// Calling realloc() is safe because preconditions on this function match the trait method preconditions.
unsafe { DLMALLOC.realloc(ptr, layout.size(), layout.align(), new_size) }
}
}
11 changes: 11 additions & 0 deletions library/std/src/sys/env_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@ pub mod os {
pub const EXE_EXTENSION: &str = "efi";
}

#[cfg(target_os = "vexos")]
pub mod os {
pub const FAMILY: &str = "";
pub const OS: &str = "vexos";
pub const DLL_PREFIX: &str = "";
pub const DLL_SUFFIX: &str = "";
pub const DLL_EXTENSION: &str = "";
pub const EXE_SUFFIX: &str = ".bin";
pub const EXE_EXTENSION: &str = "bin";
}

#[cfg(target_os = "visionos")]
pub mod os {
pub const FAMILY: &str = "unix";
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ cfg_select! {
mod uefi;
use uefi as imp;
}
target_os = "vexos" => {
mod vexos;
use vexos as imp;
}
target_os = "wasi" => {
mod wasi;
use wasi as imp;
Expand Down
Loading
Loading