Skip to content

Commit e04b2bb

Browse files
committed
[objects] Take into account the LSB bit in purecap ABI in Code::GetOffsetFromInstructionStart
When the PCC is sealed in purecap ABI, the LSB bit is set, leading to an off-by-one error in the computation of the offset from the instruction start to the current PCC address. This can cause errors such as in OptimizedFrame::LookupExceptionHandlerInTable, where the computed offset is used to look up an exception handler table.
1 parent 5802e9f commit e04b2bb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/objects/code-inl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ Address Code::InstructionEnd(Isolate* isolate, Address pc) const {
171171
}
172172

173173
int Code::GetOffsetFromInstructionStart(Isolate* isolate, Address pc) const {
174+
#if defined(__CHERI_PURE_CAPABILITY__) && defined(__aarch64__)
175+
// NOTE(zyj20): Take into account that the LSB of sealed PCC is set.
176+
// The resulting capability could be invalid but it won't be
177+
// used as a pointer anyways.
178+
const Address offset = (pc & ~1) - InstructionStart(isolate, pc);
179+
#else
174180
const Address offset = pc - InstructionStart(isolate, pc);
181+
#endif
175182
DCHECK_LE(offset, instruction_size());
176183
return static_cast<int>(offset);
177184
}

0 commit comments

Comments
 (0)