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