34#include <kernel/file.h>
35#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
107 thread_state_t state;
263 return arch_thread_get_interrupt_return_address(&
thread->
context);
275extern struct thread kernel_process_initial_thread;
326static inline void process_set_name(
struct process *
process,
const char *name,
357 void *esp,
void *ebp, u32
flags);
static void file_put(struct file *file)
Decrement an open file description's reference count.
Definition: file.h:71
#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:413
static ALWAYS_INLINE bool thread_is_initial(thread_t *thread)
The initial thread is the thread created along with the process.
Definition: process.h:175
static void thread_set_user_stack(struct thread *thread, void *stack)
Set the thread's user stack bottom address.
Definition: process.h:236
static void * thread_get_interrupt_return_address(const struct thread *thread)
Read the thread's return address when exiting the current interrupt context.
Definition: process.h:261
struct thread * thread_fork(struct thread *, thread_entry_t, void *)
Create a new fork of the given thread.
Definition: process.c:625
void thread_set_mmu(struct thread *thread, paddr_t mmu)
Set the MMU address saved inside the thread's structure.
Definition: process.c:721
static void * thread_get_user_stack(const struct thread *thread)
Get the thread's user stack bottom address.
Definition: process.h:248
struct thread * process_execute_in_userland(const char *exec_path)
Run an executable.
Definition: process.c:607
static void * thread_get_stack_pointer(struct thread *thread)
Get the thread's current stack pointer.
Definition: process.h:187
thread_state
The different states a thread can be in.
Definition: process.h:69
static void * thread_get_base_pointer(struct thread *thread)
Get the thread's current base pointer.
Definition: process.h:199
struct process * init_process
The init process is the very first executed userland process.
Definition: process.c:107
#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:226
error_t process_unregister_file(struct process *, int fd)
Remove an open file from the process's open file descriptor table.
Definition: process.c:395
static void thread_set_kernel_stack(struct thread *thread, void *stack)
Set the thread's kernel stack bottom address.
Definition: process.h:213
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:220
#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_base_pointer(struct thread *thread, void *ptr)
Set the thread's current base pointer.
Definition: process.h:193
static void thread_set_stack_pointer(struct thread *thread, void *stack)
Set the thread's current stack pointer.
Definition: process.h:181
bool thread_switch(thread_t *)
Switch the currently running thread.
Definition: process.c:531
struct process kernel_process
Process used when starting up the kernel.
Definition: process.c:94
NO_RETURN void thread_jump_to_userland(void *stack_pointer, void *base_pointer, thread_entry_t, void *)
Start executing code in userland.
Definition: process.c:715
void thread_kill(thread_t *)
Effectively kill a thread.
Definition: process.c:575
thread_t * current
The currently running thread.
Definition: process.c:105
static void process_file_put(struct process *process, struct file *file)
Release a file description retreived using process_file_get().
Definition: process.h:309
thread_flags
Definition: process.h:162
static void * thread_get_user_stack_top(const struct thread *thread)
Get the thread's user stack top address.
Definition: process.h:242
thread_t * thread_spawn(struct process *, thread_entry_t, void *data, void *esp, void *ebp, u32 flags)
Create and initialize a new thread.
Definition: process.c:430
void process_init_kernel_process(void)
Initialize the kernel process's address space.
Definition: process.c:321
static void thread_set_interrupt_frame(thread_t *thread, const struct interrupt_frame *frame)
Set a thread's curent interrupt frame.
Definition: process.h:206
int process_register_file(struct process *, struct file *)
Register an open file inside the process's open file descriptor table.
Definition: process.c:375
@ 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:73
@ SCHED_ZOMBIE
Thread waiting to be collected by its parent process.
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:163
#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:45
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:85
struct user_creds creds
Transmitted to the parent process during wait()
Definition: process.h:110
llist_t threads
Definition: process.h:91
spinlock_t files_lock
Definition: process.h:105
char name[PROCESS_NAME_MAX_LEN]
Definition: process.h:86
struct address_space * as
Definition: process.h:89
size_t refcount
Definition: process.h:95
spinlock_t lock
Process credentials.
Definition: process.h:112
llist_t children
Definition: process.h:92
pid_t pid
Definition: process.h:87
struct file * files[PROCESS_FD_COUNT]
Open file descriptors table.
Definition: process.h:104
Spinlock.
Definition: spinlock.h:29
A single thread.
Definition: process.h:127
node_t proc_this
Definition: process.h:139
thread_state_t state
Definition: process.h:136
struct process * process
Definition: process.h:138
pid_t tid
Definition: process.h:141
clock_t wakeup
Definition: process.h:155
clock_t preempt
End of the currently running thread's timeslice.
Definition: process.h:151
struct thread::@9::@11 running
For running threads only.
struct thread::@9::@12 sleep
For sleeping threads only.
u32 flags
Definition: process.h:142
thread_context_t context
Arch specific thread context.
Definition: process.h:135
User credentials.
Definition: user.h:20
Contains all the system-level information about a task.
Definition: process.h:22
Userland control mechanisms.