Skip to content

Commit

Permalink
compel: Fix ppc64le parasite stack layout
Browse files Browse the repository at this point in the history
The ppc64le ABI allows functions to store data in caller frames.
When initializing the stack pointer prior to executing parasite code
we need to pre-allocating the minimum sized stack frame before
jumping to the parasite code.

Signed-off-by: Younes Manton <ymanton@ca.ibm.com>
  • Loading branch information
ymanton authored and avagin committed Oct 2, 2022
1 parent a7cbdcb commit 615763e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions compel/arch/ppc64/src/lib/include/uapi/asm/sigframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@

/* Copied from the Linux kernel header arch/powerpc/include/asm/ptrace.h */
#define USER_REDZONE_SIZE 512
#if _CALL_ELF != 2
#error Only supporting ABIv2.
#else
#define STACK_FRAME_MIN_SIZE 32
#endif

/* Copied from the Linux kernel source file arch/powerpc/kernel/signal_64.c */
#define TRAMP_SIZE 6
Expand Down
4 changes: 2 additions & 2 deletions compel/arch/ppc64/src/lib/infect.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ void *remote_mmap(struct parasite_ctl *ctl, void *addr, size_t length, int prot,
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs)
{
/*
* OpenPOWER ABI requires that r12 is set to the calling function addressi
* OpenPOWER ABI requires that r12 is set to the calling function address
* to compute the TOC pointer.
*/
regs->gpr[12] = new_ip;
regs->nip = new_ip;
if (stack)
regs->gpr[1] = (unsigned long)stack;
regs->gpr[1] = (unsigned long)stack - STACK_FRAME_MIN_SIZE;
regs->trap = 0;
}

Expand Down

0 comments on commit 615763e

Please sign in to comment.