Set return code at beginning of termination function #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DOSBox also sets it before any other checks or assignments. Required for Turbo C++ 4.0J's
TCC.EXE
andTLINK.EXE
to correctly return their exit code to the host OS, and to build systems that rely on non-zero exit codes to indicate failure.Once again, the actual cause behind the bug is more complicated:
RTM.EXE
as a TSR.RTM.EXE
process. This is done by overriding the current PSP usingINT 21h, AH=50h
and resetting it to its original value before returning.RTM.EXE
also properly terminates itself viaINT 21h, AH=4C
shortly before the parent process does.msdos_process_terminate()
gets called three times:msdos_process_terminate()
always frees theprocess
entry, even in the function's TSR mode.throw(0x1f);
and not run to the bottom of the function whereretval
is set. Therefore,retval
stays at the 0 set during call 2), ignoring the actually intended exit code.process
entry won't fix this issue due to the way the PSP is continuously overridden:INT 21h, AH=50h
permanently changes the PSP of theprocess
entry.process
.msdos_int_21h_50h()
to a singlecurrent_psp = CPU_BX;
assignment, matching regular DOS. But that's two workarounds instead of one.In the long term, we probably want to remove the
process_t
structure and only emulate its fields in terms of the single SDA and multiple PSP structures. For example, MS-DOS exclusively keeps a process's maximum number of files in the PSP, not in any separate process structure. Just like thenew_process
allocation hacks,process_t
also dates back to the very first build from 2010, and looks like an equally temporary hack.