Repository navigation
User Programs
Oguzhan KAYNAK edited this page Dec 3, 2026
·
2 revisions
atlOS runs small C++17 programs from its disk in ring 3, each in an
address space of its own. A program talks to the kernel through int $0x80
system calls (the keyboard, the screen, files, time and threads); when it
faults, only the program ends.
atlOS:/> run /disk0/BIN/COUNT.ELF
1 2 3 4 5
[pid 1 COUNT.ELF exited with 15]
atlOS:/> run /disk0/BIN/THREADS.ELF
threads: counter 8
threads: thread ids 0x0000000100000003 0x0000000100000004
threads: all as expected
[pid 1 THREADS.ELF exited with 0]
A program is a process: it owns the address space, the open files and the heap. It runs in one or more threads; the scheduler sees only the threads, all of them in one pool. Process 0 is the kernel.
#include "atlos.hpp"
using namespace User;
static int64_t worker(void* arg)
{
return 2 * reinterpret_cast<int64_t>(arg); // the exit code
}
int main()
{
Threading::Thread t(worker, reinterpret_cast<void*>(21));
return t.wait(); // 42
}- The same
Threading::ThreadAPI as in the kernel; the destructor waits. - Thread ids: the pid in the upper 32 bits, the thread's number below.
- Each thread's stack is a 2 MB page with an unmapped guard page below it.
- The end of the main thread,
Process::exitProcessor a fault in any thread ends the whole program. - The shell's
pslists the processes,tasksthe threads.
-
Writing a program: user/README.md
— the environment (C++17, no libc, no floating point), memory layout,
threads, system calls, exit codes, a first program step by step,
debugging a crash with
scripts/symbolize.sh. -
How the kernel does it: kernel/proc/README.md
— ELF loading, entering ring 3 with
iretq,TSS.rsp0, processes and threads (and how Linux and Windows split them), user pointer checks, ending a program.
Programs are cooperative like everything else: a thread that never calls the kernel keeps the CPU.