kernel: implement eventfs/eventfd

This commit is contained in:
Matheus
2026-06-18 01:53:59 -03:00
parent 9194741bd8
commit b74f36e984
6 changed files with 305 additions and 21 deletions
+32 -19
View File
@@ -452,7 +452,7 @@ index a86353f..3e1a18c 100644
return error ? -1 : ret;
}
diff --git mlibc-clean/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
index 3b04372..b7a8ab7 100644
index 3b04372..5324a35 100644
--- mlibc-clean/sysdeps/astral/generic/generic.cpp
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
@@ -1,7 +1,9 @@
@@ -497,7 +497,7 @@ index 3b04372..b7a8ab7 100644
namespace mlibc {
int Sysdeps<SetGroups>::operator()(size_t size, const gid_t *list) {
@@ -31,14 +56,313 @@ namespace mlibc {
@@ -31,15 +56,324 @@ namespace mlibc {
return 0;
}
@@ -627,9 +627,9 @@ index 3b04372..b7a8ab7 100644
+ int Sysdeps<GetCurrentStackInfo>::operator()(void **stack_base, size_t *stack_size) {
+ *stack_size = 1024 * 1024 * 4;
+ *stack_base = (void *)(0x0000800000000000 - *stack_size);
+ return 0;
+ }
+
return 0;
}
+#ifndef MLIBC_BUILDING_RTLD
+ int Sysdeps<Getifaddrs>::operator()(struct ifaddrs **out) {
+ struct ifaddrs *list = nullptr;
@@ -804,19 +804,30 @@ index 3b04372..b7a8ab7 100644
+ *out = arr;
+ freeifaddrs(ifaddrs);
+
return 0;
}
+ return 0;
+ }
+#endif
+
+ int Sysdeps<EventfdCreate>::operator()(unsigned int initval, int flags, int *fd) {
+ long ret;
+ int error = syscall(SYSCALL_EVENTFD, &ret, initval, flags);
+ if (error)
+ return error;
+
+ *fd = ret;
+ return 0;
+ }
+
+ int Sysdeps<GetSockopt>::operator()(int fd, int layer, int number,
+ void *__restrict buffer, socklen_t *__restrict size) {
+ long ret;
+ return syscall(SYSCALL_GETSOCKOPT, &ret, fd, layer, number, (uint64_t)buffer, (uint64_t)size);
+ }
+
int Sysdeps<InetConfigured>::operator()(bool *ipv4, bool *ipv6) {
// there is no ipv6 support in the kernel currently and no way of checking for configured interfaces
@@ -47,6 +371,71 @@ namespace mlibc {
*ipv4 = true;
@@ -47,6 +381,71 @@ namespace mlibc {
return 0;
}
@@ -888,7 +899,7 @@ index 3b04372..b7a8ab7 100644
int Sysdeps<Readv>::operator()(int fd, const struct iovec *iovs, int iovc, ssize_t *bytes_read) {
long r;
int error = syscall(SYSCALL_READV, &r, fd, (uint64_t)iovs, iovc);
@@ -86,6 +475,11 @@ namespace mlibc {
@@ -86,6 +485,11 @@ namespace mlibc {
return e;
}
@@ -900,7 +911,7 @@ index 3b04372..b7a8ab7 100644
int Sysdeps<Shutdown>::operator()(int sockfd, int how) {
long ret;
return syscall(SYSCALL_SHUTDOWN, &ret, sockfd, how);
@@ -487,8 +881,15 @@ namespace mlibc {
@@ -487,8 +891,15 @@ namespace mlibc {
return err;
}
@@ -916,7 +927,7 @@ index 3b04372..b7a8ab7 100644
return syscall(SYSCALL_SETSOCKOPT, &ret, fd, layer, number, (uint64_t)buffer, size);
}
@@ -511,6 +912,11 @@ namespace mlibc {
@@ -511,6 +922,11 @@ namespace mlibc {
return err;
}
@@ -928,7 +939,7 @@ index 3b04372..b7a8ab7 100644
int Sysdeps<Renameat>::operator()(int olddirfd, const char *old_path, int newdirfd, const char *new_path) {
long ret;
return syscall(SYSCALL_RENAMEAT, &ret, olddirfd, (uint64_t)old_path, newdirfd, (uint64_t)new_path);
@@ -562,6 +968,16 @@ namespace mlibc {
@@ -562,6 +978,16 @@ namespace mlibc {
return sysdep<Ioctl>(fd, TCSETS, (void *)attr, &res);
}
@@ -945,7 +956,7 @@ index 3b04372..b7a8ab7 100644
int Sysdeps<Poll>::operator()(struct pollfd *fds, nfds_t count, int timeout, int *num_events) {
long ret;
long error = syscall(SYSCALL_POLL, &ret, (uint64_t)fds, count, timeout);
@@ -932,4 +1348,13 @@ namespace mlibc {
@@ -932,4 +1358,13 @@ namespace mlibc {
*nanos = ts.tv_nsec;
return err;
}
@@ -982,10 +993,10 @@ index 7e4f2a1..ecc2677 100644
#ifdef __cplusplus
extern "C" {
diff --git mlibc-clean/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
index a6c4067..160a140 100644
index a6c4067..9040d45 100644
--- mlibc-clean/sysdeps/astral/include/astral/syscall.h
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
@@ -103,6 +103,13 @@
@@ -103,6 +103,14 @@
#define SYSCALL_SYSINFO 96
#define SYSCALL_WRITEV 97
#define SYSCALL_READV 98
@@ -996,6 +1007,7 @@ index a6c4067..160a140 100644
+#define SYSCALL_CLOCK_GETRES 103
+#define SYSCALL_SETPRIORITY 104
+#define SYSCALL_SYSCTL 105
+#define SYSCALL_EVENTFD 106
#ifndef __MLIBC_ABI_ONLY
@@ -1062,7 +1074,7 @@ index 0000000..161f634
+
+#endif /* _ASTRAL_SYSCTL_H */
diff --git mlibc-clean/sysdeps/astral/include/mlibc/sysdeps.hpp mlibc-workdir/sysdeps/astral/include/mlibc/sysdeps.hpp
index ce91084..54ee08e 100644
index ce91084..503110a 100644
--- mlibc-clean/sysdeps/astral/include/mlibc/sysdeps.hpp
+++ mlibc-workdir/sysdeps/astral/include/mlibc/sysdeps.hpp
@@ -7,8 +7,30 @@ namespace mlibc {
@@ -1121,7 +1133,7 @@ index ce91084..54ee08e 100644
Poll,
Ppoll,
Pselect,
@@ -135,7 +161,10 @@ struct AstralSysdepTags :
@@ -135,7 +161,11 @@ struct AstralSysdepTags :
VmUnmap,
Isatty,
ClockGet,
@@ -1129,7 +1141,8 @@ index ce91084..54ee08e 100644
+ ClockGetres,
+ PrepareStack,
+ SetPriority,
+ GetCurrentStackInfo
+ GetCurrentStackInfo,
+ EventfdCreate
{};
template<typename Tag>