diff --git a/src/daemon/toks_daemon_acquire.c b/src/daemon/toks_daemon_acquire.c index f55adcd..5fae774 100644 --- a/src/daemon/toks_daemon_acquire.c +++ b/src/daemon/toks_daemon_acquire.c @@ -171,8 +171,6 @@ static int32_t toks_daemon_queue(struct toks_daemon_ctx * dctx, void * hcaller, NT_EVENT_QUERY_STATE|NT_EVENT_MODIFY_STATE, 0,0); - ntapi->zw_close(hcaller); - if (status) { ntapi->zw_close(hprocess); return status; @@ -188,6 +186,7 @@ static int32_t toks_daemon_queue(struct toks_daemon_ctx * dctx, void * hcaller, waiter = dctx->waiter_next; waiter->client.hprocess = hprocess; + waiter->client.hcaller = hcaller; waiter->client.hevent = hevent; toks_set_driver_nwaiters( @@ -210,7 +209,6 @@ int32_t __stdcall toks_daemon_acquire(struct toks_daemon_ctx * dctx) { int32_t status; nt_tty_port_msg * msg; - void * hcaller; struct toks_client_ctx client; nt_oa oa; struct toks_token * token; @@ -220,6 +218,7 @@ int32_t __stdcall toks_daemon_acquire(struct toks_daemon_ctx * dctx) client.hport = 0; client.hprocess = 0; + client.hcaller = 0; client.hswap = 0; client.hdaemon = dctx->hport_internal_client; client.cid.process_id = msg->header.client_id.process_id; @@ -263,7 +262,7 @@ int32_t __stdcall toks_daemon_acquire(struct toks_daemon_ctx * dctx) if (dctx->ftokens == 0) { status = ntapi->zw_open_process( - &hcaller, + &client.hcaller, NT_PROCESS_SYNCHRONIZE | NT_PROCESS_DUP_HANDLE | NT_PROCESS_QUERY_INFORMATION, @@ -301,7 +300,7 @@ int32_t __stdcall toks_daemon_acquire(struct toks_daemon_ctx * dctx) dctx,sizeof(*dctx)); return toks_daemon_queue( - dctx,hcaller, + dctx,client.hcaller, client.hprocess); } diff --git a/src/daemon/toks_daemon_release.c b/src/daemon/toks_daemon_release.c index d2a5136..aaedc91 100644 --- a/src/daemon/toks_daemon_release.c +++ b/src/daemon/toks_daemon_release.c @@ -29,6 +29,7 @@ static int32_t toks_daemon_unqueue(struct toks_daemon_ctx * dctx) struct toks_waiter * waiter; nt_tty_port_msg * msg; nt_tty_port_msg cmsg; + void * hcaller; msg = &dctx->reply; nwaiters = toks_get_driver_nwaiters(dctx->driver_ctx); @@ -54,6 +55,26 @@ static int32_t toks_daemon_unqueue(struct toks_daemon_ctx * dctx) if (!waiter->msg.header.msg_id) return NT_STATUS_CANCELLED; + + if ((hcaller = waiter->client.hcaller)) { + status = ntapi->zw_wait_for_single_object( + hcaller, + NT_SYNC_NON_ALERTABLE, + &(nt_timeout){.quad=0}); + + ntapi->zw_close(hcaller); + + switch (status) { + case NT_STATUS_TIMEOUT: + break; + + default: + waiter->msg.header.msg_id = 0; + return NT_STATUS_REQUEST_ABORTED; + } + } + + ntapi->tt_generic_memcpy( &cmsg,msg, sizeof(*msg)); diff --git a/src/internal/toksvc_daemon_impl.h b/src/internal/toksvc_daemon_impl.h index 5552f22..04934c3 100644 --- a/src/internal/toksvc_daemon_impl.h +++ b/src/internal/toksvc_daemon_impl.h @@ -26,6 +26,7 @@ struct toks_driver_ctx; struct toks_client_ctx { void * hprocess; + void * hcaller; void * hinstance; void * hport; void * hswap;