Skip to content

Commit

Permalink
[CHERI-RISC-V] Respect DDC relocation configuration in amoswap.c
Browse files Browse the repository at this point in the history
We were unconditionally adding the DDC address rather than using the
cheri_ddc_relative_addr() helper.
  • Loading branch information
arichardson committed Jul 28, 2023
1 parent 3ce22cd commit 4d46035
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions target/riscv/op_helper_cheri.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ void HELPER(amoswap_cap)(CPUArchState *env, uint32_t dest_reg,
assert(!qemu_tcg_mttcg_enabled() ||
(cpu_in_exclusive_context(env_cpu(env)) &&
"Should have raised EXCP_ATOMIC"));
target_long offset = 0;
target_long addr = get_capreg_cursor(env, addr_reg);
if (!cheri_in_capmode(env)) {
offset = get_capreg_cursor(env, addr_reg);
addr = cheri_ddc_relative_addr(env, addr);
addr_reg = CHERI_EXC_REGNUM_DDC;
}
const cap_register_t *cbp = get_load_store_base_cap(env, addr_reg);
Expand All @@ -269,13 +269,12 @@ void HELPER(amoswap_cap)(CPUArchState *env, uint32_t dest_reg,
raise_cheri_exception(env, CapEx_PermitStoreLocalCapViolation, val_reg);
}

target_ulong addr = (target_ulong)(cap_get_cursor(cbp) + (target_long)offset);
if (!cap_is_in_bounds(cbp, addr, CHERI_CAP_SIZE)) {
qemu_log_instr_or_mask_msg(env, CPU_LOG_INT,
"Failed capability bounds check:"
"offset=" TARGET_FMT_ld " cursor=" TARGET_FMT_lx
" addr=" TARGET_FMT_lx "\n",
offset, cap_get_cursor(cbp), addr);
qemu_log_instr_or_mask_msg(
env, CPU_LOG_INT,
"Failed capability bounds check: addr=" TARGET_FMT_ld
" base=" TARGET_FMT_lx " top=" TARGET_FMT_lx "\n",
addr, cap_get_cursor(cbp), cap_get_top(cbp));
raise_cheri_exception(env, CapEx_LengthViolation, addr_reg);
} else if (!QEMU_IS_ALIGNED(addr, CHERI_CAP_SIZE)) {
raise_unaligned_store_exception(env, addr, _host_return_address);
Expand Down

0 comments on commit 4d46035

Please sign in to comment.