mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 20:58:22 +00:00
224 lines
7.3 KiB
Diff
224 lines
7.3 KiB
Diff
diff --git mlibc-clean/options/ansi/generic/wchar.cpp mlibc-workdir/options/ansi/generic/wchar.cpp
|
|
index b44ebc2..9339316 100644
|
|
--- mlibc-clean/options/ansi/generic/wchar.cpp
|
|
+++ mlibc-workdir/options/ansi/generic/wchar.cpp
|
|
@@ -54,8 +54,13 @@ size_t mbrlen(const char *__restrict mbs, size_t mb_limit, mbstate_t *__restrict
|
|
|
|
mlibc::code_seq<const char> nseq{mbs, mbs + mb_limit};
|
|
mlibc::code_seq<wchar_t> wseq{&wc, &wc + 1};
|
|
- if(auto e = cc->decode_wtranscode(nseq, wseq, *stp); e != mlibc::charcode_error::null)
|
|
- __ensure(!"decode_wtranscode() errors are not handled");
|
|
+ if(auto e = cc->decode_wtranscode(nseq, wseq, *stp); e != mlibc::charcode_error::null) {
|
|
+ if(e == mlibc::charcode_error::input_underflow)
|
|
+ return static_cast<size_t>(-1);
|
|
+ __ensure(e == mlibc::charcode_error::illegal_input);
|
|
+ errno = EILSEQ;
|
|
+ return static_cast<size_t>(-1);
|
|
+ }
|
|
return nseq.it - mbs;
|
|
}
|
|
|
|
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/rtld/generic/linker.cpp mlibc-workdir/options/rtld/generic/linker.cpp
|
|
index 07dbe11..3ece6ec 100644
|
|
--- mlibc-clean/options/rtld/generic/linker.cpp
|
|
+++ mlibc-workdir/options/rtld/generic/linker.cpp
|
|
@@ -29,7 +29,7 @@ uintptr_t libraryBase = 0x41000000;
|
|
|
|
constexpr bool verbose = false;
|
|
constexpr bool stillSlightlyVerbose = false;
|
|
-constexpr bool logBaseAddresses = false;
|
|
+constexpr bool logBaseAddresses = true;
|
|
constexpr bool logRpath = false;
|
|
constexpr bool logLdPath = false;
|
|
constexpr bool logSymbolVersions = false;
|
|
diff --git mlibc-clean/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
|
index 939925e..4c8cb95 100644
|
|
--- mlibc-clean/sysdeps/astral/generic/generic.cpp
|
|
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
|
@@ -47,6 +47,71 @@ namespace mlibc {
|
|
return 0;
|
|
}
|
|
|
|
+ int sys_unlockpt(int fd) {
|
|
+ int r;
|
|
+ // unlockpt is a no-op kernel side, so use this to check for an invalid pty
|
|
+ return sys_ioctl(fd, 0x13376167, NULL, &r);
|
|
+ }
|
|
+
|
|
+ int sys_statfs(const char *path, struct statfs *buf) {
|
|
+ struct statvfs stvfs;
|
|
+ int ret = sys_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 sys_fstatfs(int fd, struct statfs *buf) {
|
|
+ struct statvfs stvfs;
|
|
+ int ret = sys_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 sys_statvfs(const char *path, struct statvfs *out) {
|
|
+ long r;
|
|
+ return syscall(SYSCALL_FSTATVFSAT, &r, AT_FDCWD, (uint64_t)path, (uint64_t)out, 0);
|
|
+ }
|
|
+
|
|
+ int sys_fstatvfs(int fd, struct statvfs *out) {
|
|
+ long r;
|
|
+ return syscall(SYSCALL_FSTATVFS, &r, fd, (uint64_t)out);
|
|
+ }
|
|
+
|
|
+ void sys_yield() {
|
|
+ long r;
|
|
+ syscall(SYSCALL_YIELD, &r);
|
|
+ }
|
|
+
|
|
int sys_readv(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 +554,7 @@ namespace mlibc {
|
|
|
|
int sys_setsockopt(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);
|
|
}
|
|
|
|
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..0c4f0a1 100644
|
|
--- mlibc-clean/sysdeps/astral/include/astral/syscall.h
|
|
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
|
@@ -103,6 +103,9 @@
|
|
#define SYSCALL_SYSINFO 96
|
|
#define SYSCALL_WRITEV 97
|
|
#define SYSCALL_READV 98
|
|
+#define SYSCALL_YIELD 99
|
|
+#define SYSCALL_FSTATVFS 100
|
|
+#define SYSCALL_FSTATVFSAT 101
|
|
|
|
#ifndef __MLIBC_ABI_ONLY
|
|
|