mirror of
https://github.com/momo5502/hypervisor.git
synced 2025-04-19 05:32:55 +00:00
Add write probing
This commit is contained in:
parent
db4e69f5be
commit
aa6da95b8a
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user