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.
This commit is contained in:
Дмитрий Левин 2016-07-14 22:20:04 +00:00
parent 7c37ce4055
commit 4de8de50d2
3 changed files with 75 additions and 77 deletions

1
defs.h
View File

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

View File

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

75
net.c
View File

@ -29,7 +29,6 @@
*/
#include "defs.h"
#include "msghdr.h"
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/uio.h>
@ -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)