Line | Count | Source |
1 | | // Copyright 2024 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #pragma once |
16 | | |
17 | | #include "sys_interface.hpp" |
18 | | |
19 | | #include <mtd/mtd-user.h> |
20 | | #include <sys/ioctl.h> |
21 | | #include <unistd.h> |
22 | | |
23 | | #include <cstdint> |
24 | | #include <system_error> |
25 | | |
26 | | namespace google |
27 | | { |
28 | | namespace hoth |
29 | | { |
30 | | namespace internal |
31 | | { |
32 | | |
33 | | /** @class SysImpl |
34 | | * @brief syscall concrete implementation |
35 | | * @details Passes through all calls to the normal linux syscalls |
36 | | */ |
37 | | class SysImpl : public Sys |
38 | | { |
39 | | public: |
40 | | int open(const char* pathname, int flags) const override; |
41 | | int close(int fd) const override; |
42 | | off_t lseek(int fd, off_t offset, int whence) const override; |
43 | | ssize_t read(int fd, void* buf, size_t count) const override; |
44 | | ssize_t write(int fd, const void* buf, size_t count) const override; |
45 | | int ioctl(int fd, uint64_t request, void* mtd) const override; |
46 | | }; |
47 | | |
48 | | inline std::system_error errnoException(const std::string& message) |
49 | 2.55k | { |
50 | | return std::system_error(errno, std::generic_category(), message); |
51 | 2.55k | } |
52 | | |
53 | | /** @brief Default instantiation of sys */ |
54 | | extern SysImpl sys_impl; |
55 | | |
56 | | } // namespace internal |
57 | | |
58 | | } // namespace hoth |
59 | | |
60 | | } // namespace google |