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

Kernel: Mark PhysicalAddress/VirtualAddress getters as [[nodiscard]]

There is no reason to call a getter without observing the result, doing
so indicates an error in the code. Mark these methods as [[nodiscard]]
to find these cases.
This commit is contained in:
Brian Gianforcaro 2021-02-14 15:18:35 -08:00 committed by Andreas Kling
parent d71e235894
commit 8752a27519
2 changed files with 14 additions and 14 deletions

View file

@ -37,18 +37,18 @@ public:
{ {
} }
PhysicalAddress offset(FlatPtr o) const { return PhysicalAddress(m_address + o); } [[nodiscard]] PhysicalAddress offset(FlatPtr o) const { return PhysicalAddress(m_address + o); }
FlatPtr get() const { return m_address; } [[nodiscard]] FlatPtr get() const { return m_address; }
void set(FlatPtr address) { m_address = address; } void set(FlatPtr address) { m_address = address; }
void mask(FlatPtr m) { m_address &= m; } void mask(FlatPtr m) { m_address &= m; }
bool is_null() const { return m_address == 0; } [[nodiscard]] bool is_null() const { return m_address == 0; }
u8* as_ptr() { return reinterpret_cast<u8*>(m_address); } [[nodiscard]] u8* as_ptr() { return reinterpret_cast<u8*>(m_address); }
const u8* as_ptr() const { return reinterpret_cast<const u8*>(m_address); } [[nodiscard]] const u8* as_ptr() const { return reinterpret_cast<const u8*>(m_address); }
PhysicalAddress page_base() const { return PhysicalAddress(m_address & 0xfffff000); } [[nodiscard]] PhysicalAddress page_base() const { return PhysicalAddress(m_address & 0xfffff000); }
FlatPtr offset_in_page() const { return PhysicalAddress(m_address & 0xfff).get(); } [[nodiscard]] FlatPtr offset_in_page() const { return PhysicalAddress(m_address & 0xfff).get(); }
bool operator==(const PhysicalAddress& other) const { return m_address == other.m_address; } bool operator==(const PhysicalAddress& other) const { return m_address == other.m_address; }
bool operator!=(const PhysicalAddress& other) const { return m_address != other.m_address; } bool operator!=(const PhysicalAddress& other) const { return m_address != other.m_address; }

View file

@ -42,11 +42,11 @@ public:
{ {
} }
bool is_null() const { return m_address == 0; } [[nodiscard]] bool is_null() const { return m_address == 0; }
bool is_page_aligned() const { return (m_address & 0xfff) == 0; } [[nodiscard]] bool is_page_aligned() const { return (m_address & 0xfff) == 0; }
VirtualAddress offset(FlatPtr o) const { return VirtualAddress(m_address + o); } [[nodiscard]] VirtualAddress offset(FlatPtr o) const { return VirtualAddress(m_address + o); }
FlatPtr get() const { return m_address; } [[nodiscard]] FlatPtr get() const { return m_address; }
void set(FlatPtr address) { m_address = address; } void set(FlatPtr address) { m_address = address; }
void mask(FlatPtr m) { m_address &= m; } void mask(FlatPtr m) { m_address &= m; }
@ -57,10 +57,10 @@ 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; }
bool operator!=(const VirtualAddress& other) const { return m_address != other.m_address; } bool operator!=(const VirtualAddress& other) const { return m_address != other.m_address; }
u8* as_ptr() { return reinterpret_cast<u8*>(m_address); } [[nodiscard]] u8* as_ptr() { return reinterpret_cast<u8*>(m_address); }
const u8* as_ptr() const { return reinterpret_cast<const u8*>(m_address); } [[nodiscard]] const u8* as_ptr() const { return reinterpret_cast<const u8*>(m_address); }
VirtualAddress page_base() const { return VirtualAddress(m_address & 0xfffff000); } [[nodiscard]] VirtualAddress page_base() const { return VirtualAddress(m_address & 0xfffff000); }
private: private:
FlatPtr m_address { 0 }; FlatPtr m_address { 0 };