LCOV - code coverage report
Current view: top level - strace - userfaultfd.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 3 3 100.0 %
Date: 2017-07-31 03:46:08 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
       3                 :            :  * Copyright (c) 2015-2017 The strace developers.
       4                 :            :  * All rights reserved.
       5                 :            :  *
       6                 :            :  * Redistribution and use in source and binary forms, with or without
       7                 :            :  * modification, are permitted provided that the following conditions
       8                 :            :  * are met:
       9                 :            :  * 1. Redistributions of source code must retain the above copyright
      10                 :            :  *    notice, this list of conditions and the following disclaimer.
      11                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      12                 :            :  *    notice, this list of conditions and the following disclaimer in the
      13                 :            :  *    documentation and/or other materials provided with the distribution.
      14                 :            :  * 3. The name of the author may not be used to endorse or promote products
      15                 :            :  *    derived from this software without specific prior written permission.
      16                 :            :  *
      17                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      18                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      19                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      20                 :            :  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
      21                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      22                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      23                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      24                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      25                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      26                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include "defs.h"
      30                 :            : #include "print_fields.h"
      31                 :            : #include <fcntl.h>
      32                 :            : 
      33                 :            : #include "xlat/uffd_flags.h"
      34                 :            : 
      35                 :          2 : SYS_FUNC(userfaultfd)
      36                 :            : {
      37                 :          2 :         printflags(uffd_flags, tcp->u_arg[0], "UFFD_???");
      38                 :            : 
      39                 :          2 :         return RVAL_DECODED | RVAL_FD;
      40                 :            : }
      41                 :            : 
      42                 :            : #ifdef HAVE_LINUX_USERFAULTFD_H
      43                 :            : # include <linux/ioctl.h>
      44                 :            : # include <linux/userfaultfd.h>
      45                 :            : 
      46                 :            : # include "xlat/uffd_api_features.h"
      47                 :            : # include "xlat/uffd_api_flags.h"
      48                 :            : # include "xlat/uffd_copy_flags.h"
      49                 :            : # include "xlat/uffd_register_ioctl_flags.h"
      50                 :            : # include "xlat/uffd_register_mode_flags.h"
      51                 :            : # include "xlat/uffd_zeropage_flags.h"
      52                 :            : 
      53                 :            : static void
      54                 :            : tprintf_uffdio_range(const struct uffdio_range *range)
      55                 :            : {
      56                 :            :         PRINT_FIELD_X("{", *range, start);
      57                 :            :         PRINT_FIELD_X(", ", *range, len);
      58                 :            :         tprints("}");
      59                 :            : }
      60                 :            : 
      61                 :            : #define PRINT_FIELD_UFFDIO_RANGE(prefix_, where_, field_)               \
      62                 :            :         do {                                                            \
      63                 :            :                 STRACE_PRINTF("%s%s=", (prefix_), #field_);           \
      64                 :            :                 tprintf_uffdio_range(&(where_).field_);                     \
      65                 :            :         } while (0)
      66                 :            : 
      67                 :            : int
      68                 :            : uffdio_ioctl(struct tcb *const tcp, const unsigned int code,
      69                 :            :              const kernel_ulong_t arg)
      70                 :            : {
      71                 :            :         switch (code) {
      72                 :            :         case UFFDIO_API: {
      73                 :            :                 uint64_t *entering_features;
      74                 :            :                 struct uffdio_api ua;
      75                 :            :                 if (entering(tcp)) {
      76                 :            :                         tprints(", ");
      77                 :            :                         if (umove_or_printaddr(tcp, arg, &ua))
      78                 :            :                                 return RVAL_DECODED | 1;
      79                 :            :                         PRINT_FIELD_X("{", ua, api);
      80                 :            :                         PRINT_FIELD_FLAGS(", ", ua, features, uffd_api_features,
      81                 :            :                                           "UFFD_FEATURE_???");
      82                 :            :                         entering_features = malloc(sizeof(*entering_features));
      83                 :            :                         if (entering_features) {
      84                 :            :                                 *entering_features = ua.features;
      85                 :            :                                 set_tcb_priv_data(tcp, entering_features, free);
      86                 :            :                         }
      87                 :            :                 } else {
      88                 :            :                         if (!syserror(tcp) && !umove(tcp, arg, &ua)) {
      89                 :            :                                 entering_features = get_tcb_priv_data(tcp);
      90                 :            :                                 if (!entering_features
      91                 :            :                                     || *entering_features != ua.features) {
      92                 :            :                                         PRINT_FIELD_FLAGS(" => ", ua, features,
      93                 :            :                                                           uffd_api_features,
      94                 :            :                                                           "UFFD_FEATURE_???");
      95                 :            :                                 }
      96                 :            :                                 PRINT_FIELD_FLAGS(", ", ua, ioctls,
      97                 :            :                                                   uffd_api_flags,
      98                 :            :                                                   "_UFFDIO_???");
      99                 :            :                         }
     100                 :            :                         tprints("}");
     101                 :            :                 }
     102                 :            :                 return 1;
     103                 :            :         }
     104                 :            : 
     105                 :            :         case UFFDIO_COPY: {
     106                 :            :                 struct uffdio_copy uc;
     107                 :            :                 if (entering(tcp)) {
     108                 :            :                         tprints(", ");
     109                 :            :                         if (umove_or_printaddr(tcp, arg, &uc))
     110                 :            :                                 return RVAL_DECODED | 1;
     111                 :            :                         PRINT_FIELD_X("{", uc, dst);
     112                 :            :                         PRINT_FIELD_X(", ", uc, src);
     113                 :            :                         PRINT_FIELD_X(", ", uc, len);
     114                 :            :                         PRINT_FIELD_FLAGS(", ", uc, mode, uffd_copy_flags,
     115                 :            :                                           "UFFDIO_COPY_???");
     116                 :            :                 } else {
     117                 :            :                         if (!syserror(tcp) && !umove(tcp, arg, &uc))
     118                 :            :                                 PRINT_FIELD_X(", ", uc, copy);
     119                 :            :                         tprints("}");
     120                 :            :                 }
     121                 :            :                 return 1;
     122                 :            :         }
     123                 :            : 
     124                 :            :         case UFFDIO_REGISTER: {
     125                 :            :                 struct uffdio_register ur;
     126                 :            :                 if (entering(tcp)) {
     127                 :            :                         tprints(", ");
     128                 :            :                         if (umove_or_printaddr(tcp, arg, &ur))
     129                 :            :                                 return RVAL_DECODED | 1;
     130                 :            :                         PRINT_FIELD_UFFDIO_RANGE("{", ur, range);
     131                 :            :                         PRINT_FIELD_FLAGS(", ", ur, mode,
     132                 :            :                                           uffd_register_mode_flags,
     133                 :            :                                           "UFFDIO_REGISTER_MODE_???");
     134                 :            :                 } else {
     135                 :            :                         if (!syserror(tcp) && !umove(tcp, arg, &ur)) {
     136                 :            :                                 PRINT_FIELD_FLAGS(", ", ur, ioctls,
     137                 :            :                                                   uffd_register_ioctl_flags,
     138                 :            :                                                   "UFFDIO_???");
     139                 :            :                         }
     140                 :            :                         tprints("}");
     141                 :            :                 }
     142                 :            :                 return 1;
     143                 :            :         }
     144                 :            : 
     145                 :            :         case UFFDIO_UNREGISTER:
     146                 :            :         case UFFDIO_WAKE: {
     147                 :            :                 struct uffdio_range ura;
     148                 :            :                 tprints(", ");
     149                 :            :                 if (!umove_or_printaddr(tcp, arg, &ura))
     150                 :            :                         tprintf_uffdio_range(&ura);
     151                 :            :                 return RVAL_DECODED | 1;
     152                 :            :         }
     153                 :            : 
     154                 :            :         case UFFDIO_ZEROPAGE: {
     155                 :            :                 struct uffdio_zeropage uz;
     156                 :            :                 if (entering(tcp)) {
     157                 :            :                         tprints(", ");
     158                 :            :                         if (umove_or_printaddr(tcp, arg, &uz))
     159                 :            :                                 return RVAL_DECODED | 1;
     160                 :            :                         PRINT_FIELD_UFFDIO_RANGE("{", uz, range);
     161                 :            :                         PRINT_FIELD_FLAGS(", ", uz, mode, uffd_zeropage_flags,
     162                 :            :                                           "UFFDIO_ZEROPAGE_???");
     163                 :            :                 } else {
     164                 :            :                         if (!syserror(tcp) && !umove(tcp, arg, &uz))
     165                 :            :                                 PRINT_FIELD_X(", ", uz, zeropage);
     166                 :            :                         tprints("}");
     167                 :            :                 }
     168                 :            :                 return 1;
     169                 :            :         }
     170                 :            : 
     171                 :            :         default:
     172                 :            :                 return RVAL_DECODED;
     173                 :            :         }
     174                 :            : }
     175                 :            : #endif /* HAVE_LINUX_USERFAULTFD_H */

Generated by: LCOV version 1.11