31
31
//!
32
32
33
33
#![ no_std]
34
+ #![ feature( const_refs_to_cell) ]
34
35
35
36
extern crate alloc; // TODO temp remove this
36
37
37
38
use cpu:: CpuId ;
38
39
use preemption:: { PreemptionCount , PreemptionGuard } ;
39
40
use task:: TaskRef ;
40
41
41
-
42
- struct TestU32 ( u32 ) ;
43
- impl Drop for TestU32 {
44
- fn drop ( & mut self ) {
45
- panic ! ( "Dropping TestU32({})" , self . 0 ) ;
46
- }
47
- }
48
-
49
42
/// The data stored on a per-CPU basis in Theseus.
50
43
///
51
44
/// Currently, we do not support additional arbitrary per-CPU states, e.g.,
@@ -56,6 +49,11 @@ impl Drop for TestU32 {
56
49
/// by other crates using the functions in the [`cpu_local`] crate.
57
50
#[ allow( dead_code) ] // These fields are accessed via `cpu_local` functions.
58
51
#[ repr( C ) ]
52
+ //
53
+ // IMPORTANT NOTE:
54
+ // * These fields must be kept in sync with `cpu_local::FixedCpuLocal`.
55
+ // * The same applies for the `const_assertions` module at the end of this file.
56
+ //
59
57
pub struct PerCpuData {
60
58
/// A pointer to the start of this struct in memory, similar to a TLS self pointer.
61
59
/// This has a different initial value for each CPU's data image, of course.
@@ -65,7 +63,6 @@ pub struct PerCpuData {
65
63
/// loaded in full before accessing a single sub-field. See this for more:
66
64
/// <https://github.com/rust-osdev/x86_64/pull/257#issuecomment-849514649>.
67
65
self_ptr : usize ,
68
- // NOTE: These fields must be kept in sync with `cpu_local::FixedCpuLocal`.
69
66
/// The unique ID of this CPU.
70
67
cpu_id : CpuId ,
71
68
/// The current preemption count of this CPU, which is used to determine
@@ -109,3 +106,30 @@ pub fn init(cpu_id: CpuId) -> Result<(), &'static str> {
109
106
|self_ptr| PerCpuData :: new ( self_ptr, cpu_id) ,
110
107
)
111
108
}
109
+
110
+ mod const_assertions {
111
+ use core:: mem:: { align_of, size_of} ;
112
+ use cpu_local:: FixedCpuLocal ;
113
+ use memoffset:: offset_of;
114
+ use super :: * ;
115
+
116
+ const _: ( ) = assert ! ( 0 == offset_of!( PerCpuData , self_ptr) ) ;
117
+ const _: ( ) = assert ! ( 8 == size_of:: <usize >( ) ) ;
118
+ const _: ( ) = assert ! ( 8 == align_of:: <usize >( ) ) ;
119
+
120
+ const _: ( ) = assert ! ( FixedCpuLocal :: CPU_ID . offset == offset_of!( PerCpuData , cpu_id) ) ;
121
+ const _: ( ) = assert ! ( FixedCpuLocal :: CPU_ID . size == size_of:: <CpuId >( ) ) ;
122
+ const _: ( ) = assert ! ( FixedCpuLocal :: CPU_ID . align == align_of:: <CpuId >( ) ) ;
123
+
124
+ const _: ( ) = assert ! ( FixedCpuLocal :: PREEMPTION_COUNT . offset == offset_of!( PerCpuData , preemption_count) ) ;
125
+ const _: ( ) = assert ! ( FixedCpuLocal :: PREEMPTION_COUNT . size == size_of:: <PreemptionCount >( ) ) ;
126
+ const _: ( ) = assert ! ( FixedCpuLocal :: PREEMPTION_COUNT . align == align_of:: <PreemptionCount >( ) ) ;
127
+
128
+ const _: ( ) = assert ! ( FixedCpuLocal :: TASK_SWITCH_PREEMPTION_GUARD . offset == offset_of!( PerCpuData , task_switch_preemption_guard) ) ;
129
+ const _: ( ) = assert ! ( FixedCpuLocal :: TASK_SWITCH_PREEMPTION_GUARD . size == size_of:: <Option <PreemptionGuard >>( ) ) ;
130
+ const _: ( ) = assert ! ( FixedCpuLocal :: TASK_SWITCH_PREEMPTION_GUARD . align == align_of:: <Option <PreemptionGuard >>( ) ) ;
131
+
132
+ const _: ( ) = assert ! ( FixedCpuLocal :: DROP_AFTER_TASK_SWITCH . offset == offset_of!( PerCpuData , drop_after_task_switch) ) ;
133
+ const _: ( ) = assert ! ( FixedCpuLocal :: DROP_AFTER_TASK_SWITCH . size == size_of:: <Option <TaskRef >>( ) ) ;
134
+ const _: ( ) = assert ! ( FixedCpuLocal :: DROP_AFTER_TASK_SWITCH . align == align_of:: <Option <TaskRef >>( ) ) ;
135
+ }
0 commit comments