mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:57:44 +00:00
Kernel/Memory: Add option to annotate region mapping as immutable
We add this basic functionality to the Kernel so Userspace can request a particular virtual memory mapping to be immutable. This will be useful later on in the DynamicLoader code. The annotation of a particular Kernel Region as immutable implies that the following restrictions apply, so these features are prohibited: - Changing the region's protection bits - Unmapping the region - Annotating the region with other virtual memory flags - Applying further memory advises on the region - Changing the region name - Re-mapping the region
This commit is contained in:
parent
6c0486277e
commit
8585b2dc23
4 changed files with 35 additions and 4 deletions
|
@ -59,6 +59,8 @@ ErrorOr<void> AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
|
|||
if (auto* whole_region = find_region_from_range(range_to_unmap)) {
|
||||
if (!whole_region->is_mmap())
|
||||
return EPERM;
|
||||
if (whole_region->is_immutable())
|
||||
return EPERM;
|
||||
|
||||
PerformanceManager::add_unmap_perf_event(Process::current(), whole_region->range());
|
||||
|
||||
|
@ -69,6 +71,8 @@ ErrorOr<void> AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
|
|||
if (auto* old_region = find_region_containing(range_to_unmap)) {
|
||||
if (!old_region->is_mmap())
|
||||
return EPERM;
|
||||
if (old_region->is_immutable())
|
||||
return EPERM;
|
||||
|
||||
// Remove the old region from our regions tree, since were going to add another region
|
||||
// with the exact same start address.
|
||||
|
@ -99,6 +103,8 @@ ErrorOr<void> AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
|
|||
for (auto* region : regions) {
|
||||
if (!region->is_mmap())
|
||||
return EPERM;
|
||||
if (region->is_immutable())
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
Vector<Region*, 2> new_regions;
|
||||
|
|
|
@ -88,6 +88,9 @@ public:
|
|||
[[nodiscard]] bool is_stack() const { return m_stack; }
|
||||
void set_stack(bool stack) { m_stack = stack; }
|
||||
|
||||
[[nodiscard]] bool is_immutable() const { return m_immutable; }
|
||||
void set_immutable() { m_immutable = true; }
|
||||
|
||||
[[nodiscard]] bool is_mmap() const { return m_mmap; }
|
||||
|
||||
void set_mmap(bool mmap, bool description_was_readable, bool description_was_writable)
|
||||
|
@ -235,6 +238,7 @@ private:
|
|||
bool m_cacheable : 1 { false };
|
||||
bool m_stack : 1 { false };
|
||||
bool m_mmap : 1 { false };
|
||||
bool m_immutable : 1 { false };
|
||||
bool m_syscall_region : 1 { false };
|
||||
bool m_write_combine : 1 { false };
|
||||
bool m_mmapped_from_readable : 1 { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue