Scheduler: Set the user_task field in a Task at creation time

We were previously looking at its segment registers to see if they were user-like, but this method is bad.
What is the task was executing a system call?

So now, we store that value at creation time.
This commit is contained in:
apio 2022-10-12 17:07:39 +02:00
parent edda41a7bb
commit a6f0a7056f
3 changed files with 8 additions and 1 deletions

View File

@ -36,6 +36,8 @@ struct Task
char floating_region[512] __attribute__((aligned(16)));
bool floating_saved = false;
bool user_task = true;
bool is_user_task();
ELFImage* image = nullptr;

View File

@ -41,6 +41,7 @@ void Scheduler::init()
idle_task.regs.ss = 0x10;
idle_task.regs.rflags = (1 << 21) | (1 << 9);
idle_task.task_sleep = 1000;
idle_task.user_task = false;
idle_task.state = idle_task.Idle;
base_task = new Task;
@ -51,6 +52,7 @@ void Scheduler::init()
sched_current_task->next_task = sched_current_task;
sched_current_task->prev_task = sched_current_task;
sched_current_task->state = sched_current_task->Running;
sched_current_task->user_task = false;
task_num++;
// the other registers will be saved next task switch
@ -61,6 +63,7 @@ void Scheduler::add_kernel_task(void (*task)(void))
{
Task* new_task = new Task;
ASSERT(new_task);
new_task->user_task = false;
new_task->id = free_tid++;
new_task->regs.rip = (uint64_t)task;
new_task->allocated_stack =
@ -88,6 +91,7 @@ void Scheduler::add_user_task(void* task)
{
Task* new_task = new Task;
ASSERT(new_task);
new_task->user_task = true;
new_task->id = free_tid++;
new_task->regs.rip = (uint64_t)task;
new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(
@ -124,6 +128,7 @@ void Scheduler::load_user_task(const char* filename)
delete new_task;
return;
}
new_task->user_task = true;
new_task->regs.rip = image->entry;
new_task->image = image;
new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(

View File

@ -25,5 +25,5 @@ void task_restore_floating(Task& task)
bool Task::is_user_task()
{
return (regs.cs & 3) > 0;
return user_task;
}