Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | /* NOTE: IIRC, wak@ is working on exposing some of this in stdplus, so we can |
| 4 | * transition when that's ready. |
| 5 | * |
| 6 | * Copied some from gpioplus to enable unit-testing of lpc nuvoton and later |
| 7 | * other pieces. |
| 8 | */ |
| 9 | |
| 10 | #include <sys/mman.h> |
| 11 | |
| 12 | #include <cinttypes> |
| 13 | #include <cstddef> |
| 14 | |
| 15 | namespace blobs |
| 16 | { |
| 17 | namespace flash |
| 18 | { |
| 19 | namespace internal |
| 20 | { |
| 21 | |
| 22 | /** |
| 23 | * @class Sys |
| 24 | * @brief Overridable direct syscall interface |
| 25 | */ |
| 26 | class Sys |
| 27 | { |
| 28 | public: |
| 29 | virtual ~Sys() = default; |
| 30 | |
| 31 | virtual int open(const char* pathname, int flags) const = 0; |
| 32 | virtual int close(int fd) const = 0; |
| 33 | virtual void* mmap(void* addr, size_t length, int prot, int flags, int fd, |
| 34 | off_t offset) const = 0; |
| 35 | virtual int munmap(void* addr, size_t length) const = 0; |
| 36 | virtual int getpagesize() const = 0; |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame^] | 37 | virtual int ioctl(int fd, unsigned long request, void* param) const = 0; |
Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * @class SysImpl |
| 42 | * @brief syscall concrete implementation |
| 43 | * @details Passes through all calls to the normal linux syscalls |
| 44 | */ |
| 45 | class SysImpl : public Sys |
| 46 | { |
| 47 | public: |
| 48 | int open(const char* pathname, int flags) const override; |
| 49 | int close(int fd) const override; |
| 50 | void* mmap(void* addr, size_t length, int prot, int flags, int fd, |
| 51 | off_t offset) const override; |
| 52 | int munmap(void* addr, size_t length) const override; |
| 53 | int getpagesize() const override; |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame^] | 54 | int ioctl(int fd, unsigned long request, void* param) const override; |
Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -0800 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | /** @brief Default instantiation of sys */ |
| 58 | extern SysImpl sys_impl; |
| 59 | |
| 60 | } // namespace internal |
| 61 | } // namespace flash |
| 62 | } // namespace blobs |