Skip to main content

Module thread_ops

Module thread_ops 

Source
Expand description

Thread lifecycle operations shared by the syscall layer and /thread VFS scheme.

Extracted from syscall/process.rs so that both SYS_THREAD_CREATE/JOIN/EXIT and the Plan 9 style /thread/* scheme forward to the exact same internal implementation (no duplicated WaitQueue, no duplicated validation).

Also owns the kernel-owned user stack bookkeeping: threads created via /thread/create get their user stack allocated and mapped by the kernel, which reclaims it deterministically when the thread dies. Threads created through raw SYS_THREAD_CREATE keep providing their own stack and leave the field untouched.

StructsΒ§

ThreadUserContext πŸ”’
UserEntryContext
Caller’s userspace segment/flag state used to seed the child iret frame.

ConstantsΒ§

THREAD_DEFAULT_STACK_BYTES
Default size when the caller passes stack_size == 0.
THREAD_MAX_STACK_BYTES
THREAD_MIN_STACK_BYTES
Bounds of a kernel-owned user stack request.
THREAD_OFF_ARG0 πŸ”’
THREAD_OFF_ENTRY πŸ”’
THREAD_OFF_STACK_TOP πŸ”’
THREAD_OFF_USER_CS πŸ”’
THREAD_OFF_USER_RFLAGS πŸ”’
THREAD_OFF_USER_SS πŸ”’
USER_TOP_EXCLUSIVE πŸ”’

StaticsΒ§

KERNEL_USER_STACKS_ACTIVE πŸ”’
Number of kernel-owned user stacks currently alive (allocated - reclaimed).
KERNEL_USER_STACKS_ALLOCATED πŸ”’
Total number of kernel-owned user stacks ever allocated.

FunctionsΒ§

alloc_kernel_user_stack πŸ”’
Allocate and lazily map a user stack in the parent process address space.
build_user_thread_task πŸ”’
Performs the build user thread task operation.
create_user_thread
Core of SYS_THREAD_CREATE and /thread/create.
create_user_thread_inner πŸ”’
create_user_thread_with_kernel_stack
/thread/create variant: the kernel allocates and owns the user stack.
current_thread_tid
Current TID of the calling task (scheme /thread/current fast path).
exit_current_thread
Core of SYS_THREAD_EXIT and /thread/exit.
join_task
Core of SYS_THREAD_JOIN and /thread/join/<tid>.
kernel_user_stack_stats
Snapshot of kernel-owned user stack counters (allocated_total, active).
kill_thread
Kill a thread by TID, restricted to threads of the caller’s own process.
page_align_up πŸ”’
reclaim_kernel_user_stack
Reclaim the kernel-owned user stack of task, if any.
thread_child_start πŸ”’
Performs the thread child start operation.
thread_iret_from_ctx πŸ”’ ⚠
Performs the thread iret from ctx operation.