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
|
|
@ -22,14 +22,13 @@ SharedPtr<Process> Process::RootProcess() {
|
|||
return proc;
|
||||
}
|
||||
|
||||
Process::Process(uint64_t elf_ptr) : id_(gNextId++), state_(RUNNING) {
|
||||
Process::Process() : id_(gNextId++), state_(RUNNING) {
|
||||
cr3_ = phys_mem::AllocatePage();
|
||||
InitializePml4(cr3_);
|
||||
CreateThread(elf_ptr);
|
||||
}
|
||||
|
||||
void Process::CreateThread(uint64_t elf_ptr) {
|
||||
Thread* thread = new Thread(this, next_thread_id_++, elf_ptr);
|
||||
void Process::CreateThread(uint64_t entry) {
|
||||
Thread* thread = new Thread(this, next_thread_id_++, entry);
|
||||
threads_.PushBack(thread);
|
||||
gScheduler->Enqueue(thread);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ class Process {
|
|||
FINISHED,
|
||||
};
|
||||
static SharedPtr<Process> RootProcess();
|
||||
Process(uint64_t elf_ptr);
|
||||
Process();
|
||||
|
||||
uint64_t id() const { return id_; }
|
||||
uint64_t cr3() const { return cr3_; }
|
||||
|
||||
void CreateThread(uint64_t elf_ptr);
|
||||
void CreateThread(uint64_t entry);
|
||||
SharedPtr<Thread> GetThread(uint64_t tid);
|
||||
|
||||
// Checks the state of all child threads and transitions to
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ SharedPtr<Thread> Thread::RootThread(Process* root_proc) {
|
|||
return new Thread(root_proc);
|
||||
}
|
||||
|
||||
Thread::Thread(const SharedPtr<Process>& proc, uint64_t tid, uint64_t elf_ptr)
|
||||
: process_(proc), id_(tid), elf_ptr_(elf_ptr) {
|
||||
Thread::Thread(const SharedPtr<Process>& proc, uint64_t tid, uint64_t entry)
|
||||
: process_(proc), id_(tid), rip_(entry) {
|
||||
uint64_t* stack = new uint64_t[512];
|
||||
uint64_t* stack_ptr = stack + 511;
|
||||
// 0: rip
|
||||
|
|
@ -42,12 +42,11 @@ Thread::Thread(const SharedPtr<Process>& proc, uint64_t tid, uint64_t elf_ptr)
|
|||
uint64_t Thread::pid() { return process_->id(); }
|
||||
|
||||
void Thread::Init() {
|
||||
dbgln("[%u.%u]", pid(), id_);
|
||||
uint64_t rip = LoadElfProgram(elf_ptr_, 0);
|
||||
dbgln("[%u.%u] thread start.", pid(), id_);
|
||||
uint64_t rsp = 0x80000000;
|
||||
EnsureResident(rsp - 1, 1);
|
||||
SetRsp0(rsp0_start_);
|
||||
jump_user_space(rip, rsp);
|
||||
jump_user_space(rip_, rsp);
|
||||
}
|
||||
|
||||
void Thread::Exit() {
|
||||
|
|
|
|||
|
|
@ -11,16 +11,13 @@ class Thread {
|
|||
public:
|
||||
enum State {
|
||||
UNSPECIFIED,
|
||||
CREATED,
|
||||
RUNNING,
|
||||
RUNNABLE,
|
||||
BLOCKED,
|
||||
FINISHED,
|
||||
};
|
||||
static SharedPtr<Thread> RootThread(Process* root_proc);
|
||||
|
||||
explicit Thread(const SharedPtr<Process>& proc, uint64_t tid,
|
||||
uint64_t elf_ptr);
|
||||
explicit Thread(const SharedPtr<Process>& proc, uint64_t tid, uint64_t entry);
|
||||
|
||||
uint64_t tid() { return id_; };
|
||||
uint64_t pid();
|
||||
|
|
@ -45,7 +42,8 @@ class Thread {
|
|||
uint64_t id_;
|
||||
State state_ = RUNNABLE;
|
||||
|
||||
uint64_t elf_ptr_;
|
||||
// Startup Context for the thread.
|
||||
uint64_t rip_;
|
||||
|
||||
// Stack pointer to take on resume.
|
||||
// Stack will contain the full thread context.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue