-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Add std
support for armv7a-vex-v5
#145973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tropix126
wants to merge
23
commits into
rust-lang:master
Choose a base branch
from
vexide:vex-std
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 3317cd7
vexos: move fs and stdio into respective modules
Tropix126 2fdd96d
vexos: implement global dlmalloc fallback
Tropix126 a141abf
vexos: finish bringing modules up to date
Tropix126 36d71f1
vexos: provide `dlmalloc::Allocator` implementation
Tropix126 3989b2c
vexos: block on stdout writes with size>2048
Tropix126 0163635
format, tidy
Tropix126 ba08497
bump to vex-sdk 0.27.0
Tropix126 bed0127
vexos: simplify logic by casting `count` to usize early
Tropix126 64a440f
vexos: remove accidental semicolon
Tropix126 85025ad
vexos: fix file opening logic
Tropix126 7e66bd1
vexos: improve error message when opening files in RW mode
Tropix126 4be4d68
vexos: fix logic regarding `create` and `create_new`
Tropix126 21ef17d
update `armv7a-vex-v5` target documentation
Tropix126 6b85cc9
clarify details regarding system ABI, fix typos
Tropix126 70804e4
simplify `vexFileStatus` check in `fs::exists`
Tropix126 c3a6373
remove unnecessary allocator lock on VEXos
Tropix126 7eb898e
fmt
Tropix126 7f8cb7d
switch to `run_path_with_cstr` for path conversion
Tropix126 76b70ba
vexos: refactor `FileAttr`, clean up `open` logic
Tropix126 4cc8721
vexos: improve unsafe hygiene in alloc and PAL, fix fs issues
Tropix126 9f67126
re-export relevant items from `unsupported` in vexos modules
Tropix126 fb1b204
fix type incompatibilities from `unsupported` re-exports
Tropix126 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tropix126 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
Tropix126 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.