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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
       3                 :            :  * Copyright (c) 2014-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                 :            : 
      31                 :            : #include "xlat/kexec_load_flags.h"
      32                 :            : #include "xlat/kexec_arch_values.h"
      33                 :            : 
      34                 :            : #ifndef KEXEC_ARCH_MASK
      35                 :            : # define KEXEC_ARCH_MASK 0xffff0000
      36                 :            : #endif
      37                 :            : #ifndef KEXEC_SEGMENT_MAX
      38                 :            : # define KEXEC_SEGMENT_MAX 16
      39                 :            : #endif
      40                 :            : 
      41                 :            : static bool
      42                 :         64 : print_seg(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
      43                 :            : {
      44                 :            :         const kernel_ulong_t *seg;
      45                 :            :         kernel_ulong_t seg_buf[4];
      46                 :            : 
      47         [ +  + ]:         64 :         if (elem_size < sizeof(seg_buf)) {
      48                 :            :                 unsigned int i;
      49                 :            : 
      50         [ +  + ]:        160 :                 for (i = 0; i < ARRAY_SIZE(seg_buf); ++i)
      51                 :        128 :                         seg_buf[i] = ((unsigned int *) elem_buf)[i];
      52                 :            :                 seg = seg_buf;
      53                 :            :         } else {
      54                 :            :                 seg = elem_buf;
      55                 :            :         }
      56                 :            : 
      57                 :         64 :         tprints("{buf=");
      58                 :         64 :         printaddr(seg[0]);
      59                 :         64 :         tprintf(", bufsz=%" PRI_klu ", mem=", seg[1]);
      60                 :         64 :         printaddr(seg[2]);
      61                 :         64 :         tprintf(", memsz=%" PRI_klu "}", seg[3]);
      62                 :            : 
      63                 :         64 :         return true;
      64                 :            : }
      65                 :            : 
      66                 :            : static void
      67                 :         14 : print_kexec_segments(struct tcb *const tcp, const kernel_ulong_t addr,
      68                 :            :                      const kernel_ulong_t len)
      69                 :            : {
      70         [ +  + ]:         14 :         if (len > KEXEC_SEGMENT_MAX) {
      71                 :          4 :                 printaddr(addr);
      72                 :          4 :                 return;
      73                 :            :         }
      74                 :            : 
      75                 :            :         kernel_ulong_t seg[4];
      76                 :         10 :         const size_t sizeof_seg = ARRAY_SIZE(seg) * current_wordsize;
      77                 :            : 
      78                 :         10 :         print_array(tcp, addr, len, seg, sizeof_seg,
      79                 :            :                     umoven_or_printaddr, print_seg, 0);
      80                 :            : }
      81                 :            : 
      82                 :         14 : SYS_FUNC(kexec_load)
      83                 :            : {
      84                 :            :         /* entry, nr_segments */
      85                 :         14 :         printaddr(tcp->u_arg[0]);
      86                 :         14 :         tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
      87                 :            : 
      88                 :            :         /* segments */
      89                 :         14 :         print_kexec_segments(tcp, tcp->u_arg[2], tcp->u_arg[1]);
      90                 :         14 :         tprints(", ");
      91                 :            : 
      92                 :            :         /* flags */
      93                 :         14 :         kernel_ulong_t n = tcp->u_arg[3];
      94                 :         14 :         printxval64(kexec_arch_values, n & KEXEC_ARCH_MASK, "KEXEC_ARCH_???");
      95                 :         14 :         n &= ~(kernel_ulong_t) KEXEC_ARCH_MASK;
      96         [ +  + ]:         14 :         if (n) {
      97                 :          8 :                 tprints("|");
      98                 :            :                 printflags64(kexec_load_flags, n, "KEXEC_???");
      99                 :            :         }
     100                 :            : 
     101                 :         14 :         return RVAL_DECODED;
     102                 :            : }
     103                 :            : 
     104                 :            : #include "xlat/kexec_file_load_flags.h"
     105                 :            : 
     106                 :         21 : SYS_FUNC(kexec_file_load)
     107                 :            : {
     108                 :            :         /* kernel_fd */
     109                 :         21 :         printfd(tcp, tcp->u_arg[0]);
     110                 :         21 :         tprints(", ");
     111                 :            :         /* initrd_fd */
     112                 :         21 :         printfd(tcp, tcp->u_arg[1]);
     113                 :         21 :         tprints(", ");
     114                 :            :         /* cmdline_len */
     115                 :         21 :         tprintf("%" PRI_klu ", ", tcp->u_arg[2]);
     116                 :            :         /* cmdline */
     117                 :         21 :         printstrn(tcp, tcp->u_arg[3], tcp->u_arg[2]);
     118                 :         21 :         tprints(", ");
     119                 :            :         /* flags */
     120                 :         21 :         printflags64(kexec_file_load_flags, tcp->u_arg[4], "KEXEC_FILE_???");
     121                 :            : 
     122                 :         21 :         return RVAL_DECODED;
     123                 :            : }

Generated by: LCOV version 1.11