diff options
author | Itamar <itamar8910@gmail.com> | 2020-11-23 22:38:29 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-14 23:05:53 +0100 |
commit | d2262b8f6d62cc6658574df9c12bdf99d9c8fc26 (patch) | |
tree | ae45c18fa99a517d08a0d8426f3ef4f8ab364248 /DevTools | |
parent | 93b68f5566c54699d4fcf0d982c879aeeb3eb8c1 (diff) | |
download | serenity-d2262b8f6d62cc6658574df9c12bdf99d9c8fc26.zip |
UserspaceEmulator: Update memory protection of underlying pages
If a MmapRegion is file backed, we need to call mprotect on its
underlying pages.
Diffstat (limited to 'DevTools')
-rw-r--r-- | DevTools/UserspaceEmulator/MmapRegion.cpp | 10 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/MmapRegion.h | 7 |
2 files changed, 11 insertions, 6 deletions
diff --git a/DevTools/UserspaceEmulator/MmapRegion.cpp b/DevTools/UserspaceEmulator/MmapRegion.cpp index 40efc0f9a2..61f6b06f18 100644 --- a/DevTools/UserspaceEmulator/MmapRegion.cpp +++ b/DevTools/UserspaceEmulator/MmapRegion.cpp @@ -207,4 +207,14 @@ void MmapRegion::write64(u32 offset, ValueWithShadow<u64> value) *reinterpret_cast<u64*>(m_shadow_data + offset) = value.shadow(); } +void MmapRegion::set_prot(int prot) +{ + set_readable(prot & PROT_READ); + set_writable(prot & PROT_WRITE); + set_executable(prot & PROT_EXEC); + if (m_file_backed) { + mprotect(m_data, size(), prot); + } +} + } diff --git a/DevTools/UserspaceEmulator/MmapRegion.h b/DevTools/UserspaceEmulator/MmapRegion.h index 1e91fcbaac..68c1eb864e 100644 --- a/DevTools/UserspaceEmulator/MmapRegion.h +++ b/DevTools/UserspaceEmulator/MmapRegion.h @@ -56,12 +56,7 @@ public: bool is_malloc_block() const { return m_malloc; } void set_malloc(bool b) { m_malloc = b; } - void set_prot(int prot) - { - set_readable(prot & PROT_READ); - set_writable(prot & PROT_WRITE); - set_executable(prot & PROT_EXEC); - } + void set_prot(int prot); MallocRegionMetadata* malloc_metadata() { return m_malloc_metadata; } void set_malloc_metadata(Badge<MallocTracer>, NonnullOwnPtr<MallocRegionMetadata> metadata) { m_malloc_metadata = move(metadata); } |