Commit Graph

70 Commits

Author SHA1 Message Date
Ashwin Naren
96fe0378b7 implement F_DUPFD for sys_fcntl 2026-01-13 16:48:33 -08:00
Ashwin Naren
99d881a0e6 implement pr_get_name and pr_set_name 2026-01-13 16:48:10 -08:00
Ashwin Naren
bc68aae677 stub sys_clock_nanosleep
# Conflicts:
#	src/arch/arm64/exceptions/syscall.rs
2026-01-13 16:48:01 -08:00
Ashwin Naren
cff5005c06 execute scripts
checks for shebang and executes the specified program
2026-01-12 14:23:49 -08:00
Matthew Leach
64bc004cdb process: sys_wait4: return ECHILD with no children
If the calling process has no children and no pending exit events to
handle, return ECHILD instead of waiting forever.
2026-01-11 19:23:47 -08:00
Matthew Leach
a003ab8f71 syscall: sys_exit*: add ptrace events
Add ptrace events for the exit family of syscalls.
2026-01-11 19:23:47 -08:00
Matthew Leach
abbc8261c5 kill: awake sleepy tasks on SIGKILL
If a SIGKILL has been received, ensure all sleepy tasks are set to
runnable so that they can action the signal.
2026-01-11 19:23:47 -08:00
Matthew Leach
ede1ef39d9 process: sys_rt_sigprocmask: fix UNMASKABLE_SIGNALS
We currently union the UNMASKABLE_SIGNALS set with the new signal mask.
This does the complete opposite of what we wnat, we want to *remove*
those signals from the newly computed signal mask.

This patch removes the UNMASKABLE_SIGNALS set from any newly computed
signal mask.
2026-01-11 19:23:47 -08:00
Matthew Leach
f9e02d9227 process: get_page: new
Add a function that allows an owned page to be atomically obtained from
a new process.
2026-01-11 19:23:47 -08:00
Matthew Leach
64b337ca63 ptrace: send SIGSTOP and PTRACE_EVENT_STOP for stoppable signal
When a new child stops due to a stoppable-signal after PTRACE_TRACEME,
send a SIGSTOP with a `PTRACE_EVENT_STOP`.
2026-01-11 19:23:47 -08:00
Matthew Leach
3a0e1f80e1 ptrace: implement PTRACE_SETOPTIONS
Add option definitions `PTRACE_O_*` and change the ptrace state
depdening upon which options are set in the call.
2026-01-11 19:23:47 -08:00
Matthew Leach
5911eb49ef ptrace: handle continuiation calls
handle `PTRACE_CONT` and `PTRACE_SYSCALL` operations.
2026-01-11 19:23:47 -08:00
Matthew Leach
70d9d730c0 ptrace: add event waiting
Make it such that when a ptrace event is hit:

 - The current regset is saved in the ptrace state.
 - The current task is put to sleep.
 - Arrange for a SIGCHLD to be set to the parent.
 - Notify any waiters with the appopriate signal.
2026-01-11 19:23:47 -08:00
Ashwin Naren
6d8854fe30 initial ptrace 2026-01-11 19:23:47 -08:00
Matthew Leach
1d79d6b2df process: refactor signal handling and fix action table sharing
This commit refactors the signal handling subsystem to address a bug in
process creation and to improve the separation of concerns between
signal delivery and signal disposition.

1. Fix Action Table Sharing:
Previously, the signal action table was wrapped in an `Arc`, causing
forked child processes to inadvertently share signal dispositions with
the parent. `SignalActionState` now contains a direct `SigActionSet` and
implements Clone, ensuring that processes receive a private copy of the
action table upon fork/clone.

2. Decouple Signal Selection from Execution:
The logic for selecting a pending signal has been moved from the
disposition state into a new `take_signal` method on `OwnedTask`. This
decouples the "taking" of a signal (respecting masks and priorities)
from the "actioning" of that signal. This is a prerequisite for
implementing ptrace.

3. Various cleanup bits:
- Renamed `SignalState` to `SignalActionState` to more accurately
  reflect that it manages signal dispositions.
- Removed the `pending` signal set out of the action state and directly
  into the `ThreadGroup` and `OwnedTask`.
- Renamed `set_pending` to `set_signal` for consistency.
- Simplified the signal delivery loop in `dispatch_userspace_task`
  using the new `take_signal` API.
2026-01-09 06:49:48 +00:00
Matthew Leach
e8d6c304ae syscalls: wait4: implement WNOHANG
Implement WNOHANG logic within the sys_wait4 system call. If this is
flag is set, remove the process from the ChildNotifiers set without
waiting.
2026-01-08 15:29:42 -08:00
Matthew Leach
9753639255 syscalls: sys_setfs{uid,gid}: implement
Implement deprecated syscalls sys_setfs{uid,gid}. We simply return the
euid and egid in this case.
2026-01-06 16:22:14 -08:00
Matthew Leach
a4db1debac syscalls: prctl: add stub impl
Implement PR_CAPBSET_READ with a very basic implementation.
2026-01-06 08:52:52 -08:00
Ashwin Naren
f0771dde4f exec with interpreter 2026-01-06 08:52:52 -08:00
Ashwin Naren
a8200dc067 Check and parse PT_INTERP in ELF 2026-01-06 08:52:52 -08:00
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
57e0aa364c process: task_group: implement pg priority
Currently, each task implements it's own priority value. In Linux, each
thread group (process) has a default process which all tasks in that
group inherit. Tasks can, however, override the default process
priority.

Implement that logic here which also fixes the current compilation error
on master.
2026-01-02 18:16:11 -08:00
Ashwin Naren
b5138c30f9 working ext4 2026-01-02 17:01:02 -08:00
Matthew Leach
b8bcbfe91b Merge pull request #116 from hexagonal-sun/implement-ownedtask
process: split `Task` into `Task` (shared) and `OwnedTask` (local)
2026-01-02 17:37:43 +00:00
Ashwin Naren
2383bf99bb support stat in procfs 2026-01-01 16:44:55 -08:00
Matthew Leach
37138e1ee7 sched, messenger: get SMP working with sched changes
Add various fixes to get an SMP version of `usertest` working with SMP.
2026-01-01 22:56:52 +00: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
ootinnyoo
fe4f3103dc implement linux-like process capabilities 2025-12-29 13:53:02 -08:00
Ashwin Naren
379b7ffab8 Refactor vruntime to v_runtime 2025-12-29 12:39:58 -08:00
Matthew Leach
9e80a6ae8a process: TASK_LIST: point to Task struct
Make the global `TASK_LIST` struct be a collection of `Task`s, rather
than `task.state` struct members. This allows other cores to access to
any shared task state easily.
2025-12-29 20:28:00 +00:00
Matthew Leach
9f0bf1f689 process: mod: last_cpu: use CpuId
Use the new `CpuId` type for the `last_cpu` field in `Task`.
2025-12-29 16:19:49 +00:00
Matthew Leach
116a1adbd0 clone: add all tasks to process task list
This prevents a bug where `sys_exit` calls `exit_group` for the thread's
process, even when there are still active threads.
2025-12-28 23:51:51 -08:00
Ashwin Naren
ca8555283b use messengers
# Conflicts:
#	libkernel/src/sync/per_cpu.rs
2025-12-28 23:51:51 -08:00
Ashwin Naren
0a3d0851ee include last run CPU 2025-12-28 23:51:51 -08:00
Ashwin Naren
39d0bba0c6 EEVDF improvements
Use EEVDF concepts like virtual deadline correctly and actually calculate the necessary deadline and use it to schedule.

Also dynamically preempts based on the deadline.
2025-12-28 23:51:51 -08:00
Ashwin Naren
b75f29804f schedule in round-robin fashion 2025-12-28 23:49:33 -08: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
Matthew Leach
69f50fef18 sched: fix futures race-condition
When a future returns `Poll::Pending`, there is a window where, if a
waker is called, prior to the sched code setting the task's state to
`Sleeping`, the wake-up could be lost.  We get around this by
introducing a new state `Woken`.

A waker will set a `Running` task to this state. The sched code then
detects this and *does not* set the task's state to `Sleeping`, instead
it leaves it as running and attempts to re-schedule.
2025-12-24 18:44:41 -08:00
Ashwin Naren
7122429a20 dispatch signals (#85) 2025-12-24 12:54:40 -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
Ashwin Naren
2cb93c0891 address review 2025-12-22 02:06:11 -08:00
Ashwin Naren
8bf0a72bce fix futex based thread joining 2025-12-21 17:02:19 -08:00
Matthew Leach
3273d6451e clone: implement CLONE_SETTLS
Set the TLS pointer when `CLONE_SETTLS` is set in `sys_clone`.
2025-12-21 16:13:15 -08:00
Matthew Leach
a7ebe8e214 threading: fix clone to spawn threads
Fix issues identify in `sys_clone` logic to enable basic threading.
2025-12-21 16:13:15 -08:00
Matthew Leach
eb2369f621 Merge pull request #57 from arihant2math/futex 2025-12-21 13:30:40 +00:00
Matthew Leach
03a400d2bd Merge pull request #72 from some100/master 2025-12-21 13:30:05 +00:00
Ashwin Naren
637874620b address review 2025-12-21 01:56:33 -08:00
Ashwin Naren
f004824bbd make clippy happy 2025-12-21 01:43:54 -08:00