]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
feat: enable lwIP NO_SYS=0 threaded mode with kernel sync primitives
authorTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 03:52:10 +0000 (00:52 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 03:52:10 +0000 (00:52 -0300)
commit083bebf0946f2601506d4efd92f19710ce8144c5
tree6352bdb35a3f896fc896f92a33d71d27adbf0788
parentf4d54a1f3da861ef0da24c20ae91d755eb5e3366
feat: enable lwIP NO_SYS=0 threaded mode with kernel sync primitives

Kernel synchronization primitives (include/sync.h + src/kernel/sync.c):
- ksem_t: counting semaphore with sleep/wake blocking (not spin-wait)
  - ksem_init, ksem_wait, ksem_wait_timeout, ksem_signal
  - Timeout support via process wake_at_tick mechanism
  - Race-safe: ksem_signal skips already-woken (timed-out) waiters
- kmutex_t: binary semaphore wrapper for mutual exclusion
- kmbox_t: fixed-size circular queue with not_empty/not_full semaphores
  - kmbox_init, kmbox_free, kmbox_post, kmbox_trypost
  - kmbox_fetch (with timeout), kmbox_tryfetch

lwIP sys_arch layer (include/net/arch/sys_arch.h + sys_arch.c):
- sys_sem_t, sys_mutex_t, sys_mbox_t backed by kernel primitives
- sys_thread_new: creates kernel threads via process_create_kernel
  with static trampoline array (up to 4 lwIP threads)
- sys_arch_protect/unprotect: IRQ save/restore for SYS_LIGHTWEIGHT_PROT
- sys_init, sys_now (50Hz tick to ms conversion)

lwIP configuration (lwipopts.h):
- NO_SYS=0, LWIP_NETCONN=1, SYS_LIGHTWEIGHT_PROT=1
- LWIP_SOCKET=0 (kernel uses netconn API; avoids POSIX type conflicts)
- Thread/mbox sizing: TCPIP_MBOX_SIZE=16, recvmbox sizes=8

Build system (Makefile):
- Added lwIP api/ sources: api_lib, api_msg, err, if_api, netbuf,
  netifapi, tcpip

Network init (e1000_netif.c):
- tcpip_init(callback, NULL) with volatile flag polling for sync
- netif input changed from ethernet_input to tcpip_input
- net_poll no longer calls sys_check_timeouts (handled by tcpip_thread)

Kernel stack enlargement (scheduler.c):
- Increased from 4KB (1 page) to 8KB (2 pages) per thread
- Required for deeper call chains in lwIP threaded mode
- Updated kstack_alloc, kstack_free, and all stack+offset references

LAPIC VA relocation (lapic.c):
- Moved from 0xC0200000 to 0xC0400000 to avoid collision with
  enlarged kernel BSS (~764KB with NO_SYS=0 memp pools)

lwIP third-party patch (patches/lwip-tcpip-volatile.patch):
- tcpip_init_done and tcpip_init_done_arg marked volatile in tcpip.c
- Fixes cross-thread visibility: compiler was caching NULL from BSS
  init, preventing tcpip_thread from seeing the callback set by
  tcpip_init in the init thread

All 19/19 smoke tests pass, cppcheck clean.
Makefile
include/net/arch/sys_arch.h [new file with mode: 0644]
include/net/lwipopts.h
include/sync.h [new file with mode: 0644]
patches/lwip-tcpip-volatile.patch [new file with mode: 0644]
src/arch/x86/lapic.c
src/kernel/scheduler.c
src/kernel/sync.c [new file with mode: 0644]
src/net/e1000_netif.c
src/net/lwip_port/sys_arch.c