PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
thread.c File Reference
#include <kernel/cpu/syscall.h>
#include <kernel/sched/thread.h>
#include <kernel/cpu/cpu.h>
#include <kernel/cpu/gdt.h>
#include <kernel/init/init.h>
#include <kernel/log/log.h>
#include <kernel/log/panic.h>
#include <kernel/mem/cache.h>
#include <kernel/mem/vmm.h>
#include <kernel/proc/process.h>
#include <kernel/sched/sched.h>
#include <kernel/sched/timer.h>
#include <kernel/sched/wait.h>
#include <kernel/sync/lock.h>
#include <stdlib.h>
#include <string.h>
#include <sys/list.h>
#include <sys/math.h>
Include dependency graph for thread.c:

Go to the source code of this file.

Functions

static void thread_ctor (void *ptr)
 
static uintptr_t thread_id_to_offset (tid_t tid, uint64_t maxPages)
 
thread_tthread_new (process_t *process)
 Creates a new thread structure.
 
void thread_free (thread_t *thread)
 Frees a thread structure.
 
tid_t thread_kernel_create (thread_kernel_entry_t entry, void *arg)
 Creates a new thread that runs in kernel mode and submits it to the scheduler.
 
void thread_save (thread_t *thread, const interrupt_frame_t *frame)
 Save state to a thread.
 
void thread_load (thread_t *thread, interrupt_frame_t *frame)
 Load state from a thread.
 
bool thread_is_note_pending (thread_t *thread)
 Check if a thread has a note pending.
 
uint64_t thread_send_note (thread_t *thread, const char *string)
 Send a note to a thread.
 
 SYSCALL_DEFINE (SYS_ERRNO, errno_t)
 
 SYSCALL_DEFINE (SYS_GETTID, tid_t)
 
uint64_t thread_copy_from_user (thread_t *thread, void *dest, const void *userSrc, uint64_t length)
 Safely copy data from user space.
 
uint64_t thread_copy_to_user (thread_t *thread, void *userDest, const void *src, uint64_t length)
 Safely copy data to user space.
 
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.
 
uint64_t thread_copy_from_user_string (thread_t *thread, char *dest, const char *userSrc, uint64_t size)
 Safely copy a string from user space.
 
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.
 
uint64_t thread_copy_from_user_string_array (thread_t *thread, const char **user, char ***out, uint64_t *outAmount)
 Safely copy a null-terminated array of strings and their contents from user space into a string vector.
 
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.
 
 SYSCALL_DEFINE (SYS_ARCH_PRCTL, uint64_t, arch_prctl_t op, uintptr_t addr)
 

Variables

static cache_t cache = CACHE_CREATE(cache, "thread", sizeof(thread_t), CACHE_LINE, NULL, NULL)
 

Function Documentation

◆ thread_ctor()

static void thread_ctor ( void *  ptr)
static

Definition at line 22 of file thread.c.

Here is the call graph for this function:

◆ thread_id_to_offset()

static uintptr_t thread_id_to_offset ( tid_t  tid,
uint64_t  maxPages 
)
static

Definition at line 45 of file thread.c.

Here is the caller graph for this function:

◆ SYSCALL_DEFINE() [1/3]

SYSCALL_DEFINE ( SYS_ERRNO  ,
errno_t   
)

Definition at line 192 of file thread.c.

◆ SYSCALL_DEFINE() [2/3]

SYSCALL_DEFINE ( SYS_GETTID  ,
tid_t   
)

Definition at line 197 of file thread.c.

Here is the call graph for this function:

◆ SYSCALL_DEFINE() [3/3]

SYSCALL_DEFINE ( SYS_ARCH_PRCTL  ,
uint64_t  ,
arch_prctl_t  op,
uintptr_t  addr 
)

Definition at line 391 of file thread.c.

Here is the call graph for this function:

Variable Documentation

◆ cache

cache_t cache = CACHE_CREATE(cache, "thread", sizeof(thread_t), CACHE_LINE, NULL, NULL)
static

Definition at line 43 of file thread.c.