mirror of
https://github.com/skeeto/w64devkit.git
synced 2025-06-30 14:41:50 +03:00
Replace CRT-free return with ExitProcess (#82)
ConEmu injects a thread (ConEmuCD.dll) and injects a DLL that starts threads (ConEmuHk.dll). These threads may linger after the main thread has returned, delaying the process exit and even interfering with the exit status. As a work around, call ExitProcess instead of returning from the main thread. This terminates extra threads so that the process will no longer wait for their voluntarily exit.
This commit is contained in:
18
src/alias.c
18
src/alias.c
@ -39,6 +39,8 @@ typedef struct {
|
||||
int CreateProcessW(
|
||||
void *, void *, void *, void *, int, int, void *, void *, void *, void *
|
||||
) __attribute((dllimport,stdcall));
|
||||
void ExitProcess(int)
|
||||
__attribute((dllimport,stdcall));
|
||||
char16_t *GetCommandLineW(void)
|
||||
__attribute((dllimport,stdcall));
|
||||
int GetExitCodeProcess(void *, int *)
|
||||
@ -128,11 +130,7 @@ static void fail(char *reason, int len)
|
||||
WriteFile(out, reason, len, &dummy, 0);
|
||||
}
|
||||
|
||||
#if __i386
|
||||
__attribute((force_align_arg_pointer))
|
||||
#endif
|
||||
__attribute((externally_visible))
|
||||
int mainCRTStartup(void)
|
||||
static int aliasmain(void)
|
||||
{
|
||||
// Replace alias module with adjacent target
|
||||
char16_t exebuf[MAX_PATH];
|
||||
@ -179,3 +177,13 @@ int mainCRTStartup(void)
|
||||
GetExitCodeProcess(pi.process, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if __i386
|
||||
__attribute((force_align_arg_pointer))
|
||||
#endif
|
||||
__attribute((externally_visible))
|
||||
int mainCRTStartup(void)
|
||||
{
|
||||
int r = aliasmain();
|
||||
ExitProcess(r);
|
||||
}
|
||||
|
@ -73,5 +73,6 @@ mainCRTStartup(void)
|
||||
CloseHandle(h);
|
||||
}
|
||||
}
|
||||
return GetLastError() != ERROR_NO_MORE_FILES;
|
||||
int status = GetLastError() != ERROR_NO_MORE_FILES;
|
||||
ExitProcess(status);
|
||||
}
|
||||
|
@ -152,5 +152,5 @@ mainCRTStartup(void)
|
||||
DWORD ret;
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
GetExitCodeProcess(pi.hProcess, &ret);
|
||||
return ret;
|
||||
ExitProcess(ret);
|
||||
}
|
||||
|
Reference in New Issue
Block a user