raw pointer dance for IRQ handlers

This commit is contained in:
bunnie 2024-12-02 19:05:56 +08:00
parent 9662f13d31
commit 8876f6e7f5

View file

@ -17,7 +17,7 @@ pub fn handle(irqs_pending: usize) -> Result<xous_kernel::Result, xous_kernel::E
// NOTE: This will become an issue when running with multiple cores, // NOTE: This will become an issue when running with multiple cores,
// so this should be protected by a mutex. // so this should be protected by a mutex.
unsafe { unsafe {
for (irq_no, handler) in IRQ_HANDLERS.iter().enumerate() { for (irq_no, handler) in (&mut *(&raw mut IRQ_HANDLERS)).iter().enumerate() {
if irqs_pending & (1 << irq_no) != 0 { if irqs_pending & (1 << irq_no) != 0 {
if let Some((pid, f, arg)) = handler { if let Some((pid, f, arg)) = handler {
return SystemServices::with_mut(|ss| { return SystemServices::with_mut(|ss| {
@ -59,7 +59,7 @@ where
F: Fn(usize, &PID, MemoryAddress, Option<MemoryAddress>), F: Fn(usize, &PID, MemoryAddress, Option<MemoryAddress>),
{ {
unsafe { unsafe {
for (idx, handler) in IRQ_HANDLERS.iter().enumerate() { for (idx, handler) in (&mut *(&raw mut IRQ_HANDLERS)).iter().enumerate() {
// Ignore threads that have no PC, and ignore the ISR thread // Ignore threads that have no PC, and ignore the ISR thread
if let Some(handler) = handler { if let Some(handler) = handler {
op(idx, &handler.0, handler.1, handler.2); op(idx, &handler.0, handler.1, handler.2);
@ -77,12 +77,12 @@ pub fn interrupt_claim(
// Unsafe is required since we're accessing a static mut array. // Unsafe is required since we're accessing a static mut array.
// However, we disable interrupts to prevent contention on this array. // However, we disable interrupts to prevent contention on this array.
unsafe { unsafe {
if irq > IRQ_HANDLERS.len() { if irq > (&mut *(&raw mut IRQ_HANDLERS)).len() {
Err(xous_kernel::Error::InterruptNotFound) Err(xous_kernel::Error::InterruptNotFound)
} else if IRQ_HANDLERS[irq].is_some() { } else if (&mut *(&raw mut IRQ_HANDLERS))[irq].is_some() {
Err(xous_kernel::Error::InterruptInUse) Err(xous_kernel::Error::InterruptInUse)
} else { } else {
IRQ_HANDLERS[irq] = Some((pid, f, arg)); (&mut *(&raw mut IRQ_HANDLERS))[irq] = Some((pid, f, arg));
arch::irq::enable_irq(irq); arch::irq::enable_irq(irq);
Ok(()) Ok(())
} }
@ -93,13 +93,13 @@ pub fn interrupt_free(irq: usize, pid: PID) -> Result<(), xous_kernel::Error> {
// Unsafe is required since we're accessing a static mut array. // Unsafe is required since we're accessing a static mut array.
// However, we disable interrupts to prevent contention on this array. // However, we disable interrupts to prevent contention on this array.
unsafe { unsafe {
if irq > IRQ_HANDLERS.len() { if irq > (&mut *(&raw mut IRQ_HANDLERS)).len() {
Err(xous_kernel::Error::InterruptNotFound) Err(xous_kernel::Error::InterruptNotFound)
} else if !IRQ_HANDLERS[irq].map(|f| f.0 == pid).unwrap_or(false) { } else if !(&mut *(&raw mut IRQ_HANDLERS))[irq].map(|f| f.0 == pid).unwrap_or(false) {
Err(xous_kernel::Error::InterruptNotFound) Err(xous_kernel::Error::InterruptNotFound)
} else { } else {
arch::irq::disable_irq(irq); arch::irq::disable_irq(irq);
IRQ_HANDLERS[irq] = None; (&mut *(&raw mut IRQ_HANDLERS))[irq] = None;
Ok(()) Ok(())
} }
} }
@ -109,7 +109,7 @@ pub fn interrupt_free(irq: usize, pid: PID) -> Result<(), xous_kernel::Error> {
/// for the given PID. /// for the given PID.
pub fn release_interrupts_for_pid(pid: PID) { pub fn release_interrupts_for_pid(pid: PID) {
unsafe { unsafe {
for (irq, handler) in IRQ_HANDLERS.iter_mut().enumerate() { for (irq, handler) in (&mut *(&raw mut IRQ_HANDLERS)).iter_mut().enumerate() {
if let Some(h) = handler { if let Some(h) = handler {
if h.0 == pid { if h.0 == pid {
arch::irq::disable_irq(irq); arch::irq::disable_irq(irq);