Skip to content

Commit 54a4f9a

Browse files
jbachorikclaude
andcommitted
Use SafeAccess for signal-handler memory reads in vmStructs.h
Protect methods called from signal handlers against partially initialized thread structures during GC worker thread creation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 27cdddc commit 54a4f9a

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

ddprof-lib/src/main/cpp/vmStructs.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <string.h>
1212
#include <type_traits>
1313
#include "codeCache.h"
14+
#include "safeAccess.h"
1415

1516

1617
class VMStructs {
@@ -311,23 +312,23 @@ class JavaFrameAnchor : VMStructs {
311312

312313
public:
313314
static JavaFrameAnchor* fromEntryFrame(uintptr_t fp) {
314-
const char* call_wrapper = *(const char**)(fp + _entry_frame_call_wrapper_offset);
315+
const char* call_wrapper = (const char*) SafeAccess::loadPtr((void**)(fp + _entry_frame_call_wrapper_offset), nullptr);
315316
if (!goodPtr(call_wrapper) || (uintptr_t)call_wrapper - fp > MAX_CALL_WRAPPER_DISTANCE) {
316317
return NULL;
317318
}
318319
return (JavaFrameAnchor*)(call_wrapper + _call_wrapper_anchor_offset);
319320
}
320321

321322
uintptr_t lastJavaSP() {
322-
return *(uintptr_t*) at(_anchor_sp_offset);
323+
return (uintptr_t) SafeAccess::loadPtr((void**) at(_anchor_sp_offset), nullptr);
323324
}
324325

325326
uintptr_t lastJavaFP() {
326-
return *(uintptr_t*) at(_anchor_fp_offset);
327+
return (uintptr_t) SafeAccess::loadPtr((void**) at(_anchor_fp_offset), nullptr);
327328
}
328329

329330
const void* lastJavaPC() {
330-
return *(const void**) at(_anchor_pc_offset);
331+
return SafeAccess::loadPtr((void**) at(_anchor_pc_offset), nullptr);
331332
}
332333

333334
void setLastJavaPC(const void* pc) {
@@ -382,15 +383,15 @@ class VMThread : VMStructs {
382383
}
383384

384385
int state() {
385-
return _thread_state_offset >= 0 ? *(int*) at(_thread_state_offset) : 0;
386+
return _thread_state_offset >= 0 ? SafeAccess::load32((int32_t*) at(_thread_state_offset), 0) : 0;
386387
}
387388

388389
bool inJava() {
389390
return state() == 8;
390391
}
391392

392393
bool inDeopt() {
393-
return *(void**) at(_thread_vframe_offset) != NULL;
394+
return SafeAccess::loadPtr((void**) at(_thread_vframe_offset), nullptr) != NULL;
394395
}
395396

396397
void*& exception() {

0 commit comments

Comments
 (0)