]> granicus.if.org Git - strace/blobdiff - aio.c
Add a enum for decoding to tprint_iov() and tprint_iov_upto()
[strace] / aio.c
diff --git a/aio.c b/aio.c
index e9d36e3ce515540c79dabc15a76239a8e16aad4b..29562d2d6b37ed034e3747b61d750af3f1e205b8 100644 (file)
--- a/aio.c
+++ b/aio.c
@@ -140,7 +140,9 @@ print_iocb(struct tcb *tcp, const struct iocb *cb)
                if (iocb_is_valid(cb)) {
                        tprints(", iovec=");
                        tprint_iov(tcp, cb->aio_nbytes, cb->aio_buf,
-                                  cb->aio_lio_opcode == 8);
+                                  cb->aio_lio_opcode == 8
+                                  ? IOV_DECODE_STR
+                                  : IOV_DECODE_ADDR);
                } else {
                        tprintf(", buf=%#" PRIx64 ", nbytes=%" PRIu64,
                                (uint64_t) cb->aio_buf,
@@ -154,52 +156,54 @@ print_iocb(struct tcb *tcp, const struct iocb *cb)
        }
 }
 
-SYS_FUNC(io_submit)
+static bool
+print_iocbp(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
 {
-       long nr = tcp->u_arg[1];
-       /* if nr <= 0, we end up printing just "[]" */
-       tprintf("%lu, %ld, [", tcp->u_arg[0], nr);
-       {
-               long i;
-               long iocbs = tcp->u_arg[2];
-
-               for (i = 0; i < nr; ++i, iocbs += current_wordsize) {
-                       unsigned long iocbp;
-                       struct iocb cb;
-
-                       if (i)
-                               tprints(", ");
-
-                       if (umove_ulong_or_printaddr(tcp, iocbs, &iocbp)) {
-                               /*
-                                * No point in trying to read the whole array
-                                * because nr can be ridiculously large.
-                                */
-                               break;
-                       }
+       unsigned long addr;
+       struct iocb cb;
 
-                       tprints("{");
-                       if (!umove_or_printaddr(tcp, iocbp, &cb))
-                               print_iocb(tcp, &cb);
-                       tprints("}");
-               }
+       if (elem_size < sizeof(long)) {
+               addr = * (unsigned int *) elem_buf;
+       } else {
+               addr = * (unsigned long *) elem_buf;
        }
-       tprints("]");
+
+       tprints("{");
+       if (!umove_or_printaddr(tcp, addr, &cb))
+               print_iocb(tcp, &cb);
+       tprints("}");
+
+       return true;
+}
+
+SYS_FUNC(io_submit)
+{
+       const long nr = widen_to_long(tcp->u_arg[1]);
+       const unsigned long addr = tcp->u_arg[2];
+       unsigned long iocbp;
+
+       tprintf("%lu, %ld, ", tcp->u_arg[0], nr);
+
+       if (nr < 0)
+               printaddr(addr);
+       else
+               print_array(tcp, addr, nr, &iocbp, current_wordsize,
+                           umoven_or_printaddr, print_iocbp, 0);
+
        return RVAL_DECODED;
 }
 
-static int
-print_io_event(struct tcb *tcp, const long addr)
+static bool
+print_io_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
 {
-       struct io_event event;
+       struct io_event *event = elem_buf;
 
-       if (umove_or_printaddr(tcp, addr, &event))
-               return -1;
        tprintf("{data=%#" PRIx64 ", obj=%#" PRIx64
                ", res=%" PRId64 ", res2=%" PRId64 "}",
-               (uint64_t) event.data, (uint64_t) event.obj,
-               (int64_t) event.res, (int64_t) event.res2);
-       return 0;
+               (uint64_t) event->data, (uint64_t) event->obj,
+               (int64_t) event->res, (int64_t) event->res2);
+
+       return true;
 }
 
 SYS_FUNC(io_cancel)
@@ -215,7 +219,10 @@ SYS_FUNC(io_cancel)
                }
                tprints(", ");
        } else {
-               print_io_event(tcp, tcp->u_arg[2]);
+               struct io_event event;
+
+               if (!umove_or_printaddr(tcp, tcp->u_arg[2], &event))
+                       print_io_event(tcp, &event, sizeof(event), 0);
        }
        return 0;
 }
@@ -224,27 +231,22 @@ SYS_FUNC(io_getevents)
 {
        if (entering(tcp)) {
                tprintf("%lu, %ld, %ld, ",
-                       tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
+                       tcp->u_arg[0],
+                       widen_to_long(tcp->u_arg[1]),
+                       widen_to_long(tcp->u_arg[2]));
        } else {
-               if (tcp->u_rval == 0) {
-                       tprints("[]");
-               } else {
-                       struct io_event *events = (void *)tcp->u_arg[3];
-                       long i, nr = tcp->u_rval;
-
-                       for (i = 0; i < nr; i++, events++) {
-                               if (i == 0)
-                                       tprints("[");
-                               else
-                                       tprints(", ");
-
-                               if (print_io_event(tcp, (long)events))
-                                       break;
-                       }
-                       tprints("], ");
-               }
-
+               struct io_event buf;
+               print_array(tcp, tcp->u_arg[3], tcp->u_rval, &buf, sizeof(buf),
+                           umoven_or_printaddr, print_io_event, 0);
+               tprints(", ");
+               /*
+                * Since the timeout parameter is read by the kernel
+                * on entering syscall, it has to be decoded the same way
+                * whether the syscall has failed or not.
+                */
+               temporarily_clear_syserror(tcp);
                print_timespec(tcp, tcp->u_arg[4]);
+               restore_cleared_syserror(tcp);
        }
        return 0;
 }