148 tid_t volatile tid = thread->
id;
157 thread->
frame = *frame;
162 *frame = thread->
frame;
204 if (thread ==
NULL || dest ==
NULL || userSrc ==
NULL || length == 0)
215 memcpy(dest, userSrc, length);
222 if (thread ==
NULL || userDest ==
NULL || src ==
NULL || length == 0)
233 memcpy(userDest, src, length);
241 if (thread ==
NULL || userArray ==
NULL || terminator ==
NULL || objectSize == 0 || maxCount == 0 ||
250 if (arraySize ==
ERR)
255 uint64_t elementCount = arraySize / objectSize;
258 void* kernelArray =
malloc(allocSize);
259 if (kernelArray ==
NULL)
266 memcpy(kernelArray, userArray, arraySize);
269 *outArray = kernelArray;
270 if (outCount !=
NULL)
272 *outCount = elementCount - 1;
280 if (thread ==
NULL || dest ==
NULL || userSrc ==
NULL || size <= 1)
286 char terminator =
'\0';
289 if (strLength ==
ERR)
293 dest[size - 1] =
'\0';
295 memcpy(dest, userSrc, strLength);
302 if (thread ==
NULL || pathname ==
NULL || userPath ==
NULL)
308 char terminator =
'\0';
311 if (pathLength ==
ERR)
317 memcpy(copy, userPath, pathLength);
338 char* terminator =
NULL;
340 (
void**)©, &amount) ==
ERR)
345 for (
uint64_t i = 0; i < amount; i++)
349 char strTerminator =
'\0';
365 if (outAmount !=
NULL)
375 if (thread ==
NULL || userObj ==
NULL || outValue ==
NULL)
#define MAX_PATH
Maximum length of filepaths.
#define CONFIG_MAX_ARGC
Maximum argument vector configuration.
#define CONFIG_MAX_USER_STACK_PAGES
User stack configuration.
#define CONFIG_MAX_KERNEL_STACK_PAGES
Kernel stack configuration.
#define GDT_SS_RING0
Value to load into the SS register for kernel data.
#define GDT_CS_RING0
Value to load into the CS register for kernel code.
void simd_ctx_save(simd_ctx_t *ctx)
void simd_ctx_load(simd_ctx_t *ctx)
uint64_t simd_ctx_init(simd_ctx_t *ctx)
void simd_ctx_deinit(simd_ctx_t *ctx)
#define STACK_POINTER_GUARD_PAGES
The amount of guard pages to use for stacks.
uint64_t stack_pointer_init(stack_pointer_t *stack, uintptr_t maxAddress, uint64_t maxPages)
Initializes a stack pointer structure, does not allocate or map any memory.
void syscall_ctx_init(syscall_ctx_t *ctx, const stack_pointer_t *syscallStack)
Initialize a syscall context.
#define SYSCALL_DEFINE(num, returnType,...)
Macro to define a syscall.
void syscall_ctx_load(syscall_ctx_t *ctx)
Load the syscall context into the MSR_KERNEL_GS_BASE MSR.
uint64_t pathname_init(pathname_t *pathname, const char *string)
Initialize a pathname.
uint64_t note_send(note_queue_t *queue, const char *string)
Write a note to a note queue.
uint64_t note_amount(note_queue_t *queue)
The amount of pending notes in a note queue, including special notes.
void note_queue_init(note_queue_t *queue)
Initialize a note queue.
void cache_free(void *obj)
Free an object back to its cache.
#define CACHE_LINE
Cache line size in bytes.
void * cache_alloc(cache_t *cache)
Allocate an object from the cache.
#define CACHE_CREATE(_cache, _name, _size, _alignment, _ctor, _dtor)
Macro to create a cache initializer.
uint64_t space_pin_terminated(space_t *space, const void *address, const void *terminator, size_t objectSize, size_t maxCount, stack_pointer_t *userStack)
Pins a region of memory terminated by a terminator value.
void space_unpin(space_t *space, const void *address, size_t length)
Unpins pages in a region previously pinned with space_pin() or space_pin_string().
uint64_t space_pin(space_t *space, const void *address, size_t length, stack_pointer_t *userStack)
Pins pages within a region of the address space.
#define VMM_KERNEL_STACKS_MAX
The maximum address for kernel stacks.
void vmm_load(space_t *space)
Loads a virtual address space.
#define VMM_USER_SPACE_MAX
The maximum address for user space.
process_t * process_get_kernel(void)
Gets the kernel process.
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 vecto...
bool thread_is_note_pending(thread_t *thread)
Check if a thread has a note pending.
void thread_free(thread_t *thread)
Frees a thread structure.
uint64_t thread_copy_from_user(thread_t *thread, void *dest, const void *userSrc, uint64_t length)
Safely copy data from user space.
void thread_load(thread_t *thread, interrupt_frame_t *frame)
Load state from a thread.
static thread_t * thread_current(void)
Retrieves the currently running thread.
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.
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_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(thread_t *thread, char *dest, const char *userSrc, uint64_t size)
Safely copy a string from user space.
thread_t * thread_new(process_t *process)
Creates a new thread structure.
uint64_t thread_copy_to_user(thread_t *thread, void *userDest, const void *src, uint64_t length)
Safely copy data to user space.
void thread_save(thread_t *thread, const interrupt_frame_t *frame)
Save state to a thread.
thread_state_t
Thread state enum.
void(* thread_kernel_entry_t)(void *arg)
Kernel thread entry point function type.
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.
uint64_t thread_send_note(thread_t *thread, const char *string)
Send a note to a thread.
@ THREAD_UNBLOCKING
Has started unblocking, used to prevent the same thread being unblocked multiple times.
@ THREAD_BLOCKED
Is blocking and waiting in one or multiple wait queues.
@ THREAD_PARKED
Is doing nothing, not in a queue, not blocking, think of it as "other".
void wait_client_init(wait_client_t *client)
Initialize a threads wait client.
void wait_unblock_thread(thread_t *thread, errno_t err)
Unblock a specific thread.
void sched_client_init(sched_client_t *client)
Initialize the scheduler context for a thread.
void sched_submit(thread_t *thread)
Submits a thread to the scheduler.
static void lock_release(lock_t *lock)
Releases a lock.
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
void rcu_call_cache_free(void *arg)
Helper callback to free a cache object.
void rcu_call(rcu_entry_t *entry, rcu_callback_t func, void *arg)
Add a callback to be executed after a grace period.
#define REF(ptr)
Increment reference count.
#define UNREF(ptr)
Decrement reference count.
#define EINVAL
Invalid argument.
#define EINTR
Interrupted system call.
#define ENOMEM
Out of memory.
#define errno
Error number variable.
static void list_remove_rcu(list_entry_t *entry)
Removes a list entry from its current list in a RCU-safe manner.
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
static void list_push_back_rcu(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list in a RCU-safe manner.
arch_prctl_t
Architecture specific thread data codes.
@ ARCH_GET_FS
Get the FS base address.
@ ARCH_SET_FS
Set the FS base address.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define PAGE_SIZE
The size of a memory page in bytes.
__UINT64_TYPE__ tid_t
Thread Identifier.
errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n)
#define RFLAGS_INTERRUPT_ENABLE
static void msr_write(uint32_t msr, uint64_t value)
#define RFLAGS_ALWAYS_SET
#define atomic_store(object, desired)
#define atomic_fetch_add_explicit(object, operand, order)
#define atomic_compare_exchange_strong(object, expected, desired)
#define atomic_load(object)
#define atomic_init(obj, value)
__UINTPTR_TYPE__ uintptr_t
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
Per-Thread performance context.
process_threads_t threads
list_t list
Reads are RCU protected, writes require the lock.
Intrusive RCU head structure.
Structure to define a stack in memory.
uintptr_t top
The top of the stack, this address is not inclusive.
Per thread syscall context.
Thread of execution structure.
list_entry_t processEntry
The entry for the parent process.
process_t * process
The parent process that the thread executes within.
stack_pointer_t kernelStack
The kernel stack of the thread.
uintptr_t fsBase
The FS base address for the thread.
stack_pointer_t userStack
The user stack of the thread.
tid_t id
The thread id, unique within a process_t.
Represents a thread in the waiting subsystem.
static void thread_ctor(void *ptr)
static uintptr_t thread_id_to_offset(tid_t tid, uint64_t maxPages)