Skip to content

Commit

Permalink
Check uc->uc_mcontext.fpregs sanity.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealMDoerr committed Oct 25, 2024
1 parent 6f9ed35 commit 76c45d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,17 @@ void os::print_context(outputStream *st, const void *context) {
// Add XMM registers + MXCSR. Note that C2 uses XMM to spill GPR values including pointers.
st->cr();
st->cr();
for (int i = 0; i < 16; ++i) {
const int64_t* xmm_val_addr = (int64_t*)&(uc->uc_mcontext.fpregs->_xmm[i]);
st->print_cr("XMM[%d]=" INTPTR_FORMAT " " INTPTR_FORMAT, i, xmm_val_addr[1], xmm_val_addr[0]);
size_t fpregs_offset = pointer_delta(uc->uc_mcontext.fpregs, uc, 1);
if (fpregs_offset > sizeof(ucontext_t)) {
st->print_cr("bad uc->uc_mcontext.fpregs: " INTPTR_FORMAT " (uc: " INTPTR_FORMAT ")",
p2i(uc->uc_mcontext.fpregs), p2i(uc));
} else {
for (int i = 0; i < 16; ++i) {
const int64_t* xmm_val_addr = (int64_t*)&(uc->uc_mcontext.fpregs->_xmm[i]);
st->print_cr("XMM[%d]=" INTPTR_FORMAT " " INTPTR_FORMAT, i, xmm_val_addr[1], xmm_val_addr[0]);
}
st->print(" MXCSR=" UINT32_FORMAT_X_0, uc->uc_mcontext.fpregs->mxcsr);
}
st->print(" MXCSR=" UINT32_FORMAT_X_0, uc->uc_mcontext.fpregs->mxcsr);
#endif
#else
st->print( "EAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EAX]);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/utilities/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ static void store_context(const void* context) {
*((void**) &g_stored_assertion_context.uc_mcontext.regs) = &(g_stored_assertion_context.uc_mcontext.gp_regs);
#elif defined(AMD64)
// In the copied version, fpregs should point to the copied contents. Preserve the offset.
intptr_t fpregs_offset = (address)(void*)(((const ucontext_t*)context)->uc_mcontext.fpregs) - (address)context;
size_t fpregs_offset = pointer_delta(((const ucontext_t*)context)->uc_mcontext.fpregs, context, 1);
*((void**) &g_stored_assertion_context.uc_mcontext.fpregs) = (void*)((address)(void*)&g_stored_assertion_context + fpregs_offset);
#endif
#endif
Expand Down

0 comments on commit 76c45d6

Please sign in to comment.