This commit is contained in:
parent
61c4096ae1
commit
e1e8927823
|
@ -217,32 +217,32 @@ struct AddressSpace::Impl {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Protect(VAddr virtual_addr, size_t size, bool read, bool write, bool execute) {
|
void Protect(VAddr virtual_addr, size_t size, bool read, bool write, bool execute) {
|
||||||
DWORD new_flags{};
|
DWORD new_flags{};
|
||||||
if (read && write && execute) {
|
if (read && write && execute) {
|
||||||
new_flags = PAGE_EXECUTE_READWRITE;
|
new_flags = PAGE_EXECUTE_READWRITE;
|
||||||
} else if (read && write) {
|
} else if (read && write) {
|
||||||
new_flags = PAGE_READWRITE;
|
new_flags = PAGE_READWRITE;
|
||||||
} else if (read && !write) {
|
} else if (read && !write) {
|
||||||
new_flags = PAGE_READONLY;
|
new_flags = PAGE_READONLY;
|
||||||
} else if (execute && !read && !write) {
|
} else if (execute && !read && !write) {
|
||||||
new_flags = PAGE_EXECUTE;
|
new_flags = PAGE_EXECUTE;
|
||||||
} else if (!read && !write && !execute) {
|
} else if (!read && !write && !execute) {
|
||||||
new_flags = PAGE_NOACCESS;
|
new_flags = PAGE_NOACCESS;
|
||||||
} else {
|
} else {
|
||||||
LOG_CRITICAL(Common_Memory, "Unsupported protection flag combination");
|
LOG_CRITICAL(Common_Memory, "Unsupported protection flag combination");
|
||||||
}
|
}
|
||||||
|
|
||||||
const VAddr virtual_end = virtual_addr + size;
|
const VAddr virtual_end = virtual_addr + size;
|
||||||
auto [it, end] = placeholders.equal_range({virtual_addr, virtual_end});
|
auto [it, end] = placeholders.equal_range({virtual_addr, virtual_end});
|
||||||
while (it != end) {
|
while (it != end) {
|
||||||
const size_t offset = std::max(it->lower(), virtual_addr);
|
const size_t offset = std::max(it->lower(), virtual_addr);
|
||||||
const size_t protect_length = std::min(it->upper(), virtual_end) - offset;
|
const size_t protect_length = std::min(it->upper(), virtual_end) - offset;
|
||||||
DWORD old_flags{};
|
DWORD old_flags{};
|
||||||
if (!VirtualProtect(virtual_base + offset, protect_length, new_flags, &old_flags)) {
|
if (!VirtualProtect(virtual_base + offset, protect_length, new_flags, &old_flags)) {
|
||||||
LOG_CRITICAL(Common_Memory, "Failed to change virtual memory protect rules");
|
LOG_CRITICAL(Common_Memory, "Failed to change virtual memory protect rules");
|
||||||
|
}
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue