memory::QueryProtect
This commit is contained in:
parent
64b8dcfd99
commit
88be0a362c
|
@ -63,6 +63,12 @@ bool DeallocFixed(void* base_address, size_t length,
|
||||||
bool Protect(void* base_address, size_t length, PageAccess access,
|
bool Protect(void* base_address, size_t length, PageAccess access,
|
||||||
PageAccess* out_old_access);
|
PageAccess* out_old_access);
|
||||||
|
|
||||||
|
// Queries a region of pages to get the access rights. This will modify the
|
||||||
|
// length parameter to the length of pages with the same consecutive access
|
||||||
|
// rights. The length will start from the first byte of the first page of
|
||||||
|
// the region.
|
||||||
|
bool QueryProtect(void* base_address, size_t& length, PageAccess& access_out);
|
||||||
|
|
||||||
// Allocates a block of memory for a type with the given alignment.
|
// Allocates a block of memory for a type with the given alignment.
|
||||||
// The memory must be freed with AlignedFree.
|
// The memory must be freed with AlignedFree.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -50,6 +50,27 @@ DWORD ToWin32ProtectFlags(PageAccess access) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PageAccess ToXeniaProtectFlags(DWORD access) {
|
||||||
|
if (access & PAGE_GUARD) {
|
||||||
|
// Strip the page guard flag for now...
|
||||||
|
access &= ~PAGE_GUARD;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (access) {
|
||||||
|
case PAGE_NOACCESS:
|
||||||
|
return PageAccess::kNoAccess;
|
||||||
|
case PAGE_READONLY:
|
||||||
|
return PageAccess::kReadOnly;
|
||||||
|
case PAGE_READWRITE:
|
||||||
|
return PageAccess::kReadWrite;
|
||||||
|
case PAGE_EXECUTE_READWRITE:
|
||||||
|
return PageAccess::kExecuteReadWrite;
|
||||||
|
default:
|
||||||
|
assert_unhandled_case(access);
|
||||||
|
return PageAccess::kNoAccess;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void* AllocFixed(void* base_address, size_t length,
|
void* AllocFixed(void* base_address, size_t length,
|
||||||
AllocationType allocation_type, PageAccess access) {
|
AllocationType allocation_type, PageAccess access) {
|
||||||
DWORD alloc_type = 0;
|
DWORD alloc_type = 0;
|
||||||
|
@ -103,23 +124,24 @@ bool Protect(void* base_address, size_t length, PageAccess access,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (out_old_access) {
|
if (out_old_access) {
|
||||||
switch (old_protect) {
|
*out_old_access = ToXeniaProtectFlags(old_protect);
|
||||||
case PAGE_NOACCESS:
|
|
||||||
*out_old_access = PageAccess::kNoAccess;
|
|
||||||
break;
|
|
||||||
case PAGE_READONLY:
|
|
||||||
*out_old_access = PageAccess::kReadOnly;
|
|
||||||
break;
|
|
||||||
case PAGE_READWRITE:
|
|
||||||
*out_old_access = PageAccess::kReadWrite;
|
|
||||||
break;
|
|
||||||
case PAGE_EXECUTE_READWRITE:
|
|
||||||
*out_old_access = PageAccess::kExecuteReadWrite;
|
|
||||||
default:
|
|
||||||
assert_unhandled_case(access);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QueryProtect(void* base_address, size_t& length, PageAccess& access_out) {
|
||||||
|
access_out = PageAccess::kNoAccess;
|
||||||
|
|
||||||
|
MEMORY_BASIC_INFORMATION info;
|
||||||
|
ZeroMemory(&info, sizeof(info));
|
||||||
|
|
||||||
|
SIZE_T result = VirtualQuery(base_address, &info, length);
|
||||||
|
if (!result) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
length = info.RegionSize;
|
||||||
|
access_out = ToXeniaProtectFlags(info.Protect);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue