]> granicus.if.org Git - strace/commitdiff
userfaultfd: streamline logic
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sat, 26 Aug 2017 22:54:24 +0000 (00:54 +0200)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 28 Aug 2017 00:33:20 +0000 (02:33 +0200)
Make userfaultfd ioctl handling more in line with other ioctl decoders.

* userfaultfd.c (uffdio_ioctl): Return RVAL_DECODED | 1, break instead
of returning in specific command handlers, return 0 on entering paths,
move exiting paths out of else branch of entering(tcp) condition.

userfaultfd.c

index 965bd330779b7bccd525678a68c537435233a9b6..150d98fbde36e5b4b4d49fad53af6fa8a9c5e2ef 100644 (file)
@@ -72,10 +72,11 @@ uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
        case UFFDIO_API: {
                uint64_t *entering_features;
                struct uffdio_api ua;
+
                if (entering(tcp)) {
                        tprints(", ");
                        if (umove_or_printaddr(tcp, arg, &ua))
-                               return RVAL_DECODED | 1;
+                               break;
                        PRINT_FIELD_X("{", ua, api);
                        PRINT_FIELD_FLAGS(", ", ua, features, uffd_api_features,
                                          "UFFD_FEATURE_???");
@@ -84,26 +85,32 @@ uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
                                *entering_features = ua.features;
                                set_tcb_priv_data(tcp, entering_features, free);
                        }
-               } else {
-                       if (!syserror(tcp) && !umove(tcp, arg, &ua)) {
-                               entering_features = get_tcb_priv_data(tcp);
-                               if (!entering_features
-                                   || *entering_features != ua.features) {
-                                       PRINT_FIELD_FLAGS(" => ", ua, features,
-                                                         uffd_api_features,
-                                                         "UFFD_FEATURE_???");
-                               }
-                               PRINT_FIELD_FLAGS(", ", ua, ioctls,
-                                                 uffd_api_flags,
-                                                 "_UFFDIO_???");
+
+                       return 0;
+               }
+
+               if (!syserror(tcp) && !umove(tcp, arg, &ua)) {
+                       entering_features = get_tcb_priv_data(tcp);
+
+                       if (!entering_features
+                           || *entering_features != ua.features) {
+                               PRINT_FIELD_FLAGS(" => ", ua, features,
+                                                 uffd_api_features,
+                                                 "UFFD_FEATURE_???");
                        }
-                       tprints("}");
+
+                       PRINT_FIELD_FLAGS(", ", ua, ioctls, uffd_api_flags,
+                                         "_UFFDIO_???");
                }
-               return 1;
+
+               tprints("}");
+
+               break;
        }
 
        case UFFDIO_COPY: {
                struct uffdio_copy uc;
+
                if (entering(tcp)) {
                        tprints(", ");
                        if (umove_or_printaddr(tcp, arg, &uc))
@@ -113,16 +120,21 @@ uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
                        PRINT_FIELD_X(", ", uc, len);
                        PRINT_FIELD_FLAGS(", ", uc, mode, uffd_copy_flags,
                                          "UFFDIO_COPY_???");
-               } else {
-                       if (!syserror(tcp) && !umove(tcp, arg, &uc))
-                               PRINT_FIELD_X(", ", uc, copy);
-                       tprints("}");
+
+                       return 0;
                }
-               return 1;
+
+               if (!syserror(tcp) && !umove(tcp, arg, &uc))
+                       PRINT_FIELD_X(", ", uc, copy);
+
+               tprints("}");
+
+               break;
        }
 
        case UFFDIO_REGISTER: {
                struct uffdio_register ur;
+
                if (entering(tcp)) {
                        tprints(", ");
                        if (umove_or_printaddr(tcp, arg, &ur))
@@ -131,28 +143,36 @@ uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
                        PRINT_FIELD_FLAGS(", ", ur, mode,
                                          uffd_register_mode_flags,
                                          "UFFDIO_REGISTER_MODE_???");
-               } else {
-                       if (!syserror(tcp) && !umove(tcp, arg, &ur)) {
-                               PRINT_FIELD_FLAGS(", ", ur, ioctls,
-                                                 uffd_register_ioctl_flags,
-                                                 "UFFDIO_???");
-                       }
-                       tprints("}");
+
+                       return 0;
+               }
+
+               if (!syserror(tcp) && !umove(tcp, arg, &ur)) {
+                       PRINT_FIELD_FLAGS(", ", ur, ioctls,
+                                         uffd_register_ioctl_flags,
+                                         "UFFDIO_???");
                }
-               return 1;
+
+               tprints("}");
+
+               break;
        }
 
        case UFFDIO_UNREGISTER:
        case UFFDIO_WAKE: {
                struct uffdio_range ura;
+
                tprints(", ");
+
                if (!umove_or_printaddr(tcp, arg, &ura))
                        tprintf_uffdio_range(&ura);
-               return RVAL_DECODED | 1;
+
+               break;
        }
 
        case UFFDIO_ZEROPAGE: {
                struct uffdio_zeropage uz;
+
                if (entering(tcp)) {
                        tprints(", ");
                        if (umove_or_printaddr(tcp, arg, &uz))
@@ -160,16 +180,22 @@ uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
                        PRINT_FIELD_UFFDIO_RANGE("{", uz, range);
                        PRINT_FIELD_FLAGS(", ", uz, mode, uffd_zeropage_flags,
                                          "UFFDIO_ZEROPAGE_???");
-               } else {
-                       if (!syserror(tcp) && !umove(tcp, arg, &uz))
-                               PRINT_FIELD_X(", ", uz, zeropage);
-                       tprints("}");
+
+                       return 0;
                }
-               return 1;
+
+               if (!syserror(tcp) && !umove(tcp, arg, &uz))
+                       PRINT_FIELD_X(", ", uz, zeropage);
+
+               tprints("}");
+
+               break;
        }
 
        default:
                return RVAL_DECODED;
        }
+
+       return RVAL_DECODED | 1;
 }
 #endif /* HAVE_LINUX_USERFAULTFD_H */