(v7.x backport) src: make AtExit callback's per Environment
This pull request contains two commits as the latter depends on the former. I can make these separate if needed.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes - [z] commit message follows commit guidelines
Affected core subsystem(s)
src