Commit Graph

6 Commits

Author SHA1 Message Date
Matthew Leach
74aa508197 futex: implement bitset variants
Implement FUTEX_{WAKE,WAIT}_BITSET by using a `u32` as a data
discriminant value.

Also add a bunch of tests to `usertest` to ensure proper functionality.
2026-01-03 14:36:06 -08:00
Matthew Leach
35efecad76 process: split Task into Task (shared) and OwnedTask (local)
This commit refactors the core process representation to decouple
"Identity/Resources" from "Execution/Scheduling". Previously, a
monolithic `Task` struct wrapped in `Arc<SpinLock<>>` caused lock
contention during hot scheduling paths and conflated shared state with
CPU-local state.

The `Task` struct has been split into:

1. `Task` (Shared): Holds process-wide resources (VM, FileTable,
Credentials). Managed via `Arc` and internal fine-grained locking.

2. `OwnedTask` (Private): Holds execution state (Context, v_runtime,
signal mask). Strictly owned by a specific CPU (via the Scheduler) and
accessed lock-free.

Key changes:

* Scheduler:
  chedState` now owns tasks via `Box<OwnedTask>`.
  - Transitions between `run_queue` and `running_task` involve strictly
    moving ownership of the Box, ensuring pointer stability.
  - The EEVDF comparison logic now explicitly handles comparisons
    between the queued candidates and the currently running task (which is
    not in the queue).

* Current Task Access:
  - `current()` now returns a `CurrentTaskGuard` which:
    1. Disables preemption (preventing context switches while holding
       the reference).
    2. Performs a runtime borrow check (panic on double-mutable borrow).
    3. Dereferences a cached Per-CPU raw pointer for O(1) access.
2026-01-01 22:54:43 +00:00
Matthew Leach
cdb9a73297 futex: only access timeout on _WAIT ops
The `timeout` parameter is only used for `_WAIT` futex ops. For other
ops, the `timeout` parameter is permitted to be an undefied value. The
current implementation would then try to `copy_from_user` using the
garbage pointer and fault, causing a missed wake-up and deadlock the
calling process.

Fix this by only accessing the timeout parmeter for `_WAIT` futex ops
where the parameter's value must be valid.
2025-12-28 23:38:03 -08:00
Ashwin Naren
c4f1d9acf5 support timeouts for futex 2025-12-23 13:08:37 -08:00
Matthew Leach
88549fee5a sys_set_tid_address: finish implementation
Now CLONE_CHILD_CLEARTID has been implemented properly, we can finish
the implementation of `sys_set_tid_address`.
2025-12-23 11:28:44 -08:00
Matthew Leach
6bada491b6 futex: check value while queue locked
Lock the futex queue when checking the value to ensure atomicity.
2025-12-23 10:21:30 -08:00