From 19de67d239ada60e4e0c2add5077b89bdc8bf4b2 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 26 Dec 2016 17:55:59 +0000 Subject: [PATCH] Replace widen_to_long with truncate_klong_to_current_wordsize * defs.h (widen_to_long): Remove. (truncate_klong_to_current_wordsize): New static inline function. * aio.c (SYS_FUNC(io_submit), SYS_FUNC(io_getevents): Use it instead of widen_to_long. * linux/sparc64/get_syscall_args.c (get_syscall_args): Update comment. * linux/x86_64/get_syscall_args.c (get_syscall_args): Likewise. --- aio.c | 11 ++++++----- defs.h | 20 ++++++++++++-------- linux/sparc64/get_syscall_args.c | 3 ++- linux/x86_64/get_syscall_args.c | 6 ++++-- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/aio.c b/aio.c index dc9ce467..47a4038a 100644 --- a/aio.c +++ b/aio.c @@ -180,12 +180,13 @@ print_iocbp(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) SYS_FUNC(io_submit) { - const long nr = widen_to_long(tcp->u_arg[1]); + const kernel_long_t nr = + truncate_klong_to_current_wordsize(tcp->u_arg[1]); const kernel_ulong_t addr = tcp->u_arg[2]; kernel_ulong_t iocbp; printaddr(tcp->u_arg[0]); - tprintf(", %ld, ", nr); + tprintf(", %" PRI_kld ", ", nr); if (nr < 0) printaddr(addr); @@ -236,9 +237,9 @@ SYS_FUNC(io_getevents) { if (entering(tcp)) { printaddr(tcp->u_arg[0]); - tprintf(", %ld, %ld, ", - widen_to_long(tcp->u_arg[1]), - widen_to_long(tcp->u_arg[2])); + tprintf(", %" PRI_kld ", %" PRI_kld ", ", + truncate_klong_to_current_wordsize(tcp->u_arg[1]), + truncate_klong_to_current_wordsize(tcp->u_arg[2])); } else { struct io_event buf; print_array(tcp, tcp->u_arg[3], tcp->u_rval, &buf, sizeof(buf), diff --git a/defs.h b/defs.h index d6155a8e..fbf0d40e 100644 --- a/defs.h +++ b/defs.h @@ -861,15 +861,19 @@ DECL_PRINTPAIR(int); DECL_PRINTPAIR(int64); #undef DECL_PRINTPAIR -/* In many, many places we play fast and loose and use - * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc. - * We probably need to use widen_to_long() instead: - */ -#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 -# define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v)) -#else -# define widen_to_long(v) ((long)(v)) +static inline kernel_long_t +truncate_klong_to_current_wordsize(const kernel_long_t v) +{ +#if SIZEOF_KERNEL_LONG_T > 4 \ + && (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined current_wordsize) + if (current_wordsize < sizeof(v)) { + return (int) v; + } else #endif + { + return v; + } +} static inline kernel_ulong_t truncate_kulong_to_current_wordsize(const kernel_ulong_t v) diff --git a/linux/sparc64/get_syscall_args.c b/linux/sparc64/get_syscall_args.c index 11f003e0..f5c1aa6f 100644 --- a/linux/sparc64/get_syscall_args.c +++ b/linux/sparc64/get_syscall_args.c @@ -5,7 +5,8 @@ get_syscall_args(struct tcb *tcp) if (tcp->currpers == 1) { /* * Zero-extend from 32 bits. - * Use widen_to_long(tcp->u_arg[N]) in syscall handlers + * Use truncate_klong_to_current_wordsize(tcp->u_arg[N]) + * in syscall handlers * if you need to use *sign-extended* parameter. */ tcp->u_arg[0] = (uint32_t) sparc_regs.u_regs[U_REG_O0 + 0]; diff --git a/linux/x86_64/get_syscall_args.c b/linux/x86_64/get_syscall_args.c index df3691a6..f285ac32 100644 --- a/linux/x86_64/get_syscall_args.c +++ b/linux/x86_64/get_syscall_args.c @@ -7,7 +7,8 @@ get_syscall_args(struct tcb *tcp) if (tcp->s_ent->sys_flags & COMPAT_SYSCALL_TYPES) { /* * X32 compat syscall: zero-extend from 32 bits. - * Use widen_to_long(tcp->u_arg[N]) in syscall handlers + * Use truncate_klong_to_current_wordsize(tcp->u_arg[N]) + * in syscall handlers * if you need to use *sign-extended* parameter. */ tcp->u_arg[0] = (uint32_t) x86_64_regs.rdi; @@ -27,7 +28,8 @@ get_syscall_args(struct tcb *tcp) } else { /* * i386 ABI: zero-extend from 32 bits. - * Use widen_to_long(tcp->u_arg[N]) in syscall handlers + * Use truncate_klong_to_current_wordsize(tcp->u_arg[N]) + * in syscall handlers * if you need to use *sign-extended* parameter. */ tcp->u_arg[0] = (uint32_t) i386_regs.ebx; -- 2.40.0