universalisos/docs/T10_POSIX_TASK_MANAGEMENT.md

241 lines
5.3 KiB
Markdown

# T10: POSIX Task Management
**Track:** T10
**Status:** IN PROGRESS
**Date:** 2026-07-12
**Source:** UniversalisOS 12-Month Roadmap, Month 10
---
## Overview
T10 focuses on providing robust POSIX-like process semantics for UniversalisOS. This includes implementing task_fork, task_waitpid, halt partition logic, and proper POSIX subsystem initialization.
---
## Objectives
1. **Implement task_fork** — Create child tasks with proper memory isolation
2. **Implement task_waitpid** — Wait for child task completion
3. **Implement halt partition logic** — Graceful partition shutdown
4. **Initialize POSIX subsystems** — Proper posix_config.c initialization
5. **Address POSIX ABI memory management** — Complete mm.h declarations
---
## Tasks
### T10-1: task_fork Implementation
**Status:** PENDING
Implement POSIX fork() semantics for UniversalisOS tasks:
```c
/* Fork a new task */
pid_t task_fork(void);
/* Child task gets copy of parent's address space */
/* Parent task continues execution */
/* Both tasks return from fork() with different values */
```
**Key Features:**
- Copy-on-write (COW) memory semantics
- Independent address spaces
- Shared file descriptors
- Signal handling inheritance
**TODO:**
- [ ] Implement COW page tables
- [ ] Implement task state copying
- [ ] Implement return value handling
- [ ] Add fork() to POSIX ABI
---
### T10-2: task_waitpid Implementation
**Status:** PENDING
Implement POSIX waitpid() semantics:
```c
/* Wait for child task to change state */
pid_t task_waitpid(pid_t pid, int* status, int options);
/* Options: WNOHANG, WUNTRACED, WCONTINUED */
/* Status: exit code, signal, stop/continue */
```
**Key Features:**
- Wait for specific child or any child
- Non-blocking option (WNOHANG)
- Status reporting (exit, signal, stop)
- Zombie task cleanup
**TODO:**
- [ ] Implement task state tracking
- [ ] Implement wait queue
- [ ] Implement status reporting
- [ ] Add waitpid() to POSIX ABI
---
### T10-3: Halt Partition Logic
**Status:** PENDING
Implement graceful partition shutdown:
```c
/* Halt a partition */
int partition_halt(uint32_t partition_id);
/* Steps: */
/* 1. Stop all tasks in partition */
/* 2. Free all resources */
/* 3. Clean up memory */
/* 4. Notify hypervisor */
```
**Key Features:**
- Graceful task termination
- Resource cleanup
- Memory deallocation
- Hypervisor notification
**TODO:**
- [ ] Implement task termination
- [ ] Implement resource cleanup
- [ ] Implement memory deallocation
- [ ] Add halt to partition API
---
### T10-4: POSIX Subsystem Initialization
**Status:** PENDING
Initialize POSIX subsystems properly:
```c
/* Initialize POSIX subsystems */
int posix_subsystem_init(void);
/* Subsystems: */
/* - File descriptors */
/* - Signals */
/* - Timers */
/* - Message queues */
/* - Shared memory */
```
**Key Features:**
- File descriptor table
- Signal handlers
- Timer management
- IPC initialization
**TODO:**
- [ ] Implement fd table initialization
- [ ] Implement signal handler setup
- [ ] Implement timer initialization
- [ ] Implement IPC initialization
---
### T10-5: POSIX ABI Memory Management
**Status:** PENDING
Complete POSIX ABI memory management declarations:
```c
/* Already declared in mm.h (T8-2.1): */
/* - mm_mmap_guard */
/* - mm_mmap_aligned */
/* - mm_mremap_ex */
/* - mm_quarantine */
/* - mm_set_map_count */
/* - mm_set_accountable_limit */
/* Additional declarations needed: */
/* - mm_brk */
/* - mm_sbrk */
/* - mm_mlock */
/* - mm_munlock */
/* - mm_mlockall */
/* - mm_munlockall */
```
**TODO:**
- [ ] Add mm_brk declaration
- [ ] Add mm_sbrk declaration
- [ ] Add mm_mlock declarations
- [ ] Implement memory locking
---
## Implementation Files
| File | Purpose |
|------|---------|
| `kernel/src/core/abi/uos_posix_abi.cpp` | POSIX ABI implementation |
| `kernel/src/core/abi/uos_posix_abi.h` | POSIX ABI header |
| `kernel/src/core/task.h` | Task management |
| `kernel/src/core/task.cpp` | Task implementation |
| `kernel/src/core/mm.h` | Memory management |
| `kernel/src/core/mm.cpp` | Memory implementation |
---
## Verification
- [ ] task_fork works correctly
- [ ] task_waitpid works correctly
- [ ] Halt partition works correctly
- [ ] POSIX subsystems initialize correctly
- [ ] Memory management declarations complete
---
## TODO Summary
### T10-1: task_fork
- [ ] Implement COW page tables
- [ ] Implement task state copying
- [ ] Implement return value handling
- [ ] Add fork() to POSIX ABI
### T10-2: task_waitpid
- [ ] Implement task state tracking
- [ ] Implement wait queue
- [ ] Implement status reporting
- [ ] Add waitpid() to POSIX ABI
### T10-3: Halt Partition
- [ ] Implement task termination
- [ ] Implement resource cleanup
- [ ] Implement memory deallocation
- [ ] Add halt to partition API
### T10-4: POSIX Subsystem Init
- [ ] Implement fd table initialization
- [ ] Implement signal handler setup
- [ ] Implement timer initialization
- [ ] Implement IPC initialization
### T10-5: POSIX ABI MM
- [ ] Add mm_brk declaration
- [ ] Add mm_sbrk declaration
- [ ] Add mm_mlock declarations
- [ ] Implement memory locking
---
## References
- `universalisos/docs/UniversalisOS_Stubs_Resolution_Roadmap_12Months.md` — 12-month roadmap
- `universalisos/kernel/src/core/abi/uos_posix_abi.cpp` — POSIX ABI implementation
- `universalisos/kernel/src/core/mm.h` — Memory management declarations