File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
#include <rust_syscall_macros.h>
6
6
#include <kernel.h>
7
+ #include <misc/mempool.h>
7
8
#include <device.h>
8
9
#include <uart.h>
9
10
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ extern crate derive_more;
6
6
7
7
pub mod device;
8
8
pub mod kobj;
9
+ pub mod mempool;
9
10
pub mod mutex;
10
11
pub mod semaphore;
11
12
pub mod thread;
Original file line number Diff line number Diff line change
1
+ use core:: alloc:: { GlobalAlloc , Layout } ;
2
+
3
+ pub use zephyr_sys:: raw:: sys_mem_pool;
4
+
5
+ pub struct MempoolAlloc ( pub & ' static sys_mem_pool ) ;
6
+
7
+ unsafe impl Send for MempoolAlloc { }
8
+ unsafe impl Sync for MempoolAlloc { }
9
+
10
+ unsafe impl GlobalAlloc for MempoolAlloc {
11
+ unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
12
+ zephyr_sys:: raw:: sys_mem_pool_alloc ( self . 0 as * const _ as * mut _ , layout. size ( ) ) as * mut _
13
+ }
14
+
15
+ unsafe fn dealloc ( & self , ptr : * mut u8 , _layout : Layout ) {
16
+ zephyr_sys:: raw:: sys_mem_pool_free ( ptr as * mut _ )
17
+ }
18
+ }
19
+
20
+ /// Assign a Zephyr sys mem pool as #[global_allocator]
21
+ ///
22
+ /// This should be defined with SYS_MEM_POOL_DEFINE and granted permission to any
23
+ /// Rust threads that need to use libstd or alloc.
24
+ #[ macro_export]
25
+ macro_rules! global_sys_mem_pool {
26
+ ( $pool: ident) => {
27
+ extern "C" {
28
+ #[ no_mangle]
29
+ static $pool: $crate:: mempool:: sys_mem_pool;
30
+ }
31
+
32
+ #[ global_allocator]
33
+ static GLOBAL : $crate:: mempool:: MempoolAlloc =
34
+ $crate:: mempool:: MempoolAlloc ( unsafe { & $pool } ) ;
35
+ } ;
36
+ }
Original file line number Diff line number Diff line change 1
1
#define __ZEPHYR_DEFINE_SYSCALLS__
2
2
#include <rust_syscall_macros.h>
3
3
#include <kernel.h>
4
+ #include <misc/mempool.h>
4
5
#include <device.h>
5
6
#include <uart.h>
You can’t perform that action at this time.
0 commit comments