|
PatchworkOS
da8a090
A non-POSIX operating system.
|
Thread of execution. More...
Thread of execution.
Data Structures | |
| struct | thread_t |
| Thread of execution structure. More... | |
Typedefs | |
| typedef void(* | thread_kernel_entry_t) (void *arg) |
| Kernel thread entry point function type. | |
Enumerations | |
| enum | thread_state_t { THREAD_PARKED = 0 , THREAD_ACTIVE , THREAD_PRE_BLOCK , THREAD_BLOCKED , THREAD_UNBLOCKING , THREAD_DYING } |
| Thread state enum. More... | |
Functions | |
| thread_t * | thread_new (process_t *process) |
| Creates a new 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_free (thread_t *thread) |
| Frees a thread structure. | |
| 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 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. | |
| 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_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_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. | |
| _NORETURN void | thread_jump (thread_t *thread) |
Jump to a thread by calling thread_load() and then loading its interrupt frame. | |
| typedef void(* thread_kernel_entry_t) (void *arg) |
| enum thread_state_t |
Thread state enum.
Creates a new thread structure.
Does not push the created thread to the scheduler or similar, merely handling allocation and initialization.
| process | The parent process that the thread will execute within. |
NULL and errno is set. Definition at line 70 of file thread.c.
| 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.
| entry | The entry point function for the thread. |
| arg | An argument to pass to the entry point function. |
ERR and errno is set. Definition at line 97 of file thread.c.
| void thread_free | ( | thread_t * | thread | ) |
| void thread_save | ( | thread_t * | thread, |
| const interrupt_frame_t * | frame | ||
| ) |
| void thread_load | ( | thread_t * | thread, |
| interrupt_frame_t * | frame | ||
| ) |
Load state from a thread.
Will retrieve the interrupt frame and setup the CPU with the threads contexts/data.
| thread | The source thread to load state from. |
| frame | The destination interrupt frame. |
Definition at line 147 of file thread.c.
Send a note to a thread.
This function should always be used over the note_queue_push() function, as it performs additional checks, like unblocking the thread to notify it of the received note.
| thread | The destination thread. |
| buffer | The buffer to write. |
| count | The number of bytes to write. |
0. On failure, ERR and errno is set. Definition at line 161 of file thread.c.
| uint64_t thread_copy_from_user | ( | thread_t * | thread, |
| void * | dest, | ||
| const void * | userSrc, | ||
| uint64_t | length | ||
| ) |
Safely copy data from user space.
Will pin the user pages in memory while performing the copy and expand the user stack if necessary.
| thread | The thread performing the operation. |
| dest | The destination buffer in kernel space. |
| userSrc | The source buffer in user space. |
| length | The number of bytes to copy. |
0. On failure, ERR and errno is set. Definition at line 188 of file thread.c.
| uint64_t thread_copy_to_user | ( | thread_t * | thread, |
| void * | dest, | ||
| const void * | userSrc, | ||
| uint64_t | length | ||
| ) |
Safely copy data to user space.
Will pin the user pages in memory while performing the copy and expand the user stack if necessary.
| thread | The thread performing the operation. |
| dest | The destination buffer in user space. |
| userSrc | The source buffer in kernel space. |
| length | The number of bytes to copy. |
0. On failure, ERR and errno is set. Definition at line 206 of file thread.c.
| 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.
| thread | The thread performing the operation. |
| userArray | The source array in user space. |
| terminator | A pointer to the terminator object. |
| objectSize | The size of each object in the array. |
| maxCount | The maximum number of objects to copy. |
| outArray | Output pointer to store the allocated array in kernel space, must be freed by the caller. |
| outCount | Output pointer to store the number of objects copied, can be NULL. |
0. On failure, ERR and errno is set. Definition at line 224 of file thread.c.
| 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 | The thread performing the operation. |
| pathname | A pointer to the pathname to initialize. |
| userPath | The string in user space. |
0. On failure, ERR and errno is set. Definition at line 265 of file thread.c.
| 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.
| thread | The thread performing the operation. |
| user | The source array of strings in user space. |
| out | Output pointer to store the allocated array of strings in kernel space, must be freed by the caller. |
| outAmount | Output pointer to store the number of strings copied, can be NULL. |
0. On failure, ERR and errno is set. Definition at line 294 of file thread.c.
| 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.
Will pin the user pages in memory while performing the load and expand the user stack if necessary.
| thread | The thread performing the operation. |
| userObj | The user-space atomic variable to load from. |
| outValue | Output pointer to store the loaded value. |
0. On failure, ERR and errno is set. Definition at line 333 of file thread.c.
Jump to a thread by calling thread_load() and then loading its interrupt frame.
Must be done in assembly as it requires directly modifying registers.
Will never return instead it ends up at thread->frame.rip.
| thread | The thread to jump to. |