~ chicken-core (chicken-5) 223283d24526cbe6ce94709abae4b18dec6be0aa
commit 223283d24526cbe6ce94709abae4b18dec6be0aa Author: Evan Hanson <evhan@foldling.org> AuthorDate: Sat Jun 11 13:05:37 2016 +1200 Commit: Peter Bex <peter@more-magic.net> CommitDate: Fri Jun 17 18:12:32 2016 +0200 Clear fd list and suspend I/O threads on process-fork w/kill-other-threads Previously, ##sys#kill-other-threads wouldn't clear the ##sys#fd-list, leading to errors when unrecognized file descriptors were encountered during scheduling. Additionally, it would set slots in random heap locations near ##sys#fd-list (potentially leading to heap corruption) since it incorrectly tried to suspend a list rather than a thread; the fd list has a different format than the timeout-list, and its `cdr` is a list of threads that must be each suspended individually. Signed-off-by: Peter Bex <peter@more-magic.net> diff --git a/scheduler.scm b/scheduler.scm index 4f9f8d8b..43f318e5 100644 --- a/scheduler.scm +++ b/scheduler.scm @@ -575,7 +575,7 @@ EOF ;;; Kill all threads in fd-, io- and timeout-lists and assign one thread as the -; new primordial one. Overrides "##sys#kill-all-threads" in library.scm. +; new primordial one. Overrides "##sys#kill-other-threads" in library.scm. (set! ##sys#kill-other-threads (let ((exit exit)) @@ -590,12 +590,9 @@ EOF (set! ready-queue-head (list primordial)) (set! ready-queue-tail ready-queue-head) (suspend primordial) ; clear block-obj. and recipients - (for-each - (lambda (a) (suspend (cdr a))) - ##sys#timeout-list) + (for-each (lambda (a) (suspend (cdr a))) ##sys#timeout-list) + (for-each (lambda (a) (for-each suspend (cdr a))) ##sys#fd-list) (set! ##sys#timeout-list '()) - (for-each - (lambda (a) (suspend (cdr a))) - ##sys#fd-list) + (set! ##sys#fd-list '()) (thunk) (exit)))))Trap