tasking: make jump_usermode2 lock the scheduler & test the second user task

This commit is contained in:
2025-06-01 13:53:06 +03:00
parent 8fea7a8ec6
commit 5f87e55067
+14
View File
@@ -160,6 +160,7 @@ extern void test_user_function(void);
extern void second_user_function(void); extern void second_user_function(void);
void jump_usermode2(void) { void jump_usermode2(void) {
scheduler_lock();
void* code_phys = alloc_page(); void* code_phys = alloc_page();
if (!code_phys) { if (!code_phys) {
printf("No memory for user code\n"); printf("No memory for user code\n");
@@ -193,7 +194,9 @@ void jump_usermode2(void) {
(uint32_t)code_phys, kernel_temp_virt); (uint32_t)code_phys, kernel_temp_virt);
uint32_t* proc_pd = (uint32_t*)create_page_dir(); uint32_t* proc_pd = (uint32_t*)create_page_dir();
uint32_t* proc2_pd = (uint32_t*)create_page_dir();
Process* p_task1 = task_create(0x400000, NULL, 0, 3, proc_pd); Process* p_task1 = task_create(0x400000, NULL, 0, 3, proc_pd);
Process* p_task2 = task_create(0x400000, NULL, 0, 3, proc2_pd);
if (map_page_in_directory(p_task1->page_directory, if (map_page_in_directory(p_task1->page_directory,
code_phys, code_phys,
@@ -204,4 +207,15 @@ void jump_usermode2(void) {
// TODO: Terminate/cleanup p_task1, free code_phys_task1 // TODO: Terminate/cleanup p_task1, free code_phys_task1
return; return;
} }
if (map_page_in_directory(p_task2->page_directory,
second_code_phys,
(void*)0x400000,
PAGE_PRESENT | PAGE_RW | PAGE_USER) != 0) { // PAGE_USER is critical, PAGE_RW for now, can be R-X
printf("jump_usermode2: Failed to map user code into task's PD for PID %d\n", p_task2->pid);
// TODO: Terminate/cleanup p_task1, free code_phys_task1
return;
}
scheduler_unlock();
} }