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,
// so this should be protected by a mutex.
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 let Some((pid, f, arg)) = handler {
return SystemServices::with_mut(|ss| {
@ -59,7 +59,7 @@ where
F: Fn(usize, &PID, MemoryAddress, Option<MemoryAddress>),
{
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
if let Some(handler) = handler {
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.
// However, we disable interrupts to prevent contention on this array.
unsafe {
if irq > IRQ_HANDLERS.len() {
if irq > (&mut *(&raw mut IRQ_HANDLERS)).len() {
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)
} else {
IRQ_HANDLERS[irq] = Some((pid, f, arg));
(&mut *(&raw mut IRQ_HANDLERS))[irq] = Some((pid, f, arg));
arch::irq::enable_irq(irq);
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.
// However, we disable interrupts to prevent contention on this array.
unsafe {
if irq > IRQ_HANDLERS.len() {
if irq > (&mut *(&raw mut IRQ_HANDLERS)).len() {
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)
} else {
arch::irq::disable_irq(irq);
IRQ_HANDLERS[irq] = None;
(&mut *(&raw mut IRQ_HANDLERS))[irq] = None;
Ok(())
}
}
@ -109,7 +109,7 @@ pub fn interrupt_free(irq: usize, pid: PID) -> Result<(), xous_kernel::Error> {
/// for the given PID.
pub fn release_interrupts_for_pid(pid: PID) {
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 h.0 == pid {
arch::irq::disable_irq(irq);