1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:17:35 +00:00

Add an InterruptDisabler helper class and use that for kmalloc.

The naive spinlock was not nearly enough to protect kmalloc from
reentrancy problems.

I don't want to deal with coming up with a fancy lock for kmalloc
right now, so I made an InterruptDisabler thingy instead.
It does CLI and then STI iff interrupts were previously enabled.
This commit is contained in:
Andreas Kling 2018-10-24 11:07:53 +02:00
parent 9a296d63f3
commit 0c5bbac86e
4 changed files with 35 additions and 14 deletions

View file

@ -79,6 +79,35 @@ void writeGDTEntry(WORD selector, Descriptor&);
#define cli() asm volatile("cli")
#define sti() asm volatile("sti")
static inline dword cpuFlags()
{
dword flags;
asm volatile(
"pushf\n"
"pop %0\n"
:"=rm"(flags)
::"memory");
return flags;
}
class InterruptDisabler {
public:
InterruptDisabler()
{
m_flags = cpuFlags();
cli();
}
~InterruptDisabler()
{
if (m_flags & 0x200)
sti();
}
private:
dword m_flags;
};
/* Map IRQ0-15 @ ISR 0x50-0x5F */
#define IRQ_VECTOR_BASE 0x50