]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
userspace: major refactoring — dynamic linking, new commands, SysV init
authorTulio A M Mendes <[email protected]>
Tue, 17 Feb 2026 02:22:03 +0000 (23:22 -0300)
committerTulio A M Mendes <[email protected]>
Tue, 17 Feb 2026 02:22:03 +0000 (23:22 -0300)
commitc748899420f4b5b1b863f09402b541b1b6334432
tree693a9dea0f9718eb9b0f7f8b3b9b6c99b391aabe
parent13bd34116cddb4768cd518a55152f668cca4d5b9
userspace: major refactoring — dynamic linking, new commands, SysV init

Infrastructure:
- Rename user/init.c → user/fulltest.c, move to /sbin/fulltest
- Remove .elf extensions from all InitRD binaries
- Build ulibc as shared library (libc.so) with PIC objects
- Fix crt0.S to correctly parse argc/argv/envp from execve stack
- Fix ld.so: restore stack pointer before jumping to program entry
- Fix ld.so: add R_386_GLOB_DAT/R_386_COPY eager relocation processing
- Fix ld.so: move find_shlib_info() before relocation processing
- Create dyn_linker.ld for dynamically-linked PIE executables
- Add missing ulibc functions: waitpid, getdents, stat, fstat, chmod,
  chown, link, symlink, readlink, sigaction
- Add dirent.h header, expand sys/stat.h with permission macros
- Update Makefile: dynamic linking build rules for all user commands

Rewritten commands (now use ulibc + dynamic linking via ld.so):
- cat: proper POSIX with stdin/- support, 4KB buffer
- echo: -n, -e, -E flags, escape sequence handling
- ls: -a, -l flags, getdents-based directory listing
- mkdir: -p flag for recursive parent creation
- rm: -r, -f, -d flags

New commands (all dynamically linked):
- File management: cp, mv, touch, ln (-s for symlinks)
- Text processing: head (-n), tail (-n), wc (-l/-w/-c),
  sort (-r/-n), uniq (-c/-d), cut (-d/-f)
- Permissions: chmod (octal), chown (owner:group), chgrp
- System info: date, hostname, uptime

Shell improvements (/bin/sh):
- Variable assignment (VAR=value) and expansion ($VAR, ${VAR}, $?)
- Environment variables (export VAR=value)
- Line editing: left/right arrows, Ctrl+A/E/U, backspace
- Command history: up/down arrows, dedup
- Builtins: cd, pwd, export, unset, set, type, exit, echo
- PATH-based command resolution with colon-separated dirs
- Quote handling (single and double quotes)
- Semicolon command separation
- Append redirection (>>)

SysV init (/sbin/init):
- Parses /etc/inittab (id:runlevels:action:process format)
- Actions: sysinit, wait, once, respawn, ctrlaltdel, shutdown
- Runlevel support (0-6, S)
- Default behavior without inittab: run rcS then respawn /bin/sh
- Child reaping and respawn loop

Kernel changes:
- Default init path changed to /sbin/init (was /bin/init.elf)
- grub.cfg: add fulltest and shell entries with console=serial
- Update fulltest.c references: /bin/init.elf → /sbin/fulltest,
  /bin/echo.elf → /bin/echo, /bin/pie_test.elf → /bin/pie_test

Tests: 89/89 smoke (9s), cppcheck clean
38 files changed:
Makefile
iso/boot/grub/grub.cfg
src/kernel/cmdline.c
tests/smoke_test.exp
user/cat.c
user/chgrp.c [new file with mode: 0644]
user/chmod.c [new file with mode: 0644]
user/chown.c [new file with mode: 0644]
user/cp.c [new file with mode: 0644]
user/cut.c [new file with mode: 0644]
user/date.c [new file with mode: 0644]
user/dyn_linker.ld [new file with mode: 0644]
user/echo.c
user/fulltest.c [new file with mode: 0644]
user/head.c [new file with mode: 0644]
user/hostname.c [new file with mode: 0644]
user/init.c
user/ldso.c
user/ln.c [new file with mode: 0644]
user/ls.c
user/mkdir.c
user/mv.c [new file with mode: 0644]
user/rm.c
user/sh.c
user/sort.c [new file with mode: 0644]
user/tail.c [new file with mode: 0644]
user/touch.c [new file with mode: 0644]
user/ulibc/Makefile
user/ulibc/include/dirent.h [new file with mode: 0644]
user/ulibc/include/sys/stat.h
user/ulibc/include/unistd.h
user/ulibc/src/crt0.S
user/ulibc/src/signal.c
user/ulibc/src/stdlib.c
user/ulibc/src/unistd.c
user/uniq.c [new file with mode: 0644]
user/uptime.c [new file with mode: 0644]
user/wc.c [new file with mode: 0644]