From: Julian Seward Date: Sun, 23 Feb 2003 01:41:17 +0000 (+0000) Subject: Further cleanups re new method for finding the stack segment at X-Git-Tag: svn/VALGRIND_1_9_4~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2b039db36046d0c97088bd263006441e3fffd2db;p=thirdparty%2Fvalgrind.git Further cleanups re new method for finding the stack segment at startup. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1423 --- diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h index 86e024f8f7..25e1b4e5ef 100644 --- a/coregrind/vg_include.h +++ b/coregrind/vg_include.h @@ -880,28 +880,6 @@ extern Bool VG_(scheduler_jmpbuf_valid); 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. */ diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c index 0cb7b63567..ccc3b31987 100644 --- a/coregrind/vg_main.c +++ b/coregrind/vg_main.c @@ -622,17 +622,18 @@ static Addr vg_foundstack_start = (Addr)NULL; 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); } } @@ -667,56 +668,33 @@ static void process_cmd_line_options ( void ) 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) { diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c index b1f73a21d0..3f047cfa7b 100644 --- a/coregrind/vg_scheduler.c +++ b/coregrind/vg_scheduler.c @@ -626,25 +626,6 @@ void VG_(scheduler_init) ( void ) 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;