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 | |
Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -0800 | [diff] [blame] | 15 | namespace internal |
| 16 | { |
| 17 | |
| 18 | /** |
| 19 | * @class Sys |
| 20 | * @brief Overridable direct syscall interface |
| 21 | */ |
| 22 | class Sys |
| 23 | { |
| 24 | public: |
| 25 | virtual ~Sys() = default; |
| 26 | |
| 27 | virtual int open(const char* pathname, int flags) const = 0; |
| 28 | virtual int close(int fd) const = 0; |
| 29 | virtual void* mmap(void* addr, size_t length, int prot, int flags, int fd, |
| 30 | off_t offset) const = 0; |
| 31 | virtual int munmap(void* addr, size_t length) const = 0; |
| 32 | virtual int getpagesize() const = 0; |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 33 | virtual int ioctl(int fd, unsigned long request, void* param) const = 0; |
Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -0800 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | /** |
| 37 | * @class SysImpl |
| 38 | * @brief syscall concrete implementation |
| 39 | * @details Passes through all calls to the normal linux syscalls |
| 40 | */ |
| 41 | class SysImpl : public Sys |
| 42 | { |
| 43 | public: |
| 44 | int open(const char* pathname, int flags) const override; |
| 45 | int close(int fd) const override; |
| 46 | void* mmap(void* addr, size_t length, int prot, int flags, int fd, |
| 47 | off_t offset) const override; |
| 48 | int munmap(void* addr, size_t length) const override; |
| 49 | int getpagesize() const override; |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 50 | int ioctl(int fd, unsigned long request, void* param) const override; |
Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -0800 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /** @brief Default instantiation of sys */ |
| 54 | extern SysImpl sys_impl; |
| 55 | |
| 56 | } // namespace internal |