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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#include <sys/errno.h>
#include <keyronex/syscall.h>
#include <mlibc/all-sysdeps.hpp>
#include <mlibc/allocator.hpp>
#include <mlibc/debug.hpp>
#define log_unimplemented() \
mlibc::infoLogger() << "mlibc: " << __PRETTY_FUNCTION__ \
<< " is a stub!" << frg::endlog;
namespace mlibc {
int
sys_socket(int family, int type, int protocol, int *fd)
{
auto ret = syscall3(kPXSysSocket, family, type, protocol, NULL);
if (int e = sc_error(ret); e)
return e;
*fd = ret;
return 0;
}
int
sys_bind(int fd, const struct sockaddr *addr, socklen_t addrlen)
{
auto ret = syscall3(kPXSysBind, fd, (uintptr_t)addr, addrlen, NULL);
if (int e = sc_error(ret); e)
return e;
return 0;
}
int
sys_connect(int fd, const struct sockaddr *addr, socklen_t addrlen)
{
auto ret = syscall3(kPXSysConnect, fd, (uintptr_t)addr, addrlen, NULL);
if (int e = sc_error(ret); e)
return e;
return 0;
}
int
sys_listen(int fd, int backlog)
{
auto ret = syscall2(kPXSysListen, fd, backlog, NULL);
if (int e = sc_error(ret); e)
return e;
return 0;
}
int
sys_accept(int fd, int *newfd, struct sockaddr *addr, socklen_t *addrlen,
int flags)
{
auto ret = syscall4(kPXSysAccept, fd, (uintptr_t)addr,
(uintptr_t)addrlen, flags, NULL);
if (int e = sc_error(ret); e)
return e;
*newfd = ret;
return 0;
}
int
sys_msg_send(int fd, const struct msghdr *msg, int flags, ssize_t *length)
{
auto ret = syscall3(kPXSysSendMsg, fd, (uintptr_t)msg, flags, NULL);
if (int e = sc_error(ret); e)
return e;
*length = ret;
return 0;
}
int
sys_msg_recv(int fd, struct msghdr *msg, int flags, ssize_t *length)
{
auto ret = syscall3(kPXSysRecvMsg, fd, (uintptr_t)msg, flags, NULL);
if (int e = sc_error(ret); e)
return e;
*length = ret;
return 0;
}
int
sys_socketpair(int domain, int type_and_flags, int proto, int *fds)
{
auto ret = syscall4(kPXSysSocketPair, domain, type_and_flags, proto,
(uintptr_t)fds, NULL);
if (int e = sc_error(ret); e)
return e;
return 0;
}
int
sys_getsockopt(int fd, int layer, int number, void *__restrict buffer,
socklen_t *__restrict size)
{
(void)fd;
(void)layer;
(void)number;
(void)buffer;
(void)size;
log_unimplemented();
return ENOSYS;
}
int
sys_setsockopt(int fd, int layer, int number, const void *buffer,
socklen_t size)
{
(void)fd;
(void)layer;
(void)number;
(void)buffer;
(void)size;
log_unimplemented();
return ENOSYS;
}
}
|