mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
794 lines
21 KiB
Diff
794 lines
21 KiB
Diff
diff --git mlibc-clean/options/glibc/generic/execinfo.cpp mlibc-workdir/options/glibc/generic/execinfo.cpp
|
|
index 1ed110d..ded9114 100644
|
|
--- mlibc-clean/options/glibc/generic/execinfo.cpp
|
|
+++ mlibc-workdir/options/glibc/generic/execinfo.cpp
|
|
@@ -4,6 +4,7 @@
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <unwind.h>
|
|
+#include <errno.h>
|
|
|
|
#include <bits/ensure.h>
|
|
#include <mlibc/debug.hpp>
|
|
@@ -52,29 +53,7 @@ _Unwind_Reason_Code trace(_Unwind_Context *context, void *arg) {
|
|
} // namespace
|
|
|
|
int backtrace(void **buffer, int size) {
|
|
- if (size <= 0)
|
|
- return 0;
|
|
-
|
|
- if (!libgccHandle) {
|
|
- libgccHandle = dlopen("libgcc_s.so.1", RTLD_LAZY | RTLD_LOCAL);
|
|
- if (!libgccHandle || libgccHandle.value() == nullptr) {
|
|
- auto error = dlerror();
|
|
- mlibc::infoLogger() << "Failed to load libgcc_s.so.1: " << (error ? error : "") << frg::endlog;
|
|
- return 0;
|
|
- }
|
|
-
|
|
- unwindBacktrace = reinterpret_cast<UnwindBacktrace>(dlsym(libgccHandle.value(), "_Unwind_Backtrace"));
|
|
- unwindGetIP = reinterpret_cast<UnwindGetIP>(dlsym(libgccHandle.value(), "_Unwind_GetIP"));
|
|
-
|
|
- if (!unwindBacktrace || !unwindGetIP) {
|
|
- mlibc::infoLogger() << "Failed to find unwind functions in libgcc_s.so.1: " << dlerror() << frg::endlog;
|
|
- return 0;
|
|
- }
|
|
- }
|
|
-
|
|
- UnwindState state{buffer, size};
|
|
- unwindBacktrace(trace, &state);
|
|
- return state.current_frame;
|
|
+ return ENOSYS;
|
|
}
|
|
|
|
char **backtrace_symbols(void *const *, int) {
|
|
@@ -82,25 +61,5 @@ char **backtrace_symbols(void *const *, int) {
|
|
__builtin_unreachable();
|
|
}
|
|
|
|
-void backtrace_symbols_fd(void *const *buffer, int size, int fd) {
|
|
- if (size <= 0 || fd < 0)
|
|
- return;
|
|
-
|
|
- for (int frame_num = 0; frame_num < size; frame_num++) {
|
|
- Dl_info info;
|
|
- if (dladdr(buffer[frame_num], &info) != 0) {
|
|
- if (info.dli_fname != nullptr)
|
|
- write(fd, info.dli_fname, strlen(info.dli_fname));
|
|
-
|
|
- if (info.dli_sname != nullptr)
|
|
- dprintf(fd, "(%s+0x%" PRIxPTR ") ", info.dli_sname,
|
|
- reinterpret_cast<uintptr_t>(buffer[frame_num]) - reinterpret_cast<uintptr_t>(info.dli_saddr));
|
|
- else if(info.dli_saddr)
|
|
- dprintf(fd, "(+%p) ", info.dli_saddr);
|
|
- else
|
|
- dprintf(fd, "() ");
|
|
- }
|
|
-
|
|
- dprintf(fd, "[%p]\n", buffer[frame_num]);
|
|
- }
|
|
+void backtrace_symbols_fd(void *const *, int, int) {
|
|
}
|
|
diff --git mlibc-clean/options/internal/generic/global-config.cpp mlibc-workdir/options/internal/generic/global-config.cpp
|
|
index 3b7b862..3d86e7a 100644
|
|
--- mlibc-clean/options/internal/generic/global-config.cpp
|
|
+++ mlibc-workdir/options/internal/generic/global-config.cpp
|
|
@@ -1,9 +1,15 @@
|
|
#include <stdlib.h>
|
|
-#include <string.h>
|
|
+#include <mlibc/allocator.hpp>
|
|
#include <mlibc/global-config.hpp>
|
|
|
|
namespace mlibc {
|
|
|
|
+namespace {
|
|
+
|
|
+constinit mlibc::lazy_eternal<GlobalConfig> globalConfigInstance;
|
|
+
|
|
+} // namespace
|
|
+
|
|
struct GlobalConfigGuard {
|
|
GlobalConfigGuard();
|
|
};
|
|
@@ -12,7 +18,7 @@ GlobalConfigGuard guard;
|
|
|
|
GlobalConfigGuard::GlobalConfigGuard() {
|
|
// Force the config to be created during initialization of libc.so.
|
|
- mlibc::globalConfig();
|
|
+ globalConfigInstance.get();
|
|
}
|
|
|
|
static bool envEnabled(const char *env) {
|
|
@@ -29,4 +35,8 @@ GlobalConfig::GlobalConfig() {
|
|
debugMonetaryLengths = envEnabled("MLIBC_DEBUG_MONETARY_LENGTHS");
|
|
}
|
|
|
|
+const GlobalConfig &globalConfig() {
|
|
+ return globalConfigInstance.get();
|
|
+}
|
|
+
|
|
} // namespace mlibc
|
|
diff --git mlibc-clean/options/internal/include/mlibc/allocator.hpp mlibc-workdir/options/internal/include/mlibc/allocator.hpp
|
|
index 852620a..a1bfb0a 100644
|
|
--- mlibc-clean/options/internal/include/mlibc/allocator.hpp
|
|
+++ mlibc-workdir/options/internal/include/mlibc/allocator.hpp
|
|
@@ -3,6 +3,7 @@
|
|
|
|
#include <mlibc/lock.hpp>
|
|
#include <bits/ensure.h>
|
|
+#include <frg/manual_box.hpp>
|
|
#include <frg/slab.hpp>
|
|
#include <internal-config.h>
|
|
|
|
@@ -35,4 +36,34 @@ MemoryAllocator &getAllocator();
|
|
|
|
#endif // !MLIBC_DEBUG_ALLOCATOR
|
|
|
|
+namespace mlibc {
|
|
+
|
|
+template <typename T>
|
|
+struct lazy_eternal {
|
|
+ constexpr lazy_eternal() = default;
|
|
+
|
|
+ template <typename Self>
|
|
+ auto &get(this Self &&self) {
|
|
+ if (__atomic_load_n(&self.initialized_, __ATOMIC_ACQUIRE))
|
|
+ return *self.box_.get();
|
|
+
|
|
+ {
|
|
+ frg::unique_lock lock{self.lock_};
|
|
+ if (!__atomic_load_n(&self.initialized_, __ATOMIC_RELAXED)) {
|
|
+ self.box_.initialize();
|
|
+ __atomic_store_n(&self.initialized_, 1, __ATOMIC_RELEASE);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return *self.box_.get();
|
|
+ }
|
|
+
|
|
+private:
|
|
+ mutable uint32_t initialized_ = 0;
|
|
+ mutable FutexLock lock_;
|
|
+ mutable frg::manual_box<T> box_;
|
|
+};
|
|
+
|
|
+} // namespace mlibc
|
|
+
|
|
#endif // MLIBC_FRIGG_ALLOC
|
|
diff --git mlibc-clean/options/internal/include/mlibc/global-config.hpp mlibc-workdir/options/internal/include/mlibc/global-config.hpp
|
|
index 0235c54..3fad411 100644
|
|
--- mlibc-clean/options/internal/include/mlibc/global-config.hpp
|
|
+++ mlibc-workdir/options/internal/include/mlibc/global-config.hpp
|
|
@@ -14,11 +14,8 @@ struct GlobalConfig {
|
|
bool debugMonetaryLengths;
|
|
};
|
|
|
|
-inline const GlobalConfig &globalConfig() {
|
|
- static GlobalConfig cached;
|
|
- return cached;
|
|
-}
|
|
+const GlobalConfig &globalConfig();
|
|
|
|
-}
|
|
+} // namespace mlibc
|
|
|
|
#endif // MLIBC_GLOBAL_CONFIG
|
|
diff --git mlibc-clean/options/internal/include/mlibc/lock.hpp mlibc-workdir/options/internal/include/mlibc/lock.hpp
|
|
index f447741..ab44667 100644
|
|
--- mlibc-clean/options/internal/include/mlibc/lock.hpp
|
|
+++ mlibc-workdir/options/internal/include/mlibc/lock.hpp
|
|
@@ -14,7 +14,7 @@
|
|
|
|
template<bool Recursive>
|
|
struct alignas(4) FutexLockImpl {
|
|
- FutexLockImpl() : _state{0}, _recursion{0} { }
|
|
+ constexpr FutexLockImpl() : _state{0}, _recursion{0} { }
|
|
|
|
FutexLockImpl(const FutexLockImpl &) = delete;
|
|
|
|
diff --git mlibc-clean/options/internal/include/mlibc/sysdep-signatures.hpp mlibc-workdir/options/internal/include/mlibc/sysdep-signatures.hpp
|
|
index d639e43..bff59a5 100644
|
|
--- mlibc-clean/options/internal/include/mlibc/sysdep-signatures.hpp
|
|
+++ mlibc-workdir/options/internal/include/mlibc/sysdep-signatures.hpp
|
|
@@ -23,6 +23,10 @@
|
|
|
|
#include <mlibc/sysdep-tags.hpp>
|
|
|
|
+#if __MLIBC_POSIX_OPTION
|
|
+#include <net/if.h>
|
|
+#endif
|
|
+
|
|
namespace mlibc {
|
|
|
|
template<typename Tag>
|
|
@@ -235,6 +239,7 @@ SYSDEP_FUNC(SetRegid, gid_t rgid, gid_t egid);
|
|
SYSDEP_FUNC(GetLoginR, char *name, size_t name_len);
|
|
SYSDEP_FUNC(IfIndextoname, unsigned int index, char *name);
|
|
SYSDEP_FUNC(IfNametoindex, const char *name, unsigned int *ret);
|
|
+SYSDEP_FUNC(IfNameindex, struct if_nameindex **ret);
|
|
SYSDEP_FUNC(Ptsname, int fd, char *buffer, size_t length);
|
|
SYSDEP_FUNC(Unlockpt, int fd);
|
|
SYSDEP_FUNC(ThreadSetname, void *tcb, const char *name);
|
|
diff --git mlibc-clean/options/internal/include/mlibc/sysdep-tags.hpp mlibc-workdir/options/internal/include/mlibc/sysdep-tags.hpp
|
|
index 17cf422..b90d201 100644
|
|
--- mlibc-clean/options/internal/include/mlibc/sysdep-tags.hpp
|
|
+++ mlibc-workdir/options/internal/include/mlibc/sysdep-tags.hpp
|
|
@@ -476,6 +476,8 @@ struct GetLoginR {};
|
|
struct IfIndextoname {};
|
|
// int sys_if_nametoindex(const char *name, unsigned int *ret);
|
|
struct IfNametoindex {};
|
|
+// int sys_if_nameindex(struct if_nameindex **ret);
|
|
+struct IfNameindex {};
|
|
// int sys_ptsname(int fd, char *buffer, size_t length);
|
|
struct Ptsname {};
|
|
// int sys_unlockpt(int fd);
|
|
diff --git mlibc-clean/options/posix/generic/net-if.cpp mlibc-workdir/options/posix/generic/net-if.cpp
|
|
index ed0c463..8df2580 100644
|
|
--- mlibc-clean/options/posix/generic/net-if.cpp
|
|
+++ mlibc-workdir/options/posix/generic/net-if.cpp
|
|
@@ -6,8 +6,13 @@
|
|
#include <mlibc/all-sysdeps.hpp>
|
|
#include <mlibc/debug.hpp>
|
|
|
|
-void if_freenameindex(struct if_nameindex *) {
|
|
- mlibc::infoLogger() << "mlibc: if_freenameindex is a no-op" << frg::endlog;
|
|
+void if_freenameindex(struct if_nameindex *index) {
|
|
+ if(!index)
|
|
+ return;
|
|
+
|
|
+ for(struct if_nameindex *it = index; it->if_index || it->if_name; ++it)
|
|
+ free(it->if_name);
|
|
+ free(index);
|
|
}
|
|
|
|
char *if_indextoname(unsigned int index, char *name) {
|
|
@@ -20,9 +25,13 @@ char *if_indextoname(unsigned int index, char *name) {
|
|
}
|
|
|
|
struct if_nameindex *if_nameindex(void) {
|
|
- mlibc::infoLogger() << "mlibc: if_nameindex() is a no-op" << frg::endlog;
|
|
- errno = ENOSYS;
|
|
- return nullptr;
|
|
+ struct if_nameindex *ret = nullptr;
|
|
+ if(int e = mlibc::sysdep_or_enosys<IfNameindex>(&ret); e) {
|
|
+ errno = e;
|
|
+ return nullptr;
|
|
+ }
|
|
+
|
|
+ return ret;
|
|
}
|
|
|
|
unsigned int if_nametoindex(const char *name) {
|
|
diff --git mlibc-clean/options/rtld/x86_64/runtime.S mlibc-workdir/options/rtld/x86_64/runtime.S
|
|
index ba9a520..b958ef3 100644
|
|
--- mlibc-clean/options/rtld/x86_64/runtime.S
|
|
+++ mlibc-workdir/options/rtld/x86_64/runtime.S
|
|
@@ -60,4 +60,3 @@ pltRelocateStub:
|
|
jmp *%r11
|
|
|
|
.section .note.GNU-stack,"",%progbits
|
|
-
|
|
diff --git mlibc-clean/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
|
index 3b04372..e8ef8d5 100644
|
|
--- mlibc-clean/sysdeps/astral/generic/generic.cpp
|
|
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
|
@@ -1,7 +1,9 @@
|
|
#include <bits/ensure.h>
|
|
+#include <net/if.h>
|
|
#include <mlibc/debug.hpp>
|
|
#include <mlibc/all-sysdeps.hpp>
|
|
#include <errno.h>
|
|
+#include <ifaddrs.h>
|
|
#include <astral/syscall.h>
|
|
#include <astral/archctl.h>
|
|
#include <string.h>
|
|
@@ -11,8 +13,29 @@
|
|
#include <sys/select.h>
|
|
#include <stdio.h>
|
|
#include <sys/stat.h>
|
|
+#include <sys/statfs.h>
|
|
+#include <sys/statvfs.h>
|
|
#include <unistd.h>
|
|
#include <dirent.h>
|
|
+#include <sys/sysmacros.h>
|
|
+
|
|
+typedef struct {
|
|
+ struct sockaddr addr;
|
|
+ struct sockaddr broadaddr;
|
|
+ struct sockaddr netmask;
|
|
+ struct sockaddr hwaddr;
|
|
+ short flags;
|
|
+ int mtu;
|
|
+} astral_net_info_t;
|
|
+
|
|
+typedef struct {
|
|
+ struct ifaddrs ifa;
|
|
+ unsigned int if_index;
|
|
+ char if_name[IFNAMSIZ];
|
|
+ struct sockaddr addr;
|
|
+ struct sockaddr broadaddr;
|
|
+ struct sockaddr netmask;
|
|
+} astral_ifaddrs_t;
|
|
|
|
namespace mlibc {
|
|
int Sysdeps<SetGroups>::operator()(size_t size, const gid_t *list) {
|
|
@@ -31,14 +54,276 @@ namespace mlibc {
|
|
return 0;
|
|
}
|
|
|
|
- int Sysdeps<GetSockopt>::operator()(int fd, int layer, int number,
|
|
- void *__restrict buffer, socklen_t *__restrict size) {
|
|
+ int Sysdeps<Setxattr>::operator()(const char *path, const char *name,
|
|
+ const void *val, size_t size, int flags) {
|
|
+ (void)path;
|
|
+ (void)name;
|
|
+ (void)val;
|
|
(void)size;
|
|
- (void)buffer;
|
|
- // TODO unstub
|
|
- mlibc::infoLogger() << "getsockopt: " << fd << " " << layer << " " << number << frg::endlog;
|
|
+ (void)flags;
|
|
+ return ENOTSUP;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Lsetxattr>::operator()(const char *path, const char *name,
|
|
+ const void *val, size_t size, int flags) {
|
|
+ (void)path;
|
|
+ (void)name;
|
|
+ (void)val;
|
|
+ (void)size;
|
|
+ (void)flags;
|
|
+ return ENOTSUP;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Fsetxattr>::operator()(int fd, const char *name, const void *val,
|
|
+ size_t size, int flags) {
|
|
+ (void)fd;
|
|
+ (void)name;
|
|
+ (void)val;
|
|
+ (void)size;
|
|
+ (void)flags;
|
|
+ return ENOTSUP;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Getxattr>::operator()(const char *path, const char *name,
|
|
+ void *val, size_t size, ssize_t *nread) {
|
|
+ (void)path;
|
|
+ (void)name;
|
|
+ (void)val;
|
|
+ (void)size;
|
|
+ (void)nread;
|
|
+ return ENOTSUP;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Lgetxattr>::operator()(const char *path, const char *name,
|
|
+ void *val, size_t size, ssize_t *nread) {
|
|
+ (void)path;
|
|
+ (void)name;
|
|
+ (void)val;
|
|
+ (void)size;
|
|
+ (void)nread;
|
|
+ return ENOTSUP;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Fgetxattr>::operator()(int fd, const char *name, void *val,
|
|
+ size_t size, ssize_t *nread) {
|
|
+ (void)fd;
|
|
+ (void)name;
|
|
+ (void)val;
|
|
+ (void)size;
|
|
+ (void)nread;
|
|
+ return ENOTSUP;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Listxattr>::operator()(const char *path, char *list, size_t size,
|
|
+ ssize_t *nread) {
|
|
+ (void)path;
|
|
+ (void)list;
|
|
+ (void)size;
|
|
+ (void)nread;
|
|
+ return ENOTSUP;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Llistxattr>::operator()(const char *path, char *list, size_t size,
|
|
+ ssize_t *nread) {
|
|
+ (void)path;
|
|
+ (void)list;
|
|
+ (void)size;
|
|
+ (void)nread;
|
|
+ return ENOTSUP;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Flistxattr>::operator()(int fd, char *list, size_t size,
|
|
+ ssize_t *nread) {
|
|
+ (void)fd;
|
|
+ (void)list;
|
|
+ (void)size;
|
|
+ (void)nread;
|
|
+ return ENOTSUP;
|
|
+ }
|
|
+
|
|
+#ifndef MLIBC_BUILDING_RTLD
|
|
+ int Sysdeps<Getifaddrs>::operator()(struct ifaddrs **out) {
|
|
+ struct ifaddrs *list = nullptr;
|
|
+
|
|
+ int dirfd;
|
|
+ int error = sysdep<Open>("/dev/", O_DIRECTORY | O_RDONLY, 0, &dirfd);
|
|
+ if(error)
|
|
+ return error;
|
|
+
|
|
+ struct dirent dent;
|
|
+ size_t bytes_read;
|
|
+ for(;;) {
|
|
+ error = sysdep<ReadEntries>(dirfd, &dent, sizeof(dent), &bytes_read);
|
|
+ if(error)
|
|
+ goto leave;
|
|
+
|
|
+ if(bytes_read == 0)
|
|
+ break;
|
|
+
|
|
+ struct stat st;
|
|
+ if(sysdep<Stat>(fsfd_target::fd_path, dirfd, dent.d_name, AT_SYMLINK_NOFOLLOW, &st))
|
|
+ continue;
|
|
+
|
|
+ if(!S_ISCHR(st.st_mode) || major(st.st_rdev) != 10)
|
|
+ continue;
|
|
+
|
|
+ if(strlen(dent.d_name) >= IFNAMSIZ)
|
|
+ continue;
|
|
+
|
|
+ int fd;
|
|
+ error = sysdep<Openat>(dirfd, dent.d_name, 0, 0, &fd);
|
|
+ if(error)
|
|
+ continue;
|
|
+
|
|
+ astral_net_info_t net_info = {};
|
|
+ int r;
|
|
+ error = sysdep<Ioctl>(fd, 0x1337631, &net_info, &r);
|
|
+ if(error) {
|
|
+ sysdep<Close>(fd);
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ astral_ifaddrs_t *next = (astral_ifaddrs_t *)calloc(1, sizeof(*next));
|
|
+ if(!next) {
|
|
+ sysdep<Close>(fd);
|
|
+ error = ENOMEM;
|
|
+ goto leave;
|
|
+ }
|
|
+
|
|
+ next->ifa.ifa_next = list;
|
|
+ next->if_index = minor(st.st_rdev) + 1;
|
|
+
|
|
+ strcpy(next->if_name, dent.d_name);
|
|
+ next->ifa.ifa_name = next->if_name;
|
|
+
|
|
+ next->ifa.ifa_flags = net_info.flags;
|
|
+
|
|
+ if(net_info.addr.sa_family) {
|
|
+ memcpy(&next->addr, &net_info.addr, sizeof(next->addr));
|
|
+ next->ifa.ifa_addr = &next->addr;
|
|
+ }
|
|
+
|
|
+ if(net_info.netmask.sa_family) {
|
|
+ memcpy(&next->netmask, &net_info.netmask, sizeof(next->netmask));
|
|
+ next->ifa.ifa_netmask = &next->netmask;
|
|
+ }
|
|
+
|
|
+ if(net_info.broadaddr.sa_family) {
|
|
+ memcpy(&next->broadaddr, &net_info.broadaddr, sizeof(next->broadaddr));
|
|
+ next->ifa.ifa_broadaddr = &next->broadaddr;
|
|
+ }
|
|
+
|
|
+ next->ifa.ifa_data = nullptr;
|
|
+
|
|
+ list = &next->ifa;
|
|
+ sysdep<Close>(fd);
|
|
+ }
|
|
+
|
|
+ *out = list;
|
|
+
|
|
+leave:
|
|
+ sysdep<Close>(dirfd);
|
|
+ if(error)
|
|
+ freeifaddrs(list);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<IfIndextoname>::operator()(unsigned int index, char *name) {
|
|
+ if(!index || !name)
|
|
+ return EINVAL;
|
|
+
|
|
+ struct ifaddrs *ifaddrs;
|
|
+ if(int e = sysdep<Getifaddrs>(&ifaddrs); e)
|
|
+ return e;
|
|
+
|
|
+ int error = ENXIO;
|
|
+ for(struct ifaddrs *it = ifaddrs; it; it = it->ifa_next) {
|
|
+ astral_ifaddrs_t *entry = (astral_ifaddrs_t *)it;
|
|
+ if(entry->if_index != index)
|
|
+ continue;
|
|
+
|
|
+ strcpy(name, entry->if_name);
|
|
+ error = 0;
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ freeifaddrs(ifaddrs);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<IfNametoindex>::operator()(const char *name, unsigned int *ret) {
|
|
+ if(!name)
|
|
+ return EINVAL;
|
|
+
|
|
+ struct ifaddrs *ifaddrs;
|
|
+ if(int e = sysdep<Getifaddrs>(&ifaddrs); e)
|
|
+ return e;
|
|
+
|
|
+ int error = ENXIO;
|
|
+ for(struct ifaddrs *it = ifaddrs; it; it = it->ifa_next) {
|
|
+ astral_ifaddrs_t *entry = (astral_ifaddrs_t *)it;
|
|
+ if(strcmp(entry->if_name, name))
|
|
+ continue;
|
|
+
|
|
+ *ret = entry->if_index;
|
|
+ error = 0;
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ freeifaddrs(ifaddrs);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<IfNameindex>::operator()(struct if_nameindex **out) {
|
|
+ struct ifaddrs *ifaddrs;
|
|
+ if(int e = sysdep<Getifaddrs>(&ifaddrs); e)
|
|
+ return e;
|
|
+
|
|
+ struct ifaddrs *it = ifaddrs;
|
|
+ int count = 0;
|
|
+ while(it) {
|
|
+ ++count;
|
|
+ it = it->ifa_next;
|
|
+ }
|
|
+
|
|
+ struct if_nameindex *arr = (struct if_nameindex *)malloc(sizeof(struct if_nameindex) * (count + 1));
|
|
+ if(!arr) {
|
|
+ freeifaddrs(ifaddrs);
|
|
+ return ENOMEM;
|
|
+ }
|
|
+
|
|
+ int i = 0;
|
|
+ for(struct ifaddrs *it = ifaddrs; it; it = it->ifa_next) {
|
|
+ astral_ifaddrs_t *entry = (astral_ifaddrs_t *)it;
|
|
+
|
|
+ arr[i].if_index = entry->if_index;
|
|
+ arr[i].if_name = strdup(entry->if_name);
|
|
+ if(!arr[i].if_name) {
|
|
+ for(int j = 0; j < i; ++j)
|
|
+ free(arr[j].if_name);
|
|
+ free(arr);
|
|
+ freeifaddrs(ifaddrs);
|
|
+ return ENOMEM;
|
|
+ }
|
|
+
|
|
+ ++i;
|
|
+ }
|
|
+
|
|
+ arr[count].if_index = 0;
|
|
+ arr[count].if_name = nullptr;
|
|
+
|
|
+ *out = arr;
|
|
+ freeifaddrs(ifaddrs);
|
|
+
|
|
return 0;
|
|
}
|
|
+#endif
|
|
+
|
|
+ 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 +332,71 @@ namespace mlibc {
|
|
return 0;
|
|
}
|
|
|
|
+ int Sysdeps<Unlockpt>::operator()(int fd) {
|
|
+ int r;
|
|
+ // unlockpt is a no-op kernel side, so use this to check for an invalid pty
|
|
+ return sysdep<Ioctl>(fd, 0x13376167, nullptr, &r);
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Statfs>::operator()(const char *path, struct statfs *buf) {
|
|
+ struct statvfs stvfs;
|
|
+ int ret = sysdep<Statvfs>(path, &stvfs);
|
|
+ if(ret)
|
|
+ return ret;
|
|
+
|
|
+ buf->f_type = 0; /* statvfs has no f_type */
|
|
+ buf->f_blocks = stvfs.f_blocks;
|
|
+ buf->f_bfree = stvfs.f_bfree;
|
|
+ buf->f_bavail = stvfs.f_bavail;
|
|
+ buf->f_files = stvfs.f_files;
|
|
+ buf->f_ffree = stvfs.f_ffree;
|
|
+ buf->f_fsid.__val[0] = (int)(stvfs.f_fsid & 0xFFFFFFFF);
|
|
+ buf->f_fsid.__val[1] = (int)(stvfs.f_fsid >> 32);
|
|
+ buf->f_namelen = stvfs.f_namemax;
|
|
+ buf->f_flags = stvfs.f_flag;
|
|
+ buf->f_bsize = stvfs.f_frsize;
|
|
+ buf->f_frsize = stvfs.f_bsize;
|
|
+
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Fstatfs>::operator()(int fd, struct statfs *buf) {
|
|
+ struct statvfs stvfs;
|
|
+ int ret = sysdep<Fstatvfs>(fd, &stvfs);
|
|
+ if(ret)
|
|
+ return ret;
|
|
+
|
|
+ buf->f_type = 0; /* statvfs has no f_type */
|
|
+ buf->f_bsize = stvfs.f_bsize;
|
|
+ buf->f_bfree = stvfs.f_bfree;
|
|
+ buf->f_bavail = stvfs.f_bavail;
|
|
+ buf->f_files = stvfs.f_files;
|
|
+ buf->f_ffree = stvfs.f_ffree;
|
|
+ buf->f_fsid.__val[0] = (int)(stvfs.f_fsid & 0xFFFFFFFF);
|
|
+ buf->f_fsid.__val[1] = (int)(stvfs.f_fsid >> 32);
|
|
+ buf->f_namelen = stvfs.f_namemax;
|
|
+ buf->f_flags = stvfs.f_flag;
|
|
+ buf->f_bsize = stvfs.f_frsize;
|
|
+ buf->f_frsize = stvfs.f_bsize;
|
|
+
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Statvfs>::operator()(const char *path, struct statvfs *out) {
|
|
+ long r;
|
|
+ return syscall(SYSCALL_FSTATVFSAT, &r, AT_FDCWD, (uint64_t)path, (uint64_t)out, 0);
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Fstatvfs>::operator()(int fd, struct statvfs *out) {
|
|
+ long r;
|
|
+ return syscall(SYSCALL_FSTATVFS, &r, fd, (uint64_t)out);
|
|
+ }
|
|
+
|
|
+ void Sysdeps<Yield>::operator()() {
|
|
+ long r;
|
|
+ syscall(SYSCALL_YIELD, &r);
|
|
+ }
|
|
+
|
|
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);
|
|
@@ -489,6 +839,7 @@ namespace mlibc {
|
|
|
|
int Sysdeps<SetSockopt>::operator()(int fd, int layer, int number, const void *buffer, socklen_t size) {
|
|
long ret;
|
|
+ mlibc::infoLogger() << "setsockopt: fd " << fd << " layer " << layer << " number " << number << frg::endlog;
|
|
return syscall(SYSCALL_SETSOCKOPT, &ret, fd, layer, number, (uint64_t)buffer, size);
|
|
}
|
|
|
|
@@ -562,6 +913,16 @@ namespace mlibc {
|
|
return sysdep<Ioctl>(fd, TCSETS, (void *)attr, &res);
|
|
}
|
|
|
|
+ int Sysdeps<Tcgetwinsize>::operator()(int fd, struct winsize *winsz) {
|
|
+ int res;
|
|
+ return sysdep<Ioctl>(fd, TIOCGWINSZ, (void *)winsz, &res);
|
|
+ }
|
|
+
|
|
+ int Sysdeps<Tcsetwinsize>::operator()(int fd, const struct winsize *winsz) {
|
|
+ int res;
|
|
+ return sysdep<Ioctl>(fd, TIOCSWINSZ, (void *)winsz, &res);
|
|
+ }
|
|
+
|
|
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 +1293,13 @@ namespace mlibc {
|
|
*nanos = ts.tv_nsec;
|
|
return err;
|
|
}
|
|
+
|
|
+ int Sysdeps<ClockGetres>::operator()(int clock, time_t *secs, long *nanos) {
|
|
+ struct timespec ts;
|
|
+ long ret;
|
|
+ int err = syscall(SYSCALL_CLOCK_GETRES, &ret, clock, (uint64_t)&ts);
|
|
+ *secs = ts.tv_sec;
|
|
+ *nanos = ts.tv_nsec;
|
|
+ return err;
|
|
+ }
|
|
} // namespace mlibc
|
|
diff --git mlibc-clean/sysdeps/astral/include/astral/archctl.h mlibc-workdir/sysdeps/astral/include/astral/archctl.h
|
|
index 7e4f2a1..ecc2677 100644
|
|
--- mlibc-clean/sysdeps/astral/include/astral/archctl.h
|
|
+++ mlibc-workdir/sysdeps/astral/include/astral/archctl.h
|
|
@@ -5,6 +5,17 @@
|
|
#define ARCH_CTL_SET_FSBASE 1
|
|
#define ARCH_CTL_GET_GSBASE 2
|
|
#define ARCH_CTL_GET_FSBASE 3
|
|
+#define ARCH_CTL_SET_SYSTRACE 4
|
|
+#define ARCH_CTL_SET_LDT_ENTRY 5
|
|
+
|
|
+#define ARCH_CTL_SYSTRACE_OFF 0
|
|
+#define ARCH_CTL_SYSTRACE_SELF 1
|
|
+#define ARCH_CTL_SYSTRACE_ALL 2
|
|
+
|
|
+typedef struct {
|
|
+ uint64_t entry;
|
|
+ uint16_t seg;
|
|
+} archctl_ldt_request_t;
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
diff --git mlibc-clean/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
|
index a6c4067..f1e0b65 100644
|
|
--- mlibc-clean/sysdeps/astral/include/astral/syscall.h
|
|
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
|
@@ -103,6 +103,11 @@
|
|
#define SYSCALL_SYSINFO 96
|
|
#define SYSCALL_WRITEV 97
|
|
#define SYSCALL_READV 98
|
|
+#define SYSCALL_YIELD 99
|
|
+#define SYSCALL_FSTATVFS 100
|
|
+#define SYSCALL_FSTATVFSAT 101
|
|
+#define SYSCALL_GETSOCKOPT 102
|
|
+#define SYSCALL_CLOCK_GETRES 103
|
|
|
|
#ifndef __MLIBC_ABI_ONLY
|
|
|
|
diff --git mlibc-clean/sysdeps/astral/include/mlibc/sysdeps.hpp mlibc-workdir/sysdeps/astral/include/mlibc/sysdeps.hpp
|
|
index ce91084..8af97e2 100644
|
|
--- mlibc-clean/sysdeps/astral/include/mlibc/sysdeps.hpp
|
|
+++ mlibc-workdir/sysdeps/astral/include/mlibc/sysdeps.hpp
|
|
@@ -7,8 +7,27 @@ namespace mlibc {
|
|
struct AstralSysdepTags :
|
|
SetGroups,
|
|
GetGroups,
|
|
+ Setxattr,
|
|
+ Lsetxattr,
|
|
+ Fsetxattr,
|
|
+ Getxattr,
|
|
+ Lgetxattr,
|
|
+ Fgetxattr,
|
|
+ Listxattr,
|
|
+ Llistxattr,
|
|
+ Flistxattr,
|
|
+ Getifaddrs,
|
|
+ IfIndextoname,
|
|
+ IfNametoindex,
|
|
+ IfNameindex,
|
|
GetSockopt,
|
|
InetConfigured,
|
|
+ Unlockpt,
|
|
+ Statfs,
|
|
+ Fstatfs,
|
|
+ Statvfs,
|
|
+ Fstatvfs,
|
|
+ Yield,
|
|
Readv,
|
|
Writev,
|
|
Sysinfo,
|
|
@@ -85,6 +104,8 @@ struct AstralSysdepTags :
|
|
Sleep,
|
|
Tcgetattr,
|
|
Tcsetattr,
|
|
+ Tcgetwinsize,
|
|
+ Tcsetwinsize,
|
|
Poll,
|
|
Ppoll,
|
|
Pselect,
|
|
@@ -135,6 +156,7 @@ struct AstralSysdepTags :
|
|
VmUnmap,
|
|
Isatty,
|
|
ClockGet,
|
|
+ ClockGetres,
|
|
PrepareStack
|
|
{};
|
|
|