[orbis-kernel] do not use linker for exec

implement hdd device stub
implement /dev/console rw
remove dup2 hack
fix altstack after execve
This commit is contained in:
DH 2023-11-02 16:26:58 +03:00
parent 3464f50eb9
commit 3cb4baed51
11 changed files with 289 additions and 130 deletions

View file

@ -1,4 +1,5 @@
#include "thread.hpp"
#include "align.hpp"
#include "orbis/sys/sysentry.hpp"
#include "orbis/thread/Process.hpp"
#include "orbis/thread/Thread.hpp"
@ -61,25 +62,48 @@ void rx::thread::initialize() {
void rx::thread::deinitialize() {}
void rx::thread::invoke(orbis::Thread *thread) {
orbis::g_currentThread = thread;
void rx::thread::setupSignalStack() {
stack_t ss{};
auto sigStackSize = std::max<std::size_t>(
SIGSTKSZ, ::utils::alignUp(64 * 1024 * 1024, sysconf(_SC_PAGE_SIZE)));
ss.ss_sp = malloc(sigStackSize);
if (ss.ss_sp == NULL) {
perror("malloc");
std::exit(EXIT_FAILURE);
}
ss.ss_size = sigStackSize;
ss.ss_flags = 1 << 31;
if (sigaltstack(&ss, NULL) == -1) {
perror("sigaltstack");
std::exit(EXIT_FAILURE);
}
}
void rx::thread::setupThisThread() {
sigset_t unblockSigs{};
sigset_t oldSigmask{};
sigaddset(&unblockSigs, SIGSYS);
if (pthread_sigmask(SIG_UNBLOCK, &unblockSigs, &oldSigmask)) {
perror("pthread_sigmask failed\n");
exit(-1);
std::exit(-1);
}
std::uint64_t hostFs = _readfsbase_u64();
_writegsbase_u64(hostFs);
if (prctl(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_ON,
(void *)0x100'0000'0000, ~0ull - 0x100'0000'0000, nullptr)) {
perror("prctl failed\n");
exit(-1);
std::exit(-1);
}
}
void rx::thread::invoke(orbis::Thread *thread) {
orbis::g_currentThread = thread;
std::uint64_t hostFs = _readfsbase_u64();
_writegsbase_u64(hostFs);
_writefsbase_u64(thread->fsBase);
auto context = reinterpret_cast<ucontext_t *>(thread->context);