Skip to content

Commit

Permalink
Size verification
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Dec 19, 2024
1 parent 5304622 commit 183cdc7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/hotspot/os_cpu/linux_riscv/os_linux_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ void os::print_context(outputStream *st, const void *context) {
return;
}

//size = sizeof(struct __riscv_ctx_hdr) + sizeof(struct __sc_riscv_v_state) + riscv_v_vsize;
uint32_t ext_size = ext->hdr.size;

if (ext_size < (sizeof(struct __riscv_ctx_hdr) + sizeof(*v_ext_state))) {
st->print_cr("Vector state: not found, invalid size");
return;
}

ext_size -= (sizeof(struct __riscv_ctx_hdr) + sizeof(*v_ext_state));

v_ext_state = (struct redefine_riscv_v_ext_state *)((char *)(ext) + sizeof(*ext));

st->print_cr("Vector state:");
Expand All @@ -401,9 +411,15 @@ void os::print_context(outputStream *st, const void *context) {
st->print_cr("vcsr=" INTPTR_FORMAT, v_ext_state->vcsr);
st->print_cr("vlenb=" INTPTR_FORMAT, v_ext_state->vlenb);
st->print_cr("Vector registers:");

uint64_t vr_size = v_ext_state->vlenb;

if (ext_size < (32*vr_size)) {
st->print_cr("Vector registers: not found, invalid size");
return;
}
// datap format is undocumented, but is generated by kernel function riscv_v_vstate_save().
uint8_t *regp = (uint8_t *)v_ext_state->datap;
uint64_t vr_size = v_ext_state->vlenb;
for (int r = 0; r < 32; r++) {
st->print("v%d=0x", r);
for (int i = vr_size; i > 0; i--) {
Expand Down

0 comments on commit 183cdc7

Please sign in to comment.