Luna/kernel/include/thread/Task.h
apio da2ede3450 Kernel, libc, userspace: Implement file descriptors
Kernel: Implement a descriptor struct which stores the opened node and read offset, and give each task 8 of those.
Implement three syscalls: sys_read, sys_open and sys_close (sys_write still writes to the console instead of using a fd, for now)
Implement three new errors: ENOENT, EBADF and EMFILE.

libc: Implement the new errors, and the new syscalls in syscall().
Also fix _RETURN_WITH_ERRNO() to set errno correctly, which was making strerror() return null, thus crashing perror().

userspace: make init demonstrate the new file API.
2022-10-10 20:21:39 +02:00

50 lines
881 B
C

#pragma once
#include "fs/FileDescriptor.h"
#include "interrupts/Context.h"
#include "sys/elf/Image.h"
#define TASK_MAX_FDS 8
struct Task
{
enum TaskState
{
Idle,
Running,
Sleeping,
Exited
};
uint64_t id;
Context regs;
int64_t task_sleep = 0;
int64_t exit_status;
int64_t task_time = 0;
Task* next_task = nullptr;
Task* prev_task = nullptr;
uint64_t allocated_stack = 0;
TaskState state;
uint64_t cpu_time = 0;
char floating_region[512] __attribute__((aligned(16)));
bool floating_saved = false;
bool is_user_task();
ELFImage* image = nullptr;
Descriptor files[TASK_MAX_FDS];
};
void set_context_from_task(Task& task, Context* ctx);
void get_context_to_task(Task& task, Context* ctx);
void task_save_floating(Task& task);
void task_restore_floating(Task& task);