File tree Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Expand file tree Collapse file tree 3 files changed +66
-0
lines changed 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 memdomain;
9
10
pub mod mempool;
10
11
pub mod mutex;
11
12
pub mod semaphore;
Original file line number Diff line number Diff line change
1
+ #[ cfg( not( usermode) ) ]
2
+ use core:: marker:: PhantomData ;
3
+
4
+ pub use zephyr_sys:: raw:: k_mem_domain;
5
+
6
+ use crate :: thread:: ThreadId ;
7
+
8
+ #[ cfg( usermode) ]
9
+ pub struct MemDomain < ' a > ( & ' a k_mem_domain ) ;
10
+ #[ cfg( not( usermode) ) ]
11
+ pub struct MemDomain < ' a > ( PhantomData < & ' a ( ) > ) ;
12
+
13
+ impl < ' a > MemDomain < ' a > {
14
+ #[ cfg( usermode) ]
15
+ pub unsafe fn new ( domain : & ' a k_mem_domain ) -> Self {
16
+ MemDomain ( domain)
17
+ }
18
+ #[ cfg( not( usermode) ) ]
19
+ pub fn new ( ) -> Self {
20
+ MemDomain ( PhantomData )
21
+ }
22
+
23
+ pub fn add_thread < C : MemDomainAPI > ( & self , _thread : ThreadId ) {
24
+ #[ cfg( usermode) ]
25
+ C :: k_mem_domain_add_thread ( self . 0 , _thread)
26
+ }
27
+ }
28
+
29
+ pub trait MemDomainAPI {
30
+ fn k_mem_domain_add_thread ( domain : & k_mem_domain , thread : ThreadId ) ;
31
+ }
32
+
33
+ impl MemDomainAPI for crate :: context:: Kernel {
34
+ fn k_mem_domain_add_thread ( domain : & k_mem_domain , thread : ThreadId ) {
35
+ unsafe {
36
+ zephyr_sys:: raw:: k_mem_domain_add_thread ( domain as * const _ as * mut _ , thread. tid ( ) )
37
+ }
38
+ }
39
+ }
40
+
41
+ /// Get a static reference to an external mem domain
42
+ #[ cfg( usermode) ]
43
+ #[ macro_export]
44
+ macro_rules! static_mem_domain {
45
+ ( $domain: ident) => { {
46
+ extern "C" {
47
+ #[ no_mangle]
48
+ static $domain: $crate:: memdomain:: k_mem_domain;
49
+ }
50
+
51
+ unsafe { $crate:: memdomain:: MemDomain :: new( & $domain) }
52
+ } } ;
53
+ }
54
+ /// Get a static reference to an external mem domain
55
+ #[ cfg( not( usermode) ) ]
56
+ #[ macro_export]
57
+ macro_rules! static_mem_domain {
58
+ ( $domain: ident) => { {
59
+ $crate:: memdomain:: MemDomain :: new( )
60
+ } } ;
61
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ use crate::kobj::KObj;
4
4
pub struct ThreadId ( zephyr_sys:: raw:: k_tid_t ) ;
5
5
6
6
impl ThreadId {
7
+ pub fn tid ( & self ) -> zephyr_sys:: raw:: k_tid_t {
8
+ self . 0
9
+ }
10
+
7
11
pub fn k_object_access_grant < C : ThreadSyscalls , K : KObj > ( & self , kobj : & K ) {
8
12
C :: k_object_access_grant ( kobj, * self )
9
13
}
You can’t perform that action at this time.
0 commit comments