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,
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(
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;
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__));
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);
}
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 */
/* 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)
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);
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);
}
}
*/
#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,
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;
}
/*
*/
void VGA_(main_thread_wrapper)(ThreadId tid)
{
- UInt *esp = allocstack(tid);
+ UWord* esp = allocstack(tid);
vg_assert(tid == VG_(master_tid));
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;