Commit Graph

111 Commits

Author SHA1 Message Date
Ashwin Naren
07c1739654 implement setuid, setgid, setreuid, setregid, setresuid, setresgid 2026-04-12 09:57:01 -07:00
Ashwin Naren
4f691d3e60 handle timeout, writefds, and mask correctly in pselect6 2026-04-04 19:45:43 -07:00
Matthew Leach
a3836bb88b thread_group: wait: separate out ptrace events from child events
ptrace 'child' events are treated differently during a wait than
'normal' child events.  Speciecially, a process that is being traced
receives events for all threads (all `Tid`s) from a process, rather than
the `Tgid`.

This fixes running strace on multi-threaded programs.
2026-03-23 17:30:08 +00:00
Matthew Leach
bf4d1dbac4 process: make Tid globally unique
Make the `Tid` globally unique, rather than `Tgid` creating a new number
space. This allows ptrace to differentiate between threads when using
`-f` on a program which spawns threads.
2026-03-23 06:08:21 +00:00
Matthew Leach
aaac9ffd2c sched: eliminate CUR_TASK_PTR
Replace `CUR_TASK_PTR` with `ProcessCtx`. This allows differentiation
between functions that access process context (take in `ProcessCtx` as a
parameter) and those that don't.

When creating a new class of scheduleable tasks (softirqs, kthreads),
this ensure that those functions cannot call context-sensitive
functions.
2026-03-19 20:58:15 +00:00
Matthew Leach
3d20e28c4f sched: Work: deref into Arc<Task> rather than OwnedTask
Since a Arc<Work> can be obtained from `TASK_LIST`, this would allow the
potential mutation of 'owned'-state from other CPUs thereby causing a
race condition. Thefore, ensure that the deref of an `Arc<Work>` only
permits access to `t_shared`.
2026-03-18 13:52:25 +00:00
Matthew Leach
a8aef0483f Merge pull request #259 from arihant2math/proc-exe 2026-03-18 06:43:08 +00:00
Ashwin Naren
c2dba9762c retain CPU affinity when rescheduling 2026-03-17 15:54:58 -07:00
Ashwin Naren
a3d85ced59 implement /proc/<pid>/exe 2026-03-12 10:33:30 -07:00
Matthew Leach
5ebfc29cd2 sched: introduce Work as the unified scheduleable unit
Refactor the scheduler so all scheduleable work is wrapped in Arc<Work>,
replacing the previous per-CPU wait_q design where sleeping tasks were
bound to a specific CPU. Wakers now hold direct Arc<Work> references and
can re-enqueue tasks on any CPU upon wakeup.

Key changes:

- Add Work struct wrapping OwnedTask with an AtomicTaskState and
  scheduler metadata (SchedulerData), replacing the old SchedulableTask.
  Remove Task::state (Arc<SpinLock<TaskState>>). Work::state is now the
  single source of truth for task state.

- Rewrite the run queue using BinaryHeap-based eligible/ineligible split
  (EEVDF) with a dedicated VClock, replacing the BTreeMap linear scan.
  Extract vclock into its own module.

- Rewrite wakers to hold Arc<Work> directly instead of looking up tasks
  by TaskDescriptor from TASK_LIST.

- Replace lock-based sleep transitions in uspc_ret with atomic CAS
  (try_sleep_current) that correctly detects concurrent Woken state.

- Simplify least-tasked-CPU metric to use only run-queue weight, since
  sleeping tasks are no longer bound to any CPU.

- Add current_work() accessor.
2026-03-12 10:53:22 +00:00
Ashwin Naren
ce27c4bc36 add find_process_by_tgid 2026-02-28 17:09:07 -08:00
Ashwin Naren
de358db4c4 fix clippy 2026-02-26 17:11:10 -08:00
Ashwin Naren
3d33578533 Merge pull request #187 from arihant2math/cap-raise
prctl: implement `AmbientCapOp::Raise`
2026-02-09 23:24:52 -08:00
Ashwin Naren
eb84a1ec6d Merge pull request #198 from arihant2math/more-fnctl 2026-02-09 13:59:40 -08:00
Ashwin Naren
ef10631dc4 Merge pull request #195 from hexagonal-sun/slab-allocator
slab allocator
2026-02-08 16:51:29 -08:00
Ashwin Naren
e9bcc1b10d implement fcntl F_SETFL 2026-02-07 13:53:34 -08:00
Matthew Leach
972f023edc libkernel: memory: reorganise allocators
Create a new submodule within `memory`, `allocators` which contains all
memory allocators. Also split out the `Frame` struct from the `pg_alloc`
module, allowing it to be used by other modules.
2026-02-07 08:26:35 +00:00
Ashwin Naren
04ac1e8783 implement sys_waitid 2026-01-30 08:31:26 -08:00
Ashwin Naren
ba7c517685 prctl: implement AmbientCapOp::Raise 2026-01-29 14:30:24 -08:00
Ashwin Naren
04f015848b percpu refactor 2026-01-27 00:31:47 -08:00
Ashwin Naren
7c7776ba7b working top
implements enough of procfs for `top` to run
2026-01-27 00:31:47 -08:00
Matthew Leach
87fe041ba0 procfs: implement /proc/<PID>/maps
Implement the `maps` file which shows a process's VMA entries. Example
output:

```
[root@moss-machine /]# cat /proc/1/maps
500000000000-500000117000 r-xp 0000000000                    /bin/bash
50000012b000-500000130000 r--p 000011b000                    /bin/bash
500000130000-50000013e000 rw-p 0000120000                    /bin/bash
700000000000-70000002b000 r-xp 0000000000                    /lib/ld-linux-aarch64.so.1
70000003e000-700000040000 r--p 000002e000                    /lib/ld-linux-aarch64.so.1
700000040000-700000042000 rw-p 0000030000                    /lib/ld-linux-aarch64.so.1
7fffff510000-7fffff585000 r-xp 0000000000                    /usr/lib/libncursesw.so.6
7fffff585000-7fffff59b000 ---p 0000075000                    /usr/lib/libncursesw.so.6
7fffff59b000-7fffff5a0000 r--p 000007b000                    /usr/lib/libncursesw.so.6
7fffff5a0000-7fffff5a1000 rw-p 0000080000                    /usr/lib/libncursesw.so.6
7fffff5b0000-7fffff760000 r-xp 0000000000                    /usr/lib/libc.so.6
7fffff760000-7fffff76d000 ---p 00001b0000                    /usr/lib/libc.so.6
7fffff76d000-7fffff770000 r--p 00001bd000                    /usr/lib/libc.so.6
7fffff770000-7fffff772000 rw-p 00001c0000                    /usr/lib/libc.so.6
7fffff772000-7fffff779000 rw-p 0000000000
7fffff780000-7fffff7d9000 r-xp 0000000000                    /usr/lib/libreadline.so.8
7fffff7d9000-7fffff7ed000 ---p 0000059000                    /usr/lib/libreadline.so.8
7fffff7ed000-7fffff7f0000 r--p 000005d000                    /usr/lib/libreadline.so.8
7fffff7f0000-7fffff7f6000 rw-p 0000060000                    /usr/lib/libreadline.so.8
7fffff7f6000-7fffff7fb000 rw-p 0000000000
7fffff800000-800000063000 rw-p 0000000000                    [stack]
```
2026-01-27 06:10:43 +00:00
Ashwin Naren
d7ad7b76dc fix clocks not actually updating within time slice 2026-01-25 10:50:02 -08:00
Ashwin Naren
c5a0976a73 track stime and utime
Tracks stime and utime for processes and tasks. Reports the times through procfs and `sys_clock_gettime`.
2026-01-25 10:50:02 -08:00
Matthew Leach
4a3477182a clock_nanosleep: fix arguments to syscall
The `sys_clock_nanosleep` implementation was missing a `flags` parameter
in the second position.  This meant that `rqtp` was interpreted as
`rmtp`, and when interrupted, `rmtp` would write to a garbage address
causing an `EFAULT`.

Fix the argument ordering.
2026-01-25 10:28:40 -08:00
Ashwin Naren
59adc10cee make futex wait interruptable 2026-01-23 10:23:29 -08:00
Ashwin Naren
aa5a9c7b79 fix typos 2026-01-23 01:26:04 -08:00
Ashwin Naren
92efb4cee7 enforce semicolon_if_nothing_returned and uninlined_format_args 2026-01-23 01:26:04 -08:00
Ashwin Naren
06d016eab6 implement sid syscalls 2026-01-19 18:36:00 -08:00
Matthew Leach
3b71fa3d39 signal: interruptible: prioritize wrapped future over signals
Poll the wrapped future first, ensuring that the interrupt logic doesn't
short-circuit a future which is already ready.

This fixes an issue where `sys_wait4` would return `-EINTR` when
receiving a `SIGCHLD`. Since `SIGCHLD` indicates the wait condition
is met, the underlying future is ready and should return the PID
successfully rather than aborting.
2026-01-17 12:10:37 +00:00
Matthew Leach
bc5d1cd91e syscalls: wait4: make interruptable()
Make the `sys_wait4` system call interruptable via signal delivery.

Also include some a test in `usertest` to ensure proper functionality.
2026-01-17 10:22:53 +00:00
Matthew Leach
2655e8e78a syscalls: sleep: make interruptable()
Allow the `nanosleep` family of functions to be interrupted. When an
interruption occures, calculation the remaining duration and write that
back to user-space.

Add a test to ensure proper functionality into usertest.
2026-01-17 10:21:17 +00:00
Matthew Leach
770f32c30c process: signals: add interruptable()
Add a new struct, `InterruptableFut` which allows signal
short-circuiting logic. If a future within the kernel's syscall logic is
wrapped in a `InterruptableFut`, then a wakeup with any pending signals
causes the underlying future to be dropped and it's operation cancelled.

Provide a `InterruptResult` enum to allow the caller to know whether the
operation was interrupted and allows them to take appropriate action.
Typically exiting with `-EINTR`.

Finally, provide a blanket implementation for all futures, allowing then
to call `.interruptable()` to easily wrap any future.
2026-01-17 10:21:17 +00:00
Matthew Leach
b5f184a6d9 process: peek_signal: new
Add a new function that allows for peeking at a task's currently pending
signals without consuming the signal.
2026-01-17 10:21:17 +00:00
Matthew Leach
71d120ebe7 thread_group: deliver_signal: ensure signal delivery
If all tasks within a thread group are sleeping when a signal is
delivered, wake at least one task to action the signal.
2026-01-17 10:21:17 +00:00
Matthew Leach
798cad0c38 fd_table: don't close CLOEXEC FDs until exec
Currently we close CLOEXEC FDs when we call `clone()` when making a copy
of the file descriptor table. Defer this until the `exec` syscall.

This fixes numerous bugs, namely with bash and setting the foreground
process group for the current TTY.
2026-01-17 10:21:17 +00:00
Matthew Leach
6fc1990597 thread_group: pgid: inherit from parent
Inherit the process-group ID from the parent. If there is no parent
specified then the pgid is the same as the tgid.
2026-01-17 10:21:17 +00:00
Matthew Leach
1e91c60f0b Merge pull request #165 from hexagonal-sun/ptrace-follow-forks
ptrace: trace children on fork
2026-01-17 10:19:20 +00:00
Matthew Leach
3932dd96a7 ptrace: trace children on fork
When calling `clone()` with PTRACE_O_TRACEFORK set, make the child
inherit the current ptrace context.  Also start the process with SIGSTOP
pending as per the ptrace docs.

This enable strace follow-forks functionality `strace -f`.
2026-01-17 08:35:33 +00:00
Ashwin Naren
f4a9512a41 support waiting on a value less than -1 2026-01-16 15:51:47 -08:00
Ashwin Naren
82993b05d3 implement PR_CAPBSET_DROP, PR_GET_SECUREBITS, PR_GET_NO_NEW_PRIVS, and PR_CAP_AMBIENT 2026-01-13 23:52:36 -08:00
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