Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "../include/hax_host_mem.h"
#include "include/paging.h"

int chunk_alloc(uint64 base_uva, uint64 size, hax_chunk **chunk)
int chunk_alloc(uint64_t base_uva, uint64_t size, hax_chunk **chunk)
{
hax_chunk *chk;
int ret;
Expand Down
66 changes: 33 additions & 33 deletions core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ static void cpu_vmentry_failed(struct vcpu_t *vcpu, vmx_result_t result);
static int cpu_vmexit_handler(struct vcpu_t *vcpu, exit_reason_t exit_reason,
struct hax_tunnel *htun);

static int cpu_emt64_enable()
static int cpu_emt64_enable(void)
{
uint32 effer;
uint32_t efer;

effer = ia32_rdmsr(IA32_EFER);
return effer & 0x400;
efer = ia32_rdmsr(IA32_EFER);
return efer & 0x400;
}

static int cpu_nx_enable()
static int cpu_nx_enable(void)
{
uint32 effer;
uint32_t efer;

effer = ia32_rdmsr(IA32_EFER);
return effer & 0x800;
efer = ia32_rdmsr(IA32_EFER);
return efer & 0x800;
}

bool cpu_has_feature(uint32_t feature)
Expand All @@ -71,7 +71,7 @@ bool cpu_has_feature(uint32_t feature)
return cpuid_host_has_feature(&cache, feature);
}

void cpu_init_feature_cache()
void cpu_init_feature_cache(void)
{
cpuid_host_init(&cache);
}
Expand All @@ -80,7 +80,7 @@ void cpu_init_vmx(void *arg)
{
struct info_t vmx_info;
struct per_cpu_data *cpu_data;
uint32 fc_msr;
uint32_t fc_msr;
vmcs_t *vmxon;
int nx_enable = 0, vt_enable = 0;

Expand Down Expand Up @@ -159,10 +159,10 @@ void cpu_init_vmx(void *arg)
}
#endif

if (vmx_info._vmcs_region_length > PAGE_SIZE)
if (vmx_info._vmcs_region_length > HAX_PAGE_SIZE)
hax_log("HAX: VMCS of %d bytes not supported by this Hypervisor. "
"Max supported %u bytes\n",
vmx_info._vmcs_region_length, (uint32)PAGE_SIZE);
vmx_info._vmcs_region_length, (uint32_t)HAX_PAGE_SIZE);
vmxon = (vmcs_t *)hax_page_va(cpu_data->vmxon_page);
vmxon->_revision_id = vmx_info._vmcs_revision_id;

Expand Down Expand Up @@ -283,7 +283,7 @@ static int cpu_vmexit_handler(struct vcpu_t *vcpu, exit_reason_t exit_reason,
return ret;
}
/*Remove this function. It only for debug*/
/*void dump_cs_ds(uint16 cs, uint16 ds)
/*void dump_cs_ds(uint16_t cs, uint16_t ds)
{
struct system_desc_t desc;
struct seg_desc_t *seg_desc;
Expand Down Expand Up @@ -405,7 +405,7 @@ int cpu_vmx_execute(struct vcpu_t *vcpu, struct hax_tunnel *htun)
int ret;
preempt_flag flags;
struct vcpu_state_t *state = vcpu->state;
uint32 vmcs_err = 0;
uint32_t vmcs_err = 0;

while (1) {
exit_reason_t exit_reason;
Expand All @@ -431,7 +431,7 @@ int cpu_vmx_execute(struct vcpu_t *vcpu, struct hax_tunnel *htun)
* values by vmx hardware.
*/
{
uint32 temp= vmread(vcpu, GUEST_CS_AR);
uint32_t temp= vmread(vcpu, GUEST_CS_AR);

if( (temp & 0xf) == 0xa) {
temp = temp +1;
Expand All @@ -442,7 +442,7 @@ int cpu_vmx_execute(struct vcpu_t *vcpu, struct hax_tunnel *htun)
* let's hard-code it for now
*/
{
uint32 temp = vmread(vcpu, GUEST_TR_AR);
uint32_t temp = vmread(vcpu, GUEST_TR_AR);

temp = (temp & ~0xf) | 0xb;
vmwrite(vcpu, GUEST_TR_AR, temp);
Expand Down Expand Up @@ -508,7 +508,7 @@ int cpu_vmx_execute(struct vcpu_t *vcpu, struct hax_tunnel *htun)
}
}

uint8 is_vmcs_loaded(struct vcpu_t *vcpu)
uint8_t is_vmcs_loaded(struct vcpu_t *vcpu)
{
return (vcpu && vcpu->is_vmcs_loaded);
}
Expand All @@ -517,16 +517,16 @@ int debug_vmcs_count = 0;

void restore_host_cr4_vmxe(struct per_cpu_data *cpu_data);

uint32 log_host_cr4_vmxe = 0;
uint64 log_host_cr4 = 0;
uint32_t log_host_cr4_vmxe = 0;
uint64_t log_host_cr4 = 0;
vmx_result_t log_vmxon_res = 0;
uint64 log_vmxon_addr = 0;
uint32 log_vmxon_err_type1 = 0;
uint32 log_vmxon_err_type2 = 0;
uint32 log_vmxon_err_type3 = 0;
uint32 log_vmclear_err = 0;
uint32 log_vmptrld_err = 0;
uint32 log_vmxoff_no = 0;
uint64_t log_vmxon_addr = 0;
uint32_t log_vmxon_err_type1 = 0;
uint32_t log_vmxon_err_type2 = 0;
uint32_t log_vmxon_err_type3 = 0;
uint32_t log_vmclear_err = 0;
uint32_t log_vmptrld_err = 0;
uint32_t log_vmxoff_no = 0;
vmx_result_t log_vmxoff_res = 0;

void hax_clear_panic_log(struct vcpu_t *vcpu)
Expand Down Expand Up @@ -561,7 +561,7 @@ void hax_panic_log(struct vcpu_t *vcpu)
hax_error("log_vmxoff_res %x\n", log_vmxoff_res);
}

uint32 load_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
uint32_t load_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
{
struct per_cpu_data *cpu_data;
paddr_t vmcs_phy;
Expand Down Expand Up @@ -628,7 +628,7 @@ void restore_host_cr4_vmxe(struct per_cpu_data *cpu_data)
}
}

uint32 put_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
uint32_t put_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
{
struct per_cpu_data *cpu_data = current_cpu_data();
paddr_t vmcs_phy;
Expand Down Expand Up @@ -728,7 +728,7 @@ vmx_result_t cpu_vmxroot_leave(void)
}
} else {
log_vmxoff_no = 1;
#ifdef __MACH__
#ifdef HAX_PLATFORM_DARWIN
hax_debug("Skipping VMXOFF because another VMM (VirtualBox or macOS"
" Hypervisor Framework) is running\n");
#else
Expand All @@ -745,7 +745,7 @@ vmx_result_t cpu_vmxroot_leave(void)
vmx_result_t cpu_vmxroot_enter(void)
{
struct per_cpu_data *cpu_data = current_cpu_data();
uint64 fc_msr;
uint64_t fc_msr;
paddr_t vmxon_addr;
vmx_result_t result = VMX_SUCCEED;

Expand Down Expand Up @@ -791,7 +791,7 @@ vmx_result_t cpu_vmxroot_enter(void)
} else {
bool fatal = true;

#ifdef __MACH__
#ifdef HAX_PLATFORM_DARWIN
if ((result == VMX_FAIL_INVALID) && cpu_data->host_cr4_vmxe) {
// On macOS, if VMXON fails with VMX_FAIL_INVALID and host CR4.VMXE
// was already set, it is very likely that another VMM (VirtualBox
Expand All @@ -816,8 +816,8 @@ vmx_result_t cpu_vmxroot_enter(void)

if (fatal) {
hax_error("VMXON failed for region 0x%llx (result=0x%x, vmxe=%x)\n",
hax_page_pa(cpu_data->vmxon_page), (uint32)result,
(uint32)cpu_data->host_cr4_vmxe);
hax_page_pa(cpu_data->vmxon_page), (uint32_t)result,
(uint32_t)cpu_data->host_cr4_vmxe);
restore_host_cr4_vmxe(cpu_data);
if (result == VMX_FAIL_INVALID) {
log_vmxon_err_type1 = 1;
Expand Down
10 changes: 5 additions & 5 deletions core/dump_vmcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
#include "../include/hax.h"

extern unsigned char **vmcs_names;
extern uint32 vmcs_hash(uint32 enc);
extern uint32_t vmcs_hash(uint32_t enc);

static uint32 dump_vmcs_list[] = {
static uint32_t dump_vmcs_list[] = {
VMX_PIN_CONTROLS,
VMX_PRIMARY_PROCESSOR_CONTROLS,
VMX_SECONDARY_PROCESSOR_CONTROLS,
Expand Down Expand Up @@ -180,7 +180,7 @@ static uint32 dump_vmcs_list[] = {
GUEST_ACTIVITY_STATE,
};

static int encode_type(uint32 encode)
static int encode_type(uint32_t encode)
{
return (encode >> 13) & 0x3;
}
Expand All @@ -198,10 +198,10 @@ unsigned char *get_vmcsname_entry(int num)

void dump_vmcs(struct vcpu_t *vcpu)
{
uint32 i, enc, n;
uint32_t i, enc, n;
unsigned char *name;

uint32 *list = dump_vmcs_list;
uint32_t *list = dump_vmcs_list;
n = ARRAY_ELEMENTS(dump_vmcs_list);

for (i = 0; i < n; i++) {
Expand Down
20 changes: 10 additions & 10 deletions core/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static bool is_translation_required(struct em_context_t *ctxt)
static uint64_t get_canonical_address(struct em_context_t *ctxt,
uint64_t addr, uint vaddr_bits)
{
return ((int64)addr << (64 - vaddr_bits)) >> (64 - vaddr_bits);
return ((int64_t)addr << (64 - vaddr_bits)) >> (64 - vaddr_bits);
}

static em_status_t get_linear_address(struct em_context_t *ctxt,
Expand Down Expand Up @@ -475,24 +475,24 @@ static uint64_t insn_fetch_u64(struct em_context_t *ctxt)
return result;
}

static int8 insn_fetch_s8(struct em_context_t *ctxt)
static int8_t insn_fetch_s8(struct em_context_t *ctxt)
{
return (int8)insn_fetch_u8(ctxt);
return (int8_t)insn_fetch_u8(ctxt);
}

static int16 insn_fetch_s16(struct em_context_t *ctxt)
static int16_t insn_fetch_s16(struct em_context_t *ctxt)
{
return (int16)insn_fetch_u16(ctxt);
return (int16_t)insn_fetch_u16(ctxt);
}

static int32 insn_fetch_s32(struct em_context_t *ctxt)
static int32_t insn_fetch_s32(struct em_context_t *ctxt)
{
return (int32)insn_fetch_u32(ctxt);
return (int32_t)insn_fetch_u32(ctxt);
}

static int64 insn_fetch_s64(struct em_context_t *ctxt)
static int64_t insn_fetch_s64(struct em_context_t *ctxt)
{
return (int64)insn_fetch_u64(ctxt);
return (int64_t)insn_fetch_u64(ctxt);
}

static void decode_prefixes(struct em_context_t *ctxt)
Expand Down Expand Up @@ -774,7 +774,7 @@ static em_status_t decode_op_simm8(em_context_t *ctxt,
{
op->type = OP_IMM;
op->size = 1;
op->value = (int64)(insn_fetch_s8(ctxt));
op->value = (int64_t)(insn_fetch_s8(ctxt));
return EM_CONTINUE;
}

Expand Down
34 changes: 17 additions & 17 deletions core/ept.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
#include "include/paging.h"
#include "include/vtlb.h"

static uint64 ept_capabilities;
static uint64_t ept_capabilities;

#define EPT_BASIC_CAPS (ept_cap_WB | ept_cap_invept_ac)

bool ept_set_caps(uint64 caps)
bool ept_set_caps(uint64_t caps)
{
if ((caps & EPT_BASIC_CAPS) != EPT_BASIC_CAPS) {
hax_warning("Broken host EPT support detected (caps=0x%llx)\n", caps);
Expand All @@ -62,17 +62,17 @@ bool ept_set_caps(uint64 caps)
}

caps &= ~EPT_UNSUPPORTED_FEATURES;
ASSERT(!ept_capabilities || caps == ept_capabilities);
assert(!ept_capabilities || caps == ept_capabilities);
// FIXME: This assignment is done by all logical processors simultaneously
ept_capabilities = caps;
return 1;
}

static bool ept_has_cap(uint64 cap)
static bool ept_has_cap(uint64_t cap)
{
ASSERT(ept_capabilities != 0);
// Avoid implicit conversion from uint64 to bool, because the latter may be
// typedef'ed as uint8 (see hax_types_windows.h)
assert(ept_capabilities != 0);
// Avoid implicit conversion from uint64_t to bool, because the latter may be
// typedef'ed as uint8_t (see hax_types_windows.h)
return (ept_capabilities & cap) != 0;
}

Expand All @@ -82,7 +82,7 @@ static epte_t * ept_get_pde(struct hax_ept *ept, paddr_t gpa)
epte_t *e;
uint which_g = gpa >> 30;
// PML4 and PDPTE level needs 2 pages
uint64 offset = (2 + which_g) * PAGE_SIZE_4K;
uint64_t offset = (2 + which_g) * PAGE_SIZE_4K;
// Need Xiantao's check
unsigned char *ept_addr = hax_page_va(ept->ept_root_page);

Expand Down Expand Up @@ -185,7 +185,7 @@ static bool ept_lookup(struct vcpu_t *vcpu, paddr_t gpa, paddr_t *hpa)
struct hax_ept *ept = vcpu->vm->ept;
uint which_g = gpa >> 30;

ASSERT(ept->ept_root_page);
assert(ept->ept_root_page);
if (which_g >= EPT_MAX_MEM_G) {
hax_debug("ept_lookup error!\n");
return 0;
Expand Down Expand Up @@ -224,7 +224,7 @@ static bool ept_lookup(struct vcpu_t *vcpu, paddr_t gpa, paddr_t *hpa)
// TODO: Do we need to consider cross-page case ??
bool ept_translate(struct vcpu_t *vcpu, paddr_t gpa, uint order, paddr_t *hpa)
{
ASSERT(order == PG_ORDER_4K);
assert(order == PG_ORDER_4K);
return ept_lookup(vcpu, gpa, hpa);
}

Expand Down Expand Up @@ -301,7 +301,7 @@ void ept_free (hax_vm_t *hax_vm)
struct hax_page *page, *n;
struct hax_ept *ept = hax_vm->ept;

ASSERT(ept);
assert(ept);

if (!ept->ept_root_page)
return;
Expand Down Expand Up @@ -342,11 +342,11 @@ static void invept_smpfunc(struct invept_bundle *bundle)

void invept(hax_vm_t *hax_vm, uint type)
{
uint64 eptp_value = vm_get_eptp(hax_vm);
uint64_t eptp_value = vm_get_eptp(hax_vm);
struct invept_desc desc = { eptp_value, 0 };
struct invept_bundle bundle;
int cpu_id;
uint32 res;
uint32_t res;

if (!ept_has_cap(ept_cap_invept)) {
hax_warning("INVEPT was not called due to missing host support"
Expand Down Expand Up @@ -394,17 +394,17 @@ void invept(hax_vm_t *hax_vm, uint type)
continue;
}

res = (uint32)cpu_data->vmxon_res;
res = (uint32_t)cpu_data->vmxon_res;
if (res != VMX_SUCCEED) {
hax_error("[Processor #%d] INVEPT was not called, because VMXON"
" failed (err=0x%x)\n", cpu_id, res);
} else {
res = (uint32)cpu_data->invept_res;
res = (uint32_t)cpu_data->invept_res;
if (res != VMX_SUCCEED) {
hax_error("[Processor #%d] INVEPT failed (err=0x%x)\n", cpu_id,
res);
}
res = (uint32)cpu_data->vmxoff_res;
res = (uint32_t)cpu_data->vmxoff_res;
if (res != VMX_SUCCEED) {
hax_error("[Processor #%d] INVEPT was called, but VMXOFF failed"
" (err=0x%x)\n", cpu_id, res);
Expand All @@ -413,7 +413,7 @@ void invept(hax_vm_t *hax_vm, uint type)
}
}

uint64 vcpu_get_eptp(struct vcpu_t *vcpu)
uint64_t vcpu_get_eptp(struct vcpu_t *vcpu)
{
struct hax_ept *ept = vcpu->vm->ept;

Expand Down
Loading