- tprintf("%u", cmsg_type);
- }
-}
-
-static void
-decode_msg_control(struct tcb *tcp, unsigned long addr, size_t len)
-{
- const size_t cmsg_size =
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
- (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
-#endif
- sizeof(struct cmsghdr);
-
- if (!len)
- return;
- tprints(", msg_control=");
-
- char *buf = len < cmsg_size ? NULL : malloc(len);
- if (!buf || umoven(tcp, addr, len, buf) < 0) {
- printaddr(addr);
- free(buf);
- return;
- }
-
- union_cmsghdr u = { .ptr = buf };
-
- tprints("[");
- while (len >= cmsg_size) {
- size_t cmsg_len =
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
- (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
-#endif
- u.cmsg->cmsg_len;
- int cmsg_level =
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
- (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
-#endif
- u.cmsg->cmsg_level;
- int cmsg_type =
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
- (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
-#endif
- u.cmsg->cmsg_type;
-
- if (u.ptr != buf)
- tprints(", ");
- tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
- printxval(socketlayers, cmsg_level, "SOL_???");
- tprints(", cmsg_type=");
-
- if (cmsg_len > len)
- cmsg_len = len;
-
- print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
- (const void *) (u.ptr + cmsg_size),
- cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
- tprints("}");
-
- if (cmsg_len < cmsg_size) {
- len -= cmsg_size;
- break;
- }
- cmsg_len = (cmsg_len + current_wordsize - 1) &
- (size_t) ~(current_wordsize - 1);
- if (cmsg_len >= len) {
- len = 0;
- break;
- }
- u.ptr += cmsg_len;
- len -= cmsg_len;
- }
- if (len)
- tprints(", ...");
- tprints("]");
- free(buf);
-}
-
-static void
-print_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
-{
- tprints("{msg_name=");
- decode_sockaddr(tcp, (long)msg->msg_name, msg->msg_namelen);
- tprintf(", msg_namelen=%d", msg->msg_namelen);
-
- tprints(", msg_iov=");
- tprint_iov_upto(tcp, (unsigned long) msg->msg_iovlen,
- (unsigned long) msg->msg_iov, IOV_DECODE_STR, data_size);
- tprintf(", msg_iovlen=%lu", (unsigned long) msg->msg_iovlen);
-
- decode_msg_control(tcp, (unsigned long) msg->msg_control,
- msg->msg_controllen);
- tprintf(", msg_controllen=%lu", (unsigned long) msg->msg_controllen);
-
- tprints(", msg_flags=");
- printflags(msg_flags, msg->msg_flags, "MSG_???");
- tprints("}");
-}
-
-struct msghdr32 {
- uint32_t /* void* */ msg_name;
- uint32_t /* socklen_t */msg_namelen;
- uint32_t /* iovec* */ msg_iov;
- uint32_t /* size_t */ msg_iovlen;
- uint32_t /* void* */ msg_control;
- uint32_t /* size_t */ msg_controllen;
- uint32_t /* int */ msg_flags;
-};
-struct mmsghdr32 {
- struct msghdr32 msg_hdr;
- uint32_t /* unsigned */ msg_len;
-};
-
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
-static void
-copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
-{
- to_msg->msg_name = (void*)(long)from_msg32->msg_name;
- to_msg->msg_namelen = from_msg32->msg_namelen;
- to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
- to_msg->msg_iovlen = from_msg32->msg_iovlen;
- to_msg->msg_control = (void*)(long)from_msg32->msg_control;
- to_msg->msg_controllen = from_msg32->msg_controllen;
- to_msg->msg_flags = from_msg32->msg_flags;
-}
-#endif
-
-static bool
-fetch_msghdr(struct tcb *tcp, long addr, struct msghdr *msg)
-{
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
- if (current_wordsize == 4) {
- struct msghdr32 msg32;
-
- if (umove(tcp, addr, &msg32) < 0)
- return false;
- copy_from_msghdr32(msg, &msg32);
- } else
-#endif
- if (umove(tcp, addr, msg) < 0)
- return false;
- return true;
-}
-
-static bool
-fetch_mmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
-{
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
- if (current_wordsize == 4) {
- struct mmsghdr32 mmsg32;
-
- addr += sizeof(struct mmsghdr32) * idx;
- if (umove(tcp, addr, &mmsg32) < 0)
- return false;
-
- copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
- mmsg->msg_len = mmsg32.msg_len;
- } else
-#endif
- {
- addr += sizeof(*mmsg) * idx;
- if (umove(tcp, addr, mmsg) < 0)
- return false;
- }
- return true;
-}
-
-static void
-decode_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
-{
- struct msghdr msg;
-
- if (verbose(tcp) && fetch_msghdr(tcp, addr, &msg))
- print_msghdr(tcp, &msg, data_size);
- else
- printaddr(addr);
-}
-
-void
-dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
-{
- struct msghdr msg;
-
- if (fetch_msghdr(tcp, addr, &msg))
- dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
-}
-
-static void
-decode_mmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
-{
- struct mmsghdr mmsg;
-
- if (fetch_mmsghdr(tcp, addr, idx, &mmsg)) {
- tprints("{");
- print_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
- tprintf(", %u}", mmsg.msg_len);
- }
- else
- printaddr(addr);
-}
-
-static void
-decode_mmsg(struct tcb *tcp, unsigned long msg_len)
-{
- /* mmsgvec */
- if (syserror(tcp)) {
- printaddr(tcp->u_arg[1]);
- } else {
- unsigned int len = tcp->u_rval;
- unsigned int i;
-
- tprints("{");
- for (i = 0; i < len; ++i) {
- if (i)
- tprints(", ");
- decode_mmsghdr(tcp, tcp->u_arg[1], i, msg_len);
- }
- tprints("}");
- }
- /* vlen */
- tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
- /* flags */
- printflags(msg_flags, tcp->u_arg[3], "MSG_???");
-}
-
-void
-dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
-{
- unsigned int len = tcp->u_rval;
- unsigned int i;
- struct mmsghdr mmsg;
-
- for (i = 0; i < len; ++i) {
- if (fetch_mmsghdr(tcp, addr, i, &mmsg)) {
- tprintf(" = %lu buffers in vector %u\n",
- (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
- dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
- (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
- }