blob: 932779914946377ed8bfb48a8e7afe799cb71f46 [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
15namespace blobs
16{
17namespace flash
18{
19namespace internal
20{
21
22/**
23 * @class Sys
24 * @brief Overridable direct syscall interface
25 */
26class 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 Venture7b91cbc2018-11-28 14:24:41 -080037 virtual int ioctl(int fd, unsigned long request, void* param) const = 0;
Patrick Venture8b588562018-11-18 08:44:33 -080038};
39
40/**
41 * @class SysImpl
42 * @brief syscall concrete implementation
43 * @details Passes through all calls to the normal linux syscalls
44 */
45class 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 Venture7b91cbc2018-11-28 14:24:41 -080054 int ioctl(int fd, unsigned long request, void* param) const override;
Patrick Venture8b588562018-11-18 08:44:33 -080055};
56
57/** @brief Default instantiation of sys */
58extern SysImpl sys_impl;
59
60} // namespace internal
61} // namespace flash
62} // namespace blobs