Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenSK
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
koenigl2
OpenSK
Commits
2817ca0e
Commit
2817ca0e
authored
5 years ago
by
Guillaume Endignoux
Browse files
Options
Downloads
Patches
Plain Diff
Don't lock the allocator with spin.
parent
d8c29b7e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
patches/libtock-rs/06-no_spin_allocator.patch
+77
-0
77 additions, 0 deletions
patches/libtock-rs/06-no_spin_allocator.patch
with
77 additions
and
0 deletions
patches/libtock-rs/06-no_spin_allocator.patch
0 → 100644
+
77
−
0
View file @
2817ca0e
diff --git a/Cargo.toml b/Cargo.toml
index 844e424..386a9ed 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,7 @@
license = "MIT/Apache-2.0"
edition = "2018"
[dependencies]
-linked_list_allocator = "0.6.6"
+linked_list_allocator = { version = "0.6.6", default-features = false }
[features]
panic_console = []
diff --git a/src/entry_point.rs b/src/entry_point.rs
index 15e1d03..2fe5c40 100644
--- a/src/entry_point.rs
+++ b/src/entry_point.rs
@@ -1,8 +1,10 @@
use crate::memop;
use crate::syscalls;
-use crate::ALLOCATOR;
+use core::alloc::{GlobalAlloc, Layout};
use core::intrinsics;
use core::ptr;
+use core::ptr::NonNull;
+use linked_list_allocator::Heap;
// _start and rust_start are the first two procedures executed when a Tock
// application starts. _start is invoked directly by the Tock kernel; it
@@ -357,7 +359,7 @@
pub unsafe extern "C" fn rust_start(app_start: usize, stacktop: usize, app_heap_
// Tell the kernel the new app heap break.
memop::set_brk(app_heap_end as *const u8);
- ALLOCATOR.lock().init(app_heap_start, HEAP_SIZE);
+ HEAP.init(app_heap_start, HEAP_SIZE);
main(0, ptr::null());
@@ -365,3 +367,23 @@
pub unsafe extern "C" fn rust_start(app_start: usize, stacktop: usize, app_heap_
syscalls::yieldk();
}
}
+
+#[cfg(any(target_arch = "arm", target_arch = "riscv32"))]
+#[global_allocator]
+static ALLOCATOR: TockAllocator = TockAllocator;
+
+static mut HEAP: Heap = Heap::empty();
+
+struct TockAllocator;
+
+unsafe impl GlobalAlloc for TockAllocator {
+ unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
+ HEAP.allocate_first_fit(layout)
+ .ok()
+ .map_or(0 as *mut u8, |allocation| allocation.as_ptr())
+ }
+
+ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
+ HEAP.deallocate(NonNull::new_unchecked(ptr), layout)
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index c9001bf..2f9c1c0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -44,10 +44,6 @@
pub mod syscalls;
#[path = "syscalls_mock.rs"]
pub mod syscalls;
-#[cfg(any(target_arch = "arm", target_arch = "riscv32"))]
-#[global_allocator]
-static ALLOCATOR: linked_list_allocator::LockedHeap = linked_list_allocator::LockedHeap::empty();
-
// Dummy structure to force importing the panic_handler and other no_std elements when nothing else
// is imported.
pub struct LibTock;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment