From: Dmitry V. Levin Date: Thu, 14 Jul 2016 22:26:28 +0000 (+0000) Subject: net.c: move parsers of sendmsg and recvmsg syscalls to msghdr.c X-Git-Tag: v4.13~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc84fa3646f6a4f9e81d47059fe0c84a9b70f3b4;p=strace net.c: move parsers of sendmsg and recvmsg syscalls to msghdr.c * defs.h (fetch_msghdr_namelen, decode_msghdr): Remove. * net.c (SYS_FUNC(sendmsg), SYS_FUNC(recvmsg)): Move ... * msghdr.c: ... here. (fetch_msghdr_namelen, decode_msghdr): Add static qualifier. --- diff --git a/defs.h b/defs.h index f3847c7e..cf55f114 100644 --- a/defs.h +++ b/defs.h @@ -609,8 +609,6 @@ extern int printflags64(const struct xlat *, uint64_t, const char *); extern const char *sprintflags(const char *, const struct xlat *, uint64_t); 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 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/msghdr.c b/msghdr.c index b805aa33..c70a93ae 100644 --- a/msghdr.c +++ b/msghdr.c @@ -367,7 +367,7 @@ print_struct_msghdr(struct tcb *tcp, const struct msghdr *msg, tprints("}"); } -bool +static bool fetch_msghdr_namelen(struct tcb *tcp, const long addr, int *const p_msg_namelen) { struct msghdr msg; @@ -380,7 +380,7 @@ fetch_msghdr_namelen(struct tcb *tcp, const long addr, int *const p_msg_namelen) } } -void +static void decode_msghdr(struct tcb *tcp, const int *const p_user_msg_namelen, const long addr, const unsigned long data_size) { @@ -400,3 +400,46 @@ dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size) if (fetch_struct_msghdr(tcp, addr, &msg)) dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size); } + +SYS_FUNC(sendmsg) +{ + printfd(tcp, tcp->u_arg[0]); + tprints(", "); + decode_msghdr(tcp, 0, tcp->u_arg[1], (unsigned long) -1L); + /* flags */ + tprints(", "); + printflags(msg_flags, tcp->u_arg[2], "MSG_???"); + + return RVAL_DECODED; +} + +SYS_FUNC(recvmsg) +{ + int msg_namelen; + + if (entering(tcp)) { + printfd(tcp, tcp->u_arg[0]); + tprints(", "); + if (fetch_msghdr_namelen(tcp, tcp->u_arg[1], &msg_namelen)) { + /* abuse of auxstr to retain state */ + tcp->auxstr = (void *) (long) msg_namelen; + return 0; + } + printaddr(tcp->u_arg[1]); + } else { + msg_namelen = (long) tcp->auxstr; + tcp->auxstr = NULL; + + if (syserror(tcp)) + tprintf("{msg_namelen=%d}", msg_namelen); + else + decode_msghdr(tcp, &msg_namelen, tcp->u_arg[1], + tcp->u_rval); + } + + /* flags */ + tprints(", "); + printflags(msg_flags, tcp->u_arg[2], "MSG_???"); + + return RVAL_DECODED; +} diff --git a/net.c b/net.c index a9f51dc2..47861cf8 100644 --- a/net.c +++ b/net.c @@ -281,18 +281,6 @@ SYS_FUNC(sendto) return RVAL_DECODED; } -SYS_FUNC(sendmsg) -{ - printfd(tcp, tcp->u_arg[0]); - tprints(", "); - decode_msghdr(tcp, 0, tcp->u_arg[1], (unsigned long) -1L); - /* flags */ - tprints(", "); - printflags(msg_flags, tcp->u_arg[2], "MSG_???"); - - return RVAL_DECODED; -} - SYS_FUNC(recv) { if (entering(tcp)) { @@ -366,37 +354,6 @@ SYS_FUNC(recvfrom) return 0; } -SYS_FUNC(recvmsg) -{ - int msg_namelen; - - if (entering(tcp)) { - printfd(tcp, tcp->u_arg[0]); - tprints(", "); - if (fetch_msghdr_namelen(tcp, tcp->u_arg[1], &msg_namelen)) { - /* abuse of auxstr to retain state */ - tcp->auxstr = (void *) (long) msg_namelen; - return 0; - } - printaddr(tcp->u_arg[1]); - } else { - msg_namelen = (long) tcp->auxstr; - tcp->auxstr = NULL; - - if (syserror(tcp)) - tprintf("{msg_namelen=%d}", msg_namelen); - else - decode_msghdr(tcp, &msg_namelen, tcp->u_arg[1], - tcp->u_rval); - } - - /* flags */ - tprints(", "); - printflags(msg_flags, tcp->u_arg[2], "MSG_???"); - - return RVAL_DECODED; -} - #include "xlat/shutdown_modes.h" SYS_FUNC(shutdown)