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 <poll.h> 11 #include <sys/mman.h> 12 13 #include <cinttypes> 14 #include <cstddef> 15 16 namespace internal 17 { 18 19 /** 20 * @class Sys 21 * @brief Overridable direct syscall interface 22 */ 23 class Sys 24 { 25 public: 26 virtual ~Sys() = default; 27 28 virtual int open(const char* pathname, int flags) const = 0; 29 virtual int read(int fd, void* buf, std::size_t count) const = 0; 30 virtual int close(int fd) const = 0; 31 virtual void* mmap(void* addr, std::size_t length, int prot, int flags, 32 int fd, off_t offset) const = 0; 33 virtual int munmap(void* addr, std::size_t length) const = 0; 34 virtual int getpagesize() const = 0; 35 virtual int ioctl(int fd, unsigned long request, void* param) const = 0; 36 virtual int poll(struct pollfd* fds, nfds_t nfds, int timeout) const = 0; 37 }; 38 39 /** 40 * @class SysImpl 41 * @brief syscall concrete implementation 42 * @details Passes through all calls to the normal linux syscalls 43 */ 44 class SysImpl : public Sys 45 { 46 public: 47 int open(const char* pathname, int flags) const override; 48 int read(int fd, void* buf, std::size_t count) const override; 49 int close(int fd) const override; 50 void* mmap(void* addr, std::size_t length, int prot, int flags, int fd, 51 off_t offset) const override; 52 int munmap(void* addr, std::size_t length) const override; 53 int getpagesize() const override; 54 int ioctl(int fd, unsigned long request, void* param) const override; 55 int poll(struct pollfd* fds, nfds_t nfds, int timeout) const override; 56 }; 57 58 /** @brief Default instantiation of sys */ 59 extern SysImpl sys_impl; 60 61 } // namespace internal 62