menios icon indicating copy to clipboard operation
menios copied to clipboard

Implement advanced signal features (SIGCHLD, SA_RESTART, vDSO, RT signals)

Open pbalduino opened this issue 4 months ago • 0 comments

Description

This is Part 5 of 5 for implementing UNIX signals (see #103). This issue covers advanced signal features for complete POSIX compatibility.

Scope

Implement advanced signal functionality:

  • SIGCHLD for waitpid notification
  • SA_RESTART flag for interrupted syscalls
  • Stack-based signal trampoline (vDSO)
  • Signal masks per thread (for multithreaded processes)
  • Real-time signals (SIGRTMIN-SIGRTMAX)

Implementation Notes

SIGCHLD Support:

  • Sent to parent when child exits or stops
  • Parent can register handler to reap zombies asynchronously
  • waitpid() can be called from handler
  • Avoids polling for child status

SA_RESTART:

  • Restarts interrupted syscalls automatically
  • Syscalls like read(), write() resume after signal handler
  • Some syscalls (accept(), sleep()) never restart

Signal Trampoline in vDSO:

  • Current: trampoline code on stack (security issue)
  • Better: trampoline in vDSO (virtual dynamic shared object)
  • Maps read-only page into all processes
  • Contains sigreturn stub

Per-Thread Signal Masks:

  • Each thread has own sig_blocked mask
  • pthread_sigmask() for thread-specific blocking
  • Signals can target specific threads
  • Process-wide signals delivered to any unblocked thread

Real-Time Signals:

  • SIGRTMIN (34) to SIGRTMAX (64)
  • Queued (not merged like standard signals)
  • Delivered in order
  • Can carry payload (sigqueue())

Acceptance Criteria

  • [ ] SIGCHLD sent when child exits
  • [ ] SA_RESTART restarts interrupted syscalls
  • [ ] Signal trampoline in vDSO (more secure)
  • [ ] Per-thread signal masks work correctly
  • [ ] Real-time signals are queued and ordered
  • [ ] Comprehensive test suite for all features
  • [ ] Documentation covers all advanced features

Dependencies

Depends on:

  • #213 - Shell signal integration (Part 4)
  • #109 - pthread API (for per-thread masks)

Related Issues

  • #103 - Parent issue for full signal implementation
  • #210-#213 - Parts 1-4 of signal implementation
  • #145 - waitpid implementation (needs SIGCHLD)

Known Future Work

  • Job control signals (SIGTSTP, SIGCONT, SIGTTIN, SIGTTOU)
  • Signal safety (async-signal-safe function list)
  • signalfd() for event-driven signal handling
  • sigwaitinfo(), sigtimedwait()

Estimated effort: 3-4 weeks Priority: Medium (nice to have, not blocking)

pbalduino avatar Oct 08 '25 02:10 pbalduino