forked from Bananymous/banan-os
Kernel: Invoke ELF interpreter instead if it is specified
This commit is contained in:
@@ -55,14 +55,15 @@ start_userspace_thread:
|
||||
movw %bx, %gs
|
||||
xorw %bx, %bx
|
||||
|
||||
popl %edx
|
||||
popl %esi
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %edx
|
||||
popl %ecx
|
||||
popl %ebx
|
||||
|
||||
pushl $(0x20 | 3)
|
||||
pushl %eax
|
||||
pushl $0x202
|
||||
pushl $(0x18 | 3)
|
||||
pushl %ecx
|
||||
pushl %ebx
|
||||
iret
|
||||
|
||||
@@ -39,14 +39,15 @@ start_userspace_thread:
|
||||
|
||||
call get_userspace_thread_stack_top
|
||||
|
||||
popq %rdx
|
||||
popq %rsi
|
||||
popq %rdi
|
||||
popq %rsi
|
||||
popq %rdx
|
||||
popq %rcx
|
||||
popq %rbx
|
||||
|
||||
pushq $(0x20 | 3)
|
||||
pushq %rax
|
||||
pushq $0x202
|
||||
pushq $(0x18 | 3)
|
||||
pushq %rcx
|
||||
pushq %rbx
|
||||
iretq
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace Kernel
|
||||
int argc { 0 };
|
||||
char** argv { nullptr };
|
||||
char** envp { nullptr };
|
||||
int file_fd { -1 };
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
@@ -411,7 +411,7 @@ namespace Kernel
|
||||
}
|
||||
|
||||
auto file = TRY(VirtualFileSystem::get().file_from_absolute_path(credentials, absolute_path, O_EXEC));
|
||||
return TRY(LibELF::LoadableELF::load_from_inode(page_table, file.inode));
|
||||
return TRY(LibELF::LoadableELF::load_from_inode(page_table, credentials, file.inode));
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_fork(uintptr_t sp, uintptr_t ip)
|
||||
@@ -515,6 +515,13 @@ namespace Kernel
|
||||
m_loadable_elf->reserve_address_space();
|
||||
m_loadable_elf->update_suid_sgid(m_credentials);
|
||||
m_userspace_info.entry = m_loadable_elf->entry_point();
|
||||
if (m_loadable_elf->has_interpreter())
|
||||
{
|
||||
VirtualFileSystem::File file;
|
||||
TRY(file.canonical_path.append("<self>"));
|
||||
file.inode = m_loadable_elf->inode();
|
||||
m_userspace_info.file_fd = TRY(m_open_file_descriptors.open(BAN::move(file), O_EXEC));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(m_signal_handlers) / sizeof(*m_signal_handlers); i++)
|
||||
{
|
||||
|
||||
@@ -190,22 +190,23 @@ namespace Kernel
|
||||
|
||||
// Signal mask is inherited
|
||||
|
||||
auto& userspace_info = process().userspace_info();
|
||||
const auto& userspace_info = process().userspace_info();
|
||||
ASSERT(userspace_info.entry);
|
||||
|
||||
// Initialize stack for returning
|
||||
PageTable::with_fast_page(process().page_table().physical_address_of(kernel_stack_top() - PAGE_SIZE), [&] {
|
||||
uintptr_t sp = PageTable::fast_page() + PAGE_SIZE;
|
||||
write_to_stack(sp, userspace_info.entry);
|
||||
write_to_stack(sp, userspace_info.argc);
|
||||
write_to_stack(sp, userspace_info.argv);
|
||||
write_to_stack(sp, userspace_info.file_fd);
|
||||
write_to_stack(sp, userspace_info.envp);
|
||||
write_to_stack(sp, userspace_info.argv);
|
||||
write_to_stack(sp, userspace_info.argc);
|
||||
});
|
||||
|
||||
m_interrupt_stack.ip = reinterpret_cast<vaddr_t>(start_userspace_thread);;
|
||||
m_interrupt_stack.ip = reinterpret_cast<vaddr_t>(start_userspace_thread);
|
||||
m_interrupt_stack.cs = 0x08;
|
||||
m_interrupt_stack.flags = 0x002;
|
||||
m_interrupt_stack.sp = kernel_stack_top() - 4 * sizeof(uintptr_t);
|
||||
m_interrupt_stack.sp = kernel_stack_top() - 5 * sizeof(uintptr_t);
|
||||
m_interrupt_stack.ss = 0x10;
|
||||
|
||||
memset(&m_interrupt_registers, 0, sizeof(InterruptRegisters));
|
||||
|
||||
Reference in New Issue
Block a user