extern Int VG_(longjmpd_on_signal);
-/* Possible places where the main stack might be based. We check that
- the initial stack, which we can't move, is allocated here.
- VG_(scheduler_init) checks this. Andrea Archelangi's 2.4 kernels
- have been rumoured to start stacks at 0x80000000, so that too is
- considered. It seems systems with longer uptimes tend to to use
- stacks which start at 0x40000000 sometimes. JRS 2002-Aug-21: I
- also have reports of stacks starting at 0xE0000000.*/
-
-#define VG_STARTUP_STACK_BASE_1 (Addr)0xC0000000
-#define VG_STARTUP_STACK_BASE_2 (Addr)0x80000000
-#define VG_STARTUP_STACK_BASE_3 (Addr)0x40000000
-#define VG_STARTUP_STACK_BASE_4 (Addr)0xE0000000
-#define VG_STARTUP_STACK_SMALLERTHAN 0x100000 /* 1024k */
-
-#define VG_STACK_MATCHES_BASE(zzstack, zzbase) \
- ( \
- ((zzstack) & ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN)) \
- == \
- ((zzbase) - VG_STARTUP_STACK_SMALLERTHAN) \
- )
-
-
/* The red-zone size which we put at the bottom (highest address) of
thread stacks, for paranoia reasons. This can be arbitrary, and
doesn't really need to be set at compile time. */
static UInt vg_foundstack_size = 0;
static void vg_findstack_callback ( Addr start, UInt size,
- Char r, Char w, Char x,
- UInt foffset, UChar* filename )
+ Char r, Char w, Char x,
+ UInt foffset, UChar* filename )
{
Addr lastword;
if (size == 0) return;
if (r != 'r' || w != 'w' || x != 'x') return;
lastword = start + size - 4;
- if (start <= VG_(esp_at_startup) && VG_(esp_at_startup) <= lastword) {
- vg_foundstack_start = start;
- vg_foundstack_size = size;
- vg_assert(vg_foundstack_size > 0);
+ if (start <= VG_(esp_at_startup)
+ && VG_(esp_at_startup) <= lastword) {
+ vg_foundstack_start = start;
+ vg_foundstack_size = size;
+ vg_assert(vg_foundstack_size > 0);
}
}
envc & envp. It is not fool-proof, but these structures should
change less often than the libc ones. */
{
- UInt* sp = 0; /* bogus init to keep gcc -O happy */
-#if 0
- /* locate the top of the stack */
- if (VG_STACK_MATCHES_BASE( VG_(esp_at_startup),
- VG_STARTUP_STACK_BASE_1 )) {
- sp = (UInt*)VG_STARTUP_STACK_BASE_1;
- } else
- if (VG_STACK_MATCHES_BASE( VG_(esp_at_startup),
- VG_STARTUP_STACK_BASE_2 )) {
- sp = (UInt*)VG_STARTUP_STACK_BASE_2;
- } else
- if (VG_STACK_MATCHES_BASE( VG_(esp_at_startup),
- VG_STARTUP_STACK_BASE_3 )) {
- sp = (UInt*)VG_STARTUP_STACK_BASE_3;
- } else
- if (VG_STACK_MATCHES_BASE( VG_(esp_at_startup),
- VG_STARTUP_STACK_BASE_4 )) {
- sp = (UInt*)VG_STARTUP_STACK_BASE_4;
- } else {
- args_grok_error(
- "startup %esp is not near any VG_STARTUP_STACK_BASE_*\n "
- "constants defined in vg_include.h. You should investigate."
- );
- }
- #endif
- /* we locate: NEW_AUX_ENT(1, AT_PAGESZ, ELF_EXEC_PAGESIZE) in
- the elf interpreter table */
-
-
- /* Look for the stack by reading /proc/self/maps and looking
- for a section bracketing VG_(esp_at_startup) which has rwx
- permissions. */
+ UInt* sp;
- /* Appalling hack for Gentoo; round up to the next page. */
- sp = (UInt*)VG_(esp_at_startup);
+ /* Look for the stack segment by reading /proc/self/maps and
+ looking for a section bracketing VG_(esp_at_startup) which
+ has rwx permissions and no associated file. */
VG_(read_procselfmaps)( vg_findstack_callback );
- /* make vg_foundstack_start and
-static UInt vg_foundstack_size = 0;
-be the stack. */
- if (vg_foundstack_size == 0)
- args_grok_error("Cannot determine stack segment "
- "from /proc/self/maps");
+
+ /* Now vg_foundstack_start and vg_foundstack_size
+ should delimit the stack. */
+ if (vg_foundstack_size == 0) {
+ args_grok_error("Cannot determine stack segment "
+ "from /proc/self/maps");
+ }
if (0)
- VG_(printf)("stack segment is %p .. %p\n", vg_foundstack_start, vg_foundstack_start + vg_foundstack_size - 4 );
+ VG_(printf)("stack segment is %p .. %p\n",
+ vg_foundstack_start,
+ vg_foundstack_start + vg_foundstack_size - 4 );
- sp = (UInt*)(vg_foundstack_start+ vg_foundstack_size);
- vg_assert((((UInt)(sp)) % VKI_BYTES_PER_PAGE) == 0);
+ sp = (UInt*)(vg_foundstack_start + vg_foundstack_size);
+ if ((((UInt)(sp)) % VKI_BYTES_PER_PAGE) != 0) {
+ args_grok_error("Stack segment is not page aligned?!");
+ }
+ /* we locate: NEW_AUX_ENT(1, AT_PAGESZ, ELF_EXEC_PAGESIZE) in
+ the elf interpreter table */
sp -= 2;
while (sp[0] != VKI_AT_PAGESZ || sp[1] != 4096) {
startup_esp = VG_(baseBlock)[VGOFF_(m_esp)];
-#if 0
- if (VG_STACK_MATCHES_BASE(startup_esp, VG_STARTUP_STACK_BASE_1)
- || VG_STACK_MATCHES_BASE(startup_esp, VG_STARTUP_STACK_BASE_2)
- || VG_STACK_MATCHES_BASE(startup_esp, VG_STARTUP_STACK_BASE_3)
- || VG_STACK_MATCHES_BASE(startup_esp, VG_STARTUP_STACK_BASE_4)) {
- /* Jolly good! */
- } else {
- VG_(printf)(
- "%%esp at startup = %p is not near %p, %p, %p or %p; aborting\n",
- (void*)startup_esp,
- (void*)VG_STARTUP_STACK_BASE_1,
- (void*)VG_STARTUP_STACK_BASE_2,
- (void*)VG_STARTUP_STACK_BASE_3,
- (void*)VG_STARTUP_STACK_BASE_4
- );
- VG_(core_panic)("unexpected %esp at startup");
- }
-#endif
-
for (i = 0 /* NB; not 1 */; i < VG_N_THREADS; i++) {
mostly_clear_thread_record(i);
VG_(threads)[i].stack_size = 0;