Arch-abstraction:

- account for x86's strange argument passing (via memory) for mmap()


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2785
This commit is contained in:
Nicholas Nethercote
2004-10-18 14:47:48 +00:00
parent 411cf69104
commit f3ef39ea53
3 changed files with 38 additions and 29 deletions

View File

@@ -270,16 +270,12 @@ static Int munmap_inner(void *start, UInt length)
static Addr mmap_inner(void *start, UInt length, UInt prot, UInt flags, UInt fd, UInt offset)
{
UInt args[6];
args[0] = (UInt)start;
args[1] = length;
args[2] = prot;
args[3] = flags & ~(VKI_MAP_NOSYMS|VKI_MAP_CLIENT);
args[4] = fd;
args[5] = offset;
return VG_(do_syscall)(__NR_mmap, (UInt)(&(args[0])) );
Int ret;
PLATFORM_DO_MMAP(ret, start, length, prot,
flags & ~(VKI_MAP_NOSYMS|VKI_MAP_CLIENT),
fd, offset);
return ret;
}
/* Returns -1 on failure. */

View File

@@ -4183,17 +4183,11 @@ PRE(mmap)
int flags, int fd, off_t offset);
*/
UInt* arg_block = (UInt*)arg1;
UInt a1, a2, a3, a4, a5, a6;
SYSCALL_TRACK( pre_mem_read, tid, "mmap(args)", arg1, 6*sizeof(UInt) );
vg_assert(tid = tst->tid);
PLATFORM_GET_MMAP_ARGS(tst, a1, a2, a3, a4, a5, a6);
a1 = arg_block[0];
a2 = arg_block[1];
a3 = arg_block[2];
a4 = arg_block[3];
a5 = arg_block[4];
a6 = arg_block[5];
MAYBE_PRINTF("mmap ( %p, %d, %d, %d, %d, %d )\n",
a1, a2, a3, a4, a5, a6 );
@@ -4203,7 +4197,7 @@ PRE(mmap)
res = -VKI_ENOMEM;
}
} else {
a1 = VG_(find_map_space)(arg_block[0], arg_block[1], True);
a1 = VG_(find_map_space)(a1, a2, True);
if (a1 == 0)
res = -VKI_ENOMEM;
else
@@ -4211,16 +4205,7 @@ PRE(mmap)
}
if (res != -VKI_ENOMEM) {
UInt new_arg_block[6];
new_arg_block[0] = a1;
new_arg_block[1] = a2;
new_arg_block[2] = a3;
new_arg_block[3] = a4;
new_arg_block[4] = a5;
new_arg_block[5] = a6;
res = VG_(do_syscall)(__NR_mmap, new_arg_block);
PLATFORM_DO_MMAP(res, a1, a2, a3, a4, a5, a6);
if (!VG_(is_kerror)(res)) {
vg_assert(valid_client_addr(res, a2, tid, "mmap"));

View File

@@ -93,6 +93,34 @@ extern Addr VG_(do_useseg) ( UInt seg_selector, Addr virtual_addr );
#define UCONTEXT_FRAME_PTR(uc) ((uc)->uc_mcontext.ebp)
#define UCONTEXT_SYSCALL_NUM(uc) ((uc)->uc_mcontext.eax)
/* ---------------------------------------------------------------------
mmap() stuff
------------------------------------------------------------------ */
#define PLATFORM_DO_MMAP(ret, start, length, prot, flags, fd, offset) { \
UInt __args[6]; \
\
__args[0] = (UInt)(start); \
__args[1] = (length); \
__args[2] = (prot); \
__args[3] = (flags); \
__args[4] = (fd); \
__args[5] = (offset); \
\
ret = VG_(do_syscall)(__NR_mmap, (UInt)(&(__args[0])) ); \
}
#define PLATFORM_GET_MMAP_ARGS(tst, a1, a2, a3, a4, a5, a6) do {\
UInt *arg_block = (UInt*)PLATFORM_SYSCALL_ARG1(tst->arch); \
SYSCALL_TRACK( pre_mem_read, tst->tid, "mmap(args)", arg1, 6*sizeof(UWord) ); \
a1 = arg_block[0]; \
a2 = arg_block[1]; \
a3 = arg_block[2]; \
a4 = arg_block[3]; \
a5 = arg_block[4]; \
a6 = arg_block[5]; \
} while (0)
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/