Skip to content
Open
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
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 @@ -327,6 +327,7 @@ dependencies = [
"rustc-demangle",
"std_detect",
"unwind",
"vex-sdk",
"wasi",
"windows-targets 0.0.0",
]
Expand Down Expand Up @@ -389,6 +390,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 @@ -84,6 +84,11 @@ wasi = { version = "0.11.0", 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
94 changes: 94 additions & 0 deletions library/std/src/sys/alloc/vexos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// 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 defined in the target 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) {
unsafe {
(
(&raw mut __heap_start).cast(),
(&raw const __heap_end).byte_offset_from(ptr::addr_of!(__heap_start)) as _,
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.
// 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.
// 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.
// 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.
// 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