Skip to content

Commit

Permalink
Initialize ir->branch_table->PC with safe value
Browse files Browse the repository at this point in the history
If the ra(return address) is 0x0, the
LOOKUP_OR_UPDATE_BRANCH_HISTORY_TABLE will bahave abnormally since
calloc initialize ir->branch_table->PC[i] to 0x0. The 0x0 address might
be not yet translated to a valid block, thus ir->branch_table->target[i]
might be NULL, calling a NULL function pointer cause segmentation fault.
It can be solved by initializing ir->branch_table->PC will other value
than 0x0. Here, I choose unsigned integer of -1.

Close #461
  • Loading branch information
ChinYikMing committed Jun 17, 2024
1 parent ef151e2 commit 1e4ef3c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ static void block_translate(riscv_t *rv, block_t *block)
) {
ir->branch_table = calloc(1, sizeof(branch_history_table_t));
assert(ir->branch_table);
memset(ir->branch_table->PC, -1,
sizeof(uint32_t) * HISTORY_SIZE);
}
break;
}
Expand Down

0 comments on commit 1e4ef3c

Please # to comment.