Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Mar 2010 03:39:02 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r205353 - projects/ppc64/sys/powerpc/powerpc
Message-ID:  <201003200339.o2K3d2iR054112@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Sat Mar 20 03:39:02 2010
New Revision: 205353
URL: http://svn.freebsd.org/changeset/base/205353

Log:
  Correct stack setup. This incorporates two changes:
  1. The MI code in kern_exec.c will produce a mis-aligned stack if
  sigcodesz is not a multiple of register_t. Fix this with a hammer.
  
  2. C functions (like _start) write their parent LR to the parent's stack
  frame. As such, the 48 bytes above the stack address, which used to
  include argv, can be overwritten by garbage in certain circumstances. The
  correct amount of stack padding is now applied.

Modified:
  projects/ppc64/sys/powerpc/powerpc/exec_machdep.c
  projects/ppc64/sys/powerpc/powerpc/sigcode64.S

Modified: projects/ppc64/sys/powerpc/powerpc/exec_machdep.c
==============================================================================
--- projects/ppc64/sys/powerpc/powerpc/exec_machdep.c	Sat Mar 20 02:23:58 2010	(r205352)
+++ projects/ppc64/sys/powerpc/powerpc/exec_machdep.c	Sat Mar 20 03:39:02 2010	(r205353)
@@ -496,7 +496,11 @@ exec_setregs(struct thread *td, struct i
 
 	tf = trapframe(td);
 	bzero(tf, sizeof *tf);
+	#ifdef __powerpc64__
+	tf->fixreg[1] = -roundup(-stack + 48, 16);
+	#else
 	tf->fixreg[1] = -roundup(-stack + 8, 16);
+	#endif
 
 	/*
 	 * XXX Machine-independent code has already copied arguments and
@@ -1000,8 +1004,13 @@ cpu_set_upcall_kse(struct thread *td, vo
 
 	tf = td->td_frame;
 	/* align stack and alloc space for frame ptr and saved LR */
-	sp = ((uintptr_t)stack->ss_sp + stack->ss_size - sizeof(uint64_t)) &
+	#ifdef __powerpc64__
+	sp = ((uintptr_t)stack->ss_sp + stack->ss_size - 48) &
 	    ~0x1f;
+	#else
+	sp = ((uintptr_t)stack->ss_sp + stack->ss_size - 8) &
+	    ~0x1f;
+	#endif
 	bzero(tf, sizeof(struct trapframe));
 
 	tf->fixreg[1] = (register_t)sp;

Modified: projects/ppc64/sys/powerpc/powerpc/sigcode64.S
==============================================================================
--- projects/ppc64/sys/powerpc/powerpc/sigcode64.S	Sat Mar 20 02:23:58 2010	(r205352)
+++ projects/ppc64/sys/powerpc/powerpc/sigcode64.S	Sat Mar 20 03:39:02 2010	(r205353)
@@ -58,6 +58,7 @@ CNAME(sigcode64):
 	sc				/* sigreturn(scp) */
 	li	0,SYS_exit
 	sc				/* exit(errno) */
+	nop				/* align to doubleword */
 endsigcode64:
 	
 	.data



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003200339.o2K3d2iR054112>