mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-12 06:11:37 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user