]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
fix: allocate dedicated heap kernel stack for PID 0 (idle task)
authorTulio A M Mendes <[email protected]>
Thu, 12 Feb 2026 06:23:30 +0000 (03:23 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 02:44:55 +0000 (23:44 -0300)
commit34051167e9426fa995d936fee2bb4e8b46a7c8df
tree0af0ad09640d72c1ccb603272ef4cae0faf20fd7
parent9dadf00e8747fa97b3df43f5de6c8e12224b96bc
fix: allocate dedicated heap kernel stack for PID 0 (idle task)

PID 0 previously used the boot stack from assembly (_stack_top),
which is not heap-managed. This caused two issues:
- TSS esp0 was not updated when switching to PID 0 (kernel_stack
  was NULL, so the guard in schedule() skipped the update)
- If PID 0 were ever reaped or its stack freed, it would corrupt
  memory since the boot stack is not a kmalloc'd block

Now process_init() allocates a 4KB kernel stack via kmalloc and
sets TSS esp0 to its top, matching the pattern used by all other
processes.
src/kernel/scheduler.c