Fix hook startup failure path

Returning from the EXE PE entry point merely terminates the main
thread and leaves the process hanging. We need to explicitly exit
from the process since the NTDLL RTL Start code won't do it for us.
This commit is contained in:
Tau 2021-05-23 14:17:14 -04:00
parent 5410941944
commit 49595d2c37
5 changed files with 52 additions and 21 deletions

View File

@ -1,6 +1,5 @@
#include <windows.h> #include <windows.h>
#include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include "amex/amex.h" #include "amex/amex.h"
@ -73,25 +72,25 @@ static DWORD CALLBACK chuni_pre_startup(void)
chuni_hook_mod); chuni_hook_mod);
if (FAILED(hr)) { if (FAILED(hr)) {
return EXIT_FAILURE; goto fail;
} }
hr = amex_hook_init(&chuni_hook_cfg.amex, chunithm_jvs_init); hr = amex_hook_init(&chuni_hook_cfg.amex, chunithm_jvs_init);
if (FAILED(hr)) { if (FAILED(hr)) {
return EXIT_FAILURE; goto fail;
} }
hr = slider_hook_init(&chuni_hook_cfg.slider); hr = slider_hook_init(&chuni_hook_cfg.slider);
if (FAILED(hr)) { if (FAILED(hr)) {
return EXIT_FAILURE; goto fail;
} }
hr = sg_reader_hook_init(&chuni_hook_cfg.aime, 12); hr = sg_reader_hook_init(&chuni_hook_cfg.aime, 12);
if (FAILED(hr)) { if (FAILED(hr)) {
return EXIT_FAILURE; goto fail;
} }
/* Initialize debug helpers */ /* Initialize debug helpers */
@ -103,6 +102,9 @@ static DWORD CALLBACK chuni_pre_startup(void)
/* Jump to EXE start address */ /* Jump to EXE start address */
return chuni_startup(); return chuni_startup();
fail:
ExitProcess(EXIT_FAILURE);
} }
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx) BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)

View File

@ -1,6 +1,5 @@
#include <windows.h> #include <windows.h>
#include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include "amex/amex.h" #include "amex/amex.h"
@ -48,25 +47,25 @@ static DWORD CALLBACK diva_pre_startup(void)
diva_hook_mod); diva_hook_mod);
if (FAILED(hr)) { if (FAILED(hr)) {
return EXIT_FAILURE; goto fail;
} }
hr = amex_hook_init(&diva_hook_cfg.amex, diva_jvs_init); hr = amex_hook_init(&diva_hook_cfg.amex, diva_jvs_init);
if (FAILED(hr)) { if (FAILED(hr)) {
return EXIT_FAILURE; goto fail;
} }
hr = sg_reader_hook_init(&diva_hook_cfg.aime, 10); hr = sg_reader_hook_init(&diva_hook_cfg.aime, 10);
if (FAILED(hr)) { if (FAILED(hr)) {
return EXIT_FAILURE; goto fail;
} }
hr = slider_hook_init(&diva_hook_cfg.slider); hr = slider_hook_init(&diva_hook_cfg.slider);
if (FAILED(hr)) { if (FAILED(hr)) {
return EXIT_FAILURE; goto fail;
} }
/* Initialize debug helpers */ /* Initialize debug helpers */
@ -78,6 +77,9 @@ static DWORD CALLBACK diva_pre_startup(void)
/* Jump to EXE start address */ /* Jump to EXE start address */
return diva_startup(); return diva_startup();
fail:
ExitProcess(EXIT_FAILURE);
} }
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx) BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)

View File

@ -1,6 +1,5 @@
#include <windows.h> #include <windows.h>
#include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include "amex/amex.h" #include "amex/amex.h"
@ -49,19 +48,19 @@ static DWORD CALLBACK idz_pre_startup(void)
idz_hook_mod); idz_hook_mod);
if (FAILED(hr)) { if (FAILED(hr)) {
return hr; goto fail;
} }
hr = amex_hook_init(&idz_hook_cfg.amex, idz_jvs_init); hr = amex_hook_init(&idz_hook_cfg.amex, idz_jvs_init);
if (FAILED(hr)) { if (FAILED(hr)) {
return hr; goto fail;
} }
hr = sg_reader_hook_init(&idz_hook_cfg.aime, 10); hr = sg_reader_hook_init(&idz_hook_cfg.aime, 10);
if (FAILED(hr)) { if (FAILED(hr)) {
return hr; goto fail;
} }
/* Initialize debug helpers */ /* Initialize debug helpers */
@ -73,6 +72,9 @@ static DWORD CALLBACK idz_pre_startup(void)
/* Jump to EXE start address */ /* Jump to EXE start address */
return idz_startup(); return idz_startup();
fail:
ExitProcess(EXIT_FAILURE);
} }
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx) BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)

View File

@ -1,5 +1,7 @@
#include <windows.h> #include <windows.h>
#include <stdlib.h>
#include "amex/config.h" #include "amex/config.h"
#include "amex/ds.h" #include "amex/ds.h"
@ -20,6 +22,7 @@ static DWORD CALLBACK app_pre_startup(void)
struct clock_config clock_cfg; struct clock_config clock_cfg;
struct ds_config ds_cfg; struct ds_config ds_cfg;
struct nusec_config nusec_cfg; struct nusec_config nusec_cfg;
HRESULT hr;
dprintf("--- Begin %s ---\n", __func__); dprintf("--- Begin %s ---\n", __func__);
@ -28,13 +31,30 @@ static DWORD CALLBACK app_pre_startup(void)
nusec_config_load(&nusec_cfg, L".\\segatools.ini"); nusec_config_load(&nusec_cfg, L".\\segatools.ini");
spike_hook_init(L".\\segatools.ini"); spike_hook_init(L".\\segatools.ini");
clock_hook_init(&clock_cfg); hr = clock_hook_init(&clock_cfg);
nusec_hook_init(&nusec_cfg, "SSSS", "AAV0");
ds_hook_init(&ds_cfg); if (FAILED(hr)) {
goto fail;
}
hr = nusec_hook_init(&nusec_cfg, "SSSS", "AAV0");
if (FAILED(hr)) {
goto fail;
}
hr = ds_hook_init(&ds_cfg);
if (FAILED(hr)) {
goto fail;
}
dprintf("--- End %s ---\n", __func__); dprintf("--- End %s ---\n", __func__);
return app_startup(); return app_startup();
fail:
ExitProcess(EXIT_FAILURE);
} }
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx) BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)

View File

@ -1,5 +1,7 @@
#include <windows.h> #include <windows.h>
#include <stdlib.h>
#include "board/io4.h" #include "board/io4.h"
#include "board/sg-reader.h" #include "board/sg-reader.h"
#include "board/vfd.h" #include "board/vfd.h"
@ -45,25 +47,25 @@ static DWORD CALLBACK mu3_pre_startup(void)
mu3_hook_mod); mu3_hook_mod);
if (FAILED(hr)) { if (FAILED(hr)) {
return hr; goto fail;
} }
hr = sg_reader_hook_init(&mu3_hook_cfg.aime, 1); hr = sg_reader_hook_init(&mu3_hook_cfg.aime, 1);
if (FAILED(hr)) { if (FAILED(hr)) {
return hr; goto fail;
} }
hr = vfd_hook_init(2); hr = vfd_hook_init(2);
if (FAILED(hr)) { if (FAILED(hr)) {
return hr; goto fail;
} }
hr = mu3_io4_hook_init(); hr = mu3_io4_hook_init();
if (FAILED(hr)) { if (FAILED(hr)) {
return hr; goto fail;
} }
/* Initialize Unity native plugin DLL hooks /* Initialize Unity native plugin DLL hooks
@ -82,6 +84,9 @@ static DWORD CALLBACK mu3_pre_startup(void)
/* Jump to EXE start address */ /* Jump to EXE start address */
return mu3_startup(); return mu3_startup();
fail:
ExitProcess(EXIT_FAILURE);
} }
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx) BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)