@@ -107,8 +107,29 @@ impl<System: Kernel> InterruptLine<System> {
107
107
self ,
108
108
value : InterruptPriority ,
109
109
) -> Result < ( ) , SetInterruptLinePriorityError > {
110
- let _lock = utils:: lock_cpu :: < System > ( ) ?;
110
+ let mut lock = utils:: lock_cpu :: < System > ( ) ?;
111
+
112
+ if System :: is_interrupt_context ( ) {
113
+ return Err ( SetInterruptLinePriorityError :: BadContext ) ;
114
+ }
111
115
116
+ // Safety: (1) Some of the preconditions of `set_priority_unchecked`,
117
+ // which are upheld by the caller.
118
+ // (2) A task context.
119
+ unsafe { self . set_priority_unchecked_inner ( value, lock. borrow_mut ( ) ) }
120
+ }
121
+
122
+ /// Like `set_priority_unchecked` but assumes a task context or a boot
123
+ /// phase.
124
+ ///
125
+ /// # Safety
126
+ ///
127
+ /// In addition to `set_priority_unchecked`,
128
+ unsafe fn set_priority_unchecked_inner (
129
+ self ,
130
+ value : InterruptPriority ,
131
+ _lock : utils:: CpuLockGuardBorrowMut < System > ,
132
+ ) -> Result < ( ) , SetInterruptLinePriorityError > {
112
133
// Safety: (1) We are the kernel, so it's okay to call `Port`'s methods.
113
134
// (2) CPU Lock active
114
135
unsafe { System :: set_interrupt_line_priority ( self . 0 , value) }
@@ -199,17 +220,21 @@ impl<System: Kernel> InterruptAttr<System> {
199
220
///
200
221
/// This method may call `InterruptLine::set_priority_unchecked`. The caller
201
222
/// is responsible for ensuring *unmanaged safety*.
202
- pub ( super ) unsafe fn init ( & self ) {
223
+ ///
224
+ /// Can be called only during a boot phase.
225
+ pub ( super ) unsafe fn init ( & self , mut lock : utils:: CpuLockGuardBorrowMut < System > ) {
203
226
for line_init in self . line_inits {
204
227
if line_init
205
228
. flags
206
229
. contains ( InterruptLineInitFlags :: SET_PRIORITY )
207
230
{
208
- // Safety: The caller is responsible for making sure this is safe
231
+ // Safety: (1) The caller is responsible for ensuring unmanaged
232
+ // safety.
233
+ // (2) Boot phase
209
234
unsafe {
210
235
line_init
211
236
. line
212
- . set_priority_unchecked ( line_init. priority )
237
+ . set_priority_unchecked_inner ( line_init. priority , lock . borrow_mut ( ) )
213
238
. unwrap ( )
214
239
} ;
215
240
}
0 commit comments