Task: Move functions operating on Task to member functions

Also, add an alloc_fd_greater_than_or_equal() function, for use in fcntl(F_DUPFD)
This commit is contained in:
apio 2022-10-17 17:00:07 +02:00
parent e34045a78c
commit 891651f2d6
2 changed files with 31 additions and 15 deletions

View File

@ -48,10 +48,12 @@ struct Task
AddressSpace address_space;
int alloc_fd();
};
void set_context_from_task(Task& task, Context* ctx);
void get_context_to_task(Task& task, Context* ctx);
int alloc_fd_greater_than_or_equal(int base_fd);
void task_save_floating(Task& task);
void task_restore_floating(Task& task);
void save_context(Context* context);
void restore_context(Context* context);
void save_floating();
void restore_floating();
};

View File

@ -1,26 +1,26 @@
#include "thread/Task.h"
#include "std/string.h"
void set_context_from_task(Task& task, Context* ctx)
void Task::restore_context(Context* context)
{
memcpy(ctx, &task.regs, sizeof(Context));
memcpy(context, &regs, sizeof(Context));
}
void get_context_to_task(Task& task, Context* ctx)
void Task::save_context(Context* context)
{
memcpy(&task.regs, ctx, sizeof(Context));
memcpy(&regs, context, sizeof(Context));
}
void task_save_floating(Task& task)
void Task::save_floating()
{
task.floating_saved = true;
asm volatile("fxsave (%0)" : : "r"(&task.floating_region));
floating_saved = true;
asm volatile("fxsave (%0)" : : "r"((char*)floating_region));
}
void task_restore_floating(Task& task)
void Task::restore_floating()
{
if (!task.floating_saved) return;
asm volatile("fxrstor (%0)" : : "r"(&task.floating_region));
if (!floating_saved) return;
asm volatile("fxrstor (%0)" : : "r"((char*)floating_region));
}
bool Task::is_user_task()
@ -38,5 +38,19 @@ int Task::alloc_fd()
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;
}