Skip to content

Commit

Permalink
Kernel/Memory: Make has_been_{r,w,x} flags clearly being set
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
supercomputer7 committed May 3, 2024
1 parent 6b0193a commit 96a2f9c
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions Kernel/Memory/Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class Region final
Read = 1,
Write = 2,
Execute = 4,
HasBeenReadable = 16,
HasBeenWritable = 32,
HasBeenExecutable = 64,
ReadOnly = Read,
ReadWrite = Read | Write,
ReadWriteExecute = Read | Write | Execute,
Expand All @@ -69,9 +66,9 @@ class Region final
[[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 {}; }
Expand Down Expand Up @@ -185,9 +182,24 @@ class Region final

[[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; }

Expand Down Expand Up @@ -221,7 +233,7 @@ class Region final
void set_access_bit(Access access, bool b)
{
if (b)
m_access |= access | (access << 4);
m_access |= access;
else
m_access &= ~access;
}
Expand Down Expand Up @@ -250,6 +262,9 @@ class Region final
bool m_mmapped_from_writable : 1 { false };

SetOnce m_immutable;
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;
Expand Down

0 comments on commit 96a2f9c

Please sign in to comment.