diff --git a/src/daemon/toks_daemon_acquire.c b/src/daemon/toks_daemon_acquire.c index d4802d8..5a004e9 100644 --- a/src/daemon/toks_daemon_acquire.c +++ b/src/daemon/toks_daemon_acquire.c @@ -148,6 +148,38 @@ static int32_t toks_daemon_token_instance( return NT_STATUS_SUCCESS; } +static int32_t toks_daemon_queue(struct toks_daemon_ctx * dctx) +{ + int nwaiters; + struct toks_waiter * waiter; + struct toks_waiter * waiters; + nt_tty_port_msg * msg; + int i; + + msg = &dctx->reply; + waiters = toks_get_driver_waiters(dctx->driver_ctx); + nwaiters = toks_get_driver_nwaiters(dctx->driver_ctx); + + if (nwaiters == TOKS_MAX_WAITERS) + return NT_STATUS_TIMEOUT; + + for (i=0, waiter=0; !waiter && (idriver_ctx, + ++nwaiters); + + ntapi->tt_generic_memcpy( + &waiter->msg,msg, + sizeof(*msg)); + + msg->ttyinfo.exarg = 0; + + return NT_STATUS_SUCCESS; +} + int32_t __stdcall toks_daemon_acquire(struct toks_daemon_ctx * dctx) { int32_t status; @@ -197,14 +229,14 @@ int32_t __stdcall toks_daemon_acquire(struct toks_daemon_ctx * dctx) for (; token->self && (tokenipcinfo.hevent) { + if (0 && (token == tocap) && !msg->ipcinfo.hevent) { ntapi->zw_close(client.hprocess); return NT_STATUS_TIMEOUT; } if (token == tocap) { ntapi->zw_close(client.hprocess); - return NT_STATUS_NOT_IMPLEMENTED; + return toks_daemon_queue(dctx); } toks_query_performance_counters(dctx->driver_ctx,&pcnt); diff --git a/src/daemon/toks_daemon_release.c b/src/daemon/toks_daemon_release.c index 2ed9442..2a91214 100644 --- a/src/daemon/toks_daemon_release.c +++ b/src/daemon/toks_daemon_release.c @@ -22,6 +22,54 @@ static void toks_daemon_token_reset(struct toks_token * token) token->keys.key[5] = 0; } +static int32_t toks_daemon_unqueue(struct toks_daemon_ctx * dctx) +{ + int nwaiters; + struct toks_waiter * waiter; + struct toks_waiter * waiters; + nt_tty_port_msg * msg; + nt_tty_port_msg cmsg; + int i; + + msg = &dctx->reply; + waiters = toks_get_driver_waiters(dctx->driver_ctx); + nwaiters = toks_get_driver_nwaiters(dctx->driver_ctx); + + if (nwaiters == 0) + return NT_STATUS_SUCCESS; + + for (i=0, waiter=0; !waiter && (itt_generic_memcpy( + &cmsg,msg, + sizeof(*msg)); + + ntapi->tt_generic_memcpy( + msg,&waiter->msg, + sizeof(*msg)); + + toks_set_driver_nwaiters( + dctx->driver_ctx, + --nwaiters); + + waiter->msg.header.msg_id = 0; + + msg->ttyinfo.status = toks_daemon_acquire(dctx); + msg->ttyinfo.exarg = waiter; + + ntapi->zw_reply_port( + dctx->hport_daemon, + &msg->header); + + ntapi->tt_generic_memcpy( + msg,&cmsg, + sizeof(*msg)); + + return NT_STATUS_SUCCESS; +} + int32_t __stdcall toks_daemon_release(struct toks_daemon_ctx * dctx) { nt_tty_port_msg * msg; @@ -54,5 +102,9 @@ int32_t __stdcall toks_daemon_release(struct toks_daemon_ctx * dctx) ntapi->zw_alert_thread(token->client.hinstance); ntapi->zw_close(token->client.hinstance); + do { + (void)0; + } while (toks_daemon_unqueue(dctx)); + return NT_STATUS_SUCCESS; } diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index c42e1ca..2c3aa85 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -357,6 +357,9 @@ int toks_get_driver_ctx( toks_daemon_ctx.driver_ctx = &ctx->ctx; if (cctx.drvflags & TOKS_DRIVER_MODE_SERVER) { + if (!(ctx->waiters = toks_calloc(TOKS_MAX_WAITERS,sizeof(*ctx->waiters)))) + return toks_get_driver_ctx_fail(meta); + if (!(ctx->tokens = toks_calloc(ntokens,sizeof(*ctx->tokens)))) return toks_get_driver_ctx_fail(meta); @@ -386,6 +389,9 @@ static void toks_free_driver_ctx_impl(struct toks_driver_ctx_alloc * ictx) if (ictx->ctx.tokens) toks_free(ictx->ctx.tokens); + if (ictx->ctx.waiters) + toks_free(ictx->ctx.waiters); + argv_free(ictx->meta); free(ictx); } diff --git a/src/internal/toksvc_daemon_impl.h b/src/internal/toksvc_daemon_impl.h index 487722e..e976c01 100644 --- a/src/internal/toksvc_daemon_impl.h +++ b/src/internal/toksvc_daemon_impl.h @@ -36,6 +36,11 @@ struct toks_token { struct toks_token * self; }; +struct toks_waiter { + struct toks_client_ctx client; + struct _nt_tty_port_msg msg; +}; + typedef int32_t __stdcall toks_daemon_routine(struct toks_daemon_ctx *); struct toks_daemon_ctx { diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index 8825d47..a92f8dd 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -11,6 +11,7 @@ #include "argv/argv.h" #define TOKS_OPTV_ELEMENTS 64 +#define TOKS_MAX_WAITERS 4000 extern const struct argv_option toks_default_options[]; extern const ntapi_vtbl * toks_ntapi; @@ -40,12 +41,14 @@ struct toks_driver_ctx_impl { struct toks_driver_ctx ctx; struct toks_ticks ticks; struct toks_token * tokens; + struct toks_waiter * waiters; struct _nt_port_keys keys; void * hevent; void * hsvcdir; void * hpiddir; void * hsvclink; void * hservice; + int nwaiters; int ntokens; int tokpid; nt_guid uuid; @@ -147,6 +150,27 @@ static inline const nt_guid * toks_get_driver_uuid(const struct toks_driver_ctx return &ictx->uuid; } +static inline struct toks_waiter * toks_get_driver_waiters(const struct toks_driver_ctx * dctx) +{ + struct toks_driver_ctx_impl * ictx; + ictx = toks_get_driver_ictx(dctx); + return ictx->waiters; +} + +static inline int toks_get_driver_nwaiters(const struct toks_driver_ctx * dctx) +{ + struct toks_driver_ctx_impl * ictx; + ictx = toks_get_driver_ictx(dctx); + return ictx->nwaiters; +} + +static inline void toks_set_driver_nwaiters(const struct toks_driver_ctx * dctx, int nwaiters) +{ + struct toks_driver_ctx_impl * ictx; + ictx = toks_get_driver_ictx(dctx); + ictx->nwaiters = nwaiters; +} + static inline struct toks_token * toks_get_driver_tokens(const struct toks_driver_ctx * dctx) { struct toks_driver_ctx_impl * ictx;