-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add changes to fix current implementation
- Loading branch information
1 parent
6a8b800
commit 482f70d
Showing
37 changed files
with
110 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/access.h | ||
../../../../abis/linux/access.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/aero/auxv.h | ||
../../../../abis/linux/auxv.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/blkcnt_t.h | ||
../../../../abis/linux/blkcnt_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/blksize_t.h | ||
../../../../abis/linux/blksize_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/clockid_t.h | ||
../../../../abis/linux/clockid_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/dev_t.h | ||
../../../../abis/linux/dev_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/epoll.h | ||
../../../../abis/linux/epoll.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/errno.h | ||
../../../../abis/linux/errno.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/fcntl.h | ||
../../../../abis/linux/fcntl.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/gid_t.h | ||
../../../../abis/linux/gid_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/in.h | ||
../../../../abis/linux/in.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/ino_t.h | ||
../../../../abis/linux/ino_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/inotify.h | ||
../../../../abis/linux/inotify.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/limits.h | ||
../../../../abis/linux/limits.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/mode_t.h | ||
../../../../abis/linux/mode_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../abis/linux/msg.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/nlink_t.h | ||
../../../../abis/linux/nlink_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/packet.h | ||
../../../../abis/linux/packet.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/pid_t.h | ||
../../../../abis/linux/pid_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/poll.h | ||
../../../../abis/linux/poll.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/ptrace.h | ||
../../../../abis/linux/ptrace.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/resource.h | ||
../../../../abis/linux/resource.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/wivos/seek-whence.h | ||
../../../../abis/linux/seek-whence.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/linux/signal.h | ||
../../../../abis/vinix/signal.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/socket.h | ||
../../../../abis/linux/socket.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/stat.h | ||
../../../../abis/linux/stat.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/linux/statvfs.h | ||
../../../../abis/lyre/statvfs.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../abis/linux/statx.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/time.h | ||
../../../../abis/linux/time.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/uid_t.h | ||
../../../../abis/linux/uid_t.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../abis/mlibc/vm-flags.h | ||
../../../../abis/linux/vm-flags.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../abis/linux/xattr.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters