34#include <kernel/file.h>
36#include <kernel/types.h>
37#include <kernel/vmm.h>
40#include <utils/compiler.h>
47#error Unsupported arcihtecture
51#define PROCESS_NAME_MAX_LEN 32U
54#define PROCESS_FD_COUNT 32
103 thread_state_t state;
243extern struct thread kernel_process_initial_thread;
294static inline void process_set_name(
struct process *
process,
const char *name,
static void file_put(struct file *file)
Decrement an open file description's reference count.
Definition: file.h:55
#define USER_STACK_SIZE
Definition: memory.h:59
#define KERNEL_STACK_SIZE
Definition: memory.h:55
struct file * process_file_get(struct process *, int fd)
Definition: process.c:322
static ALWAYS_INLINE bool thread_is_initial(thread_t *thread)
The initial thread is the thread created along with the process.
Definition: process.h:172
static void thread_set_user_stack(struct thread *thread, void *stack)
Set the thread's user stack bottom address.
Definition: process.h:213
struct thread * thread_fork(struct thread *, thread_entry_t, void *)
Create a new fork of the given thread.
Definition: process.c:533
thread_t * thread_spawn(struct process *, thread_entry_t, void *, void *, u32)
Create and initialize a new thread.
Definition: process.c:339
void thread_set_mmu(struct thread *thread, paddr_t mmu)
Set the MMU address saved inside the thread's structure.
Definition: process.c:619
static void * thread_get_user_stack(const struct thread *thread)
Get the thread's user stack bottom address.
Definition: process.h:225
struct thread * process_execute_in_userland(const char *exec_path)
Run an executable.
Definition: process.c:515
static void * thread_get_stack_pointer(struct thread *thread)
Get the thread's current stack pointer.
Definition: process.h:184
thread_state
The different states a thread can be in.
Definition: process.h:69
struct process * init_process
The init process is the very first executed userland process.
Definition: process.c:43
#define PROCESS_NAME_MAX_LEN
The max length of a process's name.
Definition: process.h:51
static void * thread_get_kernel_stack(const struct thread *thread)
Get the thread's kernel stack bottom address.
Definition: process.h:203
error_t process_unregister_file(struct process *, int fd)
Remove an open file from the process's open file descriptor table.
Definition: process.c:304
static void thread_set_kernel_stack(struct thread *thread, void *stack)
Set the thread's kernel stack bottom address.
Definition: process.h:190
void(* thread_entry_t)(void *data)
A function used as an entry point when creating a new thread.
Definition: process.h:64
static void * thread_get_kernel_stack_top(const struct thread *thread)
Get the thread's kernel stack top address.
Definition: process.h:197
#define PROCESS_FD_COUNT
Maximum number of files that one process can have open at any one time.
Definition: process.h:54
static void thread_set_stack_pointer(struct thread *thread, void *stack)
Set the thread's current stack pointer.
Definition: process.h:178
bool thread_switch(thread_t *)
Switch the currently running thread.
Definition: process.c:439
struct process kernel_process
Process used when starting up the kernel.
Definition: process.c:35
NO_RETURN void thread_jump_to_userland(thread_entry_t, void *)
Start executing code in userland.
Definition: process.c:614
void thread_kill(thread_t *)
Effectively kill a thread.
Definition: process.c:484
thread_t * current
The currently running thread.
Definition: process.c:41
static void process_file_put(struct process *process, struct file *file)
Release a file description retreived using process_file_get().
Definition: process.h:277
thread_flags
Definition: process.h:159
static void * thread_get_user_stack_top(const struct thread *thread)
Get the thread's user stack top address.
Definition: process.h:219
void process_init_kernel_process(void)
Initialize the kernel process's address space.
Definition: process.c:231
int process_register_file(struct process *, struct file *)
Register an open file inside the process's open file descriptor table.
Definition: process.c:284
@ SCHED_RUNNING
Currently running (or ready to run)
Definition: process.h:70
@ SCHED_KILLED
The thread has been killed waiting to be destroyed.
Definition: process.h:72
@ SCHED_WAITING
Currently waiting for a resource (timer, lock ...)
Definition: process.h:71
@ THREAD_KERNEL
This thread runs in kernel mode.
Definition: process.h:160
#define BIT(_n)
Generate the nth power of 2 (nth bit set)
Definition: bits.h:20
#define MIN(_x, _y)
Compute the minimum value between 2 numbers.
Definition: math.h:27
#define UNUSED(_x)
Avoid compiler warning when not using a symbol.
Definition: macro.h:35
Address space.
Definition: vm.h:45
Opened file description.
Definition: file.h:29
Frame passed onto the interrupt handlers by our stub handler.
Definition: interrupts.h:121
The head of a doubly linked list.
Definition: linked_list.h:43
Intrusive doubly-linked list node.
Definition: linked_list.h:27
A single process.
Definition: process.h:84
llist_t threads
Definition: process.h:90
spinlock_t files_lock
Definition: process.h:101
char name[PROCESS_NAME_MAX_LEN]
Definition: process.h:85
struct address_space * as
Definition: process.h:88
size_t refcount
Definition: process.h:91
spinlock_t lock
Transmitted to the parent process during wait()
Definition: process.h:106
pid_t pid
Definition: process.h:86
struct file * files[PROCESS_FD_COUNT]
Open file descriptors table.
Definition: process.h:100
Spinlock.
Definition: spinlock.h:29
A single thread.
Definition: process.h:121
struct interrupt_frame frame
Frame pushed during the last userland -> kernel context switch.
Definition: process.h:136
node_t proc_this
Definition: process.h:133
thread_state_t state
Definition: process.h:130
struct process * process
Definition: process.h:132
pid_t tid
Definition: process.h:138
clock_t wakeup
Definition: process.h:152
clock_t preempt
End of the currently running thread's timeslice.
Definition: process.h:148
u32 flags
Definition: process.h:139
thread_context_t context
Arch specific thread context.
Definition: process.h:129
Contains all the system-level information about a task.
Definition: process.h:20