mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-02 16:30:12 +00:00
fix "goto detected:exception_inject"
V1->V2: rename is_exception_inject to has_exception. V2->V3: remove the else statement and add new if statement to check has_exception. Misra C requires not allowed to use goto. Tracked-On: #861 Signed-off-by: Huihuang Shi <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
86526cddc5
commit
625e51d18a
@ -918,58 +918,57 @@ static void get_gva_si_nocheck(const struct acrn_vcpu *vcpu, uint8_t addrsize,
|
|||||||
static int32_t get_gva_di_check(struct acrn_vcpu *vcpu, struct instr_emul_vie *vie,
|
static int32_t get_gva_di_check(struct acrn_vcpu *vcpu, struct instr_emul_vie *vie,
|
||||||
uint8_t addrsize, uint64_t *gva)
|
uint8_t addrsize, uint64_t *gva)
|
||||||
{
|
{
|
||||||
int32_t ret;
|
int32_t ret = 0;
|
||||||
uint32_t err_code;
|
uint32_t err_code;
|
||||||
struct seg_desc desc;
|
struct seg_desc desc;
|
||||||
enum vm_cpu_mode cpu_mode;
|
enum vm_cpu_mode cpu_mode;
|
||||||
uint64_t val, gpa;
|
uint64_t val, gpa;
|
||||||
|
bool has_exception = false;
|
||||||
|
|
||||||
vm_get_seg_desc(CPU_REG_ES, &desc);
|
vm_get_seg_desc(CPU_REG_ES, &desc);
|
||||||
cpu_mode = get_vcpu_mode(vcpu);
|
cpu_mode = get_vcpu_mode(vcpu);
|
||||||
|
|
||||||
if (cpu_mode == CPU_MODE_64BIT) {
|
if (cpu_mode == CPU_MODE_64BIT) {
|
||||||
if ((addrsize != 4U) && (addrsize != 8U)) {
|
if ((addrsize != 4U) && (addrsize != 8U)) {
|
||||||
goto exception_inject;
|
has_exception = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((addrsize != 2U) && (addrsize != 4U)) {
|
if ((addrsize != 2U) && (addrsize != 4U)) {
|
||||||
goto exception_inject;
|
has_exception = true;
|
||||||
}
|
} else if (!is_desc_valid(&desc, PROT_WRITE)) {
|
||||||
|
has_exception = true;
|
||||||
if (!is_desc_valid(&desc, PROT_WRITE)) {
|
|
||||||
goto exception_inject;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!has_exception) {
|
||||||
val = vm_get_register(vcpu, CPU_REG_RDI);
|
val = vm_get_register(vcpu, CPU_REG_RDI);
|
||||||
if (vie_calculate_gla(cpu_mode, CPU_REG_ES, &desc, val, addrsize, gva) != 0) {
|
if (vie_calculate_gla(cpu_mode, CPU_REG_ES, &desc, val, addrsize, gva) != 0) {
|
||||||
goto exception_inject;
|
has_exception = true;
|
||||||
}
|
} else if (vie_canonical_check(cpu_mode, *gva) != 0) {
|
||||||
|
has_exception = true;
|
||||||
if (vie_canonical_check(cpu_mode, *gva) != 0) {
|
} else {
|
||||||
goto exception_inject;
|
|
||||||
}
|
|
||||||
|
|
||||||
err_code = PAGE_FAULT_WR_FLAG;
|
err_code = PAGE_FAULT_WR_FLAG;
|
||||||
ret = gva2gpa(vcpu, *gva, &gpa, &err_code);
|
ret = gva2gpa(vcpu, *gva, &gpa, &err_code);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (ret == -EFAULT) {
|
if (ret == -EFAULT) {
|
||||||
vcpu_inject_pf(vcpu, (uint64_t)gva, err_code);
|
vcpu_inject_pf(vcpu, (uint64_t)gva, err_code);
|
||||||
}
|
}
|
||||||
return ret;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
/* If we are checking the dest operand for movs instruction,
|
/* If we are checking the dest operand for movs instruction,
|
||||||
* we cache the gpa if check pass. It will be used during
|
* we cache the gpa if check pass. It will be used during
|
||||||
* movs instruction emulation.
|
* movs instruction emulation.
|
||||||
*/
|
*/
|
||||||
vie->dst_gpa = gpa;
|
vie->dst_gpa = gpa;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
if (has_exception) {
|
||||||
|
|
||||||
exception_inject:
|
|
||||||
vcpu_inject_gp(vcpu, 0U);
|
vcpu_inject_gp(vcpu, 0U);
|
||||||
return -EFAULT;
|
ret = -EFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MOVs gets the operands from RSI and RDI. Both operands could be memory.
|
/* MOVs gets the operands from RSI and RDI. Both operands could be memory.
|
||||||
|
Loading…
Reference in New Issue
Block a user