From 885a97ec421b0a9378ed29291c868d5231d1a2af Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 26 Dec 2016 17:47:55 +0000 Subject: [PATCH] Replace widen_to_ulong with truncate_kulong_to_current_wordsize * defs.h (widen_to_ulong): Remove. (truncate_kulong_to_current_wordsize): New static inline function. * io.c (do_preadv, do_pwritev): Use it instead of widen_to_ulong. --- defs.h | 20 +++++++++++++------- io.c | 10 ++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/defs.h b/defs.h index 6591ba89..d6155a8e 100644 --- a/defs.h +++ b/defs.h @@ -871,13 +871,19 @@ DECL_PRINTPAIR(int64); # define widen_to_long(v) ((long)(v)) #endif -#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 -# define widen_to_ulong(v) \ - (current_wordsize == 4 ? (unsigned long) (uint32_t) (v) : \ - (unsigned long) (v)) -#else -# define widen_to_ulong(v) ((unsigned long)(v)) -#endif +static inline kernel_ulong_t +truncate_kulong_to_current_wordsize(const kernel_ulong_t v) +{ +#if SIZEOF_KERNEL_LONG_T > 4 \ + && (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined current_wordsize) + if (current_wordsize < sizeof(v)) { + return (unsigned int) v; + } else +#endif + { + return v; + } +} /* * Cast a pointer or a pointer-sized integer to kernel_ulong_t. diff --git a/io.c b/io.c index 94dcf88b..c41b66fa 100644 --- a/io.c +++ b/io.c @@ -203,12 +203,13 @@ do_preadv(struct tcb *tcp, const int flags_arg) printfd(tcp, tcp->u_arg[0]); tprints(", "); } else { - unsigned long len = widen_to_ulong(tcp->u_arg[2]); + kernel_ulong_t len = + truncate_kulong_to_current_wordsize(tcp->u_arg[2]); tprint_iov_upto(tcp, len, tcp->u_arg[1], syserror(tcp) ? IOV_DECODE_ADDR : IOV_DECODE_STR, tcp->u_rval); - tprintf(", %lu, ", len); + tprintf(", %" PRI_klu ", ", len); print_lld_from_low_high_val(tcp, 3); if (flags_arg >= 0) { tprints(", "); @@ -231,12 +232,13 @@ SYS_FUNC(preadv2) static int do_pwritev(struct tcb *tcp, const int flags_arg) { - unsigned long len = widen_to_ulong(tcp->u_arg[2]); + kernel_ulong_t len = + truncate_kulong_to_current_wordsize(tcp->u_arg[2]); printfd(tcp, tcp->u_arg[0]); tprints(", "); tprint_iov(tcp, len, tcp->u_arg[1], IOV_DECODE_STR); - tprintf(", %lu, ", len); + tprintf(", %" PRI_klu ", ", len); print_lld_from_low_high_val(tcp, 3); if (flags_arg >= 0) { tprints(", "); -- 2.40.0