PatchworkOS
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1#pragma once
2
4#include <kernel/cpu/simd.h>
7#include <kernel/ipc/note.h>
10#include <kernel/sched/wait.h>
11#include <kernel/utils/ref.h>
12
13#include <sys/list.h>
14#include <sys/proc.h>
15
37
81
91
97void thread_free(thread_t* thread);
98
105void thread_save(thread_t* thread, const interrupt_frame_t* frame);
106
115void thread_load(thread_t* thread, interrupt_frame_t* frame);
116
126_NORETURN extern void thread_jump(thread_t* thread);
127
137
144bool thread_is_note_pending(thread_t* thread);
145
158
170
182
194uint64_t thread_copy_from_user(thread_t* thread, void* dest, const void* userSrc, uint64_t length);
195
207uint64_t thread_copy_to_user(thread_t* thread, void* dest, const void* userSrc, uint64_t length);
208
221uint64_t thread_copy_from_user_terminated(thread_t* thread, const void* userArray, const void* terminator,
222 uint8_t objectSize, uint64_t maxCount, void** outArray, uint64_t* outCount);
223
232uint64_t thread_copy_from_user_pathname(thread_t* thread, pathname_t* pathname, const char* userPath);
233
244uint64_t thread_load_atomic_from_user(thread_t* thread, atomic_uint64_t* userObj, uint64_t* outValue);
245
int errno_t
Definition errno_t.h:4
bool thread_is_note_pending(thread_t *thread)
Check if a thread has a note pending.
Definition thread.c:127
void thread_free(thread_t *thread)
Frees a thread structure.
Definition thread.c:89
uint64_t thread_send_note(thread_t *thread, const void *buffer, uint64_t count)
Send a note to a thread.
Definition thread.c:132
uint64_t thread_copy_from_user(thread_t *thread, void *dest, const void *userSrc, uint64_t length)
Safely copy data from user space.
Definition thread.c:230
void thread_load(thread_t *thread, interrupt_frame_t *frame)
Load state from a thread.
Definition thread.c:113
uint64_t thread_copy_to_user(thread_t *thread, void *dest, const void *userSrc, uint64_t length)
Safely copy data to user space.
Definition thread.c:248
_NORETURN void thread_jump(thread_t *thread)
Jump to a thread by calling thread_load() and then loading its interrupt frame.
uint64_t thread_load_atomic_from_user(thread_t *thread, atomic_uint64_t *userObj, uint64_t *outValue)
Atomically load a 64-bit value from a user-space atomic variable.
Definition thread.c:336
uint64_t thread_copy_from_user_terminated(thread_t *thread, const void *userArray, const void *terminator, uint8_t objectSize, uint64_t maxCount, void **outArray, uint64_t *outCount)
Safely copy a null-terminated array of objects from user space.
Definition thread.c:266
thread_t * thread_get_boot(void)
Retrieves the boot thread.
Definition thread.c:159
uint64_t thread_copy_from_user_pathname(thread_t *thread, pathname_t *pathname, const char *userPath)
Safely copy a string from user space and use it to initialize a pathname.
Definition thread.c:307
thread_t * thread_new(process_t *process)
Creates a new thread structure.
Definition thread.c:69
uint64_t thread_handle_page_fault(const interrupt_frame_t *frame)
Handles a page fault that occurred in the currently running thread.
Definition thread.c:173
void thread_save(thread_t *thread, const interrupt_frame_t *frame)
Save state to a thread.
Definition thread.c:107
thread_state_t
Thread state enum.
Definition thread.h:29
void thread_get_interrupt_frame(thread_t *thread, interrupt_frame_t *frame)
Retrieve the interrupt frame from a thread.
Definition thread.c:122
@ THREAD_UNBLOCKING
Has started unblocking, used to prevent the same thread being unblocked multiple times.
Definition thread.h:35
@ THREAD_PRE_BLOCK
Has started the process of blocking but has not yet been given to a owner cpu.
Definition thread.h:33
@ THREAD_BLOCKED
Is blocking and waiting in one or multiple wait queues.
Definition thread.h:34
@ THREAD_PARKED
Is doing nothing, not in a queue, not blocking, think of it as "other".
Definition thread.h:30
@ THREAD_RUNNING
Is currently running on a cpu.
Definition thread.h:32
@ THREAD_READY
Is ready to run and waiting to be scheduled.
Definition thread.h:31
__UINT64_TYPE__ tid_t
Thread Identifier.
Definition tid_t.h:12
#define _NORETURN
Definition config.h:28
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
static atomic_long count
Definition main.c:9
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
Trap Frame Structure.
Definition interrupt.h:42
A entry in a doubly linked list.
Definition list.h:38
Per-thread note queue.
Definition note.h:81
Pathname structure.
Definition path.h:122
Process structure.
Definition process.h:53
Per-thread scheduling context.
Definition sched.h:56
Structure to define a stack in memory.
Per thread syscall context.
Definition syscalls.h:63
Thread of execution structure.
Definition thread.h:55
list_entry_t processEntry
The entry for the parent process.
Definition thread.h:58
sched_thread_ctx_t sched
Definition thread.h:70
process_t * process
The parent process that the thread executes within.
Definition thread.h:57
_Atomic(thread_state_t) state
interrupt_frame_t frame
Definition thread.h:79
list_entry_t entry
The entry for the scheduler and wait system.
Definition thread.h:56
stack_pointer_t kernelStack
The kernel stack of the thread.
Definition thread.h:68
errno_t error
Definition thread.h:67
note_queue_t notes
Definition thread.h:73
syscall_ctx_t syscall
Definition thread.h:74
stack_pointer_t userStack
The user stack of the thread.
Definition thread.h:69
wait_thread_ctx_t wait
Definition thread.h:71
tid_t id
The thread id, unique within a process_t.
Definition thread.h:59
simd_ctx_t simd
Definition thread.h:72
Per-thread wait context.
Definition wait.h:207