Commit Graph

268 Commits

Author SHA1 Message Date
vasilito ed76375e7e fix ArrayString type for context name logging 2026-07-11 05:03:47 +03:00
vasilito 86f4f8758e add context name to openat log and filetable change logging 2026-07-11 04:51:40 +03:00
vasilito 4a7dab0f20 kernel: fix ContextHandle::Start offset check for non-positioned writes
sys_write passes u64::MAX as offset for non-positioned file descriptors.
ContextHandle::Start used an inline 'offset != 0' check which rejected
u64::MAX, causing EINVAL when bootstrap called start_fd.write(&[0]) during
fork_inner(). Replaced with require_zero_offset() which accepts both 0 and
u64::MAX (fixed in the previous commit for the same class of bug).
2026-07-10 15:12:16 +03:00
vasilito f913167973 proc: accept u64::MAX offset in require_zero_offset for non-positioned writes
sys_write passes u64::MAX as the offset sentinel for non-positioned file
descriptors. The proc scheme's require_zero_offset rejected this value,
causing bootstrap's tcb_activate to crash with EINVAL when writing
EnvRegisters (fsbase) back to the regs/env handle.

This was the root cause of the 'Invalid opcode fault' during bootstrap
(PID 0) that prevented redbear-mini from reaching a login prompt.
2026-07-10 13:42:11 +03:00
vasilito 62a3b56840 kernel: handle HardBlocked(AwaitingMmap) in proc stop — don't panic 2026-07-09 23:54:10 +03:00
vasilito 6b69974f70 kernel: resolve /proc/self/fd/N and /proc/self/stat etc.
Extended /proc/self resolution to handle sub-paths like
/proc/self/fd/0, /proc/self/stat, /proc/self/status, etc.

Previously only /proc/self (the directory itself) was resolved.
Now /proc/self/fd, /proc/self/stat, /proc/self/maps, and all
other sub-paths are resolved by replacing 'self' with the
current PID and delegating to the standard proc_open() parser.

Cross-referenced with Linux 7.1 fs/proc/self.c proc_self_get_link()
which creates a symlink to the current PID directory. This
completes the /proc/self implementation for all sub-entries.
2026-07-09 11:16:13 +03:00
vasilito 6f7752892b kernel: implement /proc/self — symlink to current process
Added /proc/self resolution in open_inner(). When /proc/self
is opened, it resolves to /proc/<current-pid> by reading
context::current().pid and returning a ProcDir handle.

Cross-referenced with Linux 7.1 fs/proc/self.c proc_self_get_link()
which creates a symlink inode pointing to the current PID.

This enables 'ls /proc/self', 'cat /proc/self/status', and all
other tools that use /proc/self to access their own process info.
2026-07-09 10:42:37 +03:00
vasilito 85347a5678 kernel: implement /proc/filesystems — supported filesystem types
Added ProcFilesystems ContextHandle that lists supported filesystems
in Linux /proc/filesystems format. Lists sysfs, proc, devtmpfs,
and redoxfs as supported types.

Cross-referenced with Linux 7.1 fs/filesystems.c filesystems_proc_show().
'nodev' prefix indicates filesystems not requiring a block device.

Also added to ProcRoot directory listing.
2026-07-09 10:15:57 +03:00
vasilito 06fcdaf54f kernel: implement /proc/version — kernel version string
Added ProcVersion ContextHandle that outputs the kernel version
string using CARGO_PKG_VERSION, TARGET, and COOKBOOK_SOURCE_IDENT
environment variables from the build system.

Cross-referenced with Linux 7.1 fs/proc/version.c version_proc_show().
Format: 'Red Bear OS version X.Y.Z (arch) source_ident'

Also added to ProcRoot directory listing.
2026-07-09 10:12:59 +03:00
vasilito a12b823396 kernel: implement /proc/loadavg — system load average
Added ProcLoadavg ContextHandle that counts runnable contexts
using context::contexts() iterator and Status::is_runnable().
Outputs Linux /proc/loadavg format:

  0.00 0.00 0.00 nr_runnable/total 0

Cross-referenced with Linux 7.1 fs/proc/loadavg.c loadavg_proc_show().
Load averages are 0.00 (Red Bear does not track 1/5/15-min EMA).
Last PID is 0 (no PID tracking yet).

Also added to ProcRoot directory listing.
2026-07-09 10:08:32 +03:00
vasilito 2b5e1e03fd kernel: implement /proc/uptime — system uptime
Added ProcUptime ContextHandle that reads monotonic() time
from the kernel and outputs it as uptime_seconds idle_seconds
in Linux /proc/uptime format (two floats with newline).

Cross-referenced with Linux 7.1 fs/proc/uptime.c uptime_proc_show().
Idle time is 0.0 since Red Bear does not track per-CPU idle time.

Also added to ProcRoot directory listing.
2026-07-09 10:04:10 +03:00
vasilito 24a7d990d4 kernel: implement /proc/meminfo — system memory information
Added ProcMeminfo ContextHandle that reads total_frames/free_frames
from the kernel memory subsystem and outputs them in Linux
/proc/meminfo format (MemTotal, MemFree, MemAvailable, Buffers,
Cached, SwapTotal, etc. all in kB).

Cross-referenced with Linux 7.1 fs/proc/meminfo.c meminfo_proc_show().

Also added to ProcRoot directory listing alongside cpuinfo.
2026-07-09 09:57:21 +03:00
vasilito 046ad5d87b kernel: implement /proc/cpuinfo — CPU information file
Added ProcCpuinfo ContextHandle that calls the arch-specific
cpu_info() function to output processor information (model,
features, cache, topology). Appears as a regular file in
/proc/cpuinfo and is listed in the ProcRoot directory.

Cross-referenced with Linux 7.1 arch/x86/kernel/cpu/proc.c
show_cpuinfo() which formats /proc/cpuinfo from cpu_data.
2026-07-09 01:41:58 +03:00
vasilito 62a1b0beac kernel: implement /proc/[pid]/fd/ directory listing
Added ProcFdDir ContextHandle that lists open file descriptors
as symlink directory entries. Reads from posix_fdtbl and outputs
fd numbers (0, 1, 2, ...) as directory entries.

Cross-referenced with Linux 7.1 fs/proc/fd.c proc_fd_link()
and tid_fd_revalidate(). Listed fds are open (non-None) entries
from the process's POSIX file descriptor table.

Each entry appears as /proc/[pid]/fd/[n] for use by tools
like ls, lsof, and ps.
2026-07-09 01:30:07 +03:00
vasilito 2d26e7442b kernel: implement /proc/[pid]/io — process I/O statistics
Added 7 I/O accounting fields to Context (rchar, wchar, syscr, syscw,
read_bytes, write_bytes, cancelled_write_bytes) and new ProcIo
ContextHandle that outputs them in Linux key=value format:

  rchar: 0
  wchar: 0
  syscr: 0
  syscw: 0
  read_bytes: 0
  write_bytes: 0
  cancelled_write_bytes: 0

Cross-referenced with Linux 7.1 fs/proc/base.c do_task_io_accounting().
All values start at 0 and will be incremented as the syscall
interface is extended to track I/O operations.
2026-07-08 19:18:47 +03:00
vasilito 207cf8707c kernel: implement /proc/[pid]/limits — resource limits
Added rlimits: [u64; 16] to Context (initialized to RLIM_INFINITY)
and new ProcLimits ContextHandle that outputs in Linux format:

  Limit                     Soft Limit          Hard Limit          Units
  Max cpu time              unlimited            unlimited            seconds
  Max file size             unlimited            unlimited            bytes
  ...

Cross-referenced with Linux 7.1 fs/proc/array.c proc_pid_limits().
All 16 RLIMIT_* resource limits are listed with their units.
2026-07-08 18:57:12 +03:00
vasilito 0b089c7582 kernel: implement /proc/[pid]/statm — memory summary
New ProcStatm ContextHandle that reports the 7-field memory summary
matching Linux /proc/[pid]/statm format:

  size resident shared text lib data dt

All values in pages. Cross-referenced with Linux 7.1
fs/proc/array.c:proc_pid_statm().

Resident count is approximated as the total physical grants
(GRANT_PHYS), since Red Bear has no paging/swapping and all
memory is resident. Other fields (shared, lib, dt) are 0 since
Red Bear's memory model doesn't distinguish these.
2026-07-08 18:54:32 +03:00
vasilito b8b9b02051 kernel: implement /proc/[pid]/maps — process memory map
New ProcMaps ContextHandle that iterates over addr_space.grants
and formats each grant in Linux /proc/[pid]/maps format:

  address_start-address_end perms 00000000 00:00 0  path

Where perms is rwxp based on GrantFlags (GRANT_READ/WRITE/EXEC),
and path is [file]/[vdso]/[heap] based on whether the grant is
file-backed and its address range.

Cross-referenced with Linux 7.1 fs/proc/task_mmu.c proc_pid_maps_op
and show_vma_header_prefix/show_map_vma().
2026-07-08 18:51:08 +03:00
vasilito ae03a7e60b kernel: Linux-compatible /proc/[pid]/stat format
Implements proper /proc/[pid]/stat output matching Linux fs/proc/array.c format:

- utime/stime: separate user/kernel CPU time accounting in context switch
- pgrp/session/start_time: process group, session, boot-time start
- proc_rss(): Resident Set Size from page table grant walker
- num_threads: thread-group counting via owner_proc_id filter
- nice: derived from priority (prio/2 - 20)
- proc_stat_line(): proper 52-field /proc/[pid]/stat format
- proc_status_text(): VmSize/VmRSS in kB

Infrastructure:
- require_zero_offset(): EINVAL for non-zero read/write offsets
- validate_kfmap_flags(): KFMAP flag validation (MAP_SHARED/PRIVATE)
- ContextHandle::Ctx: atomic FullContextRegs save/restore
- kwriteoff: offset parameter for regs/ctx/attr/start writes
- try_stop_context: preserve HardBlocked::NotYetStarted status on restore
2026-07-08 17:47:20 +03:00
vasilito eba85456c1 kernel: expose proc process info 2026-07-08 15:04:42 +03:00
vasilito ca67b1da37 0.3.0: converge kernel onto upstream master
- Rebase all Red Bear kernel changes onto upstream master (4d5d36d4).
- Update version to 0.5.12+rb0.3.0 and add Red Bear author attribution.
- Switch redox_syscall direct dependency to local fork path (../syscall).
- Bump rust-toolchain.toml to nightly-2026-05-24.
- Regenerate Cargo.lock for +rb0.3.0 suffixes and path deps.
2026-07-06 18:43:52 +03:00
Ibuki Omatsu 6c3d5d28c6 refactor: Move fd allocation logic into userspace 2026-07-01 08:02:47 -06:00
Wildan M 002fff546d Clear cloexec flag on Dup2 2026-06-20 06:35:01 +07:00
Wildan M ed31b800c4 Revert "Use weak context for Proc" 2026-06-19 17:36:41 +07:00
4lDO2 42613ddc06 WIP: simultaneous NMI-based user+kernel profiling. 2026-06-03 19:01:35 +02:00
R Aadarsh f8bc19747a Make necessary changes to the kernel in order for relibc to support posix_spawn and posix_spawnp
* `syscall::sendfd`, now, when called with a `ContextHandle::FileTable` adds the fd to the filetable removing it from the calling process's filetable

* Files can now be added to, removed from another process, and can be duplicated using `ProcScheme::kcall`

* Files of another process with the flag O_CLOEXEC can now be closed by using `kcall`
2026-06-03 15:29:02 +05:30
4lDO2 8011f3f648 Simplify acpi scheme. 2026-06-02 16:23:08 +02:00
Wildan M ec1395b554 Wrap unmap loop with handle_notify_files 2026-05-30 08:40:49 -06:00
Ibuki Omatsu e847768f2b feat: Implement multiple fds variant for call and std_fs_call 2026-05-29 13:07:36 +02:00
Wildan M 805f921e10 Use weak context for Proc and Futex 2026-05-20 12:57:37 +07:00
Wildan M a297bfcc82 Use smallvec for memory and notify_files 2026-04-30 22:00:35 +07:00
Wildan M 1070efaec8 Solve some lock ordering 2026-04-30 21:59:19 +07:00
Wildan M 844f393ae8 Downgrade context sigcontrol to read 2026-04-29 21:48:31 +07:00
Wildan M ba28216ae8 Downgrade locks to read 2026-04-29 21:26:44 +07:00
Wildan M fd5a04a121 Use status helpers 2026-04-29 11:20:43 +07:00
Wildan M 58660a9170 Handle AddrSpace munmap 2026-04-24 17:52:05 +07:00
Akshit Gaur 976756991a Deficit Weighted Round Robin Scheduler 2026-04-17 06:52:03 -06:00
bjorn3 2f39aade30 Use mmap_anywhere in a couple of places 2026-04-10 20:23:01 +02:00
bjorn3 654ee6ca3e size_of and align_of are part of the prelude nowadays 2026-04-09 15:23:34 -06:00
Wildan M ce08b60502 Solve lock token and contexts for fdstat and debugger 2026-04-09 15:22:38 -06:00
Speedy_Lex ee1260363c Fix many clippy lints 2026-04-08 19:40:41 +01:00
bjorn3 ab4abf63c9 Deduplicate Page and other paging related things between architectures 2026-04-03 22:15:00 +02:00
bjorn3 b805336cfc Fix a bunch of warnings 2026-04-03 22:15:00 +02:00
Wildan M d835a3d8f0 Solve all borrow checker leaving some violation 2026-04-01 08:42:18 -06:00
Wildan M a42ec44dbf Partially solve borrow rules 2026-04-01 08:42:18 -06:00
Wildan M 3b5a0e4c60 Apply ordered lock to AddrSpaceWrapper without solving borrow checker 2026-04-01 08:42:18 -06:00
Akshit Gaur 004509587d Fix ForceKill 2026-04-01 13:58:27 +05:30
bjorn3 f8d93023dd Fix a couple of warnings 2026-03-28 17:07:33 +01:00
Ron Williams fde164b2a0 Revert "Deficit based Weighted Round Robin Scheduler"
This reverts commit b7dabfc3c2.
2026-03-22 18:44:41 +00:00
Akshit Gaur b7dabfc3c2 Deficit based Weighted Round Robin Scheduler 2026-03-22 07:00:31 -06:00