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