Skip to content

Commit

Permalink
Fix gregs usage on 32-bit powerpc (#8)
Browse files Browse the repository at this point in the history
The old code was wrong as `uc_regs` is not a registers array,
but rather an `mcontext_t` pointer on glibc, therefore indexing
it goes way past the memory bounds. The actual registers array
is `gregs` inside the `mcontext_t` structure.

On non-glibc libcs (as well as inside the kernel definitions),
the structure is defined differently, with `uc_mcontext` being
an actual value member just like on ppc64, so we can use that.
On glibc/ppc32, `mcontext_t` is an union of `uc_regs` and `regs`
pointers, with the value of the member being a pointer to where
the real `uc_mcontext` field would be.
  • Loading branch information
q66 authored and dvzrv committed Oct 28, 2019
1 parent 7e347f0 commit 9f87918
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sigsegv.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ static void signal_segv(int signum, siginfo_t* info, void*ptr) {
for(i = 0; i < NGREG; i++)
a2j_error("reg[%02d] = 0x" REGFORMAT, i,
#if defined(__powerpc__) && !defined(__powerpc64__)
ucontext->uc_mcontext.uc_regs[i]
#if defined(__GLIBC__)
ucontext->uc_mcontext.uc_regs->gregs[i]
#else
ucontext->uc_mcontext.gregs[i]
#endif
#elif defined(__powerpc64__)
ucontext->uc_mcontext.gp_regs[i]
#elif defined(__sparc__) && defined(__arch64__)
Expand Down

0 comments on commit 9f87918

Please sign in to comment.