Renamed and retyped the fields relating to valgrind's stack in os_state_t to

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
This commit is contained in:
Nicholas Nethercote 2005-04-05 02:49:09 +00:00
parent eaea598d41
commit fe21329e16
8 changed files with 60 additions and 52 deletions

View 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;

View 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__));

View 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);
}

View 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 */

View 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)

View 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);

View 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);
}
}

View 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;