Introduce ANY_WORDSIZE_LESS_THAN_KERNEL_LONG macro

* defs.h (ANY_WORDSIZE_LESS_THAN_KERNEL_LONG): New macro.
(truncate_klong_to_current_wordsize,
truncate_kulong_to_current_wordsize): Use it.
* mem.c (SYS_FUNC(old_mmap)): Likewise.
* util.c (umoven, umovestr, dumpiov_upto): Likewise.
* syscall.c (trace_syscall_exiting): Likewise.
This commit is contained in:
2016-12-26 20:12:23 +00:00
parent 835fb3c5f2
commit f91679316b
4 changed files with 20 additions and 16 deletions

10
defs.h
View File

@ -796,6 +796,10 @@ extern unsigned current_klongsize;
# endif # endif
#endif #endif
#define ANY_WORDSIZE_LESS_THAN_KERNEL_LONG \
(SIZEOF_KERNEL_LONG_T > 4 \
&& (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined(current_wordsize)))
#define DECL_PRINTNUM(name) \ #define DECL_PRINTNUM(name) \
extern bool \ extern bool \
printnum_ ## name(struct tcb *, kernel_ulong_t addr, const char *fmt) \ printnum_ ## name(struct tcb *, kernel_ulong_t addr, const char *fmt) \
@ -864,8 +868,7 @@ DECL_PRINTPAIR(int64);
static inline kernel_long_t static inline kernel_long_t
truncate_klong_to_current_wordsize(const kernel_long_t v) truncate_klong_to_current_wordsize(const kernel_long_t v)
{ {
#if SIZEOF_KERNEL_LONG_T > 4 \ #if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
&& (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined current_wordsize)
if (current_wordsize < sizeof(v)) { if (current_wordsize < sizeof(v)) {
return (int) v; return (int) v;
} else } else
@ -878,8 +881,7 @@ truncate_klong_to_current_wordsize(const kernel_long_t v)
static inline kernel_ulong_t static inline kernel_ulong_t
truncate_kulong_to_current_wordsize(const kernel_ulong_t v) truncate_kulong_to_current_wordsize(const kernel_ulong_t v)
{ {
#if SIZEOF_KERNEL_LONG_T > 4 \ #if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
&& (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined current_wordsize)
if (current_wordsize < sizeof(v)) { if (current_wordsize < sizeof(v)) {
return (unsigned int) v; return (unsigned int) v;
} else } else

2
mem.c
View File

@ -94,7 +94,7 @@ print_mmap(struct tcb *tcp, kernel_ulong_t *u_arg, unsigned long long offset)
SYS_FUNC(old_mmap) SYS_FUNC(old_mmap)
{ {
kernel_ulong_t u_arg[6]; kernel_ulong_t u_arg[6];
# ifndef current_klongsize # if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
/* We are here only in a 32-bit personality. */ /* We are here only in a 32-bit personality. */
unsigned int narrow_arg[6]; unsigned int narrow_arg[6];
if (umove_or_printaddr(tcp, tcp->u_arg[0], &narrow_arg)) if (umove_or_printaddr(tcp, tcp->u_arg[0], &narrow_arg))

View File

@ -901,26 +901,30 @@ trace_syscall_exiting(struct tcb *tcp)
else { else {
switch (sys_res & RVAL_MASK) { switch (sys_res & RVAL_MASK) {
case RVAL_HEX: case RVAL_HEX:
#if SUPPORTED_PERSONALITIES > 1 #if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
if (current_wordsize < sizeof(tcp->u_rval)) if (current_wordsize < sizeof(tcp->u_rval)) {
tprintf("= %#x", tprintf("= %#x",
(unsigned int) tcp->u_rval); (unsigned int) tcp->u_rval);
else } else
#endif #endif
{
tprintf("= %#" PRI_klx, tcp->u_rval); tprintf("= %#" PRI_klx, tcp->u_rval);
}
break; break;
case RVAL_OCTAL: case RVAL_OCTAL:
tprints("= "); tprints("= ");
print_numeric_long_umask(tcp->u_rval); print_numeric_long_umask(tcp->u_rval);
break; break;
case RVAL_UDECIMAL: case RVAL_UDECIMAL:
#if SUPPORTED_PERSONALITIES > 1 #if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
if (current_wordsize < sizeof(tcp->u_rval)) if (current_wordsize < sizeof(tcp->u_rval)) {
tprintf("= %u", tprintf("= %u",
(unsigned int) tcp->u_rval); (unsigned int) tcp->u_rval);
else } else
#endif #endif
{
tprintf("= %" PRI_klu, tcp->u_rval); tprintf("= %" PRI_klu, tcp->u_rval);
}
break; break;
case RVAL_DECIMAL: case RVAL_DECIMAL:
tprintf("= %" PRI_kld, tcp->u_rval); tprintf("= %" PRI_kld, tcp->u_rval);

8
util.c
View File

@ -942,7 +942,7 @@ void
dumpiov_upto(struct tcb *const tcp, const int len, const kernel_ulong_t addr, dumpiov_upto(struct tcb *const tcp, const int len, const kernel_ulong_t addr,
kernel_ulong_t data_size) kernel_ulong_t data_size)
{ {
#if SUPPORTED_PERSONALITIES > 1 #if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
union { union {
struct { uint32_t base; uint32_t len; } *iov32; struct { uint32_t base; uint32_t len; } *iov32;
struct { uint64_t base; uint64_t len; } *iov64; struct { uint64_t base; uint64_t len; } *iov64;
@ -1141,8 +1141,7 @@ umoven(struct tcb *const tcp, kernel_ulong_t addr, unsigned int len,
char x[sizeof(long)]; char x[sizeof(long)];
} u; } u;
#if SIZEOF_KERNEL_LONG_T > 4 \ #if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
&& (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined current_wordsize)
if (current_wordsize < sizeof(addr) if (current_wordsize < sizeof(addr)
&& (addr & (~ (kernel_ulong_t) -1U))) { && (addr & (~ (kernel_ulong_t) -1U))) {
return -1; return -1;
@ -1290,8 +1289,7 @@ umovestr(struct tcb *const tcp, kernel_ulong_t addr, unsigned int len, char *lad
char x[sizeof(long)]; char x[sizeof(long)];
} u; } u;
#if SIZEOF_KERNEL_LONG_T > 4 \ #if ANY_WORDSIZE_LESS_THAN_KERNEL_LONG
&& (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined current_wordsize)
if (current_wordsize < sizeof(addr) if (current_wordsize < sizeof(addr)
&& (addr & (~ (kernel_ulong_t) -1U))) { && (addr & (~ (kernel_ulong_t) -1U))) {
return -1; return -1;