From 4de8de50d25f515100e7d13a9b7d551613d8d27e Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Thu, 14 Jul 2016 22:20:04 +0000 Subject: [PATCH] net.c: move parsers of sendmmsg and recvmmsg syscalls to mmsghdr.c * defs.h (decode_mmsgvec): Remove. * net.c: Do not include "msghdr.h". (SYS_FUNC(sendmmsg), SYS_FUNC(recvmmsg)): Move ... * mmsghdr.c: ... here. (decode_mmsgvec): Add static qualifier. --- defs.h | 1 - mmsghdr.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- net.c | 75 ------------------------------------------------------ 3 files changed, 75 insertions(+), 77 deletions(-) diff --git a/defs.h b/defs.h index 5b537cbe..f3847c7e 100644 --- a/defs.h +++ b/defs.h @@ -611,7 +611,6 @@ extern const char *sprintmode(unsigned int); extern const char *sprinttime(time_t); extern bool fetch_msghdr_namelen(struct tcb *, long, int *); extern void decode_msghdr(struct tcb *, const int *, long, unsigned long); -extern void decode_mmsgvec(struct tcb *, unsigned long, unsigned int, bool); extern void dumpiov_in_msghdr(struct tcb *, long, unsigned long); extern void dumpiov_in_mmsghdr(struct tcb *, long); extern void dumpiov_upto(struct tcb *, int, long, unsigned long); diff --git a/mmsghdr.c b/mmsghdr.c index b79bd7df..8501f4a5 100644 --- a/mmsghdr.c +++ b/mmsghdr.c @@ -50,7 +50,7 @@ decode_mmsghdr(struct tcb *tcp, const int *const p_user_msg_namelen, return fetched; } -void +static void decode_mmsgvec(struct tcb *tcp, unsigned long addr, unsigned int len, bool use_msg_len) { @@ -88,3 +88,77 @@ dumpiov_in_mmsghdr(struct tcb *tcp, long addr) (long) mmsg.msg_hdr.msg_iov, mmsg.msg_len); } } + +SYS_FUNC(sendmmsg) +{ + if (entering(tcp)) { + /* sockfd */ + printfd(tcp, tcp->u_arg[0]); + tprints(", "); + if (!verbose(tcp)) { + printaddr(tcp->u_arg[1]); + /* vlen */ + tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); + /* flags */ + printflags(msg_flags, tcp->u_arg[3], "MSG_???"); + return RVAL_DECODED; + } + } else { + decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_rval, false); + /* vlen */ + tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); + /* flags */ + printflags(msg_flags, tcp->u_arg[3], "MSG_???"); + } + return 0; +} + +SYS_FUNC(recvmmsg) +{ + static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE]; + + if (entering(tcp)) { + printfd(tcp, tcp->u_arg[0]); + tprints(", "); + if (verbose(tcp)) { + /* Abusing tcp->auxstr as temp storage. + * Will be used and cleared on syscall exit. + */ + tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]); + } else { + printaddr(tcp->u_arg[1]); + /* vlen */ + tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); + /* flags */ + printflags(msg_flags, tcp->u_arg[3], "MSG_???"); + tprints(", "); + print_timespec(tcp, tcp->u_arg[4]); + } + return 0; + } else { + if (verbose(tcp)) { + decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_rval, true); + /* vlen */ + tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); + /* flags */ + printflags(msg_flags, tcp->u_arg[3], "MSG_???"); + tprints(", "); + /* timeout on entrance */ + tprints(tcp->auxstr); + tcp->auxstr = NULL; + } + if (syserror(tcp)) + return 0; + if (tcp->u_rval == 0) { + tcp->auxstr = "Timeout"; + return RVAL_STR; + } + if (!verbose(tcp)) + return 0; + /* timeout on exit */ + snprintf(str, sizeof(str), "left %s", + sprint_timespec(tcp, tcp->u_arg[4])); + tcp->auxstr = str; + return RVAL_STR; + } +} diff --git a/net.c b/net.c index c3f4dbfb..a9f51dc2 100644 --- a/net.c +++ b/net.c @@ -29,7 +29,6 @@ */ #include "defs.h" -#include "msghdr.h" #include #include #include @@ -294,30 +293,6 @@ SYS_FUNC(sendmsg) return RVAL_DECODED; } -SYS_FUNC(sendmmsg) -{ - if (entering(tcp)) { - /* sockfd */ - printfd(tcp, tcp->u_arg[0]); - tprints(", "); - if (!verbose(tcp)) { - printaddr(tcp->u_arg[1]); - /* vlen */ - tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); - /* flags */ - printflags(msg_flags, tcp->u_arg[3], "MSG_???"); - return RVAL_DECODED; - } - } else { - decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_rval, false); - /* vlen */ - tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); - /* flags */ - printflags(msg_flags, tcp->u_arg[3], "MSG_???"); - } - return 0; -} - SYS_FUNC(recv) { if (entering(tcp)) { @@ -422,56 +397,6 @@ SYS_FUNC(recvmsg) return RVAL_DECODED; } -SYS_FUNC(recvmmsg) -{ - static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE]; - - if (entering(tcp)) { - printfd(tcp, tcp->u_arg[0]); - tprints(", "); - if (verbose(tcp)) { - /* Abusing tcp->auxstr as temp storage. - * Will be used and cleared on syscall exit. - */ - tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]); - } else { - printaddr(tcp->u_arg[1]); - /* vlen */ - tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); - /* flags */ - printflags(msg_flags, tcp->u_arg[3], "MSG_???"); - tprints(", "); - print_timespec(tcp, tcp->u_arg[4]); - } - return 0; - } else { - if (verbose(tcp)) { - decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_rval, true); - /* vlen */ - tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); - /* flags */ - printflags(msg_flags, tcp->u_arg[3], "MSG_???"); - tprints(", "); - /* timeout on entrance */ - tprints(tcp->auxstr); - tcp->auxstr = NULL; - } - if (syserror(tcp)) - return 0; - if (tcp->u_rval == 0) { - tcp->auxstr = "Timeout"; - return RVAL_STR; - } - if (!verbose(tcp)) - return 0; - /* timeout on exit */ - snprintf(str, sizeof(str), "left %s", - sprint_timespec(tcp, tcp->u_arg[4])); - tcp->auxstr = str; - return RVAL_STR; - } -} - #include "xlat/shutdown_modes.h" SYS_FUNC(shutdown) -- 2.40.0