]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Renamed and retyped the fields relating to valgrind's stack in os_state_t to
authorNicholas Nethercote <njn@valgrind.org>
Tue, 5 Apr 2005 02:49:09 +0000 (02:49 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Tue, 5 Apr 2005 02:49:09 +0000 (02:49 +0000)
make their role clearer and their behaviour more consistent with the fields
describing the client's stack.  Also made the code in x86-linux/syscalls.c
and amd64-linux/syscalls.c more word-size-independent, which is not strictly
necessary but makes the code similarities between the two files more
obvious.

One consequence of this is that Valgrind's stack on AMD64 is now 16384 * 8
bytes, rather than 16384 * 4 bytes.

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

coregrind/amd64-linux/syscalls.c
coregrind/core.h
coregrind/linux/core_os.c
coregrind/linux/core_os.h
coregrind/vg_main.c
coregrind/vg_mylibc.c
coregrind/vg_signals.c
coregrind/x86-linux/syscalls.c

index 21dda51c14b1a7bd83f16599aa29d38500bd8d4b..150b9d726369be8b397951ca7025bc1bb3d36e92 100644 (file)
@@ -180,16 +180,15 @@ void VGA_(client_syscall)(Int syscallno, ThreadState *tst,
 
    They're allocated lazily, but never freed.
  */
-#define FILL   0xdeadbeef
+#define FILL   0xdeadbeefcabafeed
 
-static ULong *allocstack(ThreadId tid)
+static UWord* allocstack(ThreadId tid)
 {
    ThreadState *tst = VG_(get_ThreadState)(tid);
-   ULong* rsp;
-   UInt*  pUInt;
+   UWord* rsp;
 
-   if (tst->os_state.stack == NULL) {
-      void *stk = VG_(mmap)(0, VGA_STACK_SIZE_W * sizeof(Int) + VKI_PAGE_SIZE,
+   if (tst->os_state.valgrind_stack_base == 0) {
+      void *stk = VG_(mmap)(0, VGA_STACK_SIZE_W * sizeof(UWord) + VKI_PAGE_SIZE,
                            VKI_PROT_READ|VKI_PROT_WRITE,
                            VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS,
                            SF_VALGRIND,
@@ -197,54 +196,56 @@ static ULong *allocstack(ThreadId tid)
 
       if (stk != (void *)-1) {
         VG_(mprotect)(stk, VKI_PAGE_SIZE, VKI_PROT_NONE); /* guard page */
-        tst->os_state.stack = (UInt *)stk + VKI_PAGE_SIZE/sizeof(UInt);
-        tst->os_state.stacksize = VGA_STACK_SIZE_W;
+        tst->os_state.valgrind_stack_base = ((Addr)stk) + VKI_PAGE_SIZE;
+        tst->os_state.valgrind_stack_szB  = VGA_STACK_SIZE_W * sizeof(UWord);
       } else 
-        return (ULong *)-1;
+        return (UWord*)-1;
    }
 
-   for (pUInt = tst->os_state.stack; 
-        pUInt < (tst->os_state.stack + tst->os_state.stacksize); 
-        pUInt++)
-      *pUInt = FILL;
+   for (rsp = (UWord*) tst->os_state.valgrind_stack_base; 
+        rsp < (UWord*)(tst->os_state.valgrind_stack_base +
+                       tst->os_state.valgrind_stack_szB); 
+        rsp++)
+      *rsp = FILL;
    /* rsp is left at top of stack */
-   rsp = (ULong*)pUInt;
 
    if (0)
-      VG_(printf)("stack for tid %d at %p (%x); rsp=%p\n",
-                 tid, tst->os_state.stack, *tst->os_state.stack,
-                 rsp);
+      VG_(printf)("stack for tid %d at %p (%llx); rsp=%p\n",
+                 tid, tst->os_state.valgrind_stack_base,
+                  *(UWord*)(tst->os_state.valgrind_stack_base), rsp);
 
    return rsp;
 }
 
 /* NB: this is identical the the x86 version. */
 /* Return how many bytes of this stack have not been used */
-Int VGA_(stack_unused)(ThreadId tid)
+SSizeT VGA_(stack_unused)(ThreadId tid)
 {
    ThreadState *tst = VG_(get_ThreadState)(tid);
-   UInt *p;
+   UWord* p;
 
-   for (p = tst->os_state.stack; 
-       p && (p < (tst->os_state.stack + tst->os_state.stacksize)); 
+   for (p = (UWord*)tst->os_state.valgrind_stack_base; 
+       p && (p < (UWord*)(tst->os_state.valgrind_stack_base +
+                           tst->os_state.valgrind_stack_szB)); 
        p++)
       if (*p != FILL)
         break;
 
    if (0)
-      VG_(printf)("p=%p %x tst->os_state.stack=%p\n", p, *p, tst->os_state.stack);
+      VG_(printf)("p=%p %llx tst->os_state.valgrind_stack_base=%p\n",
+                  p, *p, tst->os_state.valgrind_stack_base);
 
-   return (p - tst->os_state.stack) * sizeof(*p);
+   return ((Addr)p) - tst->os_state.valgrind_stack_base;
 }
 
-
 /*
    Allocate a stack for the main thread, and call VGA_(thread_wrapper)
    on that stack.
  */
 void VGA_(main_thread_wrapper)(ThreadId tid)
 {
-   ULong *rsp = allocstack(tid);
+   UWord* rsp = allocstack(tid);
+
    vg_assert(tid == VG_(master_tid));
 
    call_on_new_stack_0_1( 
@@ -318,7 +319,7 @@ static Int do_clone(ThreadId ptid,
    ThreadId ctid = VG_(alloc_ThreadState)();
    ThreadState *ptst = VG_(get_ThreadState)(ptid);
    ThreadState *ctst = VG_(get_ThreadState)(ctid);
-   ULong *stack;
+   UWord *stack;
    Segment *seg;
    Int ret;
    vki_sigset_t blockall, savedmask;
index ace647785e8364f6f9640a1323a71fe37486134f..7b03d96a2f3d0729a21aaeaea75261d504cf9729 100644 (file)
@@ -1681,7 +1681,7 @@ void VGA_(thread_wrapper)(Word /*ThreadId*/ tid);
 void VGA_(main_thread_wrapper)(ThreadId tid) __attribute__ ((__noreturn__));
 
 // Return how many bytes of a thread's Valgrind stack are unused
-Int VGA_(stack_unused)(ThreadId tid);
+SSizeT VGA_(stack_unused)(ThreadId tid);
 
 // Terminate the process.  Does not return.
 void VGA_(terminate)(ThreadId tid, VgSchedReturnCode src) __attribute__((__noreturn__));
index f71d331bfdf6e18cbd70f3e83641bbcacbb02ab4..7b25cb113c0a24e11ea811762f11a4f00304c30b 100644 (file)
@@ -8,8 +8,8 @@ void VGA_(os_state_clear)(ThreadState *tst)
 
 void VGA_(os_state_init)(ThreadState *tst)
 {
-   tst->os_state.stack = 0;
-   tst->os_state.stacksize = 0;
+   tst->os_state.valgrind_stack_base = 0;
+   tst->os_state.valgrind_stack_szB  = 0;
 
    VGA_(os_state_clear)(tst);
 }
index 54784346aa9b1c63db30c3131f99c7607351bb94..8457539b30e575ddf17aae9a50c68cbe827351e6 100644 (file)
@@ -172,8 +172,8 @@ typedef struct {
    ThreadId parent;            /* parent tid (if any) */
 
    /* runtime details */
-   UInt *stack;                        /* stack base */
-   UInt stacksize;             /* stack size in UInts */
+   Addr  valgrind_stack_base;  /* Valgrind's stack base */
+   SizeT valgrind_stack_szB;   /* stack size in bytes */
 
    /* exit details */
    Int  exitcode;              /* in the case of exitgroup, set by someone else */
index ba8f21e96b7bdf9bf39862bf837547a910f5196d..a7505702a6c155dc042056cc3e01fd8c076b5718 100644 (file)
@@ -2317,7 +2317,7 @@ void VG_(sanity_check_general) ( Bool force_expensive )
 
       /* Look for stack overruns.  Visit all threads. */
       for(tid = 1; tid < VG_N_THREADS; tid++) {
-        Int remains;
+        SSizeT remains;
 
         if (VG_(threads)[tid].status == VgTs_Empty ||
             VG_(threads)[tid].status == VgTs_Zombie)
index e8f7e26f35047b71f512702501936b035e02e97b..13d2844630f23ecfc57028821fd30973bcf4c8d6 100644 (file)
@@ -1153,7 +1153,8 @@ static inline void get_and_pp_real_StackTrace(Addr ret)
    VGA_GET_REAL_STACK_PTR(sp);
    VGA_GET_REAL_FRAME_PTR(fp);
 
-   stacktop = (Addr)(tst->os_state.stack + tst->os_state.stacksize);
+   stacktop = tst->os_state.valgrind_stack_base + 
+              tst->os_state.valgrind_stack_szB;
 
    VG_(get_StackTrace2)(ips, VG_(clo_backtrace_size),
                         ret, fp, sp, stacktop);
index 6eb5f8b84ac88fbf6ef23f837cb7bb024fd73f29..01e42c1368880724f65c02c7e9a0d661129c8b85 100644 (file)
@@ -1940,7 +1940,8 @@ void sync_signalhandler ( Int sigNo, vki_siginfo_t *info, struct vki_ucontext *u
                            VGP_UCONTEXT_INSTR_PTR(uc),
                            VGP_UCONTEXT_FRAME_PTR(uc),
                            VGP_UCONTEXT_STACK_PTR(uc),
-                           (Addr)(tst->os_state.stack + tst->os_state.stacksize));
+                           tst->os_state.valgrind_stack_base + 
+                           tst->os_state.valgrind_stack_szB);
       VG_(core_panic_at)("Killed by fatal signal", ips);
    }
 }
index 5f046cbe0c182b5ded078eb53ddb14b5c367e703..bbf566b191fe2301bac1a21f036e4b46801d71a9 100644 (file)
@@ -180,13 +180,13 @@ void VGA_(client_syscall)(Int syscallno, ThreadState *tst,
  */
 #define FILL   0xdeadbeef
 
-static UInt *allocstack(ThreadId tid)
+static UWord* allocstack(ThreadId tid)
 {
    ThreadState *tst = VG_(get_ThreadState)(tid);
-   UInt *esp;
+   UWord *esp;
 
-   if (tst->os_state.stack == NULL) {
-      void *stk = VG_(mmap)(0, VGA_STACK_SIZE_W * sizeof(Int) + VKI_PAGE_SIZE,
+   if (tst->os_state.valgrind_stack_base == 0) {
+      void *stk = VG_(mmap)(0, VGA_STACK_SIZE_W * sizeof(UWord) + VKI_PAGE_SIZE,
                            VKI_PROT_READ|VKI_PROT_WRITE,
                            VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS,
                            SF_VALGRIND,
@@ -194,41 +194,46 @@ static UInt *allocstack(ThreadId tid)
 
       if (stk != (void *)-1) {
         VG_(mprotect)(stk, VKI_PAGE_SIZE, VKI_PROT_NONE); /* guard page */
-        tst->os_state.stack = (UInt *)stk + VKI_PAGE_SIZE/sizeof(UInt);
-        tst->os_state.stacksize = VGA_STACK_SIZE_W;
+        tst->os_state.valgrind_stack_base = ((Addr)stk) + VKI_PAGE_SIZE;
+        tst->os_state.valgrind_stack_szB  = VGA_STACK_SIZE_W * sizeof(UWord);
       } else 
-        return (UInt *)-1;
+        return (UWord*)-1;
    }
 
-   for(esp = tst->os_state.stack; esp < (tst->os_state.stack + tst->os_state.stacksize); esp++)
+   for (esp = (UWord*) tst->os_state.valgrind_stack_base;
+        esp < (UWord*)(tst->os_state.valgrind_stack_base + 
+                       tst->os_state.valgrind_stack_szB); 
+        esp++)
       *esp = FILL;
    /* esp is left at top of stack */
 
    if (0)
       VG_(printf)("stack for tid %d at %p (%x); esp=%p\n",
-                 tid, tst->os_state.stack, *tst->os_state.stack,
-                 esp);
+                 tid, tst->os_state.valgrind_stack_base, 
+                  *(UWord*)(tst->os_state.valgrind_stack_base), esp);
 
    return esp;
 }
 
 /* NB: this is identical the the amd64 version. */
 /* Return how many bytes of this stack have not been used */
-Int VGA_(stack_unused)(ThreadId tid)
+SSizeT VGA_(stack_unused)(ThreadId tid)
 {
    ThreadState *tst = VG_(get_ThreadState)(tid);
-   UInt *p;
+   UWord* p;
 
-   for (p = tst->os_state.stack; 
-       p && (p < (tst->os_state.stack + tst->os_state.stacksize)); 
+   for (p = (UWord*)tst->os_state.valgrind_stack_base; 
+       p && (p < (UWord*)(tst->os_state.valgrind_stack_base +
+                           tst->os_state.valgrind_stack_szB)); 
        p++)
       if (*p != FILL)
         break;
 
    if (0)
-      VG_(printf)("p=%p %x tst->os_state.stack=%p\n", p, *p, tst->os_state.stack);
+      VG_(printf)("p=%p %x tst->os_state.valgrind_stack_base=%p\n",
+                  p, *p, tst->os_state.valgrind_stack_base);
 
-   return (p - tst->os_state.stack) * sizeof(*p);
+   return ((Addr)p) - tst->os_state.valgrind_stack_base;
 }
 
 /*
@@ -237,7 +242,7 @@ Int VGA_(stack_unused)(ThreadId tid)
  */
 void VGA_(main_thread_wrapper)(ThreadId tid)
 {
-   UInt *esp = allocstack(tid);
+   UWord* esp = allocstack(tid);
 
    vg_assert(tid == VG_(master_tid));
 
@@ -312,7 +317,7 @@ static Int do_clone(ThreadId ptid,
    ThreadId ctid = VG_(alloc_ThreadState)();
    ThreadState *ptst = VG_(get_ThreadState)(ptid);
    ThreadState *ctst = VG_(get_ThreadState)(ctid);
-   UInt *stack;
+   UWord *stack;
    Segment *seg;
    Int ret;
    vki_sigset_t blockall, savedmask;