Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ddprof-lib/src/main/cpp/safeAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class SafeAccess {

NOINLINE __attribute__((aligned(16)))
static void *loadPtr(void** ptr, void* default_value);

static inline bool isReadable(void* ptr) {
return load32((int32_t*)ptr, 1) != 1 ||
load32((int32_t*)ptr, -1) != -1;
}
};

#endif // _SAFEACCESS_H
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/stackWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static inline void fillFrame(ASGCT_CallFrame& frame, FrameTypeId type, int bci,
}

static jmethodID getMethodId(VMMethod* method) {
if (!inDeadZone(method) && aligned((uintptr_t)method)) {
if (!inDeadZone(method) && aligned((uintptr_t)method) && SafeAccess::isReadable((void*)method)) {
return method->validatedId();
}
return NULL;
Expand Down
6 changes: 6 additions & 0 deletions ddprof-lib/src/test/cpp/safefetch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ TEST_F(SafeFetchTest, invalidAccessPtr) {
EXPECT_EQ(res, bp);
}

TEST_F(SafeFetchTest, isReadable) {
char c = 'x';
EXPECT_TRUE(SafeAccess::isReadable(&c));
EXPECT_FALSE(SafeAccess::isReadable(nullptr));
}

/**
* Tests that safeFetch32 correctly handles mprotected memory.
*
Expand Down
Loading