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 1271161 : errno_saver(int errnum) : saved_errno_(errnum) {} 44 : 45 1271184 : ~errno_saver() { 46 1271184 : errno = saved_errno_; 47 : } 48 : 49 : const int saved_errno_; 50 : }; 51 : 52 : } // namespace detail 53 : 54 : template <typename FmtBuffer> 55 : inline void 56 635431 : decode(FmtBuffer& buffer, const long syscall_number, 57 : const long argv[MAX_ARGS]) { 58 : 59 1270885 : detail::errno_saver _(errno); 60 : 61 635431 : const auto sc = lookup_by_number(syscall_number, argv); 62 : 63 635433 : fmt::format_to(std::back_inserter(buffer), "{}(", sc.name()); 64 : 65 2448592 : for(int i = 0; i < sc.num_args(); ++i) { 66 1813155 : const auto arg = sc.args().at(i); 67 : 68 1813155 : arg.formatter<FmtBuffer>()(buffer, {arg.name(), argv[i]}); 69 : 70 1813127 : if(i < sc.num_args() - 1) { 71 1187309 : fmt::format_to(std::back_inserter(buffer), ", "); 72 : } 73 : } 74 : 75 635437 : fmt::format_to(std::back_inserter(buffer), ") = ?"); 76 635454 : } 77 : 78 : template <typename FmtBuffer> 79 : inline void 80 635730 : decode(FmtBuffer& buffer, const long syscall_number, const long argv[MAX_ARGS], 81 : const long result) { 82 : 83 628154 : detail::errno_saver _(errno); 84 : 85 635730 : const auto sc = lookup_by_number(syscall_number, argv); 86 : 87 635727 : fmt::format_to(std::back_inserter(buffer), "{}(", sc.name()); 88 : 89 2454066 : for(int i = 0; i < sc.num_args(); ++i) { 90 1818334 : const auto arg = sc.args().at(i); 91 : 92 1818334 : arg.formatter<FmtBuffer>()(buffer, {arg.name(), argv[i]}); 93 : 94 1818346 : if(i < sc.num_args() - 1) { 95 1192246 : fmt::format_to(std::back_inserter(buffer), ", "); 96 : } 97 : } 98 : 99 635732 : if(never_returns(syscall_number)) { 100 0 : fmt::format_to(std::back_inserter(buffer), ") = ?"); 101 7576 : return; 102 : } 103 : 104 635733 : if(error_code(result) != 0) { 105 7576 : fmt::format_to(std::back_inserter(buffer), ") = {} {} ({})", 106 7576 : static_cast<int>(-1), errno_name(-result), 107 7576 : errno_message(-result)); 108 7576 : return; 109 : } 110 : 111 628157 : fmt::format_to(std::back_inserter(buffer), ") = "); 112 628157 : const auto& ret = sc.return_type(); 113 628157 : ret.formatter<FmtBuffer>()(buffer, result); 114 : } 115 : 116 : } // namespace gkfs::syscall 117 : 118 : #endif // GKFS_SYSCALLS_DECODER_HPP