Skip to content

Instantly share code, notes, and snippets.

View drew-gpf's full-sized avatar

drew drew-gpf

View GitHub Profile
//this requires being able to run at kernel mode and assumes you're using MSVC
//this also uses an unnamed structure for cr0_t, which is a nonstandard extension of the C language
//data structure for cr0
typedef union _cr0_t
{
struct
{
uint64_t protection_enable : 1;
/*
purpose: update the control register value and read shadow based off of the host mask, and determine if an invalid bit was set
new_value: the new value of the control register that the guest wants to set
host_mask_must_be_set: host bits which the guest should not change
host_mask_dont_care: host bits which can be any value, but only change for the read shadow (generally should be set to the bits required by the cpu)
host_mask_trap: host bits which are updated in the actual control register and are trapped on
read_shadow_encoding: VMCS field for the read shadow
control_register_encoding: VMCS field for the control register
different_bits_buffer (optional): pointer to variable which will be filled out with all the bits which were changed