Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.

Commit 245bdd6

Browse files
authored
Merge pull request #110 from kryptoslogic/refactor
Codebase cleanup and portability refactoring
2 parents a12f704 + 4cef403 commit 245bdd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1619
-1617
lines changed

core/chunk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "../include/hax_host_mem.h"
3434
#include "include/paging.h"
3535

36-
int chunk_alloc(uint64 base_uva, uint64 size, hax_chunk **chunk)
36+
int chunk_alloc(uint64_t base_uva, uint64_t size, hax_chunk **chunk)
3737
{
3838
hax_chunk *chk;
3939
int ret;

core/cpu.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ static void cpu_vmentry_failed(struct vcpu_t *vcpu, vmx_result_t result);
4747
static int cpu_vmexit_handler(struct vcpu_t *vcpu, exit_reason_t exit_reason,
4848
struct hax_tunnel *htun);
4949

50-
static int cpu_emt64_enable()
50+
static int cpu_emt64_enable(void)
5151
{
52-
uint32 effer;
52+
uint32_t efer;
5353

54-
effer = ia32_rdmsr(IA32_EFER);
55-
return effer & 0x400;
54+
efer = ia32_rdmsr(IA32_EFER);
55+
return efer & 0x400;
5656
}
5757

58-
static int cpu_nx_enable()
58+
static int cpu_nx_enable(void)
5959
{
60-
uint32 effer;
60+
uint32_t efer;
6161

62-
effer = ia32_rdmsr(IA32_EFER);
63-
return effer & 0x800;
62+
efer = ia32_rdmsr(IA32_EFER);
63+
return efer & 0x800;
6464
}
6565

6666
bool cpu_has_feature(uint32_t feature)
@@ -71,7 +71,7 @@ bool cpu_has_feature(uint32_t feature)
7171
return cpuid_host_has_feature(&cache, feature);
7272
}
7373

74-
void cpu_init_feature_cache()
74+
void cpu_init_feature_cache(void)
7575
{
7676
cpuid_host_init(&cache);
7777
}
@@ -80,7 +80,7 @@ void cpu_init_vmx(void *arg)
8080
{
8181
struct info_t vmx_info;
8282
struct per_cpu_data *cpu_data;
83-
uint32 fc_msr;
83+
uint32_t fc_msr;
8484
vmcs_t *vmxon;
8585
int nx_enable = 0, vt_enable = 0;
8686

@@ -159,10 +159,10 @@ void cpu_init_vmx(void *arg)
159159
}
160160
#endif
161161

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

@@ -283,7 +283,7 @@ static int cpu_vmexit_handler(struct vcpu_t *vcpu, exit_reason_t exit_reason,
283283
return ret;
284284
}
285285
/*Remove this function. It only for debug*/
286-
/*void dump_cs_ds(uint16 cs, uint16 ds)
286+
/*void dump_cs_ds(uint16_t cs, uint16_t ds)
287287
{
288288
struct system_desc_t desc;
289289
struct seg_desc_t *seg_desc;
@@ -405,7 +405,7 @@ int cpu_vmx_execute(struct vcpu_t *vcpu, struct hax_tunnel *htun)
405405
int ret;
406406
preempt_flag flags;
407407
struct vcpu_state_t *state = vcpu->state;
408-
uint32 vmcs_err = 0;
408+
uint32_t vmcs_err = 0;
409409

410410
while (1) {
411411
exit_reason_t exit_reason;
@@ -431,7 +431,7 @@ int cpu_vmx_execute(struct vcpu_t *vcpu, struct hax_tunnel *htun)
431431
* values by vmx hardware.
432432
*/
433433
{
434-
uint32 temp= vmread(vcpu, GUEST_CS_AR);
434+
uint32_t temp= vmread(vcpu, GUEST_CS_AR);
435435

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

447447
temp = (temp & ~0xf) | 0xb;
448448
vmwrite(vcpu, GUEST_TR_AR, temp);
@@ -508,7 +508,7 @@ int cpu_vmx_execute(struct vcpu_t *vcpu, struct hax_tunnel *htun)
508508
}
509509
}
510510

511-
uint8 is_vmcs_loaded(struct vcpu_t *vcpu)
511+
uint8_t is_vmcs_loaded(struct vcpu_t *vcpu)
512512
{
513513
return (vcpu && vcpu->is_vmcs_loaded);
514514
}
@@ -517,16 +517,16 @@ int debug_vmcs_count = 0;
517517

518518
void restore_host_cr4_vmxe(struct per_cpu_data *cpu_data);
519519

520-
uint32 log_host_cr4_vmxe = 0;
521-
uint64 log_host_cr4 = 0;
520+
uint32_t log_host_cr4_vmxe = 0;
521+
uint64_t log_host_cr4 = 0;
522522
vmx_result_t log_vmxon_res = 0;
523-
uint64 log_vmxon_addr = 0;
524-
uint32 log_vmxon_err_type1 = 0;
525-
uint32 log_vmxon_err_type2 = 0;
526-
uint32 log_vmxon_err_type3 = 0;
527-
uint32 log_vmclear_err = 0;
528-
uint32 log_vmptrld_err = 0;
529-
uint32 log_vmxoff_no = 0;
523+
uint64_t log_vmxon_addr = 0;
524+
uint32_t log_vmxon_err_type1 = 0;
525+
uint32_t log_vmxon_err_type2 = 0;
526+
uint32_t log_vmxon_err_type3 = 0;
527+
uint32_t log_vmclear_err = 0;
528+
uint32_t log_vmptrld_err = 0;
529+
uint32_t log_vmxoff_no = 0;
530530
vmx_result_t log_vmxoff_res = 0;
531531

532532
void hax_clear_panic_log(struct vcpu_t *vcpu)
@@ -561,7 +561,7 @@ void hax_panic_log(struct vcpu_t *vcpu)
561561
hax_error("log_vmxoff_res %x\n", log_vmxoff_res);
562562
}
563563

564-
uint32 load_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
564+
uint32_t load_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
565565
{
566566
struct per_cpu_data *cpu_data;
567567
paddr_t vmcs_phy;
@@ -628,7 +628,7 @@ void restore_host_cr4_vmxe(struct per_cpu_data *cpu_data)
628628
}
629629
}
630630

631-
uint32 put_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
631+
uint32_t put_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
632632
{
633633
struct per_cpu_data *cpu_data = current_cpu_data();
634634
paddr_t vmcs_phy;
@@ -728,7 +728,7 @@ vmx_result_t cpu_vmxroot_leave(void)
728728
}
729729
} else {
730730
log_vmxoff_no = 1;
731-
#ifdef __MACH__
731+
#ifdef HAX_PLATFORM_DARWIN
732732
hax_debug("Skipping VMXOFF because another VMM (VirtualBox or macOS"
733733
" Hypervisor Framework) is running\n");
734734
#else
@@ -745,7 +745,7 @@ vmx_result_t cpu_vmxroot_leave(void)
745745
vmx_result_t cpu_vmxroot_enter(void)
746746
{
747747
struct per_cpu_data *cpu_data = current_cpu_data();
748-
uint64 fc_msr;
748+
uint64_t fc_msr;
749749
paddr_t vmxon_addr;
750750
vmx_result_t result = VMX_SUCCEED;
751751

@@ -791,7 +791,7 @@ vmx_result_t cpu_vmxroot_enter(void)
791791
} else {
792792
bool fatal = true;
793793

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

817817
if (fatal) {
818818
hax_error("VMXON failed for region 0x%llx (result=0x%x, vmxe=%x)\n",
819-
hax_page_pa(cpu_data->vmxon_page), (uint32)result,
820-
(uint32)cpu_data->host_cr4_vmxe);
819+
hax_page_pa(cpu_data->vmxon_page), (uint32_t)result,
820+
(uint32_t)cpu_data->host_cr4_vmxe);
821821
restore_host_cr4_vmxe(cpu_data);
822822
if (result == VMX_FAIL_INVALID) {
823823
log_vmxon_err_type1 = 1;

core/dump_vmcs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
#include "../include/hax.h"
3535

3636
extern unsigned char **vmcs_names;
37-
extern uint32 vmcs_hash(uint32 enc);
37+
extern uint32_t vmcs_hash(uint32_t enc);
3838

39-
static uint32 dump_vmcs_list[] = {
39+
static uint32_t dump_vmcs_list[] = {
4040
VMX_PIN_CONTROLS,
4141
VMX_PRIMARY_PROCESSOR_CONTROLS,
4242
VMX_SECONDARY_PROCESSOR_CONTROLS,
@@ -180,7 +180,7 @@ static uint32 dump_vmcs_list[] = {
180180
GUEST_ACTIVITY_STATE,
181181
};
182182

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

199199
void dump_vmcs(struct vcpu_t *vcpu)
200200
{
201-
uint32 i, enc, n;
201+
uint32_t i, enc, n;
202202
unsigned char *name;
203203

204-
uint32 *list = dump_vmcs_list;
204+
uint32_t *list = dump_vmcs_list;
205205
n = ARRAY_ELEMENTS(dump_vmcs_list);
206206

207207
for (i = 0; i < n; i++) {

core/emulate.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static bool is_translation_required(struct em_context_t *ctxt)
288288
static uint64_t get_canonical_address(struct em_context_t *ctxt,
289289
uint64_t addr, uint vaddr_bits)
290290
{
291-
return ((int64)addr << (64 - vaddr_bits)) >> (64 - vaddr_bits);
291+
return ((int64_t)addr << (64 - vaddr_bits)) >> (64 - vaddr_bits);
292292
}
293293

294294
static em_status_t get_linear_address(struct em_context_t *ctxt,
@@ -475,24 +475,24 @@ static uint64_t insn_fetch_u64(struct em_context_t *ctxt)
475475
return result;
476476
}
477477

478-
static int8 insn_fetch_s8(struct em_context_t *ctxt)
478+
static int8_t insn_fetch_s8(struct em_context_t *ctxt)
479479
{
480-
return (int8)insn_fetch_u8(ctxt);
480+
return (int8_t)insn_fetch_u8(ctxt);
481481
}
482482

483-
static int16 insn_fetch_s16(struct em_context_t *ctxt)
483+
static int16_t insn_fetch_s16(struct em_context_t *ctxt)
484484
{
485-
return (int16)insn_fetch_u16(ctxt);
485+
return (int16_t)insn_fetch_u16(ctxt);
486486
}
487487

488-
static int32 insn_fetch_s32(struct em_context_t *ctxt)
488+
static int32_t insn_fetch_s32(struct em_context_t *ctxt)
489489
{
490-
return (int32)insn_fetch_u32(ctxt);
490+
return (int32_t)insn_fetch_u32(ctxt);
491491
}
492492

493-
static int64 insn_fetch_s64(struct em_context_t *ctxt)
493+
static int64_t insn_fetch_s64(struct em_context_t *ctxt)
494494
{
495-
return (int64)insn_fetch_u64(ctxt);
495+
return (int64_t)insn_fetch_u64(ctxt);
496496
}
497497

498498
static void decode_prefixes(struct em_context_t *ctxt)
@@ -774,7 +774,7 @@ static em_status_t decode_op_simm8(em_context_t *ctxt,
774774
{
775775
op->type = OP_IMM;
776776
op->size = 1;
777-
op->value = (int64)(insn_fetch_s8(ctxt));
777+
op->value = (int64_t)(insn_fetch_s8(ctxt));
778778
return EM_CONTINUE;
779779
}
780780

core/ept.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@
4343
#include "include/paging.h"
4444
#include "include/vtlb.h"
4545

46-
static uint64 ept_capabilities;
46+
static uint64_t ept_capabilities;
4747

4848
#define EPT_BASIC_CAPS (ept_cap_WB | ept_cap_invept_ac)
4949

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

6464
caps &= ~EPT_UNSUPPORTED_FEATURES;
65-
ASSERT(!ept_capabilities || caps == ept_capabilities);
65+
assert(!ept_capabilities || caps == ept_capabilities);
6666
// FIXME: This assignment is done by all logical processors simultaneously
6767
ept_capabilities = caps;
6868
return 1;
6969
}
7070

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

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

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

188-
ASSERT(ept->ept_root_page);
188+
assert(ept->ept_root_page);
189189
if (which_g >= EPT_MAX_MEM_G) {
190190
hax_debug("ept_lookup error!\n");
191191
return 0;
@@ -224,7 +224,7 @@ static bool ept_lookup(struct vcpu_t *vcpu, paddr_t gpa, paddr_t *hpa)
224224
// TODO: Do we need to consider cross-page case ??
225225
bool ept_translate(struct vcpu_t *vcpu, paddr_t gpa, uint order, paddr_t *hpa)
226226
{
227-
ASSERT(order == PG_ORDER_4K);
227+
assert(order == PG_ORDER_4K);
228228
return ept_lookup(vcpu, gpa, hpa);
229229
}
230230

@@ -301,7 +301,7 @@ void ept_free (hax_vm_t *hax_vm)
301301
struct hax_page *page, *n;
302302
struct hax_ept *ept = hax_vm->ept;
303303

304-
ASSERT(ept);
304+
assert(ept);
305305

306306
if (!ept->ept_root_page)
307307
return;
@@ -342,11 +342,11 @@ static void invept_smpfunc(struct invept_bundle *bundle)
342342

343343
void invept(hax_vm_t *hax_vm, uint type)
344344
{
345-
uint64 eptp_value = vm_get_eptp(hax_vm);
345+
uint64_t eptp_value = vm_get_eptp(hax_vm);
346346
struct invept_desc desc = { eptp_value, 0 };
347347
struct invept_bundle bundle;
348348
int cpu_id;
349-
uint32 res;
349+
uint32_t res;
350350

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

397-
res = (uint32)cpu_data->vmxon_res;
397+
res = (uint32_t)cpu_data->vmxon_res;
398398
if (res != VMX_SUCCEED) {
399399
hax_error("[Processor #%d] INVEPT was not called, because VMXON"
400400
" failed (err=0x%x)\n", cpu_id, res);
401401
} else {
402-
res = (uint32)cpu_data->invept_res;
402+
res = (uint32_t)cpu_data->invept_res;
403403
if (res != VMX_SUCCEED) {
404404
hax_error("[Processor #%d] INVEPT failed (err=0x%x)\n", cpu_id,
405405
res);
406406
}
407-
res = (uint32)cpu_data->vmxoff_res;
407+
res = (uint32_t)cpu_data->vmxoff_res;
408408
if (res != VMX_SUCCEED) {
409409
hax_error("[Processor #%d] INVEPT was called, but VMXOFF failed"
410410
" (err=0x%x)\n", cpu_id, res);
@@ -413,7 +413,7 @@ void invept(hax_vm_t *hax_vm, uint type)
413413
}
414414
}
415415

416-
uint64 vcpu_get_eptp(struct vcpu_t *vcpu)
416+
uint64_t vcpu_get_eptp(struct vcpu_t *vcpu)
417417
{
418418
struct hax_ept *ept = vcpu->vm->ept;
419419

0 commit comments

Comments
 (0)