Commit Graph

324 Commits

Author SHA1 Message Date
Matthew Leach
1906f1be5e arch: arm64: memory: heap: new
Add a new heap module which integrates the per-cpu cache and
`SlabAllocator` into a usable `GlobalAlloc` for the kernel.
2026-02-07 08:26:35 +00:00
Matthew Leach
0f0febdad0 arch: arm64: exceptions: use SP_EL0 as scratch reg
When detecting stack overflow in the kernel exception handler, use
`SP_EL0`, rather than `TPIDR_EL1` as the scratch register.  This allows
us to use the `TPIDR_EL1` register as a CPU-banked register for other
purposes.

Use of `SP_EL0` is safe here since the stack overflow check occurs
during kernel exceptions and SP_EL0 will be restored by the user-space
context restore logic, overriding the clobber.
2026-02-07 08:26:35 +00:00
Matthew Leach
424d6b126e libkernel: memory: slab: cache: new
Add a new per-cpu slab cache for caching slab allocations on a given
CPU.
2026-02-07 08:26:35 +00:00
Matthew Leach
1bdaaef14a libkernel: memory: slab: allocator: new
Add a new slab allocator implementation. The `SlabAllocator` manages
lists of slabs for each size class.
2026-02-07 08:26:35 +00:00
Matthew Leach
a2f636cebb libkernel: memory: slab: slab: new
Add a new module for managing objects within a slab. The `Slab` struct
manages objects of a given set within a contiguous set of pages. It is
the handle to the underlying memory, allowing for objects to be
allocated, and free'd. It manages a free list of 'indexes' within the
object slots themselves.
2026-02-07 08:26:35 +00:00
Matthew Leach
c0ecac05f3 libkernel: memory: PageAllocGetter: return ref to allocator
Rather than returning a reference to the `OnceCell` wrapping the
allocator, return a static reference to the allocator itself. This
allows flexibility for how the allocator is wrapped.
2026-02-07 08:26:35 +00:00
Matthew Leach
1b8ef1bc88 libkernel: memory: allocs: move FrameList impl into frame
Move the FrameList logic out of the physical memory allocator into its
own module. This allows `FrameList` to be shared between the physical
memory allocator and the slab allocator.
2026-02-07 08:26:35 +00: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
Matthew Leach
64469bb79c Merge pull request #185 from hexagonal-sun/hardware-smp-fixes 2026-01-28 09:14:25 +00:00
Matthew Leach
462de189b0 arm64: boot: secondaries: ensure WFI doesn't trap
The WFI insn is set not to trap on the primary core. Ensure it's also
set on the secondary cores too.
2026-01-28 08:00:01 +00:00
Matthew Leach
ba53418382 arm64: secondary: ensure boot_ctx is flushed to RAM
When the secondary boots and derefes the boot_ctx pointer passed in as a
parameter, it reads NULL, causing the secondary to end up stuck in an
exception loop. The data is sat in the primary core's cache and hasn't
been flushed to RAM. Since the secondary starts without the MMU (and
caches) enabled, the CCI doesn't kick in and we read stale data.

Manually flush the boot_ctx data to RAM before waking up the secondary.
2026-01-28 08:00:01 +00:00
Matthew Leach
d92945379a arm64: memory: flush_to_ram: new
Create a new function which takes a pointer to an object `T` and ensures
that the data is flushed from the caches to the point of
coherency (RAM).
2026-01-28 08:00:01 +00:00
Ashwin Naren
253a907c62 fix tests 2026-01-27 00:31:47 -08:00
Ashwin Naren
17b347cdc4 naming changes 2026-01-27 00:31:47 -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
e7eebb4494 Merge pull request #183 from hexagonal-sun/procfs-maps
procfs: implement /proc/<PID>/maps
2026-01-27 07:26:59 +00:00
Ashwin Naren
4ba1c029f1 optimize docker image size 2026-01-26 23:22:34 -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
d386b8ba36 post rebase fixes 2026-01-25 10:50:02 -08:00
Ashwin Naren
d8c77ebca7 procfs bugfixes 2026-01-25 10:50:02 -08:00
Ashwin Naren
d7ad7b76dc fix clocks not actually updating within time slice 2026-01-25 10:50:02 -08:00
Ashwin Naren
2d34ebcef9 procfs refactor 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
Ashwin Naren
bed6b65db0 fix clockid enum 2026-01-25 10:50:02 -08:00
Matthew Leach
3aca7b2122 devfs: set attr id the same as the inode id
Ensure that the ID of the attr contains the ID of the devfs inode,
instead of the default value.
2026-01-25 10:29:43 -08:00
Matthew Leach
4c94f6e3d4 pipe: add PipeInode for fstat
Add a PipeInode struct which allows `fstat` for an FD which is backed by
a pipe.
2026-01-25 10:29:43 -08:00
Matthew Leach
fae5dc1a4f usertest: fix test output
Since the test driver now outputs the test name, remove test name
printing in the signal tests.

Also flush stdout when the test has began running so if a problem
occures it's easier to know which test was running.
2026-01-25 10:29:16 -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
Matthew Leach
53dea094e3 Merge pull request #175 from arihant2math/more-interrupts
Make futex wait interruptable
2026-01-24 07:09:17 +00: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
Matthew Leach
190bc06994 Merge pull request #160 from arihant2math/mincore 2026-01-21 06:12:40 +00:00
Ashwin Naren
aca5c0db79 implement mincore 2026-01-20 19:52:47 -08:00
Matthew Leach
9eb2fcc185 Merge pull request #172 from arihant2math/sid
Implement sid syscalls
2026-01-20 06:24:27 +00:00
Ashwin Naren
7e2de367a9 update table 2026-01-19 18:36:31 -08:00
Ashwin Naren
06d016eab6 implement sid syscalls 2026-01-19 18:36:00 -08:00
Matthew Leach
76d4d0023f Merge pull request #170 from arihant2math/better-ext4-writing 2026-01-19 16:19:14 +00:00
Matthew Leach
0979e5f71a Merge pull request #171 from arihant2math/fix-intermittent-ci 2026-01-19 16:18:12 +00:00
Ashwin Naren
fb27ed3320 add retry logic to wget 2026-01-18 17:02:52 -08:00
Ashwin Naren
8df12a027c implement truncation 2026-01-18 01:17:19 -08:00
Ashwin Naren
782bef29e6 move fs tests to their own file 2026-01-17 10:24:05 -08:00
Ashwin Naren
8908b1e332 use macro for registration 2026-01-17 10:24:05 -08:00
Matthew Leach
b9fa68d9a3 Merge pull request #167 from hexagonal-sun/fix-interrupt-poll-order 2026-01-17 17:13:15 +00: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
abccd323ca Merge pull request #164 from hexagonal-sun/tty-signal-fixes
tty signal fixes
2026-01-17 10:27:50 +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
ecdfd360d1 sched: remove force_resched()
This function is used to force the scheduler to reschedule another task,
avoiding the fast-path exit.  Given the sheer number of task state
change points in the code, the fast-path exit code has become too
brittle.

Instead, check that the current task's state is still `Running` before
taking the fast-path short-circuit. The cost of one spinlock uncontended
lock-unlock cycle is worth the cost of avoiding many subtle scheduling
logic bugs.
2026-01-17 10:21:17 +00:00
Matthew Leach
4a88739804 syscalls: tty: read: make interruptable()
Allow a `read()` on a tty to be interrupted by a syscall. This is the
fundamental fix for making '^C' interrupt a process like `cat` when it's
reading from `stdin`.
2026-01-17 10:21:17 +00:00