Skip to content

Commit

Permalink
[libunwind] fix unwinding from signal handler
Browse files Browse the repository at this point in the history
In case of this is frame of signal handler, the IP should be
incremented, because the IP saved in the signal handler points to first
non-executed instruction, while FDE/CIE expects IP to be after the
first non-executed instruction.

v2: move the increment from DwarfInstructions<A, R>::stepWithDwarf()
into the UnwindCursor<A, R>::setInfoBasedOnIPRegister() to avoid
exposing posslibly unaligned IP (also note, that this matches with gcc
implementation as well)

Refs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26208
  • Loading branch information
azat committed Jul 9, 2024
1 parent 687531f commit 7066c0d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libunwind/src/UnwindCursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2589,6 +2589,12 @@ void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
--pc;
#endif

// In case of this is frame of signal handler, the IP saved in the signal
// handler points to first non-executed instruction, while FDE/CIE expects IP
// to be after the first non-executed instruction.
if (_isSignalFrame)
++pc;

// Ask address space object to find unwind sections for this pc.
UnwindInfoSections sects;
if (_addressSpace.findUnwindSections(pc, sects)) {
Expand Down

0 comments on commit 7066c0d

Please sign in to comment.