Skip to content

Commit

Permalink
feat(proc): sync declarations and add docs
Browse files Browse the repository at this point in the history
* Sync function and struct declarations with definitions
* Add documentation public facing functions
  • Loading branch information
FedorLap2006 committed May 30, 2023
1 parent 2c3e91f commit 60babcf
Showing 1 changed file with 111 additions and 6 deletions.
117 changes: 111 additions & 6 deletions include/depthos/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ typedef enum task_state {
struct process {
pid_t pid;
char *filepath;
char const **argv;
char const **envp;
process_state_t state;
struct process *parent;
struct list_entry *parent_entry;
Expand Down Expand Up @@ -67,32 +69,135 @@ struct task {
struct fs_node **filetable;
};

struct process *process_spawn(const char *filepath, struct process *parent);

/**
* @brief Spawn a process from the given parent process.
*
* @param filepath Executable file path (ELF).
* @param parent Parent process to link to.
* @param argv Arguments passed to the process.
* @param envp Environment variables passed to the process.
* @return struct process* Newly created process.
*/
struct process *process_spawn(const char *filepath, struct process *parent,
char const **argv, char const **envp);
/**
* @brief Kill a process with all it's threads and child processes.
*/
void process_kill(struct process *);

struct task *create_task(void *entry, pagedir_t pgd, bool do_stack,
void *stack);
void bootstrap_user_task(struct task *task, bool do_stack, void *stack);
void setup_task_filetable(struct fs_node *ft);
/**
* @brief Create a task
*
* @param entry Address of the task entrypoint
* @param pgd Address space of the task (page directory)
* @param kernel Whether the task is executed with kernel privileges
* @param stack Base of the stack
* @param stack_size Size of task the stack
* @return struct task* Newly created task
*/
struct task *create_task(void *entry, pagedir_t pgd, bool kernel,
uintptr_t stack, size_t stack_size);

/**
* @brief Create a task with kernel privileges
*
* @param entry Address of the task entrypoint
* @param do_stack Whether to setup kernel stack for the task.
* @return struct task* Newly created task
*/
struct task *create_kernel_task(void *entry, bool do_stack);
struct task *create_task_fork(struct task *original);

/**
* @brief Fork the task
*
* @param original Task to fork.
* @return struct task* Forked task.
*/
struct task *fork_task(struct task *original);

/**
* @brief Initialise kernel stack for a task.
*
* @param task Task to initialise stack for.
* @param esp Stack pointer.
*/
void task_init_kstack(struct task *task, uintptr_t esp);
/*
* @brief Initialise kernel stack for a task with kernel privileges.
*
* @param task Task to initialise stack for.
* @param esp Stack pointer.
*/
void kernel_task_init_kstack(struct task *task, uintptr_t esp);

/**
* @brief Initialise specified filetable.
*
* @param ft Filetable to initialise.
*/
void task_setup_filetable(struct fs_node **ft);
/**
* @brief Create a thread in the current process.
*
* @param entry Address of the thread entrypoint.
* @param stack Thread stack base.
* @param pgd Address space of the thread (page directory)
* @param filetable Filetable to use for the thread.
* @return struct task* Newly created thread.
*/
struct task *thread_create(void *entry, void *stack, pagedir_t pgd,
struct fs_node **filetable);
/**
* @brief Destroy the specified thread.
*
* @param thread Thread to destroy.
*/
void thread_destroy(struct task *thread);

/**
* @brief Reschedule to a particular task.
*
* @param next Task to reschedule to.
*/
void reschedule_to(struct task *next);

/**
* @brief Reschedule to the next task in the queue
*/
void reschedule(void);

/**
* @brief Add task to the scheduler queue.
*
*/
void sched_add(struct task *);
/**
* @brief Remove the task from the scheduler queue.
*
* @param task Task to remove.
*/
void sched_remove(struct task *);
void sched_init(void);

void preempt_enable();
void preempt_disable();

/**
* @brief Task that is currently being executed.
*
*/
extern struct task *current_task;

#define SC_CLONE_MEM 0x1
struct sc_clone_params {
int flags;
};

/**
* @brief Parameters of the sys_thcreate system call.
*
*/
struct sc_thcreate_params {
int flags;
bool join;
Expand Down

0 comments on commit 60babcf

Please sign in to comment.