blob: c013d3dec51d61fc27c9dcb6658a3464b5645f7d [file] [log] [blame]
Patrick Venture8b588562018-11-18 08:44:33 -08001#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 Venture8b588562018-11-18 08:44:33 -080015namespace internal
16{
17
18/**
19 * @class Sys
20 * @brief Overridable direct syscall interface
21 */
22class 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 Venture7b91cbc2018-11-28 14:24:41 -080033 virtual int ioctl(int fd, unsigned long request, void* param) const = 0;
Patrick Venture8b588562018-11-18 08:44:33 -080034};
35
36/**
37 * @class SysImpl
38 * @brief syscall concrete implementation
39 * @details Passes through all calls to the normal linux syscalls
40 */
41class 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 Venture7b91cbc2018-11-28 14:24:41 -080050 int ioctl(int fd, unsigned long request, void* param) const override;
Patrick Venture8b588562018-11-18 08:44:33 -080051};
52
53/** @brief Default instantiation of sys */
54extern SysImpl sys_impl;
55
56} // namespace internal