Kernel/Memory: Make has_been_{r,w,x} flags clearly being set

Before of this change, actually setting the m_access to contain the
HasBeen{Readeable,Writable,Executable} bits was done by the method of
Region set_access_bit which added ORing with (access << 4) when enabling
a certain access bit to achieve this.

Now this is changed and when calling set_{readeable,writable,executable}
methods, they will set an appropriate SetOnce flag that could be checked
later.
This commit is contained in:
Liav A. 2024-05-03 14:11:27 +03:00 committed by Andrew Kaster
parent 15ddc1f17a
commit 5194ab59b5

View file

@ -43,9 +43,6 @@ public:
Read = 1,
Write = 2,
Execute = 4,
HasBeenReadable = 16,
HasBeenWritable = 32,
HasBeenExecutable = 64,
ReadOnly = Read,
ReadWrite = Read | Write,
ReadWriteExecute = Read | Write | Execute,
@ -69,9 +66,9 @@ public:
[[nodiscard]] bool is_writable() const { return (m_access & Access::Write) == Access::Write; }
[[nodiscard]] bool is_executable() const { return (m_access & Access::Execute) == Access::Execute; }
[[nodiscard]] bool has_been_readable() const { return (m_access & Access::HasBeenReadable) == Access::HasBeenReadable; }
[[nodiscard]] bool has_been_writable() const { return (m_access & Access::HasBeenWritable) == Access::HasBeenWritable; }
[[nodiscard]] bool has_been_executable() const { return (m_access & Access::HasBeenExecutable) == Access::HasBeenExecutable; }
[[nodiscard]] bool has_been_readable() const { return m_has_been_readable.was_set(); }
[[nodiscard]] bool has_been_writable() const { return m_has_been_writable.was_set(); }
[[nodiscard]] bool has_been_executable() const { return m_has_been_executable.was_set(); }
[[nodiscard]] bool is_cacheable() const { return m_cacheable; }
[[nodiscard]] StringView name() const { return m_name ? m_name->view() : StringView {}; }
@ -188,9 +185,24 @@ public:
[[nodiscard]] size_t cow_pages() const;
void set_readable(bool b) { set_access_bit(Access::Read, b); }
void set_writable(bool b) { set_access_bit(Access::Write, b); }
void set_executable(bool b) { set_access_bit(Access::Execute, b); }
void set_readable(bool b)
{
set_access_bit(Access::Read, b);
if (b)
m_has_been_readable.set();
}
void set_writable(bool b)
{
set_access_bit(Access::Write, b);
if (b)
m_has_been_writable.set();
}
void set_executable(bool b)
{
set_access_bit(Access::Execute, b);
if (b)
m_has_been_executable.set();
}
void unsafe_clear_access() { m_access = Region::None; }
@ -224,7 +236,7 @@ private:
void set_access_bit(Access access, bool b)
{
if (b)
m_access |= access | (access << 4);
m_access |= access;
else
m_access &= ~access;
}
@ -254,6 +266,9 @@ private:
SetOnce m_immutable;
SetOnce m_initially_loaded_executable_segment;
SetOnce m_has_been_readable;
SetOnce m_has_been_writable;
SetOnce m_has_been_executable;
IntrusiveRedBlackTreeNode<FlatPtr, Region, RawPtr<Region>> m_tree_node;
IntrusiveListNode<Region> m_vmobject_list_node;