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:
parent
edda41a7bb
commit
a6f0a7056f
@ -36,6 +36,8 @@ struct Task
|
|||||||
char floating_region[512] __attribute__((aligned(16)));
|
char floating_region[512] __attribute__((aligned(16)));
|
||||||
bool floating_saved = false;
|
bool floating_saved = false;
|
||||||
|
|
||||||
|
bool user_task = true;
|
||||||
|
|
||||||
bool is_user_task();
|
bool is_user_task();
|
||||||
|
|
||||||
ELFImage* image = nullptr;
|
ELFImage* image = nullptr;
|
||||||
|
@ -41,6 +41,7 @@ void Scheduler::init()
|
|||||||
idle_task.regs.ss = 0x10;
|
idle_task.regs.ss = 0x10;
|
||||||
idle_task.regs.rflags = (1 << 21) | (1 << 9);
|
idle_task.regs.rflags = (1 << 21) | (1 << 9);
|
||||||
idle_task.task_sleep = 1000;
|
idle_task.task_sleep = 1000;
|
||||||
|
idle_task.user_task = false;
|
||||||
idle_task.state = idle_task.Idle;
|
idle_task.state = idle_task.Idle;
|
||||||
|
|
||||||
base_task = new Task;
|
base_task = new Task;
|
||||||
@ -51,6 +52,7 @@ void Scheduler::init()
|
|||||||
sched_current_task->next_task = sched_current_task;
|
sched_current_task->next_task = sched_current_task;
|
||||||
sched_current_task->prev_task = sched_current_task;
|
sched_current_task->prev_task = sched_current_task;
|
||||||
sched_current_task->state = sched_current_task->Running;
|
sched_current_task->state = sched_current_task->Running;
|
||||||
|
sched_current_task->user_task = false;
|
||||||
task_num++;
|
task_num++;
|
||||||
// the other registers will be saved next task switch
|
// 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;
|
Task* new_task = new Task;
|
||||||
ASSERT(new_task);
|
ASSERT(new_task);
|
||||||
|
new_task->user_task = false;
|
||||||
new_task->id = free_tid++;
|
new_task->id = free_tid++;
|
||||||
new_task->regs.rip = (uint64_t)task;
|
new_task->regs.rip = (uint64_t)task;
|
||||||
new_task->allocated_stack =
|
new_task->allocated_stack =
|
||||||
@ -88,6 +91,7 @@ void Scheduler::add_user_task(void* task)
|
|||||||
{
|
{
|
||||||
Task* new_task = new Task;
|
Task* new_task = new Task;
|
||||||
ASSERT(new_task);
|
ASSERT(new_task);
|
||||||
|
new_task->user_task = true;
|
||||||
new_task->id = free_tid++;
|
new_task->id = free_tid++;
|
||||||
new_task->regs.rip = (uint64_t)task;
|
new_task->regs.rip = (uint64_t)task;
|
||||||
new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(
|
new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(
|
||||||
@ -124,6 +128,7 @@ void Scheduler::load_user_task(const char* filename)
|
|||||||
delete new_task;
|
delete new_task;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
new_task->user_task = true;
|
||||||
new_task->regs.rip = image->entry;
|
new_task->regs.rip = image->entry;
|
||||||
new_task->image = image;
|
new_task->image = image;
|
||||||
new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(
|
new_task->allocated_stack = (uint64_t)MemoryManager::get_pages(
|
||||||
|
@ -25,5 +25,5 @@ void task_restore_floating(Task& task)
|
|||||||
|
|
||||||
bool Task::is_user_task()
|
bool Task::is_user_task()
|
||||||
{
|
{
|
||||||
return (regs.cs & 3) > 0;
|
return user_task;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user