add system interface to enable testing
Add system interface to enable testing of the linux syscalls.
Change-Id: Ia135695de4ae8ed561516b8355f03c7191523780
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/lpc_nuvoton.cpp b/lpc_nuvoton.cpp
index 76edb97..416980e 100644
--- a/lpc_nuvoton.cpp
+++ b/lpc_nuvoton.cpp
@@ -20,7 +20,6 @@
#include <fcntl.h>
#include <sys/mman.h>
-#include <unistd.h>
#include <cinttypes>
#include <cstdint>
@@ -98,10 +97,10 @@
* Until then program the register through /dev/mem.
*/
int fd;
- if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
+ if ((fd = sys->open("/dev/mem", O_RDWR | O_SYNC)) == -1)
{
std::fprintf(stderr, "Failed to open /dev/mem\n");
- close(fd);
+ sys->close(fd);
return std::make_pair(0, 0);
}
@@ -111,9 +110,11 @@
const uint8_t bmcWindowSizeValue = 0xc; // 4k
const uint16_t bmcWindowBaseValue = 0x8000; // BMC phyAddr from 0xc0008000
+ int pageSize = sys->getpagesize();
+
auto mapBasePtr = reinterpret_cast<uint8_t*>(
- mmap(nullptr, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd,
- bmcMapConfigBaseAddr));
+ sys->mmap(nullptr, pageSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
+ bmcMapConfigBaseAddr));
uint8_t* bmcWindowSize = mapBasePtr + bmcMapConfigWindowSizeOffset;
uint16_t* bmcWindowBase =
@@ -122,8 +123,8 @@
*bmcWindowSize = bmcWindowSizeValue;
*bmcWindowBase = bmcWindowBaseValue;
- munmap(mapBasePtr, getpagesize());
- close(fd);
+ sys->munmap(mapBasePtr, pageSize);
+ sys->close(fd);
return std::make_pair(windowOffset, windowSize);
}