forked from Bananymous/banan-os
Kernel/LibC: pass environ pointer to process
This commit is contained in:
parent
668517a723
commit
b0e9ab0519
|
@ -25,7 +25,7 @@ continue_thread:
|
|||
movq $0, %rax
|
||||
jmp *%rsi
|
||||
|
||||
# void thread_userspace_trampoline(uint64_t rsp, uint64_t rip, int argc, char** argv)
|
||||
# void thread_userspace_trampoline(uint64_t rsp, uint64_t rip, int argc, char** argv, char** envp)
|
||||
.global thread_userspace_trampoline
|
||||
thread_userspace_trampoline:
|
||||
pushq $0x23
|
||||
|
@ -35,4 +35,5 @@ thread_userspace_trampoline:
|
|||
pushq %rsi
|
||||
movq %rdx, %rdi
|
||||
movq %rcx, %rsi
|
||||
movq %r8, %rdx
|
||||
iretq
|
||||
|
|
|
@ -9,10 +9,12 @@ _start:
|
|||
movq %rsp, %rbp
|
||||
|
||||
# We need those in a moment when we call main.
|
||||
pushq %rdx
|
||||
pushq %rsi
|
||||
pushq %rdi
|
||||
|
||||
# Prepare signals, memory allocation, stdio and such.
|
||||
movq %rdx, %rdi
|
||||
call _init_libc
|
||||
|
||||
# Run the global constructors.
|
||||
|
@ -21,6 +23,7 @@ _start:
|
|||
# Restore argc and argv.
|
||||
popq %rdi
|
||||
popq %rsi
|
||||
popq %rdx
|
||||
|
||||
# Run main
|
||||
call main
|
||||
|
|
|
@ -31,7 +31,8 @@ namespace Kernel
|
|||
{
|
||||
uintptr_t entry { 0 };
|
||||
int argc { 0 };
|
||||
char** argv { 0 };
|
||||
char** argv { nullptr };
|
||||
char** envp { nullptr };
|
||||
};
|
||||
|
||||
public:
|
||||
|
|
|
@ -78,6 +78,7 @@ namespace Kernel
|
|||
|
||||
process->m_userspace_entry.argc = 1;
|
||||
process->m_userspace_entry.argv = argv;
|
||||
process->m_userspace_entry.envp = (char**)0x69696969;
|
||||
process->m_userspace_entry.entry = elf->file_header_native().e_entry;
|
||||
|
||||
delete elf;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace Kernel
|
||||
{
|
||||
|
||||
extern "C" void thread_userspace_trampoline(uint64_t rsp, uint64_t rip, int argc, char** argv);
|
||||
extern "C" void thread_userspace_trampoline(uint64_t rsp, uint64_t rip, int argc, char** argv, char** envp);
|
||||
extern "C" uintptr_t read_rip();
|
||||
|
||||
template<size_t size, typename T>
|
||||
|
@ -131,7 +131,7 @@ namespace Kernel
|
|||
[](void*)
|
||||
{
|
||||
const auto& entry = Process::current().userspace_entry();
|
||||
thread_userspace_trampoline(Thread::current().rsp(), entry.entry, entry.argc, entry.argv);
|
||||
thread_userspace_trampoline(Thread::current().rsp(), entry.entry, entry.argc, entry.argv, entry.envp);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -9,10 +9,13 @@
|
|||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char** environ;
|
||||
|
||||
extern "C" void _init_stdio();
|
||||
|
||||
extern "C" void _init_libc()
|
||||
extern "C" void _init_libc(char** _environ)
|
||||
{
|
||||
environ = _environ;
|
||||
_init_stdio();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue