From 5f87e550675afe6d30e058bb0723ea4a58357ed2 Mon Sep 17 00:00:00 2001 From: Ruslan Isaev Date: Sun, 1 Jun 2025 13:53:06 +0300 Subject: [PATCH] tasking: make jump_usermode2 lock the scheduler & test the second user task --- src/tasking/task.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tasking/task.c b/src/tasking/task.c index 27504d0..d5726dc 100644 --- a/src/tasking/task.c +++ b/src/tasking/task.c @@ -160,6 +160,7 @@ extern void test_user_function(void); extern void second_user_function(void); void jump_usermode2(void) { + scheduler_lock(); void* code_phys = alloc_page(); if (!code_phys) { printf("No memory for user code\n"); @@ -193,7 +194,9 @@ void jump_usermode2(void) { (uint32_t)code_phys, kernel_temp_virt); 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_task2 = task_create(0x400000, NULL, 0, 3, proc2_pd); if (map_page_in_directory(p_task1->page_directory, code_phys, @@ -204,4 +207,15 @@ void jump_usermode2(void) { // TODO: Terminate/cleanup p_task1, free code_phys_task1 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(); }