Improve JVS bus life cycle handling

This commit is contained in:
Tau
2019-11-03 13:01:03 -05:00
parent 93fcdf8f6d
commit 0e1cfb66db
24 changed files with 164 additions and 65 deletions

View File

@ -9,7 +9,7 @@
#include <assert.h>
HRESULT amex_hook_init(const struct amex_config *cfg)
HRESULT amex_hook_init(const struct amex_config *cfg, jvs_provider_t jvs)
{
HRESULT hr;
@ -33,7 +33,7 @@ HRESULT amex_hook_init(const struct amex_config *cfg)
return hr;
}
hr = jvs_hook_init(&cfg->jvs);
hr = jvs_hook_init(&cfg->jvs, jvs);
if (FAILED(hr)) {
return hr;

View File

@ -3,5 +3,8 @@
#include <windows.h>
#include "amex/config.h"
#include "amex/jvs.h"
HRESULT amex_hook_init(const struct amex_config *cfg);
HRESULT amex_hook_init(
const struct amex_config *cfg,
jvs_provider_t jvs);

View File

@ -39,8 +39,9 @@ static HRESULT jvs_ioctl_transact(struct irp *irp);
static HANDLE jvs_fd;
static struct jvs_node *jvs_root;
static jvs_provider_t jvs_provider;
HRESULT jvs_hook_init(const struct jvs_config *cfg)
HRESULT jvs_hook_init(const struct jvs_config *cfg, jvs_provider_t provider)
{
HRESULT hr;
@ -50,12 +51,6 @@ HRESULT jvs_hook_init(const struct jvs_config *cfg)
return S_FALSE;
}
hr = iohook_open_nul_fd(&jvs_fd);
if (FAILED(hr)) {
return hr;
}
hr = iohook_push_handler(jvs_handle_irp);
if (FAILED(hr)) {
@ -68,12 +63,9 @@ HRESULT jvs_hook_init(const struct jvs_config *cfg)
return hr;
}
return S_OK;
}
jvs_provider = provider;
void jvs_attach(struct jvs_node *root)
{
jvs_root = root;
return S_OK;
}
static HRESULT jvs_handle_irp(struct irp *irp)
@ -94,11 +86,35 @@ static HRESULT jvs_handle_irp(struct irp *irp)
static HRESULT jvs_handle_open(struct irp *irp)
{
struct jvs_node *root;
HRESULT hr;
if (!wstr_eq(irp->open_filename, L"$jvs")) {
return iohook_invoke_next(irp);
}
if (jvs_fd != NULL) {
dprintf("JVS Port: Already open\n");
return HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION);
}
hr = iohook_open_nul_fd(&jvs_fd);
if (FAILED(hr)) {
return hr;
}
dprintf("JVS Port: Open device\n");
if (jvs_provider != NULL) {
hr = jvs_provider(&root);
if (SUCCEEDED(hr)) {
jvs_root = root;
}
}
irp->fd = jvs_fd;
return S_OK;
@ -107,8 +123,9 @@ static HRESULT jvs_handle_open(struct irp *irp)
static HRESULT jvs_handle_close(struct irp *irp)
{
dprintf("JVS Port: Close device\n");
jvs_fd = NULL;
return S_OK;
return iohook_invoke_next(irp);
}
static HRESULT jvs_handle_ioctl(struct irp *irp)

View File

@ -13,5 +13,6 @@ DEFINE_GUID(
0x4288,
0xAA, 0x00, 0x6C, 0x00, 0xD7, 0x67, 0xBD, 0xBF);
HRESULT jvs_hook_init(const struct jvs_config *cfg);
void jvs_attach(struct jvs_node *root);
typedef HRESULT (*jvs_provider_t)(struct jvs_node **root);
HRESULT jvs_hook_init(const struct jvs_config *cfg, jvs_provider_t provider);