First Contribution
This page walks you through a small, self-contained change to the kernel: adding a new debug syscall that returns the number of free physical frames. By the end, you will have modified the kernel, the userland library, and verified the result.
What We Will Build
A new syscall SYS_DEBUG_FREE_FRAMES (number 31, the next unused slot in the Syscall enum) that returns the current count of free physical frames.
This is a read-only, side-effect-free operation — safe to add and easy to verify.
Step 1: Add the Syscall to the Kernel
1a. Add the enum variant
Open kernite/src/syscall/mod.rs and find the Syscall enum.
Add a new variant at the end:
pub enum Syscall {
// ... existing variants ...
NotifReturn = 27,
ThreadExit = 28,
SysInfo = 29,
SysMemInfo = 30,
DebugFreeFrames = 31, // ← add this
}
Step 2: Add the Userland Constant
Open lib/trona/uapi/consts/kernel.rs and add:
pub const SYS_DEBUG_FREE_FRAMES: u64 = 31;
Step 3: Add the Userland Wrapper
Open lib/trona/substrate/syscall.rs and add a wrapper function:
pub fn sys_debug_free_frames() -> u64 {
let result = syscall0(SYS_DEBUG_FREE_FRAMES);
result.value
}
syscall0 is the existing helper that invokes a syscall with no arguments.
Step 4: Build and Test
# Rebuild (kernel source file already exists, no distclean needed)
just build
# Run
just run
To test, you can add a call in the test runner or any userland program:
let free = trona::syscall::sys_debug_free_frames();
trona::println!("Free frames: {}", free);
The output should show a number like 12345 (depending on your system’s RAM and current usage).
What You Just Learned
This small exercise touched every layer of the kernel:
-
Syscall dispatch (
syscall/mod.rs) — how the kernel routes syscall numbers to handlers. -
PMM API (
mm/) — how the kernel queries internal state. -
UAPI constants (
lib/trona/uapi/) — how kernel and userland agree on syscall numbers. -
Trona substrate (
lib/trona/substrate/) — how userland invokes raw syscalls.
Next Steps: Bigger Contributions
Now that you understand the flow, here are ideas for more substantial contributions:
Add a capability invocation
Follow the Developer Guide to add a new invoke label.
For example: TCB_GET_STATE that returns the current thread state.
Add a test module
The test runner (userland/tests/test_runner/) has 16 test modules.
Add a new module that tests your new syscall or exercises an existing feature.
Fix a bug
Look at the serial output during boot. If you see warnings or unexpected behavior, investigate:
-
Read the relevant source code.
-
Add
DebugPutStrcalls to trace execution. -
Use
just run --gdbto attach a debugger.
Port a library
The Developer Guide explains how to add new userland programs.
The ports system (ports/) can build third-party software for SaltyOS.
Code Style Reminders
Before submitting:
-
just fmt-checkpasses. -
just buildsucceeds with no new warnings. -
just runboots without panics. -
just run --smp 2does not deadlock. -
Every
unsafe {}block has a// SAFETY:comment. -
New constants are defined in both kernel and
lib/trona/uapi/consts/kernel.rs. -
Commit message follows conventional commits:
feat(syscall): add DebugFreeFrames syscall.
Where to Get Help
-
Read the Architecture page for the module map.
-
Read the Glossary for unfamiliar terms.
-
Read the source code — it is well-commented with
// SAFETY:and doc comments. -
Check the Developer Guide for step-by-step procedures.
Related Pages
-
What Is a Microkernel? — if you need the conceptual foundation.
-
Syscall Walkthrough — the detailed journey of a syscall through the kernel.
-
Developer Guide — procedures for all types of kernel changes.