]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
minor cleanup with the stack-related fields in ThreadState:
authorNicholas Nethercote <njn@valgrind.org>
Mon, 4 Apr 2005 02:41:42 +0000 (02:41 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Mon, 4 Apr 2005 02:41:42 +0000 (02:41 +0000)
- removed "stack_base" which wasn't used in any meaningful way
- added "client_" prefix to make it clear they concern the client's stack
- renamed "stack_size" as "client_stack_szB" to make the units clear

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

coregrind/amd64-linux/syscalls.c
coregrind/amd64/signals.c
coregrind/core.h
coregrind/stacktrace.c
coregrind/vg_scheduler.c
coregrind/vg_signals.c
coregrind/vg_syscalls.c
coregrind/x86-linux/syscalls.c
coregrind/x86/signals.c

index 67dab790ee9527c1d6012494745a8e8b0df45105..c9d39e8cbff4482ad9bd041055f09c2fccc7ce8b 100644 (file)
@@ -364,9 +364,10 @@ static Int do_clone(ThreadId ptid,
       only go down to the start of the mmaped segment. */
    seg = VG_(find_segment)((Addr)rsp);
    if (seg) {
-      ctst->stack_base = seg->addr;
-      ctst->stack_highest_word = (Addr)PGROUNDUP(rsp);
-      ctst->stack_size = ctst->stack_highest_word - ctst->stack_base;
+      ctst->client_stack_base = seg->addr;
+      ctst->client_stack_highest_word = (Addr)PGROUNDUP(rsp);
+      ctst->client_stack_szB  = ctst->client_stack_highest_word 
+                              - ctst->client_stack_base;
 
       if (debug)
         VG_(printf)("tid %d: guessed client stack range %p-%p\n",
@@ -374,8 +375,8 @@ static Int do_clone(ThreadId ptid,
    } else {
       VG_(message)(Vg_UserMsg, "!? New thread %d starts with RSP(%p) unmapped\n",
                   ctid, rsp);
-      ctst->stack_base = 0;
-      ctst->stack_size = 0;
+      ctst->client_stack_base = 0;
+      ctst->client_stack_szB  = 0;
    }
 
    if (flags & VKI_CLONE_SETTLS) {
index 8f738e34f5012c325de13f411fc4adb714c9f9d7..95e2ff5eeaf470ff263c0ee7a85b2c42245e4f54 100644 (file)
@@ -377,7 +377,7 @@ static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
    ThreadId tid = tst->tid;
    Segment *stackseg = NULL;
 
-   if (VG_(extend_stack)(addr, tst->stack_size)) {
+   if (VG_(extend_stack)(addr, tst->client_stack_szB)) {
       stackseg = VG_(find_segment)(addr);
       if (0 && stackseg)
         VG_(printf)("frame=%p seg=%p-%p\n",
index fcfd1bf5570e7ed22a591a4a5c7f21ed55523274..ace647785e8364f6f9640a1323a71fe37486134f 100644 (file)
@@ -596,7 +596,7 @@ struct _ThreadState {
       post-syscall function. */
    void *tool_pre_syscall_value;
 
-   /* Stacks.  When a thread slot is freed, we don't deallocate its
+   /* Client stacks.  When a thread slot is freed, we don't deallocate its
       stack; we just leave it lying around for the next use of the
       slot.  If the next use of the slot requires a larger stack,
       only then is the old one deallocated and a new one
@@ -608,18 +608,13 @@ struct _ThreadState {
 
    /* The allocated size of this thread's stack (permanently zero
       if this is ThreadId == 0, since we didn't allocate its stack) */
-   UInt stack_size;
-
-   /* Address of the lowest word in this thread's stack.  NULL means
-      not allocated yet.
-   */
-   Addr stack_base;
+   SizeT client_stack_szB;
 
    /* Address of the highest legitimate word in this stack.  This is
       used for error messages only -- not critical for execution
       correctness.  Is is set for all stacks, specifically including
       ThreadId == 0 (the main thread). */
-   Addr stack_highest_word;
+   Addr client_stack_highest_word;
 
    /* Alternate signal stack */
    vki_stack_t altstack;
index f8c7c4e1411678ed5c3f18e769c345669f9a1b7c..5821d584d37d255c9b96bba5d87fb6e9e172e299 100644 (file)
@@ -116,7 +116,7 @@ UInt VG_(get_StackTrace) ( ThreadId tid, StackTrace ips, UInt n_ips )
    Addr ip                 = INSTR_PTR(tst->arch);
    Addr fp                 = FRAME_PTR(tst->arch);
    Addr sp                 = STACK_PTR(tst->arch);
-   Addr stack_highest_word = tst->stack_highest_word;
+   Addr stack_highest_word = tst->client_stack_highest_word;
 
 #ifdef __x86__
    /* Nasty little hack to deal with sysinfo syscalls - if libc is
index 59f89b546350b2788ea45760a3b4f9e03e77ed36..91ac17305c2680d65b145e498a92dddec67f1c90 100644 (file)
@@ -144,7 +144,7 @@ ThreadId VG_(first_matching_thread_stack)
       if (VG_(threads)[tid].status == VgTs_Empty) continue;
 
       if ( p ( STACK_PTR(VG_(threads)[tid].arch),
-               VG_(threads)[tid].stack_highest_word, d ) )
+               VG_(threads)[tid].client_stack_highest_word, d ) )
          return tid;
    }
    return VG_INVALID_THREADID;
@@ -350,16 +350,6 @@ void VG_(exit_thread)(ThreadId tid)
    vg_assert(VG_(is_running_thread)(tid));
    vg_assert(VG_(is_exiting)(tid));
 
-   /* It's stack is now off-limits
-
-      XXX Don't do this - the client thread implementation can touch
-      the stack after thread death... */
-   if (0 && VG_(threads)[tid].stack_base) {
-      Segment *seg = VG_(find_segment)( VG_(threads)[tid].stack_base );
-      if (seg)
-        VG_TRACK( die_mem_stack, seg->addr, seg->len );
-   }
-
    VGA_(cleanup_thread)( &VG_(threads)[tid].arch );
 
    mostly_clear_thread_record(tid);
@@ -627,10 +617,9 @@ void VG_(scheduler_init) ( void )
       VGA_(os_state_init)(&VG_(threads)[i]);
       mostly_clear_thread_record(i);
 
-      VG_(threads)[i].status               = VgTs_Empty;
-      VG_(threads)[i].stack_size           = 0;
-      VG_(threads)[i].stack_base           = (Addr)NULL;
-      VG_(threads)[i].stack_highest_word   = (Addr)NULL;
+      VG_(threads)[i].status                    = VgTs_Empty;
+      VG_(threads)[i].client_stack_szB          = 0;
+      VG_(threads)[i].client_stack_highest_word = (Addr)NULL;
    }
 
    tid_main = VG_(alloc_ThreadState)();
@@ -638,9 +627,9 @@ void VG_(scheduler_init) ( void )
    VG_(master_tid) = tid_main;
 
    /* Initial thread's stack is the original process stack */
-   VG_(threads)[tid_main].stack_highest_word = VG_(clstk_end) - sizeof(UInt);
-   VG_(threads)[tid_main].stack_base = VG_(clstk_base);
-   VG_(threads)[tid_main].stack_size = VG_(client_rlimit_stack).rlim_cur;
+   VG_(threads)[tid_main].client_stack_highest_word 
+                                            = VG_(clstk_end) - sizeof(UInt);
+   VG_(threads)[tid_main].client_stack_szB  = VG_(client_rlimit_stack).rlim_cur;
 
    VG_(atfork)(NULL, NULL, sched_fork_cleanup);
 }
index 86a37e1a10d7bfc55cb88dd3d4114ec0f33fe192..6eb5f8b84ac88fbf6ef23f837cb7bb024fd73f29 100644 (file)
@@ -1842,7 +1842,7 @@ void sync_signalhandler ( Int sigNo, vki_siginfo_t *info, struct vki_ucontext *u
            then extend the stack segment. 
         */
          Addr base = PGROUNDDN(esp - VGA_STACK_REDZONE_SIZE);
-        if (VG_(extend_stack)(base, VG_(threads)[tid].stack_size)) {
+        if (VG_(extend_stack)(base, VG_(threads)[tid].client_stack_szB)) {
            if (VG_(clo_trace_signals))
               VG_(message)(Vg_DebugMsg, 
                            "       -> extended stack base to %p", PGROUNDDN(fault));
index 45d3eb60eaf2a74754eb4faa2785a29af046fcb7..344ee6d61b9b532c2ac3c52e834252f00a2f5f37 100644 (file)
@@ -5004,7 +5004,7 @@ PRE(sys_setrlimit, 0)
          SET_RESULT( -VKI_EPERM );
       }
       else {
-         VG_(threads)[tid].stack_size = ((struct vki_rlimit *)ARG2)->rlim_cur;
+         VG_(threads)[tid].client_stack_szB  = ((struct vki_rlimit *)ARG2)->rlim_cur;
          VG_(client_rlimit_stack) = *(struct vki_rlimit *)ARG2;
          SET_RESULT( 0 );
       }
index 2dc52b560173aff49f3b63de3e6973c10e1bedd3..5f046cbe0c182b5ded078eb53ddb14b5c367e703 100644 (file)
@@ -358,9 +358,8 @@ static Int do_clone(ThreadId ptid,
       only go down to the start of the mmaped segment. */
    seg = VG_(find_segment)((Addr)esp);
    if (seg) {
-      ctst->stack_base = seg->addr;
-      ctst->stack_highest_word = (Addr)PGROUNDUP(esp);
-      ctst->stack_size = ctst->stack_highest_word - ctst->stack_base;
+      ctst->client_stack_highest_word = (Addr)PGROUNDUP(esp);
+      ctst->client_stack_szB  = ctst->client_stack_highest_word - seg->addr;
 
       if (debug)
         VG_(printf)("tid %d: guessed client stack range %p-%p\n",
@@ -368,8 +367,7 @@ static Int do_clone(ThreadId ptid,
    } else {
       VG_(message)(Vg_UserMsg, "!? New thread %d starts with ESP(%p) unmapped\n",
                   ctid, esp);
-      ctst->stack_base = 0;
-      ctst->stack_size = 0;
+      ctst->client_stack_szB  = 0;
    }
 
    if (flags & VKI_CLONE_SETTLS) {
index 2f72fe4130b8b4441b915faacfbe1fbc6039917e..88895d4682cc85162c87ac653a6391b74851f0eb 100644 (file)
@@ -397,7 +397,7 @@ static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
    ThreadId tid = tst->tid;
    Segment *stackseg = NULL;
 
-   if (VG_(extend_stack)(addr, tst->stack_size)) {
+   if (VG_(extend_stack)(addr, tst->client_stack_szB)) {
       stackseg = VG_(find_segment)(addr);
       if (0 && stackseg)
         VG_(printf)("frame=%p seg=%p-%p\n",