]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
feat: POSIX Phases 2-6 — syscalls, ulibc functions, headers, malloc, Newlib prep
authorTulio A M Mendes <[email protected]>
Sat, 14 Mar 2026 00:47:53 +0000 (21:47 -0300)
committerTulio A M Mendes <[email protected]>
Sat, 14 Mar 2026 00:47:53 +0000 (21:47 -0300)
commit9b56e33725a387882e42233bea50ca9539caf5f8
tree054b20fa854798900ea7b250664d892f3b0440f2
parenta179eafc59ea3b15b5c7f951db769f42f1c71492
feat: POSIX Phases 2-6 — syscalls, ulibc functions, headers, malloc, Newlib prep

Phase 2 — Critical Kernel Syscalls:
- SYSCALL_GETRLIMIT (129) / SYSCALL_SETRLIMIT (130): per-process resource
  limits (RLIMIT_NOFILE, RLIMIT_STACK, RLIMIT_CORE, etc.) stored in process
  struct, inherited on fork, enforced by setrlimit with root privilege check
- SYSCALL_SETSOCKOPT (131) / SYSCALL_GETSOCKOPT (132): SO_REUSEADDR,
  SO_KEEPALIVE, SO_RCVBUF/SNDBUF, SO_ERROR, SO_TYPE via lwIP
- SYSCALL_SHUTDOWN (133): TCP half-close via tcp_shutdown
- SYSCALL_GETPEERNAME (134) / SYSCALL_GETSOCKNAME (135): socket address query
- Added missing errno codes: ENOPROTOOPT, EOVERFLOW, ELOOP

Phase 3 — Critical ulibc Functions (12 new source files):
- setjmp/longjmp/_setjmp/_longjmp/sigsetjmp/siglongjmp (i386 assembly)
- sleep()/usleep() wrappers over nanosleep
- execvp()/execlp()/execl() with PATH search
- getopt()/getopt_long() full POSIX implementation
- strerror()/perror() with 35-entry error string table
- strtoul()/strtoll()/strtoull() with base auto-detection
- setenv()/unsetenv()/putenv() with owned environ array
- signal() wrapper over sigaction (SA_RESTART)
- abort() sends SIGABRT, atexit() with 32-handler registry
- exit() now calls atexit handlers in reverse order
- rand()/srand() LCG PRNG (RAND_MAX=0x7FFF)
- strtok_r(), strnlen(), strspn(), strcspn(), strpbrk()

Phase 4 — Critical Headers (9 new headers):
- setjmp.h: jmp_buf, sigjmp_buf for i386
- locale.h: LC_* constants, struct lconv, setlocale/localeconv stubs
- pwd.h/grp.h: struct passwd/group, getpwnam/getpwuid/getpwent stubs
- getopt.h: struct option, getopt_long declarations
- fnmatch.h + fnmatch(): glob-style pattern matching with FNM_PATHNAME
- sys/select.h: fd_set, FD_SET/CLR/ISSET/ZERO macros, select()
- sys/resource.h: struct rlimit, RLIMIT_* constants, getrlimit/setrlimit

Phase 5 — Proper malloc with free():
- Replaced bump allocator with address-ordered free-list allocator
- 8-byte aligned blocks with 8-byte header (size | used_bit, next_free)
- First-fit allocation with block splitting
- free() with address-ordered insertion and bidirectional coalescing
- realloc() now preserves old data size from block header

Phase 6 — Newlib Port (from previous commit):
- libgloss stubs already complete, syscall numbers updated

97/97 smoke tests pass, cppcheck clean.
37 files changed:
include/errno.h
include/process.h
include/socket.h
include/syscall.h
src/arch/x86/arch_platform.c
src/kernel/scheduler.c
src/kernel/socket.c
src/kernel/syscall.c
user/ulibc/include/fnmatch.h [new file with mode: 0644]
user/ulibc/include/getopt.h [new file with mode: 0644]
user/ulibc/include/grp.h [new file with mode: 0644]
user/ulibc/include/locale.h [new file with mode: 0644]
user/ulibc/include/pwd.h [new file with mode: 0644]
user/ulibc/include/setjmp.h [new file with mode: 0644]
user/ulibc/include/stdio.h
user/ulibc/include/stdlib.h
user/ulibc/include/string.h
user/ulibc/include/sys/resource.h [new file with mode: 0644]
user/ulibc/include/sys/select.h [new file with mode: 0644]
user/ulibc/include/syscall.h
user/ulibc/include/unistd.h
user/ulibc/src/abort_atexit.c [new file with mode: 0644]
user/ulibc/src/environ.c [new file with mode: 0644]
user/ulibc/src/execvp.c [new file with mode: 0644]
user/ulibc/src/fnmatch.c [new file with mode: 0644]
user/ulibc/src/getopt.c [new file with mode: 0644]
user/ulibc/src/locale.c [new file with mode: 0644]
user/ulibc/src/pwd_grp.c [new file with mode: 0644]
user/ulibc/src/rand.c [new file with mode: 0644]
user/ulibc/src/resource.c [new file with mode: 0644]
user/ulibc/src/setjmp.S [new file with mode: 0644]
user/ulibc/src/signal_wrap.c [new file with mode: 0644]
user/ulibc/src/sleep.c [new file with mode: 0644]
user/ulibc/src/stdlib.c
user/ulibc/src/strerror.c [new file with mode: 0644]
user/ulibc/src/string.c
user/ulibc/src/strtoul.c [new file with mode: 0644]