]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Further cleanups re new method for finding the stack segment at
authorJulian Seward <jseward@acm.org>
Sun, 23 Feb 2003 01:41:17 +0000 (01:41 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 23 Feb 2003 01:41:17 +0000 (01:41 +0000)
startup.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1423

coregrind/vg_include.h
coregrind/vg_main.c
coregrind/vg_scheduler.c

index 86e024f8f7cb3d6cde20ba945aabf8eb16dfe4a4..25e1b4e5ef5305ae09ff47d51911d550c37a51ef 100644 (file)
@@ -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. */
index 0cb7b6356748a6a666a1df9b8790409884a34c2c..ccc3b319873f17567c126498eb91c3f8faba76b3 100644 (file)
@@ -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) {
index b1f73a21d052531ba4591a478b01628ed01cbf31..3f047cfa7b81f329201b8d90cdafc6d9117afa58 100644 (file)
@@ -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;