From 31f9cb6f4889c4b3b28993eb259f20ef097b2b6a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <dvlasenk@redhat.com> Date: Fri, 19 Aug 2011 16:11:07 +0200 Subject: [PATCH] Untangle ifdef forest in sys_mmap64. No code changes After careful analysis, it looks like !LINUX and ALPHA pass all seven parameters in registers; and in all other cases parameters are on stack (pointed to by tcp->u_arg[0]). In light of this, reorganize ifdefs, making them simpler, without changing any logic. After this, it's apparent we use tcp->u_arg[4,5,6] and possibly [7] without checking that it's valid to do so. So far, just add a comment about this. * mem.c (sys_mmap64): Rewrite ifdefs in a much simpler way. Add comments about apparent bugs. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com> --- mem.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/mem.c b/mem.c index f0ccfc79..de9b6bbe 100644 --- a/mem.c +++ b/mem.c @@ -334,25 +334,15 @@ sys_mmap(struct tcb *tcp) int sys_mmap64(struct tcb *tcp) { -#ifdef linux -#ifdef ALPHA - long *u_arg = tcp->u_arg; -#else /* !ALPHA */ - long u_arg[7]; -#endif /* !ALPHA */ -#else /* !linux */ - long *u_arg = tcp->u_arg; -#endif /* !linux */ - if (entering(tcp)) { -#ifdef linux -#ifndef ALPHA +#if !defined(LINUX) || defined(ALPHA) + long *u_arg = tcp->u_arg; +#else + long u_arg[7]; if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1) return 0; -#endif /* ALPHA */ -#endif /* linux */ - +#endif /* addr */ tprintf("%#lx, ", u_arg[0]); /* len */ @@ -369,13 +359,16 @@ sys_mmap64(struct tcb *tcp) #endif /* fd */ tprintf(", "); + /* BUG?! should be u_arg[4] (without tcp->)? */ printfd(tcp, tcp->u_arg[4]); /* offset */ + /* BUG?! on non-ALPHA linux, offset will be not in tcp->u_arg, + * but in local u_arg, but printllval prints tcp->u_arg! */ printllval(tcp, ", %#llx", 5); } return RVAL_HEX; } -#endif +#endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */ int -- 2.40.0