summaryrefslogtreecommitdiff
path: root/Kernel/Locking/LockRank.h
blob: 9aff2bf6c0d1be9a5a2b0b06c57803c5cd33cc21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/EnumBits.h>

namespace Kernel {
// To catch bugs where locks are taken out of order, we annotate all locks
// in the kernel with a rank. The rank describes the order in which locks
// are allowed to be taken. If a lock is acquired, and it is of an incompatible
// rank with the lock held by the executing thread then the system can detect
// the lock order violation and respond appropriately (crash with error).
//
// A thread holding a lower ranked lock cannot acquire a lock of a greater or equal rank.
enum class LockRank : int {
    // Special marker for locks which haven't been annotated yet.
    // Note: This should be removed once all locks are annotated.
    None = 0x000,

    // We need to be able to handle page faults from anywhere, so
    // memory manager locks are our lowest rank lock.
    MemoryManager = 0x001,

    Interrupts = 0x002,

    FileSystem = 0x004,

    Thread = 0x008,

    // Process locks are the highest rank, as they normally are taken
    // first thing when processing syscalls.
    Process = 0x010,
};

AK_ENUM_BITWISE_OPERATORS(LockRank);

void track_lock_acquire(LockRank);
void track_lock_release(LockRank);
}