blob: fb824ef7665381f32e06693dadb5760576c85f92 [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;
37};
38
39/**
40 * @class SysImpl
41 * @brief syscall concrete implementation
42 * @details Passes through all calls to the normal linux syscalls
43 */
44class SysImpl : public Sys
45{
46 public:
47 int open(const char* pathname, int flags) const override;
48 int close(int fd) const override;
49 void* mmap(void* addr, size_t length, int prot, int flags, int fd,
50 off_t offset) const override;
51 int munmap(void* addr, size_t length) const override;
52 int getpagesize() const override;
53};
54
55/** @brief Default instantiation of sys */
56extern SysImpl sys_impl;
57
58} // namespace internal
59} // namespace flash
60} // namespace blobs