amex: Defer NVRAM file open

This will hopefully allow us to use hook DLLs from multiple
processes simultaneously (and so the cycle goes on).
This commit is contained in:
Tau 2019-10-20 22:41:59 -04:00
parent d31d13e0da
commit bd61b3e3d9
2 changed files with 36 additions and 12 deletions

View File

@ -30,6 +30,7 @@ static HRESULT eeprom_handle_write(struct irp *irp);
static HRESULT eeprom_ioctl_get_geometry(struct irp *irp); static HRESULT eeprom_ioctl_get_geometry(struct irp *irp);
static struct eeprom_config eeprom_config;
static HANDLE eeprom_file; static HANDLE eeprom_file;
HRESULT eeprom_hook_init(const struct eeprom_config *cfg) HRESULT eeprom_hook_init(const struct eeprom_config *cfg)
@ -42,11 +43,7 @@ HRESULT eeprom_hook_init(const struct eeprom_config *cfg)
return S_FALSE; return S_FALSE;
} }
hr = nvram_open_file(&eeprom_file, cfg->path, 0x2000); memcpy(&eeprom_config, cfg, sizeof(*cfg));
if (FAILED(hr)) {
return hr;
}
hr = iohook_push_handler(eeprom_handle_irp); hr = iohook_push_handler(eeprom_handle_irp);
@ -83,11 +80,25 @@ static HRESULT eeprom_handle_irp(struct irp *irp)
static HRESULT eeprom_handle_open(struct irp *irp) static HRESULT eeprom_handle_open(struct irp *irp)
{ {
HRESULT hr;
if (!wstr_eq(irp->open_filename, L"$eeprom") != 0) { if (!wstr_eq(irp->open_filename, L"$eeprom") != 0) {
return iohook_invoke_next(irp); return iohook_invoke_next(irp);
} }
if (eeprom_file != NULL) {
dprintf("EEPROM: Already open\n");
return HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION);
}
dprintf("EEPROM: Open device\n"); dprintf("EEPROM: Open device\n");
hr = nvram_open_file(&eeprom_file, eeprom_config.path, 0x2000);
if (FAILED(hr)) {
return hr;
}
irp->fd = eeprom_file; irp->fd = eeprom_file;
return S_OK; return S_OK;
@ -96,8 +107,9 @@ static HRESULT eeprom_handle_open(struct irp *irp)
static HRESULT eeprom_handle_close(struct irp *irp) static HRESULT eeprom_handle_close(struct irp *irp)
{ {
dprintf("EEPROM: Close device\n"); dprintf("EEPROM: Close device\n");
eeprom_file = NULL;
return S_OK; return iohook_invoke_next(irp);
} }
static HRESULT eeprom_handle_ioctl(struct irp *irp) static HRESULT eeprom_handle_ioctl(struct irp *irp)

View File

@ -28,6 +28,7 @@ static HRESULT sram_handle_ioctl(struct irp *irp);
static HRESULT sram_ioctl_get_geometry(struct irp *irp); static HRESULT sram_ioctl_get_geometry(struct irp *irp);
static struct sram_config sram_config;
static HANDLE sram_file; static HANDLE sram_file;
HRESULT sram_hook_init(const struct sram_config *cfg) HRESULT sram_hook_init(const struct sram_config *cfg)
@ -40,11 +41,7 @@ HRESULT sram_hook_init(const struct sram_config *cfg)
return S_FALSE; return S_FALSE;
} }
hr = nvram_open_file(&sram_file, cfg->path, 0x80000); memcpy(&sram_config, cfg, sizeof(*cfg));
if (FAILED(hr)) {
return hr;
}
hr = iohook_push_handler(sram_handle_irp); hr = iohook_push_handler(sram_handle_irp);
@ -79,11 +76,25 @@ static HRESULT sram_handle_irp(struct irp *irp)
static HRESULT sram_handle_open(struct irp *irp) static HRESULT sram_handle_open(struct irp *irp)
{ {
HRESULT hr;
if (!wstr_eq(irp->open_filename, L"$sram")) { if (!wstr_eq(irp->open_filename, L"$sram")) {
return iohook_invoke_next(irp); return iohook_invoke_next(irp);
} }
if (sram_file != NULL) {
dprintf("SRAM: Already open\n");
return HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION);
}
dprintf("SRAM: Open device\n"); dprintf("SRAM: Open device\n");
hr = nvram_open_file(&sram_file, sram_config.path, 0x80000);
if (FAILED(hr)) {
return hr;
}
irp->fd = sram_file; irp->fd = sram_file;
return S_OK; return S_OK;
@ -92,8 +103,9 @@ static HRESULT sram_handle_open(struct irp *irp)
static HRESULT sram_handle_close(struct irp *irp) static HRESULT sram_handle_close(struct irp *irp)
{ {
dprintf("SRAM: Close device\n"); dprintf("SRAM: Close device\n");
sram_file = NULL;
return S_OK; return iohook_invoke_next(irp);
} }
static HRESULT sram_handle_ioctl(struct irp *irp) static HRESULT sram_handle_ioctl(struct irp *irp)