LCOV - code coverage report
Current view: top level - include/client/syscalls - decoder.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 32 33 97.0 %
Date: 2024-04-30 13:21:35 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain
       3             :   Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany
       4             : 
       5             :   This software was partially supported by the
       6             :   EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
       7             : 
       8             :   This software was partially supported by the
       9             :   ADA-FS project under the SPPEXA project funded by the DFG.
      10             : 
      11             :   This file is part of GekkoFS' POSIX interface.
      12             : 
      13             :   GekkoFS' POSIX interface is free software: you can redistribute it and/or
      14             :   modify it under the terms of the GNU Lesser General Public License as
      15             :   published by the Free Software Foundation, either version 3 of the License,
      16             :   or (at your option) any later version.
      17             : 
      18             :   GekkoFS' POSIX interface is distributed in the hope that it will be useful,
      19             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      20             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      21             :   GNU Lesser General Public License for more details.
      22             : 
      23             :   You should have received a copy of the GNU Lesser General Public License
      24             :   along with GekkoFS' POSIX interface.  If not, see
      25             :   <https://www.gnu.org/licenses/>.
      26             : 
      27             :   SPDX-License-Identifier: LGPL-3.0-or-later
      28             : */
      29             : 
      30             : #ifndef GKFS_SYSCALLS_DECODER_HPP
      31             : #define GKFS_SYSCALLS_DECODER_HPP
      32             : 
      33             : #include <client/syscalls/syscall.hpp>
      34             : #include <client/syscalls/args.hpp>
      35             : #include <client/syscalls/rets.hpp>
      36             : 
      37             : namespace gkfs::syscall {
      38             : 
      39             : namespace detail {
      40             : 
      41             : /** a RAII saver/restorer of errno values */
      42             : struct errno_saver {
      43     1172103 :     errno_saver(int errnum) : saved_errno_(errnum) {}
      44             : 
      45     1172112 :     ~errno_saver() {
      46     1172112 :         errno = saved_errno_;
      47             :     }
      48             : 
      49             :     const int saved_errno_;
      50             : };
      51             : 
      52             : } // namespace detail
      53             : 
      54             : template <typename FmtBuffer>
      55             : inline void
      56      585942 : decode(FmtBuffer& buffer, const long syscall_number,
      57             :        const long argv[MAX_ARGS]) {
      58             : 
      59     1171886 :     detail::errno_saver _(errno);
      60             : 
      61      585942 :     const auto sc = lookup_by_number(syscall_number, argv);
      62             : 
      63      585941 :     fmt::format_to(buffer, "{}(", sc.name());
      64             : 
      65     2258078 :     for(int i = 0; i < sc.num_args(); ++i) {
      66     1672133 :         const auto& arg = sc.args().at(i);
      67             : 
      68     1672133 :         arg.formatter<FmtBuffer>()(buffer, {arg.name(), argv[i]});
      69             : 
      70     1672136 :         if(i < sc.num_args() - 1) {
      71     1094933 :             fmt::format_to(buffer, ", ");
      72             :         }
      73             :     }
      74             : 
      75      585945 :     fmt::format_to(buffer, ") = ?");
      76      585944 : }
      77             : 
      78             : template <typename FmtBuffer>
      79             : inline void
      80      586161 : decode(FmtBuffer& buffer, const long syscall_number, const long argv[MAX_ARGS],
      81             :        const long result) {
      82             : 
      83      581192 :     detail::errno_saver _(errno);
      84             : 
      85      586161 :     const auto sc = lookup_by_number(syscall_number, argv);
      86             : 
      87      586162 :     fmt::format_to(buffer, "{}(", sc.name());
      88             : 
      89     2262596 :     for(int i = 0; i < sc.num_args(); ++i) {
      90     1676427 :         const auto& arg = sc.args().at(i);
      91             : 
      92     1676427 :         arg.formatter<FmtBuffer>()(buffer, {arg.name(), argv[i]});
      93             : 
      94     1676435 :         if(i < sc.num_args() - 1) {
      95     1098990 :             fmt::format_to(buffer, ", ");
      96             :         }
      97             :     }
      98             : 
      99      586169 :     if(never_returns(syscall_number)) {
     100           0 :         fmt::format_to(buffer, ") = ?");
     101        4976 :         return;
     102             :     }
     103             : 
     104        4976 :     if(error_code(result) != 0) {
     105        4976 :         fmt::format_to(buffer, ") = {} {} ({})", static_cast<int>(-1),
     106        9952 :                        errno_name(-result), errno_message(-result));
     107        4976 :         return;
     108             :     }
     109             : 
     110      581192 :     fmt::format_to(buffer, ") = ");
     111      581193 :     const auto& ret = sc.return_type();
     112      581193 :     ret.formatter<FmtBuffer>()(buffer, result);
     113             : }
     114             : 
     115             : } // namespace gkfs::syscall
     116             : 
     117             : #endif // GKFS_SYSCALLS_DECODER_HPP

Generated by: LCOV version 1.16