Orion
Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)diff --git a/task/task.h b/task/task.h new file mode 100644 index 0000000..228c3d8 --- /dev/null +++ b/task/task.h @@ -0,0 +1,128 @@ +#ifndef KERNEL_TASK_H +#define KERNEL_TASK_H + +#include <stdint.h> +#include <sys/ipc.h> +#include <sys/times.h> +#include <time.h> +#include <signal.h> +#include "../mem/paging.h" +#include "../mem/vm.h" +#include "../proc/proc.h" +#include "../vfs/vfs.h" +#include "../spinlock.h" + +typedef struct Task Task; +typedef struct TaskQueue TaskQueue; + +/* Process priorities */ +enum Priority { + NONE, + LOWEST, + LOW, + NORMAL, + HIGH, + HIGHEST, +}; + +/* Task states */ +enum States { + RUNNING, + READY, + TERMINATED, + WAITING_FOR_CHILD, + WAITING_FOR_READ, + SLEEP, +}; + +/* Structure for a Task Queue */ +struct TaskQueue { + Task *start, *end; + Spinlock lock; +}; + +/* Structure of a Task */ +struct Task { + pid_t tid, tgid; + uid_t uid, euid, suid; + gid_t gid, egid, sgid; + uint8_t priority; + char *name; + uint32_t usertime, systime; + int state; + uint64_t sleepExpiry; + int status; + uintptr_t esp, ebp, eip; + Task *next, *tnext, *parent; + pid_t ppid; + page_dir_t pageDir; + Spinlock lock; + uint8_t inSyscall; + File *executable; + VMRegion *stack, *tls; + TaskQueue waiting; + sigset_t sigset; + sigset_t blockedSignals; + void (*sig_handler[32])(int); + + /* Messages */ + Message *msgQueue; + + /* Namespaces */ + FileSystem *fs; + Files *files; + VirtualMemory *vm; +// Messages *ipc; +// Signals *signals; +}; + +extern Task *currentTask[]; +#define current currentTask[CPUID] + +/* Check if a routine is running as a syscall */ +static inline uint8_t +in_syscall(void) +{ + if (!current) + return 0; + return (current->inSyscall); +} + +/* Check if super-user */ +static inline int +super_user(void) +{ + return (current->euid == 0); +} + +void init_tasking(void); +void syscall_handler(InterruptFrame *frame); +Task *find_task(pid_t tid); +void add_to_queue(TaskQueue *queue, Task *task); +void remove_from_queue(TaskQueue *queue, Task *task); +Task *pop_from_queue(TaskQueue *queue); +void timer_handler(InterruptFrame *frame); +void block_task(int reason); +void unblock_task(Task *task); +void schedule(void); +pid_t fork(void); +pid_t clone(int flags); +void terminate(void); +void exit(int status); +pid_t waitpid(pid_t pid, int *wstatus, int options); +pid_t getpid(void); +uid_t getuid(void); +int setuid(uid_t uid); +uid_t geteuid(void); +int seteuid(uid_t euid); +gid_t getgid(void); +int setgid(gid_t gid); +gid_t getegid(void); +int setegid(gid_t egid); +int isatty(int fd); +int execve(const char *file, char *argv[], char *envp[]); + +int tgkill(pid_t tgid, pid_t tid, int sig); +int kill(pid_t pid, int sig); + +#endif