HomeFreeBSD

libc/powerpc64: Fix swapcontext(3)

Description

libc/powerpc64: Fix swapcontext(3)

On PowerPC platforms a valid link to the Table of Contents (TOC) is
required for PLT lookups to function. This TOC pointer is stored in
a dedicated register, and is used along with the stack pointer by both
C prologue and PLT lookup code.

When calling swapcontext() with uc_link != NULL, a PLT lookup to
setcontext(3) is attempted from within the _ctx_done context. The
exiting process has usually trashed both r1 and r2 at this point,
leading to a crash within the PLT lookup before setcontext(2) is
reached to restore the linked context.

Save and restore r2 as in a regular function. This ensures the
subsequent PLT lookup to setcontext(3) succeeds.

Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com>

MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/1759

Details

Provenance
tpearson_raptorengineering.comAuthored on Tue, Jul 8, 1:41 PM
jhibbitsCommitted on Sun, Jul 13, 6:00 PM
Parents
rG077e30e61d7e: powerpc: Fix multiple issues with FP/VSX save/restore
Branches
Unknown
Tags
Unknown