[NFC] Add MprotectReadWrite
authorVitaly Buka <vitalybuka@google.com>
Mon, 24 Jul 2023 22:52:16 +0000 (15:52 -0700)
committerVitaly Buka <vitalybuka@google.com>
Mon, 24 Jul 2023 23:12:20 +0000 (16:12 -0700)
It's unused, but I need it for debuging.
Seems usefull for completeness.

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D156180

compiler-rt/lib/sanitizer_common/sanitizer_common.h
compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
compiler-rt/lib/sanitizer_common/sanitizer_win.cpp

index 7c25644..e7e4b8c 100644 (file)
@@ -117,6 +117,7 @@ void *MmapAlignedOrDieOnFatalError(uptr size, uptr alignment,
 // unaccessible memory.
 bool MprotectNoAccess(uptr addr, uptr size);
 bool MprotectReadOnly(uptr addr, uptr size);
+bool MprotectReadWrite(uptr addr, uptr size);
 
 void MprotectMallocZones(void *addr, int prot);
 
index a92e84c..1e25265 100644 (file)
@@ -285,6 +285,12 @@ bool MprotectReadOnly(uptr addr, uptr size) {
          ZX_OK;
 }
 
+bool MprotectReadWrite(uptr addr, uptr size) {
+  return _zx_vmar_protect(_zx_vmar_root_self(),
+                          ZX_VM_PERM_READ | ZX_VM_PERM_WRITE, addr,
+                          size) == ZX_OK;
+}
+
 void *MmapAlignedOrDieOnFatalError(uptr size, uptr alignment,
                                    const char *mem_type) {
   CHECK_GE(size, GetPageSize());
index f6b0bbd..8d2c5b2 100644 (file)
@@ -154,6 +154,10 @@ bool MprotectReadOnly(uptr addr, uptr size) {
   return 0 == internal_mprotect((void *)addr, size, PROT_READ);
 }
 
+bool MprotectReadWrite(uptr addr, uptr size) {
+  return 0 == internal_mprotect((void *)addr, size, PROT_READ | PROT_WRITE);
+}
+
 #if !SANITIZER_APPLE
 void MprotectMallocZones(void *addr, int prot) {}
 #endif
index 1c9b2dd..06e4965 100644 (file)
@@ -362,6 +362,11 @@ bool MprotectReadOnly(uptr addr, uptr size) {
   return VirtualProtect((LPVOID)addr, size, PAGE_READONLY, &old_protection);
 }
 
+bool MprotectReadWrite(uptr addr, uptr size) {
+  DWORD old_protection;
+  return VirtualProtect((LPVOID)addr, size, PAGE_READWRITE, &old_protection);
+}
+
 void ReleaseMemoryPagesToOS(uptr beg, uptr end) {
   uptr beg_aligned = RoundDownTo(beg, GetPageSizeCached()),
        end_aligned = RoundDownTo(end, GetPageSizeCached());