mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Protect Inode list with SpinLock (#2748)
Fixes crashes when a context switch happens in the middle of modifying it, or when another thread on another processor modifies it at the same time.
This commit is contained in:
parent
d4b87fb18e
commit
6df87b51f7
Notes:
sideshowbarker
2024-07-19 05:00:30 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/6df87b51f7d Pull-request: https://github.com/SerenityOS/serenity/pull/2748
1 changed files with 7 additions and 1 deletions
|
@ -36,8 +36,12 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
static SpinLock s_all_inodes_lock;
|
||||
|
||||
InlineLinkedList<Inode>& all_inodes()
|
||||
{
|
||||
ASSERT(s_all_inodes_lock.is_locked());
|
||||
|
||||
static InlineLinkedList<Inode>* list;
|
||||
if (!list)
|
||||
list = new InlineLinkedList<Inode>;
|
||||
|
@ -48,7 +52,7 @@ void Inode::sync()
|
|||
{
|
||||
NonnullRefPtrVector<Inode, 32> inodes;
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
ScopedSpinLock all_inodes_lock(s_all_inodes_lock);
|
||||
for (auto& inode : all_inodes()) {
|
||||
if (inode.is_metadata_dirty())
|
||||
inodes.append(inode);
|
||||
|
@ -111,11 +115,13 @@ Inode::Inode(FS& fs, unsigned index)
|
|||
: m_fs(fs)
|
||||
, m_index(index)
|
||||
{
|
||||
ScopedSpinLock all_inodes_lock(s_all_inodes_lock);
|
||||
all_inodes().append(this);
|
||||
}
|
||||
|
||||
Inode::~Inode()
|
||||
{
|
||||
ScopedSpinLock all_inodes_lock(s_all_inodes_lock);
|
||||
all_inodes().remove(this);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue