#include "thread/Task.h" #include "std/string.h" void Task::restore_context(Context* context) { memcpy(context, ®s, sizeof(Context)); } void Task::save_context(Context* context) { memcpy(®s, context, sizeof(Context)); } void Task::save_floating() { floating_saved = true; asm volatile("fxsave (%0)" : : "r"((char*)floating_region)); } void Task::restore_floating() { if (!floating_saved) return; asm volatile("fxrstor (%0)" : : "r"((char*)floating_region)); } bool Task::is_user_task() { return user_task; } int Task::alloc_fd() { int fd; for (fd = 0; fd < TASK_MAX_FDS; fd++) { if (!files[fd].is_open()) break; } if (fd == TASK_MAX_FDS) { return -1; } return fd; } int Task::alloc_fd_greater_than_or_equal(int base_fd) { int fd; if (base_fd >= TASK_MAX_FDS) return -1; for (fd = base_fd; fd < TASK_MAX_FDS; fd++) { if (!files[fd].is_open()) break; } if (fd == TASK_MAX_FDS) { return -1; } return fd; }