Skip to content

Commit

Permalink
Add changes to fix current implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
StartForKiller committed Jan 28, 2025
1 parent 6a8b800 commit 482f70d
Show file tree
Hide file tree
Showing 37 changed files with 110 additions and 55 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions sysdeps/wivos/crt-x86_64/crt0.S
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
.section .text

.global _start
_start:
mov $main, %rdi
call __mlibc_entry

.size _start, . - _start
.section .note.GNU-stack,"",%progbits

85 changes: 63 additions & 22 deletions sysdeps/wivos/generic/entry.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,76 @@
#include <bits/ensure.h>
#include <mlibc/elf/startup.h>
#include <stdint.h>
#include <stdlib.h>
#include <bits/ensure.h>
#include <mlibc/debug.hpp>
#include <mlibc/elf/startup.h>
#include <mlibc/all-sysdeps.hpp>
#include <bits/posix/posix_signal.h>

// 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);
}
1 change: 0 additions & 1 deletion sysdeps/wivos/generic/generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
#include <asm/ioctls.h>
#include <stdlib.h>

#include <wivos/syscall.h>
Expand Down
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/access.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/auxv.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/blkcnt_t.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/blksize_t.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/clockid_t.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/dev_t.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/epoll.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/errno.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/fcntl.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/gid_t.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/in.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/ino_t.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/inotify.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/limits.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/mode_t.h
1 change: 1 addition & 0 deletions sysdeps/wivos/include/abi-bits/msg.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/nlink_t.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/packet.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/pid_t.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/poll.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/ptrace.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/resource.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/seek-whence.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/signal.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/socket.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/stat.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/statvfs.h
1 change: 1 addition & 0 deletions sysdeps/wivos/include/abi-bits/statx.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/time.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/uid_t.h
2 changes: 1 addition & 1 deletion sysdeps/wivos/include/abi-bits/vm-flags.h
1 change: 1 addition & 0 deletions sysdeps/wivos/include/abi-bits/xattr.h
13 changes: 11 additions & 2 deletions sysdeps/wivos/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@

rtdl_sources += files(
sysdep_supported_options = {
'posix': true,
'linux': false,
'glibc': true,
'bsd': true,
}

rtld_sources += files(
'generic/generic.cpp'
)

Expand All @@ -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',
Expand Down

0 comments on commit 482f70d

Please sign in to comment.