|
From: <sv...@va...> - 2010-06-29 16:37:45
|
Author: sewardj
Date: 2010-06-29 17:37:36 +0100 (Tue, 29 Jun 2010)
New Revision: 11192
Log:
Get rid of m_start-<arch>-darwin.S, and push the relevant bits of assembly into
m_main, just like on Linux. More importantly, switch to the VG_(interim_stack)
right at startup (again, like on Linux) so we don't wind up executing the
(host-side) Valgrind main thread on the stack the kernel starts the process with.
Removed:
branches/MACOSX106/coregrind/m_start-amd64-darwin.S
branches/MACOSX106/coregrind/m_start-x86-darwin.S
Modified:
branches/MACOSX106/coregrind/Makefile.am
branches/MACOSX106/coregrind/m_main.c
Modified: branches/MACOSX106/coregrind/Makefile.am
===================================================================
--- branches/MACOSX106/coregrind/Makefile.am 2010-06-29 06:16:52 UTC (rev 11191)
+++ branches/MACOSX106/coregrind/Makefile.am 2010-06-29 16:37:36 UTC (rev 11192)
@@ -314,8 +314,6 @@
m_sigframe/sigframe-ppc64-aix5.c \
m_sigframe/sigframe-x86-darwin.c \
m_sigframe/sigframe-amd64-darwin.c \
- m_start-x86-darwin.S \
- m_start-amd64-darwin.S \
m_syswrap/syscall-x86-linux.S \
m_syswrap/syscall-amd64-linux.S \
m_syswrap/syscall-ppc32-linux.S \
Modified: branches/MACOSX106/coregrind/m_main.c
===================================================================
--- branches/MACOSX106/coregrind/m_main.c 2010-06-29 06:16:52 UTC (rev 11191)
+++ branches/MACOSX106/coregrind/m_main.c 2010-06-29 16:37:36 UTC (rev 11192)
@@ -1526,9 +1526,6 @@
// Ensure we're on a plausible stack.
// p: logging
//--------------------------------------------------------------
-# if defined(VGO_darwin)
- // Darwin doesn't use the interim stack.
-# else
VG_(debugLog)(1, "main", "Checking current stack is plausible\n");
{ HChar* limLo = (HChar*)(&VG_(interim_stack).bytes[0]);
HChar* limHi = limLo + sizeof(VG_(interim_stack));
@@ -1556,7 +1553,6 @@
VG_(debugLog)(0, "main", " Cannot continue. Sorry.\n");
VG_(exit)(1);
}
-# endif
//--------------------------------------------------------------
// Start up the address space manager, and determine the
@@ -2977,6 +2973,68 @@
#elif defined(VGO_darwin)
+/*
+ Memory layout established by kernel:
+
+ 0(%esp) argc
+ 4(%esp) argv[0]
+ ...
+ argv[argc-1]
+ NULL
+ envp[0]
+ ...
+ envp[n]
+ NULL
+ executable name (presumably, a pointer to it)
+ NULL
+
+ Ditto in the 64-bit case, except all offsets from SP are obviously
+ twice as large.
+*/
+
+/* The kernel hands control to _start, which extracts the initial
+ stack pointer and calls onwards to _start_in_C_darwin. This also
+ switches to the new stack. */
+#if defined(VGP_x86_darwin)
+asm("\n"
+ ".text\n"
+ ".align 2,0x90\n"
+ "\t.globl __start\n"
+ "__start:\n"
+ /* set up the new stack in %eax */
+ "\tmovl $_vgPlain_interim_stack, %eax\n"
+ "\taddl $"VG_STRINGIFY(VG_STACK_GUARD_SZB)", %eax\n"
+ "\taddl $"VG_STRINGIFY(VG_STACK_ACTIVE_SZB)", %eax\n"
+ "\tsubl $16, %eax\n"
+ "\tandl $~15, %eax\n"
+ /* install it, and collect the original one */
+ "\txchgl %eax, %esp\n"
+ /* call _start_in_C_darwin, passing it the startup %esp */
+ "\tpushl %eax\n"
+ "\tcall __start_in_C_darwin\n"
+ "\tint $3\n"
+ "\tint $3\n"
+);
+#elif defined(VGP_amd64_darwin)
+asm("\n"
+ ".text\n"
+ "\t.globl __start\n"
+ ".align 3,0x90\n"
+ "__start:\n"
+ /* set up the new stack in %rdi */
+ "\tmovabsq $_vgPlain_interim_stack, %rdi\n"
+ "\taddq $"VG_STRINGIFY(VG_STACK_GUARD_SZB)", %rdi\n"
+ "\taddq $"VG_STRINGIFY(VG_STACK_ACTIVE_SZB)", %rdi\n"
+ "\tandq $~15, %rdi\n"
+ /* install it, and collect the original one */
+ "\txchgq %rdi, %rsp\n"
+ /* call _start_in_C_darwin, passing it the startup %rsp */
+ "\tcall __start_in_C_darwin\n"
+ "\tint $3\n"
+ "\tint $3\n"
+);
+#endif
+
void* __memcpy_chk(void *dest, const void *src, SizeT n, SizeT n2);
void* __memcpy_chk(void *dest, const void *src, SizeT n, SizeT n2) {
// skip check
@@ -3001,15 +3059,13 @@
return VG_(memset)(s,c,n);
}
-/* _start in m_start-<arch>-darwin.S calls _start_in_C_darwin(). */
-
/* Avoid compiler warnings: this fn _is_ used, but labelling it
'static' causes gcc to complain it isn't. */
void _start_in_C_darwin ( UWord* pArgc );
void _start_in_C_darwin ( UWord* pArgc )
{
Int r;
- Int argc = *(Int *)pArgc; // not pArgc[0] on LP64
+ Int argc = *(Int *)pArgc; // not pArgc[0] on LP64
HChar** argv = (HChar**)&pArgc[1];
HChar** envp = (HChar**)&pArgc[1+argc+1];
Deleted: branches/MACOSX106/coregrind/m_start-amd64-darwin.S
===================================================================
--- branches/MACOSX106/coregrind/m_start-amd64-darwin.S 2010-06-29 06:16:52 UTC (rev 11191)
+++ branches/MACOSX106/coregrind/m_start-amd64-darwin.S 2010-06-29 16:37:36 UTC (rev 11192)
@@ -1,68 +0,0 @@
-
-/*--------------------------------------------------------------------*/
-/*--- Darwin amd64 bootstrap. m_start-amd64-darwin.S ---*/
-/*--------------------------------------------------------------------*/
-
-/*
- This file is part of Valgrind, a dynamic binary instrumentation
- framework.
-
- Copyright (C) 2007 Apple Inc.
- Greg Parker gp...@ap...
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307, USA.
-
- The GNU General Public License is contained in the file COPYING.
-*/
-
-#if defined(VGP_amd64_darwin)
-
-#include "pub_core_basics_asm.h"
-
- // Memory layout established by kernel:
- //
- // 0
- // executable_name
- // 0
- // envp[n]
- // ...
- // envp[0]
- // 0
- // argv[argc-1]
- // ...
- // sp+8-> argv[0]
- // sp -> argc
-
- .text
- .align 3,0x90
- .globl __start
-__start:
- movq %rsp, %rdi // save &argc
- andq $-16, %rsp // align stack
- pushq $0 // push NULL "return address" for backtraces
- pushq $0 // push fake saved ebp and align stack
- movq %rsp, %rbp // save frame pointer
- call __start_in_C_darwin // __start_in_C_darwin(&argc)
-
- // should not reach here
- int $3
- int $3
-
-#endif // defined(VGP_amd64_darwin)
-
-/*--------------------------------------------------------------------*/
-/*--- end ---*/
-/*--------------------------------------------------------------------*/
Deleted: branches/MACOSX106/coregrind/m_start-x86-darwin.S
===================================================================
--- branches/MACOSX106/coregrind/m_start-x86-darwin.S 2010-06-29 06:16:52 UTC (rev 11191)
+++ branches/MACOSX106/coregrind/m_start-x86-darwin.S 2010-06-29 16:37:36 UTC (rev 11192)
@@ -1,70 +0,0 @@
-
-/*--------------------------------------------------------------------*/
-/*--- Darwin x86 bootstrap. m_start-x86-darwin.S ---*/
-/*--------------------------------------------------------------------*/
-
-/*
- This file is part of Valgrind, a dynamic binary instrumentation
- framework.
-
- Copyright (C) 2007 Apple Inc.
- Greg Parker gp...@ap...
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307, USA.
-
- The GNU General Public License is contained in the file COPYING.
-*/
-
-#if defined(VGP_x86_darwin)
-
-#include "pub_core_basics_asm.h"
-
- // Memory layout established by kernel:
- //
- // 0
- // executable_name
- // 0
- // envp[n]
- // ...
- // envp[0]
- // 0
- // argv[argc-1]
- // ...
- // sp+4-> argv[0]
- // sp -> argc
-
- .text
- .align 2,0x90
- .globl __start
-__start:
- movl %esp, %eax // save &argc
- andl $-16, %esp // align stack
- pushl $0 // push NULL "return address" for backtraces
- pushl $0 // push fake saved ebp
- movl %esp, %ebp // save frame pointer
- pushl $0 // align stack
- pushl %eax // start_in_C_darwin(&argc)
- call __start_in_C_darwin
-
- // should not reach here
- int $3
- int $3
-
-#endif // defined(VGP_x86_darwin)
-
-/*--------------------------------------------------------------------*/
-/*--- end ---*/
-/*--------------------------------------------------------------------*/
|