From: Eugene Syromyatnikov Date: Sat, 26 Aug 2017 22:54:24 +0000 (+0200) Subject: userfaultfd: streamline logic X-Git-Tag: v4.19~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d4555fd56e3837a9afdd1eb907c03e68ca4b0015;p=strace userfaultfd: streamline logic 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. --- diff --git a/userfaultfd.c b/userfaultfd.c index 965bd330..150d98fb 100644 --- a/userfaultfd.c +++ b/userfaultfd.c @@ -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 */