aboutsummaryrefslogtreecommitdiff
path: root/fakefbdev/FakeFBDev.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fakefbdev/FakeFBDev.cpp')
-rw-r--r--fakefbdev/FakeFBDev.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/fakefbdev/FakeFBDev.cpp b/fakefbdev/FakeFBDev.cpp
new file mode 100644
index 0000000..a37b0a0
--- /dev/null
+++ b/fakefbdev/FakeFBDev.cpp
@@ -0,0 +1,59 @@
+#include "IOCTL.h"
+#include "SharedBuffer.h"
+
+#include <cstring>
+#include <dlfcn.h>
+#include <string>
+#include <sys/types.h>
+#include <unistd.h>
+
+SharedFB fb(default_fb_name);
+
+extern "C" {
+
+int
+open64(const char* pathname, int flags, mode_t mode = 0) {
+ if (pathname == std::string("/dev/fb0")) {
+ return fb.fd;
+ }
+
+ static const auto func_open =
+ (int (*)(const char*, int, mode_t))dlsym(RTLD_NEXT, "open64");
+
+ return func_open(pathname, flags, mode);
+}
+
+int
+open(const char* pathname, int flags, mode_t mode = 0) {
+ if (pathname == std::string("/dev/fb0")) {
+ return fb.fd;
+ }
+
+ static const auto func_open =
+ (int (*)(const char*, int, mode_t))dlsym(RTLD_NEXT, "open");
+
+ return func_open(pathname, flags, mode);
+}
+
+int
+close(int fd) {
+ if (fd == fb.fd) {
+ return 0;
+ }
+
+ static const auto func_close = (int (*)(int))dlsym(RTLD_NEXT, "close");
+ return func_close(fd);
+}
+
+int
+ioctl(int fd, unsigned long request, char* ptr) {
+ if (fd == fb.fd) {
+ return handleIOCTL(request, ptr);
+ }
+
+ static auto func_ioctl =
+ (int (*)(int, unsigned long request, ...))dlsym(RTLD_NEXT, "ioctl");
+
+ return func_ioctl(fd, request, ptr);
+}
+}