Skip to content

Commit 947754d

Browse files
executor: x86: fix check-syzos error
Replace the switch statement in guest_handle_wr_crn() with a series of if statements.
1 parent 698c735 commit 947754d

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

executor/common_kvm_amd64_syzos.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,29 +185,31 @@ GUEST_CODE static noinline void guest_handle_rdmsr(uint64 reg)
185185
GUEST_CODE static noinline void guest_handle_wr_crn(struct api_call_2* cmd)
186186
{
187187
uint64 value = cmd->args[1];
188-
switch (cmd->args[0]) {
189-
case 0:
188+
// Prevent the compiler from generating a switch table.
189+
volatile uint64 reg = cmd->args[0];
190+
if (reg == 0) {
190191
// Move value to CR0.
191192
asm volatile("movq %0, %%cr0" ::"r"(value) : "memory");
192-
break;
193-
case 2:
193+
return;
194+
}
195+
if (reg == 2) {
194196
// Move value to CR2.
195197
asm volatile("movq %0, %%cr2" ::"r"(value) : "memory");
196-
break;
197-
case 3:
198+
return;
199+
}
200+
if (reg == 3) {
198201
// Move value to CR3.
199202
asm volatile("movq %0, %%cr3" ::"r"(value) : "memory");
200-
break;
201-
case 4:
203+
return;
204+
}
205+
if (reg == 4) {
202206
// Move value to CR4.
203207
asm volatile("movq %0, %%cr4" ::"r"(value) : "memory");
204-
break;
205-
case 8:
208+
return;
209+
}
210+
if (reg == 8) {
206211
// Move value to CR8 (TPR - Task Priority Register).
207212
asm volatile("movq %0, %%cr8" ::"r"(value) : "memory");
208-
break;
209-
default:
210-
// Do nothing.
211-
break;
213+
return;
212214
}
213215
}

0 commit comments

Comments
 (0)