[kernel] Move pml4 create/delete into vm_space
vm_space and page_table continue to take over duties from page_manager: - creation and deletion of address spaces / pml4s - cross-address-space copies for endpoints - taking over pml4 ownership from process Also fixed the bug where the wrong process was being set in the cpu data. To solve: now the kernel process has its own vm_space which is not g_kernel_space.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "objects/endpoint.h"
|
||||
#include "objects/process.h"
|
||||
#include "objects/thread.h"
|
||||
#include "page_manager.h"
|
||||
#include "scheduler.h"
|
||||
#include "vm_space.h"
|
||||
|
||||
endpoint::endpoint() :
|
||||
kobject(kobject::type::endpoint)
|
||||
@@ -86,9 +88,9 @@ endpoint::do_message_copy(const endpoint::thread_data &sender, endpoint::thread_
|
||||
return j6_err_insufficient;
|
||||
|
||||
page_manager *pm = page_manager::get();
|
||||
void *send_data = pm->get_offset_from_mapped(sender.data, sender.th->tcb()->pml4);
|
||||
void *recv_data = pm->get_offset_from_mapped(receiver.data, receiver.th->tcb()->pml4);
|
||||
kutil::memcpy(recv_data, send_data, sender.len);
|
||||
vm_space &source = sender.th->parent().space();
|
||||
vm_space &dest = receiver.th->parent().space();
|
||||
vm_space::copy(source, dest, sender.data, receiver.data, sender.len);
|
||||
*receiver.len_p = sender.len;
|
||||
|
||||
// TODO: this will not work if non-contiguous pages are mapped!!
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
|
||||
kutil::vector<process*> process::s_processes;
|
||||
|
||||
process::process(page_table *pml4) :
|
||||
process::process() :
|
||||
kobject(kobject::type::process),
|
||||
m_pml4(pml4),
|
||||
m_space(pml4),
|
||||
m_next_handle(0),
|
||||
m_state(state::running)
|
||||
{
|
||||
@@ -41,7 +39,6 @@ process::exit(unsigned code)
|
||||
thread->exit(code);
|
||||
}
|
||||
m_return_code = code;
|
||||
page_manager::get()->delete_process_map(m_pml4);
|
||||
assert_signal(j6_signal_process_exit);
|
||||
}
|
||||
|
||||
@@ -76,13 +73,7 @@ process::create_thread(uint8_t priority, bool user)
|
||||
|
||||
if (user) {
|
||||
uintptr_t stack_top = stacks_top - (m_threads.count() * stack_size);
|
||||
auto *pm = page_manager::get();
|
||||
pm->map_pages(
|
||||
stack_top - stack_size,
|
||||
page_manager::page_count(stack_size),
|
||||
true, // user stack
|
||||
m_pml4);
|
||||
|
||||
m_space.allow(stack_top - stack_size, stack_size, true);
|
||||
th->tcb()->rsp3 = stack_top;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ public:
|
||||
constexpr static size_t stack_size = 0x4000;
|
||||
|
||||
/// Constructor.
|
||||
/// \args pml4 Root of the process' page tables
|
||||
process(page_table *pml4);
|
||||
process();
|
||||
|
||||
/// Destructor.
|
||||
virtual ~process();
|
||||
@@ -35,9 +34,6 @@ public:
|
||||
/// Update internal bookkeeping about threads.
|
||||
void update();
|
||||
|
||||
/// Get the process' page table root
|
||||
page_table * pml4() { return m_pml4; }
|
||||
|
||||
/// Get the process' virtual memory space
|
||||
vm_space & space() { return m_space; }
|
||||
|
||||
@@ -75,7 +71,6 @@ public:
|
||||
private:
|
||||
uint32_t m_return_code;
|
||||
|
||||
page_table *m_pml4;
|
||||
vm_space m_space;
|
||||
|
||||
kutil::vector<thread*> m_threads;
|
||||
|
||||
@@ -17,7 +17,7 @@ thread::thread(process &parent, uint8_t pri, uintptr_t rsp0) :
|
||||
m_wait_data(0),
|
||||
m_wait_obj(0)
|
||||
{
|
||||
m_tcb.pml4 = parent.pml4();
|
||||
parent.space().initialize_tcb(m_tcb);
|
||||
m_tcb.priority = pri;
|
||||
|
||||
if (!rsp0)
|
||||
|
||||
@@ -15,7 +15,7 @@ struct TCB
|
||||
uintptr_t rsp;
|
||||
uintptr_t rsp0;
|
||||
uintptr_t rsp3;
|
||||
page_table *pml4;
|
||||
uintptr_t pml4;
|
||||
|
||||
uint8_t priority;
|
||||
// note: 3 bytes padding
|
||||
|
||||
Reference in New Issue
Block a user