1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);
}
}
|