My Kernel v0.1.0
process.h File Reference

Process management. More...

#include <kernel/file.h>
#include <kernel/interrupts.h>
#include <kernel/types.h>
#include <kernel/vmm.h>
#include <libalgo/linked_list.h>
#include <utils/compiler.h>
#include <string.h>
#include <kernel/arch/i686/process.h>
Include dependency graph for process.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  process
 A single process. More...
 
struct  thread
 A single thread. More...
 

Macros

#define PROCESS_NAME_MAX_LEN   32U
 The max length of a process's name.
 
#define PROCESS_FD_COUNT   32
 Maximum number of files that one process can have open at any one time.
 

Typedefs

typedef void(* thread_entry_t) (void *data)
 A function used as an entry point when creating a new thread. More...
 

Enumerations

enum  thread_state { SCHED_RUNNING , SCHED_WAITING , SCHED_KILLED }
 The different states a thread can be in. More...
 
enum  thread_flags { THREAD_KERNEL = BIT(0) }
 

Functions

static ALWAYS_INLINE bool thread_is_initial (thread_t *thread)
 The initial thread is the thread created along with the process. More...
 
static void thread_set_stack_pointer (struct thread *thread, void *stack)
 Set the thread's current stack pointer.
 
static void * thread_get_stack_pointer (struct thread *thread)
 Get the thread's current stack pointer.
 
static void thread_set_kernel_stack (struct thread *thread, void *stack)
 Set the thread's kernel stack bottom address.
 
static void * thread_get_kernel_stack_top (const struct thread *thread)
 Get the thread's kernel stack top address.
 
static void * thread_get_kernel_stack (const struct thread *thread)
 Get the thread's kernel stack bottom address.
 
static void thread_set_user_stack (struct thread *thread, void *stack)
 Set the thread's user stack bottom address.
 
static void * thread_get_user_stack_top (const struct thread *thread)
 Get the thread's user stack top address.
 
static void * thread_get_user_stack (const struct thread *thread)
 Get the thread's user stack bottom address.
 
void process_init_kernel_process (void)
 Initialize the kernel process's address space. More...
 
int process_register_file (struct process *, struct file *)
 Register an open file inside the process's open file descriptor table. More...
 
error_t process_unregister_file (struct process *, int fd)
 Remove an open file from the process's open file descriptor table.
 
struct fileprocess_file_get (struct process *, int fd)
 
static void process_file_put (struct process *process, struct file *file)
 Release a file description retreived using process_file_get().
 
struct threadprocess_execute_in_userland (const char *exec_path)
 Run an executable. More...
 
bool thread_switch (thread_t *)
 Switch the currently running thread. More...
 
thread_tthread_spawn (struct process *, thread_entry_t, void *, void *, u32)
 Create and initialize a new thread. More...
 
NO_RETURN void thread_jump_to_userland (thread_entry_t, void *)
 Start executing code in userland. More...
 
void thread_set_mmu (struct thread *thread, paddr_t mmu)
 Set the MMU address saved inside the thread's structure. More...
 
void thread_kill (thread_t *)
 Effectively kill a thread. More...
 
struct threadthread_fork (struct thread *, thread_entry_t, void *)
 Create a new fork of the given thread. More...
 

Variables

struct process kernel_process
 Process used when starting up the kernel. More...
 
struct processinit_process
 The init process is the very first executed userland process. More...
 
thread_tcurrent
 The currently running thread.
 

Detailed Description

This file defines the data structures and functions for managing processes and threads in a multithreading model.

A process is an instance of a program that is being executed by one or more threads. Each process has its own unique address space, which means that it has its own virtual memory space that is separate from other processes. This allows each process to have its own private memory space, which is not accessible to other processes. A process also has its own set of system resources, such as open files descriptors.

A thread is an execution context that is created within a process. Threads within the same process share the same address space. They do not share the same execution context (registers, stack).

Both processes and threads are identified using a unique id: PID and TID. Threads do not exist without a containing process, and processes are forced to always contain at least one alive thread.

The file provides functions for creating and killing processes, creating and killing threads, as well as switching between them.