Hello @Rodrigo Lozano Marroquin and thank you for reaching out.
Regrettably, I could not find a Microsoft-documented guarantee for what you require. The documentation describes the individual APIs, but not the combined sequence or the guarantee that no normal target user-mode code can run.
That said, I would still like to share what the API documentation establishes and what I observed in testing.
1. Is
TerminateProcesssupported while the initial event remains pending, and can termination complete without callingContinueDebugEventon that event?
I confirmed that termination can complete while the initial CREATE_PROCESS_DEBUG_EVENT remains pending, without calling ContinueDebugEvent.
I created the target with DEBUG_ONLY_THIS_PROCESS, left the initial creation event pending, and called TerminateProcess(..., 123). The retained process handle became signaled, and GetExitCodeProcess returned 123.
This also shows the distinction you raised: a successful call to TerminateProcess means that termination was requested. The process handle becoming signaled shows that termination completed.
2. If continuation is necessary for teardown, what supported ordering prevents target execution? Can that requirement include target loader execution, DLL initialization, TLS callbacks and application instructions? I am not assuming that pending-event status alone establishes all these exclusions.
Continuing the initial event was not needed for termination to complete in the first test.
I also tested calling TerminateProcess(..., 123) while the creation event was pending and then continuing that event. I later received and continued LOAD_DLL_DEBUG_EVENT and EXIT_PROCESS_DEBUG_EVENT. The exit event reported 123, and the retained process handle then became signaled with the same exit code.
To check whether target initialization code ran, I used a target with a TLS callback, an imported DLL with DllMain(DLL_PROCESS_ATTACH), and main. Each created a separate marker file. None of the files was created.
This is consistent with those routines not running. However, it does not prove that no target user-mode instruction ran at all. Receiving LOAD_DLL_DEBUG_EVENT also does not prove that the DLL’s DllMain ran.
Regarding your clarified concern: I could not find an explicit Microsoft guarantee that, after TerminateProcess succeeds but before termination is confirmed, continuing the initial event cannot allow any normal target user-mode code to run.
The individual API contracts suggest calling TerminateProcess before continuing the event, and my test showed no sign that the TLS callback, DllMain, or main ran. However, the documentation does not guarantee that this sequence blocks all loader activity, DLL initialization, TLS callbacks, application code, or other normal target user-mode execution.
3. Which events must be received/continued, including
EXIT_PROCESS_DEBUG_EVENT, and when does a retained process handle becoming signaled establish completed shutdown?
Which events must be handled depends on whether the initial event is continued.
When I left CREATE_PROCESS_DEBUG_EVENT pending, termination completed without further event processing. When I continued it, I received and continued LOAD_DLL_DEBUG_EVENT and EXIT_PROCESS_DEBUG_EVENT.
If EXIT_PROCESS_DEBUG_EVENT is received, it must be continued before the kernel-mode part of process shutdown can complete. After that, WAIT_OBJECT_0 on the retained process handle confirms completed shutdown. A successful call to TerminateProcess only confirms that termination was requested, and receiving the exit event does not by itself confirm final completion.
I could not find a supported recovery method that both forces progress if termination or debugging stalls and preserves the requested guarantee against target execution. I also found no guaranteed completion time or stronger Windows-version or architecture-specific guarantee.
Regarding the overall scope of this answer: A definitive support statement for this API combination is not something I can independently provide through this forum. My response is limited to the public documentation and the behavior I could test. If your design requires an authoritative clarification of the API contract, I recommend opening a case with Microsoft Support for Business, where the appropriate product team can review the question. If you do not have a business support plan, you can contact Microsoft Support instead.
If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation. Thank you.