On Sun, Apr 13, 2014 at 12:33 AM, Nick Hudson <sk...@netbsd.org> wrote: > On 04/12/14 16:08, Masao Uebayashi wrote: >> >> Module Name: src >> Committed By: uebayasi >> Date: Sat Apr 12 15:08:56 UTC 2014 >> >> Modified Files: >> src/sys/kern: kern_exec.c >> >> Log Message: >> execve_runproc: Correct thinko in Rev. 1.386; the new SP always points to >> after (higher adderss) argc/argv/env/aux/strings regardless of stack >> growing >> direction . > > Doesn't this mean that argc, etc will get overwritten on _rtld_start call > for stack grows down machines? > > SP needs to point to the first available stack address. On stack grows down > machines this is a lower value than argc, etc. On stack grows up machines > this is a higher value.
http://www.netbsd.org/~uebayasi/execve-stack-growdown.pdf http://www.netbsd.org/~uebayasi/execve-stack-growup.pdf Initial SP points to STACK_GROW(minsaddr, ssize). rtld can use the given stack freely (contradicting obsolete comments found in kern_exec.c). stack-growing-up rtld has to figure out &argc. This is possible by (vaddr_t)ps_argvstr - (vaddr_t)sizeof(argc). Note that argc on stack is long (== char *), not int. hppa's rtld assumes int, which has to be fixed for hppa64. http://nxr.netbsd.org/xref/src/libexec/ld.elf_so/arch/hppa/rtld_start.S#88 > btw, why do you keep adding 4 space idented { } ? To narrow local var scopes. They should go away eventually...