Skip to content

Commit 50b0e1e

Browse files
committed
sysdeps/zinnia: Implement PosixMadvise, Pause, Ifaddrs
1 parent e825f58 commit 50b0e1e

9 files changed

Lines changed: 81 additions & 9 deletions

File tree

abis/zinnia/limits.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef _ABIBITS_LIMITS_H
2+
#define _ABIBITS_LIMITS_H
3+
4+
#define __MLIBC_IOV_MAX 1024
5+
#define __MLIBC_LOGIN_NAME_MAX 256
6+
#define __MLIBC_HOST_NAME_MAX 64
7+
#define __MLIBC_NAME_MAX 255
8+
#define __MLIBC_OPEN_MAX 1024
9+
10+
#endif /*_ABIBITS_LIMITS_H */

abis/zinnia/socket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct cmsghdr {
8989
#define SO_PRIORITY 31
9090
#define SO_MARK 32
9191

92-
#define SOMAXCONN 1
92+
#define SOMAXCONN 128
9393

9494
#define MSG_CTRUNC 0x1
9595
#define MSG_DONTROUTE 0x2

sysdeps/zinnia/generic/ifaddrs.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <ifaddrs.h>
2+
#include <stdlib.h>
3+
4+
// TODO
5+
6+
int getifaddrs(struct ifaddrs **ifap) {
7+
*ifap = nullptr;
8+
return 0;
9+
}
10+
11+
void freeifaddrs(struct ifaddrs *ifa) {
12+
while (ifa != nullptr) {
13+
struct ifaddrs *next = ifa->ifa_next;
14+
free(ifa);
15+
ifa = next;
16+
}
17+
}

sysdeps/zinnia/generic/internal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int Sysdeps<FutexWait>::operator()(int *pointer, int expected, const struct time
5050
}
5151

5252
int Sysdeps<FutexWake>::operator()(int *pointer, bool all) {
53-
return zinnia_syscall(SYSCALL_FUTEX_WAKE, (size_t)pointer, all).error;
53+
return zinnia_syscall(SYSCALL_FUTEX_WAKE, (size_t)pointer, all ? UINT32_MAX : 1).error;
5454
}
5555

5656
int Sysdeps<AnonAllocate>::operator()(size_t size, void **pointer) {

sysdeps/zinnia/generic/posix.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,8 @@ void Sysdeps<Yield>::operator()() { zinnia_syscall(SYSCALL_YIELD); }
326326

327327
int
328328
Sysdeps<Waitpid>::operator()(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid) {
329-
if (ru) {
330-
mlibc::infoLogger() << "mlibc: struct rusage in sys_waitpid is unsupported" << frg::endlog;
331-
return ENOSYS;
332-
}
333329
again:
334-
auto r = zinnia_syscall(SYSCALL_WAITPID, pid, (size_t)status, flags);
330+
auto r = zinnia_syscall(SYSCALL_WAITPID, pid, (size_t)status, flags, (size_t)ru);
335331
if (r.error) {
336332
if (r.error == EINTR)
337333
goto again;
@@ -740,6 +736,10 @@ int Sysdeps<Madvise>::operator()(void *addr, size_t length, int advice) {
740736
return zinnia_syscall(SYSCALL_MADVISE, (size_t)addr, length, advice).error;
741737
}
742738

739+
int Sysdeps<PosixMadvise>::operator()(void *addr, size_t length, int advice) {
740+
return zinnia_syscall(SYSCALL_MADVISE, (size_t)addr, length, advice).error;
741+
}
742+
743743
int Sysdeps<GetItimer>::operator()(int which, struct itimerval *curr_value) {
744744
return zinnia_syscall(SYSCALL_ITIMER_GET, which, (size_t)curr_value).error;
745745
}
@@ -889,4 +889,8 @@ int Sysdeps<Sysconf>::operator()(int num, long *ret) {
889889
return 0;
890890
}
891891

892+
int Sysdeps<Pause>::operator()() {
893+
return sysdep<Ppoll>(NULL, 0, NULL, NULL, NULL);
894+
}
895+
892896
} // namespace mlibc
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../../abis/linux/limits.h
1+
../../../../abis/zinnia/limits.h

sysdeps/zinnia/include/ifaddrs.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
#ifndef _IFADDRS_H
3+
#define _IFADDRS_H
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
#include <netinet/in.h>
10+
#include <sys/socket.h>
11+
12+
/* Struct definitions taken from musl */
13+
struct ifaddrs {
14+
struct ifaddrs *ifa_next;
15+
char *ifa_name;
16+
unsigned ifa_flags;
17+
struct sockaddr *ifa_addr;
18+
struct sockaddr *ifa_netmask;
19+
/* the man page (and glibc) place `ifa_broadaddr` and `ifa_dstaddr` in a union */
20+
/* TODO: decide whether we should do it, too */
21+
struct sockaddr *ifa_broadaddr;
22+
struct sockaddr *ifa_dstaddr;
23+
void *ifa_data;
24+
};
25+
26+
#ifndef __MLIBC_ABI_ONLY
27+
28+
int getifaddrs(struct ifaddrs **__ifap);
29+
void freeifaddrs(struct ifaddrs *__ifa);
30+
31+
#endif /* !__MLIBC_ABI_ONLY */
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif /* _IFADDRS_H */

sysdeps/zinnia/include/mlibc/sysdeps.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ struct ZinniaSysdepTags :
133133
Sigsuspend,
134134
Sigpending,
135135
Madvise,
136+
PosixMadvise,
136137
GetItimer,
137138
SetItimer,
138139
TimerCreate,
@@ -167,7 +168,8 @@ struct ZinniaSysdepTags :
167168
TimerfdGettime,
168169
Msync,
169170
InetConfigured,
170-
Sysconf
171+
Sysconf,
172+
Pause
171173
{};
172174

173175
template<typename Tag>

sysdeps/zinnia/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ libc_sources += files(
2626
'generic/signalfd.cpp',
2727
'generic/timerfd.cpp',
2828
'generic/eventfd.cpp',
29+
'generic/ifaddrs.cpp',
2930
host_machine.cpu_family() / 'thread.S',
3031
host_machine.cpu_family() / 'signal.S',
3132
)
@@ -105,6 +106,7 @@ if not no_headers
105106
)
106107

107108
install_headers('include/mntent.h')
109+
install_headers('include/ifaddrs.h')
108110
endif
109111

110112
if not headers_only

0 commit comments

Comments
 (0)