Add the ability to copy memory to non resident process.
Use/Test this by loading the user space elf from the kernel process before it starts rather than as a part of the first thread. This simplifies thread start a fair bit.
This commit is contained in:
parent
f6609983d2
commit
b9b45c5e45
9 changed files with 55 additions and 38 deletions
|
|
@ -46,17 +46,9 @@ typedef struct {
|
|||
uint64_t align;
|
||||
} Elf64ProgramHeader;
|
||||
|
||||
void badmemcpy(uint64_t base, uint64_t offset, uint64_t dest) {
|
||||
uint8_t* ptr = reinterpret_cast<uint8_t*>(base);
|
||||
uint8_t* dest_ptr = reinterpret_cast<uint8_t*>(dest);
|
||||
for (uint64_t i = 0; i < offset; i++) {
|
||||
dest_ptr[i] = ptr[i];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
uint64_t LoadElfProgram(uint64_t base, uint64_t offset) {
|
||||
uint64_t LoadElfProgram(uint64_t cr3, uint64_t base, uint64_t offset) {
|
||||
Elf64Header* header = reinterpret_cast<Elf64Header*>(base);
|
||||
dbgln("phoff: %u phnum: %u", header->phoff, header->phnum);
|
||||
Elf64ProgramHeader* programs =
|
||||
|
|
@ -68,8 +60,8 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t offset) {
|
|||
"filesz: %u, memsz: %u, align: %u",
|
||||
program.type, program.flags, program.offset, program.vaddr,
|
||||
program.paddr, program.filesz, program.memsz, program.align);
|
||||
EnsureResident(program.vaddr, program.memsz);
|
||||
badmemcpy(base + program.offset, program.filesz, program.vaddr);
|
||||
CopyIntoNonResidentProcess(base + program.offset, program.filesz, cr3,
|
||||
program.vaddr);
|
||||
}
|
||||
return header->entry;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@
|
|||
#include <stdint.h>
|
||||
|
||||
// Loads the elf program and returns its entry point.
|
||||
uint64_t LoadElfProgram(uint64_t base, uint64_t length);
|
||||
uint64_t LoadElfProgram(uint64_t cr3, uint64_t base, uint64_t length);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ const limine_file& GetInitProgram() {
|
|||
void LoadInitProgram() {
|
||||
const limine_file& init_prog = GetInitProgram();
|
||||
|
||||
gProcMan->InsertProcess(
|
||||
new Process(reinterpret_cast<uint64_t>(init_prog.address)));
|
||||
SharedPtr<Process> proc = MakeShared<Process>();
|
||||
gProcMan->InsertProcess(proc);
|
||||
|
||||
uint64_t entry =
|
||||
LoadElfProgram(proc->cr3(), reinterpret_cast<uint64_t>(init_prog.address),
|
||||
init_prog.size);
|
||||
proc->CreateThread(entry);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue