Kernel: Resolve clang-tidy readability-make-member-function-const

... In files included from Kernel/Thread.cpp or Kernel/Process.cpp

Some places the warning is suppressed, because we do not want a const
object do have non-const access to the returned sub-object.
This commit is contained in:
Andrew Kaster 2021-10-31 15:54:39 -06:00 committed by Andreas Kling
parent a92132e44a
commit 65edc62c02
Notes: sideshowbarker 2024-07-18 01:07:20 +09:00
11 changed files with 18 additions and 14 deletions

View File

@ -160,7 +160,7 @@ struct [[gnu::packed]] IDTEntry
{
}
FlatPtr off()
FlatPtr off() const
{
#if ARCH(I386)
return (u32)offset_2 << 16 & (u32)offset_1;
@ -168,7 +168,7 @@ struct [[gnu::packed]] IDTEntry
return (u64)offset_3 << 32 & (u64)offset_2 << 16 & (u64)offset_1;
#endif
}
IDTEntryType type()
IDTEntryType type() const
{
return IDTEntryType(type_attr.gate_type);
}

View File

@ -93,7 +93,7 @@ public:
}
template<typename T>
ALWAYS_INLINE void out(T value)
ALWAYS_INLINE void out(T value) const
{
static_assert(sizeof(T) <= 4);
if constexpr (sizeof(T) == 4) {
@ -111,7 +111,7 @@ public:
VERIFY_NOT_REACHED();
}
inline void out(u32 value, u8 bit_width)
inline void out(u32 value, u8 bit_width) const
{
if (bit_width == 32) {
IO::out32(get(), value);

View File

@ -77,7 +77,7 @@ private:
class PageTableEntry {
public:
PhysicalPtr physical_page_base() { return PhysicalAddress::physical_page_base(m_raw); }
PhysicalPtr physical_page_base() const { return PhysicalAddress::physical_page_base(m_raw); }
void set_physical_page_base(PhysicalPtr value)
{
m_raw &= 0x8000000000000fffULL;

View File

@ -120,12 +120,12 @@ public:
void detect_hypervisor();
void detect_hypervisor_hyperv(CPUID const& hypervisor_leaf_range);
void idle_begin()
void idle_begin() const
{
s_idle_cpu_mask.fetch_or(1u << m_cpu, AK::MemoryOrder::memory_order_relaxed);
}
void idle_end()
void idle_end() const
{
s_idle_cpu_mask.fetch_and(~(1u << m_cpu), AK::MemoryOrder::memory_order_relaxed);
}

View File

@ -78,7 +78,7 @@ private:
bool m_readonly { false };
};
inline FileSystem* InodeIdentifier::fs()
inline FileSystem* InodeIdentifier::fs() // NOLINT(readability-make-member-function-const) const InodeIdentifiers should not be able to modify the FileSystem
{
return FileSystem::from_fsid(m_fsid);
}

View File

@ -34,7 +34,7 @@ class SysFSDeviceComponent final
public:
static NonnullRefPtr<SysFSDeviceComponent> must_create(Device const&);
bool is_block_device() { return m_block_device; }
bool is_block_device() const { return m_block_device; }
private:
explicit SysFSDeviceComponent(Device const&);

View File

@ -38,8 +38,9 @@ public:
[[nodiscard]] bool is_null() const { return m_address == 0; }
// NOLINTNEXTLINE(readability-make-member-function-const) const PhysicalAddress shouldn't be allowed to modify the underlying memory
[[nodiscard]] u8* as_ptr() { return reinterpret_cast<u8*>(m_address); }
[[nodiscard]] const u8* as_ptr() const { return reinterpret_cast<const u8*>(m_address); }
[[nodiscard]] const u8* as_ptr() const { return reinterpret_cast<u8 const*>(m_address); }
[[nodiscard]] PhysicalAddress page_base() const { return PhysicalAddress(physical_page_base(m_address)); }
[[nodiscard]] PhysicalPtr offset_in_page() const { return PhysicalAddress(m_address & 0xfff).get(); }

View File

@ -502,7 +502,7 @@ Time kgettimeofday()
return TimeManagement::now();
}
siginfo_t Process::wait_info()
siginfo_t Process::wait_info() const
{
siginfo_t siginfo {};
siginfo.si_signo = SIGCHLD;
@ -889,7 +889,7 @@ static constexpr StringView to_string(Pledge promise)
VERIFY_NOT_REACHED();
}
void Process::require_no_promises()
void Process::require_no_promises() const
{
if (!has_promises())
return;

View File

@ -421,7 +421,7 @@ public:
static void initialize();
[[noreturn]] void crash(int signal, FlatPtr ip, bool out_of_memory = false);
[[nodiscard]] siginfo_t wait_info();
[[nodiscard]] siginfo_t wait_info() const;
const TTY* tty() const { return m_tty; }
void set_tty(TTY*);
@ -509,7 +509,7 @@ public:
VirtualAddress signal_trampoline() const { return m_protected_values.signal_trampoline; }
void require_promise(Pledge);
void require_no_promises();
void require_no_promises() const;
private:
friend class MemoryManager;

View File

@ -445,12 +445,14 @@ void Thread::relock_process(LockMode previous_locked, u32 lock_count_to_restore)
}
}
// NOLINTNEXTLINE(readability-make-member-function-const) False positive; We call block<SleepBlocker> which is not const
auto Thread::sleep(clockid_t clock_id, const Time& duration, Time* remaining_time) -> BlockResult
{
VERIFY(state() == Thread::Running);
return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(false, &duration, nullptr, clock_id), remaining_time);
}
// NOLINTNEXTLINE(readability-make-member-function-const) False positive; We call block<SleepBlocker> which is not const
auto Thread::sleep_until(clockid_t clock_id, const Time& deadline) -> BlockResult
{
VERIFY(state() == Thread::Running);

View File

@ -37,6 +37,7 @@ public:
bool operator==(const VirtualAddress& other) const { return m_address == other.m_address; }
bool operator!=(const VirtualAddress& other) const { return m_address != other.m_address; }
// NOLINTNEXTLINE(readability-make-member-function-const) const VirtualAddress shouldn't be allowed to modify the underlying memory
[[nodiscard]] u8* as_ptr() { return reinterpret_cast<u8*>(m_address); }
[[nodiscard]] const u8* as_ptr() const { return reinterpret_cast<const u8*>(m_address); }