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.
This commit is contained in:
Дмитрий Левин 2016-12-26 17:55:59 +00:00
parent 885a97ec42
commit 19de67d239
4 changed files with 24 additions and 16 deletions

11
aio.c
View File

@ -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),

20
defs.h
View File

@ -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)

View File

@ -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];

View File

@ -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;