Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable the kvm_legacy to fetch multicpu reg info #994

Merged
merged 9 commits into from Nov 3, 2021
20 changes: 14 additions & 6 deletions libvmi/driver/kvm/kvm_legacy.c
Expand Up @@ -104,7 +104,7 @@ exec_info_registers(
kvm_instance_t *kvm)
{
char *query =
"{\"execute\": \"human-monitor-command\", \"arguments\": {\"command-line\": \"info registers\"}}";
"{\"execute\": \"human-monitor-command\", \"arguments\": {\"command-line\": \"info registers -a\"}}";
return exec_qmp_cmd(kvm, query);
}

Expand Down Expand Up @@ -774,16 +774,23 @@ kvm_get_vcpureg(
vmi_instance_t vmi,
uint64_t *value,
reg_t reg,
unsigned long UNUSED(vcpu))
unsigned long vcpu)
{
// TODO: vCPU specific registers
char *all_regs = NULL;
char *regs = NULL;

if (NULL == regs)
regs = exec_info_registers(kvm_get_instance(vmi));
char specific_vcpu_regs_finder[16] = "";

status_t ret = VMI_SUCCESS;

snprintf(specific_vcpu_regs_finder, sizeof(specific_vcpu_regs_finder), "CPU#%ld", vcpu);

all_regs = exec_info_registers(kvm_get_instance(vmi));
regs = strstr(all_regs, specific_vcpu_regs_finder);
if (NULL == regs) {
ret = VMI_FAILURE;
goto exit;
}

switch (reg) {
case CR0:
*value = parse_reg_value("CR0", regs);
Expand Down Expand Up @@ -1028,6 +1035,7 @@ kvm_get_vcpureg(
break;
}

exit:
if (regs)
free(regs);
return ret;
Expand Down