Page MenuHomeFreeBSD

Don't clobber td->td_retval[0] in proc_reap().
ClosedPublic

Authored by ed on Jul 9 2015, 8:54 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 26, 6:03 AM
Unknown Object (File)
Fri, Apr 26, 6:03 AM
Unknown Object (File)
Dec 20 2023, 8:19 AM
Unknown Object (File)
Nov 25 2023, 4:06 PM
Unknown Object (File)
Nov 23 2023, 3:04 PM
Unknown Object (File)
Nov 16 2023, 6:25 AM
Unknown Object (File)
Nov 13 2023, 10:22 PM
Unknown Object (File)
Nov 9 2023, 1:28 PM
Subscribers

Details

Summary

While writing tests for CloudABI, I noticed that close() on process descriptors returns the process ID of the child process. This is interesting, as close() is only allowed to return 0 or -1. It turns out that we clobber td->td_retval[0] in proc_reap(), so that wait*() properly returns the process ID.

Change proc_reap() to leave td->td_retval[0] alone. Set the process ID in kern_wait6() instead, by keeping track of the PID before we (potentially) reap the process.

Test Plan

CloudABI unit tests pass. FreeBSD wait*() still seems to work; the system works fine.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

ed retitled this revision from to Don't clobber td->td_retval[0] in proc_reap()..
ed updated this object.
ed edited the test plan for this revision. (Show Details)
ed added reviewers: rwatson, kib, jilles.
ed set the repository for this revision to rS FreeBSD src repository - subversion.

Overall it is fine, just consider my minor note above.

sys/kern/kern_exit.c
842 ↗(On Diff #6807)

This is fine.

1193 ↗(On Diff #6807)

But I do not like this part of the change. IMO the explicit placement of the assignment for each return branch would make both your goal and code cleaner, rather then finding yet another 'common' place.

From what I see, this means that the line commented should move to the block with 'return 0' right below the proc_to_reap() call. Everything else is already handled by the method I see as cleaner.

ed updated this object.
ed edited edge metadata.
sys/kern/kern_exit.c
1193 ↗(On Diff #6812)

Yes, I can see what you're hinting at. Makes sense!

We do need to keep track of the PID now, as proc_reap() might destroy the process structure. Let's keep track of the PID in a new variable pid and set it right before we return (0);. Does this look all right?

kib edited edge metadata.
This revision is now accepted and ready to land.Jul 9 2015, 11:41 AM
This revision was automatically updated to reflect the committed changes.