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

Commit ef10681

Browse files
committed
Removed hax_log macro and using hax_info instead
- Some functions used hax_log, which was macro'ed to hax_info. Most likely a leftover from older HAXM revisions. This has been removed and replaced with hax_info directly. - Fixed some incorrect format specifiers and improved documentation of `name_vmcs_component`. Signed-off-by: Alexandro Sanchez Bach <[email protected]>
1 parent 24fdff5 commit ef10681

File tree

8 files changed

+47
-41
lines changed

8 files changed

+47
-41
lines changed

core/cpu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void cpu_init_vmx(void *arg)
132132
/* get VMX capabilities */
133133
vmx_read_info(&vmx_info);
134134
#if 0
135-
//hax_log("-----------cpu %d---------------\n", cpu_data->cpu_id);
135+
//hax_info("-----------cpu %d---------------\n", cpu_data->cpu_id);
136136

137137
if ((cpu_data->cpu_id == 0 ||
138138
memcmp(&vmx_info, &hax_cpu_data[0]->vmx_info,
@@ -142,13 +142,13 @@ void cpu_init_vmx(void *arg)
142142
#endif
143143

144144
if (vmx_info._vmcs_region_length > HAX_PAGE_SIZE)
145-
hax_log("VMCS of %d bytes not supported by this Hypervisor. "
145+
hax_info("VMCS of %d bytes not supported by this Hypervisor. "
146146
"Max supported %u bytes\n",
147147
vmx_info._vmcs_region_length, (uint32_t)HAX_PAGE_SIZE);
148148
vmxon = (vmcs_t *)hax_page_va(cpu_data->vmxon_page);
149149
vmxon->_revision_id = vmx_info._vmcs_revision_id;
150150

151-
//hax_log("enabled VMX mode (vmxon = %p)\n",
151+
//hax_info("enabled VMX mode (vmxon = %p)\n",
152152
// hax_page_va(cpu_data->vmxon_page));
153153

154154
vmx_read_info(&cpu_data->vmx_info);
@@ -654,7 +654,7 @@ static void cpu_vmentry_failed(struct vcpu_t *vcpu, vmx_result_t result)
654654
reason = vmread(vcpu, VM_EXIT_INFO_REASON);
655655
if (result == VMX_FAIL_VALID) {
656656
error = vmread(vcpu, VMX_INSTRUCTION_ERROR_CODE);
657-
hax_error("VMfailValid. Prev exit: %llx. Error code: %lld (%s)\n",
657+
hax_error("VMfailValid. Prev exit: %llx. Error code: %llu (%s)\n",
658658
reason, error, name_vmx_error(error));
659659
} else {
660660
hax_error("VMfailInvalid. Prev exit: %llx no error code\n",

core/dump.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -195,30 +195,30 @@ void dump_vmcs(struct vcpu_t *vcpu)
195195

196196
void dump_vmx_info(struct info_t *info)
197197
{
198-
hax_log("VMCS Rev %d\n", info->_vmcs_revision_id);
198+
hax_info("VMCS Rev %d\n", info->_vmcs_revision_id);
199199

200-
hax_log("VMX basic info : 0x%016llX\n",
201-
info->_basic_info);
202-
hax_log("VMX misc info : 0x%08llX\n",
203-
info->_miscellaneous);
204-
hax_log("VMX revision control : %d\n",
205-
info->_vmcs_revision_id);
206-
hax_log("VMX exit ctls : 0x%X, 0x%X\n",
207-
info->exit_ctls_0, info->exit_ctls_1);
208-
hax_log("VMX entry ctls : 0x%X, 0x%X\n",
209-
info->entry_ctls_0, info->entry_ctls_1);
210-
hax_log("VMX pin ctls : 0x%X, 0x%X\n",
211-
info->pin_ctls_0, info->pin_ctls_1);
212-
hax_log("VMX cpu prim ctrls : 0x%X, 0x%X\n",
213-
info->pcpu_ctls_0, info->pcpu_ctls_1);
214-
hax_log("VMX cpu sec ctrl : 0x%X, 0x%X\n",
215-
info->scpu_ctls_0, info->scpu_ctls_1);
216-
hax_log("VMX fixed CR0 bits : 0x%llX, %llX\n",
217-
info->_cr0_fixed_0, info->_cr0_fixed_1);
218-
hax_log("VMX fixed CR4 bits : 0x%llX, %llX\n",
219-
info->_cr4_fixed_0, info->_cr4_fixed_1);
220-
hax_log("VMX EPT/VPID caps : 0x%016llX\n",
221-
info->_ept_cap);
200+
hax_info("VMX basic info : 0x%016llX\n",
201+
info->_basic_info);
202+
hax_info("VMX misc info : 0x%016llX\n",
203+
info->_miscellaneous);
204+
hax_info("VMX revision control : %u\n",
205+
info->_vmcs_revision_id);
206+
hax_info("VMX exit ctls : 0x%X, 0x%X\n",
207+
info->exit_ctls_0, info->exit_ctls_1);
208+
hax_info("VMX entry ctls : 0x%X, 0x%X\n",
209+
info->entry_ctls_0, info->entry_ctls_1);
210+
hax_info("VMX pin ctls : 0x%X, 0x%X\n",
211+
info->pin_ctls_0, info->pin_ctls_1);
212+
hax_info("VMX cpu prim ctrls : 0x%X, 0x%X\n",
213+
info->pcpu_ctls_0, info->pcpu_ctls_1);
214+
hax_info("VMX cpu sec ctrl : 0x%X, 0x%X\n",
215+
info->scpu_ctls_0, info->scpu_ctls_1);
216+
hax_info("VMX fixed CR0 bits : 0x%llX, %llX\n",
217+
info->_cr0_fixed_0, info->_cr0_fixed_1);
218+
hax_info("VMX fixed CR4 bits : 0x%llX, %llX\n",
219+
info->_cr4_fixed_0, info->_cr4_fixed_1);
220+
hax_info("VMX EPT/VPID caps : 0x%016llX\n",
221+
info->_ept_cap);
222222
}
223223

224224
/*Remove this function. It only for debug*/

core/name.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,22 @@
3333

3434
const char *name_vmcs_component(int value)
3535
{
36+
// The following macro compactifies the VMCS component encoding to 9 bits,
37+
// thus all major compilers will optimize the switch-case via jump tables.
38+
// Compilers will ensure this is a perfect hash function, by preventing
39+
// the two identical cases to exist.
40+
// The original encoding is described by:
3641
// Intel SDM Vol. 3C: Table 24-17. Structure of VMCS Component Encoding
42+
// Our compact encoding is described by:
43+
// [W WTTI IIII] W=Width, T=Type, I=Index
44+
45+
// As of this writing, no VMCS component is encoded with an Index of more
46+
// than 5 bits (Intel SDM Vol. 3D, Appendix B: Field Encoding in VMCS),
47+
// even though 9 bits are allocated to Index.
3748
#define HASH(x) \
3849
(((x) & 0x003E) >> 1) /* Index */ | \
39-
(((x) & 0x0C00) >> 4) /* Type */ | \
40-
(((x) & 0x6000) >> 5) /* Width */
50+
(((x) & 0x0C00) >> 5) /* Type */ | \
51+
(((x) & 0x6000) >> 6) /* Width */
4152
#define CASE(x) \
4253
case HASH(x): \
4354
return #x

core/vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ int hax_vm_core_open(struct vm_t *vm)
226226
int hax_teardown_vm(struct vm_t *vm)
227227
{
228228
if (!hax_list_empty(&(vm->vcpu_list))) {
229-
hax_log("Try to teardown non-empty vm\n");
229+
hax_info("Try to teardown non-empty vm\n");
230230
return -1;
231231
}
232232
#ifdef HAX_ARCH_X86_32

include/darwin/hax_mac.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ extern int default_hax_log_level;
191191
printf("haxm_debug: " x); \
192192
}
193193

194-
#define hax_log hax_info
195-
196194
#define hax_panic panic
197195

198196
#define hax_panic_vcpu(v, x...) { \

include/windows/hax_windows.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ void hax_error(char *fmt, ...);
200200
void hax_warning(char *fmt, ...);
201201
void hax_info(char *fmt, ...);
202202
void hax_debug(char *fmt, ...);
203-
void hax_log(char *fmt, ...);
204-
205-
#define hax_log hax_info
206203

207204
#define hax_panic DbgPrint
208205

platforms/windows/hax_entry.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ NTSTATUS HaxClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
191191
NTSTATUS ret = STATUS_SUCCESS;
192192
devext = (struct hax_dev_ext *)DeviceObject->DeviceExtension;
193193

194-
hax_log("HaxClose device %x at process %p\n", devext->type,
194+
hax_info("HaxClose device %x at process %p\n", devext->type,
195195
(ULONG_PTR)PsGetCurrentThread());
196196
switch (devext->type) {
197197
case HAX_DEVEXT_TYPE_UP:
@@ -201,7 +201,7 @@ NTSTATUS HaxClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
201201
case HAX_DEVEXT_TYPE_VM:
202202
vm = &devext->vmdev_ext;
203203
cvm = vm->cvm;
204-
hax_log("Close VM %x\n", vm->vm_id);
204+
hax_info("Close VM %x\n", vm->vm_id);
205205
if (cvm)
206206
hax_put_vm(cvm);
207207
break;
@@ -433,7 +433,7 @@ NTSTATUS HaxVcpuControl(PDEVICE_OBJECT DeviceObject,
433433
default:
434434
hax_error("Unknow vcpu ioctl %lx\n",
435435
irpSp->Parameters.DeviceIoControl.IoControlCode);
436-
hax_log("set regs ioctl %lx get regs %lx", HAX_VCPU_SET_REGS,
436+
hax_info("set regs ioctl %lx get regs %lx", HAX_VCPU_SET_REGS,
437437
HAX_VCPU_GET_REGS );
438438
ret = STATUS_INVALID_PARAMETER;
439439
break;
@@ -487,7 +487,7 @@ NTSTATUS HaxVmControl(PDEVICE_OBJECT DeviceObject, struct hax_vm_windows *ext,
487487
vm_id = vm->vm_id;
488488
cvcpu = vcpu_create(cvm, vm, vcpu_id);
489489
if (!cvcpu) {
490-
hax_log("Failed to create vcpu %x on vm %x\n", vcpu_id, vm_id);
490+
hax_info("Failed to create vcpu %x on vm %x\n", vcpu_id, vm_id);
491491
ret = STATUS_UNSUCCESSFUL;
492492
goto done;
493493
}
@@ -744,7 +744,7 @@ VOID HaxUnloadDriver(__in PDRIVER_OBJECT DriverObject)
744744
RtlInitUnicodeString(&ntWin32NameString, DOS_DEVICE_NAME);
745745
IoDeleteSymbolicLink(&ntWin32NameString);
746746
IoDeleteDevice(HaxDeviceObject);
747-
hax_log("Unload the driver\n");
747+
hax_info("Unload the driver\n");
748748
hax_host_exit();
749749
write_event(HaxDriverUnloaded, DriverObject, NULL, 0);
750750
HaxDeviceObject = NULL;

platforms/windows/haxm-core.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
</ClCompile>
114114
</ItemDefinitionGroup>
115115
<ItemGroup>
116-
<!-- We only add items (e.g. form ClSourceFiles) that do not already exist (e.g in the ClCompile list), this avoids duplication -->
117116
<ClCompile Include="..\..\core\name.c" />
118117
<ClCompile Include="..\..\core\chunk.c" />
119118
<ClCompile Include="..\..\core\cpu.c" />
@@ -135,6 +134,7 @@
135134
<ClCompile Include="..\..\core\vm.c" />
136135
<ClCompile Include="..\..\core\vmx.c" />
137136
<ClCompile Include="..\..\core\vtlb.c" />
137+
<!-- We only add items (e.g. form ClSourceFiles) that do not already exist (e.g in the ClCompile list), this avoids duplication -->
138138
<ClCompile Include="@(ClSourceFiles)" Exclude="@(ClCompile)" />
139139
<ResourceCompile Include="@(RcSourceFiles)" Exclude="@(ResourceCompile)" />
140140
<Midl Include="@(IdlSourceFiles)" Exclude="@(Midl)" />

0 commit comments

Comments
 (0)