When waiting on the current process, we would return WAIT_FAILED, as waitpid would return -1, with errno set to ECHILD.
But the semantic of WaitForSingleObjectEx and WaitForMultipleObjectsEx when waiting on current process is to return WAIT_TIMEOUT. This is then a special case that we need to add to this code.
if (!mp) {
pid_t res;
+ if (pid == mono_process_current_pid ()) {
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s (%p, %u): waiting on current process", __func__, handle, timeout);
+ return WAIT_TIMEOUT;
+ }
+
/* This path is used when calling Process.HasExited, so
* it is only used to poll the state of the process, not
* to actually wait on it to exit */