Commit Graph

92 Commits

Author SHA1 Message Date
Matthew Leach
39a5ef331d libkernel/slab: fix UB and accounting bugs identified by Miri
Fix several issues in the slab allocator identified by the heap stress
tests (intermittent) and running the tests under Miri.

1. Fix Undefined Behavior. Previously, the allocator created temporary
   `&mut Frame` references while raw pointers to that frame existed in the
   intrusive `partial` or `free` lists. Under Miri's strict aliasing rules,
   creating a unique reference to the whole struct invalidated the list
   pointers.

   The fix implements "split borrowing": we now maintain raw pointers to
   the frame and only create mutable references to the `.state` field
   when needed, ensuring the `.link` field remains valid for the
   intrusive list.

2. Fix `free_list_sz` accounting. In `try_alloc`, the `free_list_sz`
   counter was not being decremented when a slab was successfully popped
   from the free list. This caused the allocator to believe it had free
   slabs when the list was actually empty, leading to panics during
   batch-free operations.

3. Increase heap stress tests. The test suite now runs the stress test
   in a loop to catch state persistence bugs and ensures the allocator is
   fully torn down and reset between iterations.

Fixes: #220
2026-02-21 14:38:18 -08:00
Ashwin Naren
37def9264e implement copy_file_range 2026-02-19 12:51:20 -08:00
Ashwin Naren
600f228d69 address review 2026-02-19 12:51:11 -08:00
Ashwin Naren
2fa3b490d3 implement rwlock 2026-02-19 12:51:11 -08:00
Matthew Leach
ba0ff25b20 Merge pull request #203 from arihant2math/statfs
Implement `sys_statfs` and `sys_fstatfs`
2026-02-15 20:05:13 +00:00
Matthew Leach
d85fe47374 Merge pull request #209 from arihant2math/update-ext4
Update ext4-view fork
2026-02-15 19:52:07 +00:00
Ashwin Naren
6aebef2168 enable clippy lints for libkernel 2026-02-13 10:24:13 -08:00
Ashwin Naren
901a2b3303 update ext4-view fork 2026-02-12 14:18:39 -08:00
Matthew Leach
141fbf8a1b Merge pull request #202 from hexagonal-sun/slab-alloc-stress-test 2026-02-10 07:21:18 +00:00
Ashwin Naren
f1c0cba3b8 statfs 2026-02-09 16:59:15 -08:00
Ashwin Naren
2855ef7a51 Merge pull request #201 from arihant2math/hostname
Store hostname and allow for updates via `sys_sethostname`
2026-02-09 16:48:10 -08:00
Ashwin Naren
8281ea798f Merge pull request #197 from arihant2math/sysfs 2026-02-09 13:59:28 -08:00
Matthew Leach
9f21618058 libkernel: memory: slab: heap: new
Add a new module which implements the high-level heap logic (implements
`GlobalAlloc`) for the slab allocator.

Also implement a multi-threaded stress test of the heap ensuring
concurrent allocation is unique (doesn't corrupt other allocs) and all
memory is free'd back to the `FrameAllocator` when all caches are
purged.
2026-02-09 07:00:13 +00: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
c07dd2140c implement hostname properly 2026-02-08 00:39:55 -08:00
Ashwin Naren
479926f767 stub cgroup fs 2026-02-07 18:25:30 -08:00
Ashwin Naren
4c69c969e2 report and edit nlinks 2026-02-07 16:37:41 -08: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
Ashwin Naren
c394e18231 tmp 2026-02-07 00:20:37 -08:00
Matthew Leach
8a84ba0fb9 libkernel: arm64: pg_tables; pg_tear_down: new
Add a new module which walks the page table hierarchy for a given
address space and applies a freeing closure to every allocated frame.
2026-01-30 19:39:59 -08:00
Matthew Leach
c49396ed35 libkernel: arm64: pg_tables: get_idx: new
Add a function which returns a descriptor from a page table by it's
numerical index.
2026-01-30 19:39:59 -08:00
Ashwin Naren
253a907c62 fix tests 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
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
2d34ebcef9 procfs refactor 2026-01-25 10:50:02 -08:00
Ashwin Naren
aa5a9c7b79 fix typos 2026-01-23 01:26:04 -08:00
Ashwin Naren
8df12a027c implement truncation 2026-01-18 01:17:19 -08:00
Matthew Leach
3ba7f668d6 libkernel: error: add Interrupted
Add the `Interrupted` discriminant for the `KernelError` enum. Also map
it to Linux's `EINTR` error value.
2026-01-17 10:21:17 +00:00
Matthew Leach
4bb3158812 Merge pull request #153 from arihant2math/prctl-updates
Implement more of prctl
2026-01-15 12:24:27 +00:00
Matthew Leach
2b55e1d972 sycalls: name_to_handle_at: stub
Return EOPNOTSUPP for `sys_name_to_handle_at`.
2026-01-14 14:24:35 -08:00
Ashwin Naren
3e60a57d67 implement xattr syscalls 2026-01-14 10:51:48 -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
ff13b392f1 some support for ext4 writing 2026-01-13 16:47:51 -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
Ashwin Naren
15c70a1aea ext4 timestamps 2026-01-10 10:11:52 -08:00
Matthew Leach
bb8b3fec29 libkernel: ext4: add inode id to metadata
Add the proper inode and fs id to the `FileAttr` struct returned by
`getattr`. This prevents the dynamic loader from skipping files which it
considers to be hard-links (share the same inode ID).
2026-01-06 08:52:52 -08:00
Ashwin Naren
f0771dde4f exec with interpreter 2026-01-06 08:52:52 -08:00
Matthew Leach
957e3f04cf libkernel: waker_set: allow data to be associted
Allow data to be associated with a waker set. This allows discriminating
upon which wakes should be woken up via the new `wake_if` function.
2026-01-03 14:36:06 -08:00
Matthew Leach
d8bcc015de arch: arm64: detect kernel stack overflow condition
Currently, when a kernel stack overflow occures, the exception handler
blindly attempts to write the current context to the stack. If the SP
isn't valid this causes another fault, and so on - locking up the
system.

This commit re-arranges the stack layout, performs SP validation before
usage and switches to an emergency stack when SP isn't valid. This
allows the handler to run and panic gracefully.

Fixes: #98
2026-01-03 14:33:51 -08:00
Ashwin Naren
477215e641 optimize lookup 2026-01-02 17:01:02 -08:00
Ashwin Naren
8677d7a404 support readlink 2026-01-02 17:01:02 -08:00
Ashwin Naren
9d8379c311 fix readdir 2026-01-02 17:01:02 -08:00
Ashwin Naren
d14d2ff355 add note about lookup being suboptimal 2026-01-02 17:01:02 -08:00