]> granicus.if.org Git - strace/commitdiff
userfaultfd: use PRINT_FIELD_* macros
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 18 Jul 2017 21:54:38 +0000 (21:54 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 18 Jul 2017 21:54:38 +0000 (21:54 +0000)
This also fixes output correctness for struct uffdio_api.features.

* userfaultfd.c: Include "print_fields.h".
(tprintf_uffdio_range): Use PRINT_FIELD_X.
(PRINT_FIELD_UFFDIO_RANGE): New macro.
(uffdio_ioctl): Use it, PRINT_FIELD_FLAGS64, and PRINT_FIELD_X.
* tests/ioctl_uffdio.c (main): Update expected output.

tests/ioctl_uffdio.c
userfaultfd.c

index 817e3c72c0b8c98c0920bfe8e410465c20da3774..a4115c55e3d6c431698b0ecc87d8bc2c99cb6f5d 100644 (file)
@@ -70,8 +70,8 @@ main(void)
        api_struct->api = UFFD_API;
        api_struct->features = 0;
        rc = ioctl(fd, UFFDIO_API, api_struct);
-       printf("ioctl(%d, UFFDIO_API, {api=0xaa, features=0"
-              "features.out=%#" PRIx64 ", ioctls=1<<_UFFDIO_REGISTER|"
+       printf("ioctl(%d, UFFDIO_API, {api=0xaa, features=0"
+              " => features=%#" PRIx64 ", ioctls=1<<_UFFDIO_REGISTER|"
               "1<<_UFFDIO_UNREGISTER|1<<_UFFDIO_API",
               fd, (uint64_t)api_struct->features);
        api_struct->ioctls &= ~(1ull<<_UFFDIO_REGISTER|
index 6003588029c32a88dc755fd5c2a5a5039dfa4d19..41224e2f0d9bbabda6d1e284b560a129be38ae18 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 #include "defs.h"
+#include "print_fields.h"
 #include <fcntl.h>
 
 #include "xlat/uffd_flags.h"
@@ -51,10 +52,17 @@ SYS_FUNC(userfaultfd)
 static void
 tprintf_uffdio_range(const struct uffdio_range *range)
 {
-       tprintf("{start=%#" PRI__x64 ", len=%#" PRI__x64 "}",
-               range->start, range->len);
+       PRINT_FIELD_X("{", *range, start);
+       PRINT_FIELD_X(", ", *range, len);
+       tprints("}");
 }
 
+#define PRINT_FIELD_UFFDIO_RANGE(prefix_, where_, field_)              \
+       do {                                                            \
+               STRACE_PRINTF("%s%s=", (prefix_), #field_);             \
+               tprintf_uffdio_range(&(where_).field_);                 \
+       } while (0)
+
 int
 uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
             const kernel_ulong_t arg)
@@ -69,15 +77,14 @@ uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
                        /* Features is intended to contain some flags, but
                         * there aren't any defined yet.
                         */
-                       tprintf("{api=%#" PRI__x64
-                               ", features=%#" PRI__x64,
-                               ua.api, ua.features);
+                       PRINT_FIELD_X("{", ua, api);
+                       PRINT_FIELD_X(", ", ua, features);
                } else {
                        if (!syserror(tcp) && !umove(tcp, arg, &ua)) {
-                               tprintf(", features.out=%#" PRI__x64
-                                       ", ioctls=", ua.features);
-                               printflags64(uffd_api_flags, ua.ioctls,
-                                            "_UFFDIO_???");
+                               PRINT_FIELD_X(" => ", ua, features);
+                               PRINT_FIELD_FLAGS64(", ", ua, ioctls,
+                                                   uffd_api_flags,
+                                                   "_UFFDIO_???");
                        }
                        tprints("}");
                }
@@ -90,14 +97,14 @@ uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
                        tprints(", ");
                        if (umove_or_printaddr(tcp, arg, &uc))
                                return RVAL_DECODED | 1;
-                       tprintf("{dst=%#" PRI__x64 ", src=%#" PRI__x64
-                               ", len=%#" PRI__x64 ", mode=",
-                               uc.dst, uc.src, uc.len);
-                       printflags64(uffd_copy_flags, uc.mode,
-                                    "UFFDIO_COPY_???");
+                       PRINT_FIELD_X("{", uc, dst);
+                       PRINT_FIELD_X(", ", uc, src);
+                       PRINT_FIELD_X(", ", uc, len);
+                       PRINT_FIELD_FLAGS64(", ", uc, mode, uffd_copy_flags,
+                                           "UFFDIO_COPY_???");
                } else {
                        if (!syserror(tcp) && !umove(tcp, arg, &uc))
-                               tprintf(", copy=%#" PRI__x64, uc.copy);
+                               PRINT_FIELD_X(", ", uc, copy);
                        tprints("}");
                }
                return 1;
@@ -109,16 +116,15 @@ uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
                        tprints(", ");
                        if (umove_or_printaddr(tcp, arg, &ur))
                                return RVAL_DECODED | 1;
-                       tprints("{range=");
-                       tprintf_uffdio_range(&ur.range);
-                       tprints(", mode=");
-                       printflags64(uffd_register_mode_flags, ur.mode,
-                                    "UFFDIO_REGISTER_MODE_???");
+                       PRINT_FIELD_UFFDIO_RANGE("{", ur, range);
+                       PRINT_FIELD_FLAGS64(", ", ur, mode,
+                                           uffd_register_mode_flags,
+                                           "UFFDIO_REGISTER_MODE_???");
                } else {
                        if (!syserror(tcp) && !umove(tcp, arg, &ur)) {
-                               tprints(", ioctls=");
-                               printflags64(uffd_register_ioctl_flags,
-                                            ur.ioctls, "UFFDIO_???");
+                               PRINT_FIELD_FLAGS64(", ", ur, ioctls,
+                                                   uffd_register_ioctl_flags,
+                                                   "UFFDIO_???");
                        }
                        tprints("}");
                }
@@ -140,14 +146,12 @@ uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
                        tprints(", ");
                        if (umove_or_printaddr(tcp, arg, &uz))
                                return RVAL_DECODED | 1;
-                       tprints("{range=");
-                       tprintf_uffdio_range(&uz.range);
-                       tprints(", mode=");
-                       printflags64(uffd_zeropage_flags, uz.mode,
-                                    "UFFDIO_ZEROPAGE_???");
+                       PRINT_FIELD_UFFDIO_RANGE("{", uz, range);
+                       PRINT_FIELD_FLAGS64(", ", uz, mode, uffd_zeropage_flags,
+                                           "UFFDIO_ZEROPAGE_???");
                } else {
                        if (!syserror(tcp) && !umove(tcp, arg, &uz))
-                               tprintf(", zeropage=%#" PRI__x64, uz.zeropage);
+                               PRINT_FIELD_X(", ", uz, zeropage);
                        tprints("}");
                }
                return 1;