119 tid_t volatile tid = thread->
id;
144 thread->
frame = *frame;
149 *frame = thread->
frame;
190 if (thread ==
NULL || dest ==
NULL || userSrc ==
NULL || length == 0)
201 memcpy(dest, userSrc, length);
208 if (thread ==
NULL || dest ==
NULL || userSrc ==
NULL || length == 0)
219 memcpy(dest, userSrc, length);
227 if (thread ==
NULL || userArray ==
NULL || terminator ==
NULL || objectSize == 0 || maxCount == 0 ||
236 if (arraySize ==
ERR)
241 uint64_t elementCount = arraySize / objectSize;
242 uint64_t allocSize = (elementCount + 1) * objectSize;
244 void* kernelArray =
malloc(allocSize);
245 if (kernelArray ==
NULL)
252 memcpy(kernelArray, userArray, arraySize);
253 memcpy((
uint8_t*)kernelArray + arraySize, terminator, objectSize);
256 *outArray = kernelArray;
257 if (outCount !=
NULL)
259 *outCount = elementCount;
267 if (thread ==
NULL || pathname ==
NULL || userPath ==
NULL)
273 char terminator =
'\0';
276 if (pathLength ==
ERR)
282 memcpy(copy, userPath, pathLength);
283 copy[pathLength] =
'\0';
298 char* terminator =
NULL;
300 (
void**)©, &amount) ==
ERR)
305 for (
uint64_t i = 0; i < amount; i++)
309 char strTerminator =
'\0';
325 if (outAmount !=
NULL)
335 if (thread ==
NULL || userObj ==
NULL || outValue ==
NULL)
#define MAX_PATH
Maximum length of filepaths.
#define assert(expression)
@ GDT_CS_RING0
Value to load into the CS register for kernel code.
@ GDT_SS_RING0
Value to load into the SS register for kernel data.
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_queue_length(note_queue_t *queue)
Get the length of a note queue.
uint64_t note_queue_write(note_queue_t *queue, const void *buffer, uint64_t count)
Write a note to a note queue.
void note_queue_init(note_queue_t *queue)
Initialize a note queue.
#define LOG_DEBUG(format,...)
void space_unpin(space_t *space, const void *address, uint64_t length)
Unpins pages in a region previously pinned with space_pin() or space_pin_string().
uint64_t space_pin_terminated(space_t *space, const void *address, const void *terminator, uint8_t objectSize, uint64_t maxCount, stack_pointer_t *userStack)
Pins a region of memory terminated by a terminator value.
uint64_t space_pin(space_t *space, const void *address, uint64_t length, stack_pointer_t *userStack)
Pins pages within a region of the address space.
void space_load(space_t *space)
Loads a virtual address space.
#define VMM_KERNEL_STACKS_MAX
The maximum address for kernel stacks.
#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_send_note(thread_t *thread, const void *buffer, uint64_t count)
Send a note to a thread.
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.
uint64_t thread_copy_to_user(thread_t *thread, void *dest, const void *userSrc, uint64_t length)
Safely copy data to user space.
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.
thread_t * thread_new(process_t *process)
Creates a new thread structure.
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.
@ 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.
thread_t * sched_thread(void)
Retrieves the currently running 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.
#define REF(ptr)
Increment reference count.
#define UNREF(ptr)
Decrement reference count.
#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 EINVAL
Invalid argument.
#define EINTR
Interrupted system call.
#define ENOMEM
Out of memory.
#define errno
Error number variable.
static void list_push_back(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
static void list_remove(list_t *list, list_entry_t *entry)
Removes a list entry from its current list.
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
#define PAGE_SIZE
The size of a memory page in bytes.
#define NULL
Pointer error value.
#define ERR
Integer error value.
__UINT64_TYPE__ tid_t
Thread Identifier.
static uint64_t thread_init(thread_t *thread, process_t *process)
static uintptr_t thread_id_to_offset(tid_t tid, uint64_t maxPages)
EFI_PHYSICAL_ADDRESS buffer
#define RFLAGS_INTERRUPT_ENABLE
#define RFLAGS_ALWAYS_SET
#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)
_PUBLIC void * memset(void *s, int c, size_t n)
process_threads_t threads
uintptr_t top
The top of the stack, this address is not inclusive.
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.
stack_pointer_t userStack
The user stack of the thread.
tid_t id
The thread id, unique within a process_t.