-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmq.cpp
More file actions
86 lines (75 loc) · 1.72 KB
/
mq.cpp
File metadata and controls
86 lines (75 loc) · 1.72 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "mq.h"
#include <unordered_map>
#include <errno.h>
#include <string.h>
int replyFd = 1;
int commandFd = 2;
#pragma push(pack, 1)
struct linux_mq_attr
{
long mq_flags; /* Flags: 0 or O_NONBLOCK */
long mq_maxmsg; /* Max. # of messages on queue */
long mq_msgsize; /* Max. message size (bytes) */
long mq_curmsgs; /* # of messages currently in queue */
};
#pragma pop(pack)
int jmp_mq_open(const char *name, int oflag, int mode, void *arg)
{
if (strcmp(name, "/Sys.Monitor.Command") == 0)
{
errno = 0;
return commandFd;
}
if (strcmp(name, "/Sys.Monitor.Reply") == 0)
{
errno = 0;
return replyFd;
}
errno = EACCES;
return -1;
}
int jmp_mq_getattr(int fd, linux_mq_attr *attr)
{
attr->mq_msgsize = 0xffff;
errno = 0;
return 0;
}
int jmp_mq_notify(int fd, void *sevp)
{
errno = 0;
return 0;
}
int jmp_mq_send(int fd, const char *msg_ptr, size_t msg_len, unsigned int msg_prio)
{
errno = 0;
return 0;
}
int jmp_mq_receive(int fd, char *msg_ptr, size_t msg_len, unsigned int *msg_prio)
{
errno = EAGAIN;
return -1;
}
int jmp_mq_close(int fd)
{
errno = 0;
return 0;
}
std::unordered_map<const char *, void *> MQ_FUNCS_STUB = {
{"mq_open", (void *)jmp_mq_open},
{"mq_getattr", (void *)jmp_mq_getattr},
{"mq_notify", (void *)jmp_mq_notify},
{"mq_send", (void *)jmp_mq_send},
{"mq_receive", (void *)jmp_mq_receive},
{"mq_close", (void *)jmp_mq_close}};
bool mq_resolve(const char *symbol, void **result)
{
for (auto &it : MQ_FUNCS_STUB)
{
if (strcmp(it.first, symbol) == 0)
{
*result = it.second;
return true;
}
}
return false;
}