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

Commit

Permalink
Fixed races and macOS build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAltea committed Jun 19, 2018
1 parent d8cd858 commit 1946f80
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include "include/intr.h"
#include "include/ept.h"

static cpuid_cache_t cache = {
.initialized = 0
};

static vmx_error_t cpu_vmentry_failed(struct vcpu_t *vcpu, vmx_error_t err);
static int cpu_vmexit_handler(struct vcpu_t *vcpu, exit_reason_t exit_reason,
struct hax_tunnel *htun);
Expand All @@ -61,15 +65,17 @@ static int cpu_nx_enable()

bool cpu_has_feature(uint32_t feature)
{
static cpuid_cache_t cache = {
.initialized = 0
};
if (!cache.initialized) {
cpuid_host_init(&cache);
}
return cpuid_host_has_feature(&cache, feature);
}

void cpu_init_feature_cache()
{
cpuid_host_init(&cache);
}

void cpu_init_vmx(void *arg)
{
struct info_t vmx_info;
Expand Down
1 change: 1 addition & 0 deletions core/hax.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ int hax_module_init(void)
hax_clear_page(hax_cpu_data[cpu]->hstate.hfxpage);
hax_cpu_data[cpu]->cpu_id = cpu;
}
cpu_init_feature_cache();
ret = hax_vmx_init();
if (ret < 0)
goto out_2;
Expand Down
1 change: 1 addition & 0 deletions core/include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void cpu_enter_vmx(void *arg);

void cpu_pmu_init(void *arg);

void cpu_init_feature_cache();
bool cpu_has_feature(uint32_t feature);

void hax_panic_log(struct vcpu_t *vcpu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
6448A2211EDFCDAB000B4B32 /* hax_host_mem.h in Headers */ = {isa = PBXBuildFile; fileRef = 6448A2201EDFCDAB000B4B32 /* hax_host_mem.h */; };
6456261F1EEFF705005280EF /* ept2.h in Headers */ = {isa = PBXBuildFile; fileRef = 6456261E1EEFF705005280EF /* ept2.h */; };
645626211EEFF720005280EF /* ept_tree.c in Sources */ = {isa = PBXBuildFile; fileRef = 645626201EEFF720005280EF /* ept_tree.c */; };
6496936F20D8AE0000C9BBAF /* cpuid.c in Sources */ = {isa = PBXBuildFile; fileRef = 6496936E20D8AE0000C9BBAF /* cpuid.c */; };
64B72B851EDFFF7E00A8C202 /* hax_host_mem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 64B72B841EDFFF7E00A8C202 /* hax_host_mem.cpp */; };
64B85BE91EF4D34D00223ABD /* ept2.c in Sources */ = {isa = PBXBuildFile; fileRef = 64B85BE81EF4D34D00223ABD /* ept2.c */; };
6E2DBBCC18EB6125003B66C9 /* page_walker.c in Sources */ = {isa = PBXBuildFile; fileRef = 6E2DBBCB18EB6125003B66C9 /* page_walker.c */; };
Expand Down Expand Up @@ -127,6 +128,7 @@
6448A2201EDFCDAB000B4B32 /* hax_host_mem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = hax_host_mem.h; path = ../../../include/hax_host_mem.h; sourceTree = "<group>"; };
6456261E1EEFF705005280EF /* ept2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ept2.h; path = ../../../core/include/ept2.h; sourceTree = "<group>"; };
645626201EEFF720005280EF /* ept_tree.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ept_tree.c; path = ../../../core/ept_tree.c; sourceTree = "<group>"; };
6496936E20D8AE0000C9BBAF /* cpuid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cpuid.c; path = ../../../core/cpuid.c; sourceTree = "<group>"; };
64B72B841EDFFF7E00A8C202 /* hax_host_mem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = hax_host_mem.cpp; sourceTree = "<group>"; };
64B85BE81EF4D34D00223ABD /* ept2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ept2.c; path = ../../../core/ept2.c; sourceTree = "<group>"; };
6E2DBBCB18EB6125003B66C9 /* page_walker.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = page_walker.c; path = ../../../core/page_walker.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -207,6 +209,7 @@
247142CAFF3F8F9811CA285C /* Source */ = {
isa = PBXGroup;
children = (
6496936E20D8AE0000C9BBAF /* cpuid.c */,
6E2DBBCB18EB6125003B66C9 /* page_walker.c */,
43038AD9145F94190014BEE6 /* memory.c */,
4BCC4E0113FB6729005E4BE4 /* asm */,
Expand Down Expand Up @@ -457,6 +460,7 @@
4BCC4E0713FB6729005E4BE4 /* vmcs.c in Sources */,
43038ADA145F94190014BEE6 /* memory.c in Sources */,
645626211EEFF720005280EF /* ept_tree.c in Sources */,
6496936F20D8AE0000C9BBAF /* cpuid.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions include/asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

#include "hax_types.h"

union cpuid_args_t;
struct vcpu_t;
struct vcpu_state_t;
struct invept_desc;

mword get_cr0(void);
Expand Down

0 comments on commit 1946f80

Please sign in to comment.