diff --git a/meson.build b/meson.build index 3f17f2152a..8f0f409c80 100644 --- a/meson.build +++ b/meson.build @@ -257,7 +257,7 @@ elif host_machine.system() == 'dripos' libc_include_dirs += include_directories('sysdeps/dripos/include') subdir('sysdeps/dripos') elif host_machine.system() == 'wivos' - rtdl_include_dirs += include_directories('sysdeps/wivos/include') + rtld_include_dirs += include_directories('sysdeps/wivos/include') libc_include_dirs += include_directories('sysdeps/wivos/include') subdir('sysdeps/wivos') elif host_machine.system() == 'astral' diff --git a/sysdeps/wivos/crt-x86_64/crt0.S b/sysdeps/wivos/crt-x86_64/crt0.S index d16a46f860..62298e3708 100644 --- a/sysdeps/wivos/crt-x86_64/crt0.S +++ b/sysdeps/wivos/crt-x86_64/crt0.S @@ -1,7 +1,10 @@ .section .text + .global _start _start: mov $main, %rdi call __mlibc_entry + +.size _start, . - _start .section .note.GNU-stack,"",%progbits diff --git a/sysdeps/wivos/generic/entry.cpp b/sysdeps/wivos/generic/entry.cpp index dc01b2ca50..288aaf3d1d 100644 --- a/sysdeps/wivos/generic/entry.cpp +++ b/sysdeps/wivos/generic/entry.cpp @@ -1,35 +1,76 @@ -#include -#include #include #include +#include +#include +#include +#include +#include -// defined by the POSIX library -void __mlibc_initLocale(); - -extern "C" uintptr_t *__dlapi_entrystack(); +extern "C" void __dlapi_enter(uintptr_t *); extern char **environ; -static mlibc::exec_stack_data __mlibc_stack_data; -struct LibraryGuard { - LibraryGuard(); +struct GPRState { + uint64_t ds; + uint64_t es; + uint64_t rax; + uint64_t rbx; + uint64_t rcx; + uint64_t rdx; + uint64_t rsi; + uint64_t rdi; + uint64_t rbp; + uint64_t r8; + uint64_t r9; + uint64_t r10; + uint64_t r11; + uint64_t r12; + uint64_t r13; + uint64_t r14; + uint64_t r15; + uint64_t err; + uint64_t rip; + uint64_t cs; + uint64_t rflags; + uint64_t rsp; + uint64_t ss; }; -static LibraryGuard guard; +namespace mlibc { + [[noreturn]] int sys_sigreturn(void *context, sigset_t old_mask) { + (void)context; + (void)old_mask; + //TODO + while(1); + //__syscall(30, context, old_mask); + //__builtin_unreachable(); + } +} + +static void __mlibc_sigentry(int which, siginfo_t *siginfo, + void (*sa)(int, siginfo_t *, void *), + GPRState *ret_context, sigset_t prev_mask) { + switch ((uintptr_t)sa) { + // DFL + case (uintptr_t)(-2): + mlibc::infoLogger() << "mlibc: Unhandled signal " << which << frg::endlog; + mlibc::sys_exit(128 + which); + // IGN + case (uintptr_t)(-3): + break; + default: + sa(which, siginfo, NULL); + break; + } -LibraryGuard::LibraryGuard() { - __mlibc_initLocale(); + mlibc::sys_sigreturn(ret_context, prev_mask); - // Parse the exec() stack. - mlibc::parse_exec_stack(__dlapi_entrystack(), &__mlibc_stack_data); - mlibc::set_startup_data(__mlibc_stack_data.argc, __mlibc_stack_data.argv, - __mlibc_stack_data.envp); + __builtin_unreachable(); } -extern "C" void __mlibc_entry(int (*main_fn)(int argc, char *argv[], - char *env[])) { - // TODO: call __dlapi_enter, otherwise static builds will break (see Linux sysdeps) - auto result = - main_fn(__mlibc_stack_data.argc, __mlibc_stack_data.argv, environ); - exit(result); +extern "C" void __mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, char *argv[], char *env[])) { + __dlapi_enter(entry_stack); + + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); + exit(result); } diff --git a/sysdeps/wivos/generic/generic.cpp b/sysdeps/wivos/generic/generic.cpp index 78f6f92610..9e2f4e983a 100644 --- a/sysdeps/wivos/generic/generic.cpp +++ b/sysdeps/wivos/generic/generic.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include diff --git a/sysdeps/wivos/include/abi-bits/access.h b/sysdeps/wivos/include/abi-bits/access.h index 171f75f81b..cb83931670 120000 --- a/sysdeps/wivos/include/abi-bits/access.h +++ b/sysdeps/wivos/include/abi-bits/access.h @@ -1 +1 @@ -../../../../abis/mlibc/access.h \ No newline at end of file +../../../../abis/linux/access.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/auxv.h b/sysdeps/wivos/include/abi-bits/auxv.h index 86157e87f8..c43f878641 120000 --- a/sysdeps/wivos/include/abi-bits/auxv.h +++ b/sysdeps/wivos/include/abi-bits/auxv.h @@ -1 +1 @@ -../../../../abis/aero/auxv.h \ No newline at end of file +../../../../abis/linux/auxv.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/blkcnt_t.h b/sysdeps/wivos/include/abi-bits/blkcnt_t.h index e9d9f1b4ea..0b0ec270d7 120000 --- a/sysdeps/wivos/include/abi-bits/blkcnt_t.h +++ b/sysdeps/wivos/include/abi-bits/blkcnt_t.h @@ -1 +1 @@ -../../../../abis/mlibc/blkcnt_t.h \ No newline at end of file +../../../../abis/linux/blkcnt_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/blksize_t.h b/sysdeps/wivos/include/abi-bits/blksize_t.h index c6dfb6e0f6..7dc8d7cfa6 120000 --- a/sysdeps/wivos/include/abi-bits/blksize_t.h +++ b/sysdeps/wivos/include/abi-bits/blksize_t.h @@ -1 +1 @@ -../../../../abis/mlibc/blksize_t.h \ No newline at end of file +../../../../abis/linux/blksize_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/clockid_t.h b/sysdeps/wivos/include/abi-bits/clockid_t.h index 71f37bb6bd..6a42da56aa 120000 --- a/sysdeps/wivos/include/abi-bits/clockid_t.h +++ b/sysdeps/wivos/include/abi-bits/clockid_t.h @@ -1 +1 @@ -../../../../abis/mlibc/clockid_t.h \ No newline at end of file +../../../../abis/linux/clockid_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/dev_t.h b/sysdeps/wivos/include/abi-bits/dev_t.h index 0c1143b935..bca881e92c 120000 --- a/sysdeps/wivos/include/abi-bits/dev_t.h +++ b/sysdeps/wivos/include/abi-bits/dev_t.h @@ -1 +1 @@ -../../../../abis/mlibc/dev_t.h \ No newline at end of file +../../../../abis/linux/dev_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/epoll.h b/sysdeps/wivos/include/abi-bits/epoll.h index 9efc3a05b7..eb4b76dcfc 120000 --- a/sysdeps/wivos/include/abi-bits/epoll.h +++ b/sysdeps/wivos/include/abi-bits/epoll.h @@ -1 +1 @@ -../../../../abis/mlibc/epoll.h \ No newline at end of file +../../../../abis/linux/epoll.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/errno.h b/sysdeps/wivos/include/abi-bits/errno.h index 589859fb9d..6e507deff2 120000 --- a/sysdeps/wivos/include/abi-bits/errno.h +++ b/sysdeps/wivos/include/abi-bits/errno.h @@ -1 +1 @@ -../../../../abis/mlibc/errno.h \ No newline at end of file +../../../../abis/linux/errno.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/fcntl.h b/sysdeps/wivos/include/abi-bits/fcntl.h index ea5323ad0e..463e2c9545 120000 --- a/sysdeps/wivos/include/abi-bits/fcntl.h +++ b/sysdeps/wivos/include/abi-bits/fcntl.h @@ -1 +1 @@ -../../../../abis/mlibc/fcntl.h \ No newline at end of file +../../../../abis/linux/fcntl.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/gid_t.h b/sysdeps/wivos/include/abi-bits/gid_t.h index 6a77218044..abce6d69ad 120000 --- a/sysdeps/wivos/include/abi-bits/gid_t.h +++ b/sysdeps/wivos/include/abi-bits/gid_t.h @@ -1 +1 @@ -../../../../abis/mlibc/gid_t.h \ No newline at end of file +../../../../abis/linux/gid_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/in.h b/sysdeps/wivos/include/abi-bits/in.h index b58c683f27..418d1d5c04 120000 --- a/sysdeps/wivos/include/abi-bits/in.h +++ b/sysdeps/wivos/include/abi-bits/in.h @@ -1 +1 @@ -../../../../abis/mlibc/in.h \ No newline at end of file +../../../../abis/linux/in.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/ino_t.h b/sysdeps/wivos/include/abi-bits/ino_t.h index 10d644e77e..4c20aca26a 120000 --- a/sysdeps/wivos/include/abi-bits/ino_t.h +++ b/sysdeps/wivos/include/abi-bits/ino_t.h @@ -1 +1 @@ -../../../../abis/mlibc/ino_t.h \ No newline at end of file +../../../../abis/linux/ino_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/inotify.h b/sysdeps/wivos/include/abi-bits/inotify.h index 3f19ef6e17..b5cb28237a 120000 --- a/sysdeps/wivos/include/abi-bits/inotify.h +++ b/sysdeps/wivos/include/abi-bits/inotify.h @@ -1 +1 @@ -../../../../abis/mlibc/inotify.h \ No newline at end of file +../../../../abis/linux/inotify.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/limits.h b/sysdeps/wivos/include/abi-bits/limits.h index 1aa589426a..6c88db2ed6 120000 --- a/sysdeps/wivos/include/abi-bits/limits.h +++ b/sysdeps/wivos/include/abi-bits/limits.h @@ -1 +1 @@ -../../../../abis/mlibc/limits.h \ No newline at end of file +../../../../abis/linux/limits.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/mode_t.h b/sysdeps/wivos/include/abi-bits/mode_t.h index 29d7733123..5d78fdfc3b 120000 --- a/sysdeps/wivos/include/abi-bits/mode_t.h +++ b/sysdeps/wivos/include/abi-bits/mode_t.h @@ -1 +1 @@ -../../../../abis/mlibc/mode_t.h \ No newline at end of file +../../../../abis/linux/mode_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/msg.h b/sysdeps/wivos/include/abi-bits/msg.h new file mode 120000 index 0000000000..f402b49306 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/msg.h @@ -0,0 +1 @@ +../../../../abis/linux/msg.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/nlink_t.h b/sysdeps/wivos/include/abi-bits/nlink_t.h index 7618c27f51..bb3b625c32 120000 --- a/sysdeps/wivos/include/abi-bits/nlink_t.h +++ b/sysdeps/wivos/include/abi-bits/nlink_t.h @@ -1 +1 @@ -../../../../abis/mlibc/nlink_t.h \ No newline at end of file +../../../../abis/linux/nlink_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/packet.h b/sysdeps/wivos/include/abi-bits/packet.h index 47067e2149..998ef1ab03 120000 --- a/sysdeps/wivos/include/abi-bits/packet.h +++ b/sysdeps/wivos/include/abi-bits/packet.h @@ -1 +1 @@ -../../../../abis/mlibc/packet.h \ No newline at end of file +../../../../abis/linux/packet.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/pid_t.h b/sysdeps/wivos/include/abi-bits/pid_t.h index 3fd26a7f05..baa90f6af6 120000 --- a/sysdeps/wivos/include/abi-bits/pid_t.h +++ b/sysdeps/wivos/include/abi-bits/pid_t.h @@ -1 +1 @@ -../../../../abis/mlibc/pid_t.h \ No newline at end of file +../../../../abis/linux/pid_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/poll.h b/sysdeps/wivos/include/abi-bits/poll.h index ab989c75eb..8ea6a0a39c 120000 --- a/sysdeps/wivos/include/abi-bits/poll.h +++ b/sysdeps/wivos/include/abi-bits/poll.h @@ -1 +1 @@ -../../../../abis/mlibc/poll.h \ No newline at end of file +../../../../abis/linux/poll.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/ptrace.h b/sysdeps/wivos/include/abi-bits/ptrace.h index f391fb72f8..b2517b2cf1 120000 --- a/sysdeps/wivos/include/abi-bits/ptrace.h +++ b/sysdeps/wivos/include/abi-bits/ptrace.h @@ -1 +1 @@ -../../../../abis/mlibc/ptrace.h \ No newline at end of file +../../../../abis/linux/ptrace.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/resource.h b/sysdeps/wivos/include/abi-bits/resource.h index 3e59c75080..88d74025fa 120000 --- a/sysdeps/wivos/include/abi-bits/resource.h +++ b/sysdeps/wivos/include/abi-bits/resource.h @@ -1 +1 @@ -../../../../abis/mlibc/resource.h \ No newline at end of file +../../../../abis/linux/resource.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/seek-whence.h b/sysdeps/wivos/include/abi-bits/seek-whence.h index 76d0b1a80f..df7bccf02c 120000 --- a/sysdeps/wivos/include/abi-bits/seek-whence.h +++ b/sysdeps/wivos/include/abi-bits/seek-whence.h @@ -1 +1 @@ -../../../../abis/wivos/seek-whence.h \ No newline at end of file +../../../../abis/linux/seek-whence.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/signal.h b/sysdeps/wivos/include/abi-bits/signal.h index 4dcb0b7ce5..709546b101 120000 --- a/sysdeps/wivos/include/abi-bits/signal.h +++ b/sysdeps/wivos/include/abi-bits/signal.h @@ -1 +1 @@ -../../../../abis/linux/signal.h \ No newline at end of file +../../../../abis/vinix/signal.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/socket.h b/sysdeps/wivos/include/abi-bits/socket.h index 0e1d6be9d5..f1dc016e6d 120000 --- a/sysdeps/wivos/include/abi-bits/socket.h +++ b/sysdeps/wivos/include/abi-bits/socket.h @@ -1 +1 @@ -../../../../abis/mlibc/socket.h \ No newline at end of file +../../../../abis/linux/socket.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/stat.h b/sysdeps/wivos/include/abi-bits/stat.h index 82642c3ce4..1f63b41fdf 120000 --- a/sysdeps/wivos/include/abi-bits/stat.h +++ b/sysdeps/wivos/include/abi-bits/stat.h @@ -1 +1 @@ -../../../../abis/mlibc/stat.h \ No newline at end of file +../../../../abis/linux/stat.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/statvfs.h b/sysdeps/wivos/include/abi-bits/statvfs.h index 1fc80c2a76..d0bdd40859 120000 --- a/sysdeps/wivos/include/abi-bits/statvfs.h +++ b/sysdeps/wivos/include/abi-bits/statvfs.h @@ -1 +1 @@ -../../../../abis/linux/statvfs.h \ No newline at end of file +../../../../abis/lyre/statvfs.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/statx.h b/sysdeps/wivos/include/abi-bits/statx.h new file mode 120000 index 0000000000..8702a1d000 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/statx.h @@ -0,0 +1 @@ +../../../../abis/linux/statx.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/time.h b/sysdeps/wivos/include/abi-bits/time.h index 97f3d52dd7..2a02625743 120000 --- a/sysdeps/wivos/include/abi-bits/time.h +++ b/sysdeps/wivos/include/abi-bits/time.h @@ -1 +1 @@ -../../../../abis/mlibc/time.h \ No newline at end of file +../../../../abis/linux/time.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/uid_t.h b/sysdeps/wivos/include/abi-bits/uid_t.h index 1113eba6e0..b306777852 120000 --- a/sysdeps/wivos/include/abi-bits/uid_t.h +++ b/sysdeps/wivos/include/abi-bits/uid_t.h @@ -1 +1 @@ -../../../../abis/mlibc/uid_t.h \ No newline at end of file +../../../../abis/linux/uid_t.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/vm-flags.h b/sysdeps/wivos/include/abi-bits/vm-flags.h index f1a985e6ac..bbe258cff1 120000 --- a/sysdeps/wivos/include/abi-bits/vm-flags.h +++ b/sysdeps/wivos/include/abi-bits/vm-flags.h @@ -1 +1 @@ -../../../../abis/mlibc/vm-flags.h \ No newline at end of file +../../../../abis/linux/vm-flags.h \ No newline at end of file diff --git a/sysdeps/wivos/include/abi-bits/xattr.h b/sysdeps/wivos/include/abi-bits/xattr.h new file mode 120000 index 0000000000..66412d7061 --- /dev/null +++ b/sysdeps/wivos/include/abi-bits/xattr.h @@ -0,0 +1 @@ +../../../../abis/linux/xattr.h \ No newline at end of file diff --git a/sysdeps/wivos/meson.build b/sysdeps/wivos/meson.build index 668141de06..48dc92f45a 100644 --- a/sysdeps/wivos/meson.build +++ b/sysdeps/wivos/meson.build @@ -1,5 +1,12 @@ -rtdl_sources += files( +sysdep_supported_options = { + 'posix': true, + 'linux': false, + 'glibc': true, + 'bsd': true, +} + +rtld_sources += files( 'generic/generic.cpp' ) @@ -16,9 +23,11 @@ if not no_headers 'include/abi-bits/errno.h', 'include/abi-bits/fcntl.h', 'include/abi-bits/in.h', + 'include/abi-bits/reboot.h', 'include/abi-bits/resource.h', - 'include/abi-bits/signal.h', 'include/abi-bits/stat.h', + 'include/abi-bits/statx.h', + 'include/abi-bits/signal.h', 'include/abi-bits/socket.h', 'include/abi-bits/termios.h', 'include/abi-bits/time.h',