Browse Source

UserspaceEmulator: Update memory protection of underlying pages

If a MmapRegion is file backed, we need to call mprotect on its
underlying pages.
Itamar 4 years ago
parent
commit
d2262b8f6d

+ 10 - 0
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();
     *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);
+    }
+}
+
 }
 }

+ 1 - 6
DevTools/UserspaceEmulator/MmapRegion.h

@@ -56,12 +56,7 @@ public:
     bool is_malloc_block() const { return m_malloc; }
     bool is_malloc_block() const { return m_malloc; }
     void set_malloc(bool b) { m_malloc = b; }
     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; }
     MallocRegionMetadata* malloc_metadata() { return m_malloc_metadata; }
     void set_malloc_metadata(Badge<MallocTracer>, NonnullOwnPtr<MallocRegionMetadata> metadata) { m_malloc_metadata = move(metadata); }
     void set_malloc_metadata(Badge<MallocTracer>, NonnullOwnPtr<MallocRegionMetadata> metadata) { m_malloc_metadata = move(metadata); }