Add write probing

This commit is contained in:
momo5502 2022-04-23 21:43:59 +02:00
parent db4e69f5be
commit aa6da95b8a
2 changed files with 23 additions and 0 deletions

View File

@ -124,4 +124,24 @@ namespace memory
throw std::runtime_error("Access violation");
}
}
bool prope_for_write(const void* address, const size_t length, const uint64_t alignment)
{
__try
{
ProbeForWrite(const_cast<volatile void*>(address), length, static_cast<ULONG>(alignment));
return true;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return false;
}
}
void assert_writability(const void* address, const size_t length, const uint64_t alignment)
{
if (!prope_for_write(address, length, alignment)) {
throw std::runtime_error("Access violation");
}
}
}

View File

@ -26,6 +26,9 @@ namespace memory
bool prope_for_read(const void* address, size_t length, uint64_t alignment = 1);
void assert_readability(const void* address, size_t length, uint64_t alignment = 1);
bool prope_for_write(const void* address, size_t length, uint64_t alignment = 1);
void assert_writability(const void* address, size_t length, uint64_t alignment = 1);
template <typename T, typename... Args>
T* allocate_non_paged_object(Args ... args)
{