RWTH-OS / eduOS-rs

A teaching operating system written in Rust
https://rwth-os.github.io/eduOS-rs/
Apache License 2.0
412 stars 26 forks source link

Disable interrupts before fetching a ticket in SpinlockIrqSave to guard against possible race conditions #5

Closed ColinFinck closed 6 years ago

ColinFinck commented 6 years ago

To prevent a possible race condition, when fetching a ticket and being interrupted by an IRQ Handler that also fetches a ticket, we need to disable interrupts before fetching a ticket.

As discussed, I originally wanted to tackle this problem by implementing recursive spinlocks, just like in the C version of HermitCore. However, they would have also required disabling interrupts before fetching a ticket to be absolutely safe from race conditions. When interrupts are disabled early in obtain_lock() though, no recursive locking situation can happen inside eduOS-rs, so we can solve the race condition without introducing recursive spinlocks.