From 9985a179c0df4a50c21fdf1b49f54affcf14fe86 Mon Sep 17 00:00:00 2001 From: midipix Date: Jun 08 2020 01:00:10 +0000 Subject: daemon: change signature of handlers for a tighter context-oriented design. --- diff --git a/src/daemon/toks_daemon_connect.c b/src/daemon/toks_daemon_connect.c index 66595db..05212ee 100644 --- a/src/daemon/toks_daemon_connect.c +++ b/src/daemon/toks_daemon_connect.c @@ -11,11 +11,14 @@ #include "toksvc_daemon_impl.h" #include "toksvc_driver_impl.h" -int32_t __stdcall toks_daemon_connect(nt_tty_port_msg * msg) +int32_t __stdcall toks_daemon_connect(struct toks_daemon_ctx * dctx) { - void * hport = 0; + nt_tty_port_msg * msg; + void * hport; + msg = &dctx->reply; msg->ttyinfo.exarg = 0; + hport = 0; ntapi->zw_accept_connect_port( &hport, diff --git a/src/daemon/toks_daemon_loop.c b/src/daemon/toks_daemon_loop.c index ea62e6f..93a8b8f 100644 --- a/src/daemon/toks_daemon_loop.c +++ b/src/daemon/toks_daemon_loop.c @@ -28,9 +28,6 @@ int32_t __stdcall toks_daemon_loop(void * ctx) struct toks_daemon_ctx * dctx; nt_rtdata * rtdata; - nt_tty_port_msg inbuf; - nt_tty_port_msg outbuf; - nt_tty_port_msg * request; nt_tty_port_msg * reply; @@ -43,7 +40,9 @@ int32_t __stdcall toks_daemon_loop(void * ctx) dctx = (struct toks_daemon_ctx *)ctx; /* init */ - request = &inbuf; + request = &dctx->request; + reply = &dctx->reply; + ntapi->tt_aligned_block_memset( request,0,sizeof(*request)); @@ -73,8 +72,6 @@ int32_t __stdcall toks_daemon_loop(void * ctx) } /* dispatch */ - reply = &outbuf; - ntapi->tt_aligned_block_memcpy( (uintptr_t *)reply, (uintptr_t *)request, @@ -87,7 +84,7 @@ int32_t __stdcall toks_daemon_loop(void * ctx) opcode -= TOKS_DAEMON_OPCODE_BASE; if (toks_daemon_vtbl[opcode]) - reply->ttyinfo.status = toks_daemon_vtbl[opcode](reply); + reply->ttyinfo.status = toks_daemon_vtbl[opcode](dctx); else reply->ttyinfo.status = NT_STATUS_NOT_IMPLEMENTED; } else { @@ -98,10 +95,7 @@ int32_t __stdcall toks_daemon_loop(void * ctx) ntapi->tt_aligned_block_memset( request,0,sizeof(*request)); - reply = reply->ttyinfo.exarg - ? &outbuf : 0; - - if (!reply) + if (!reply->ttyinfo.exarg) ntapi->zw_reply_wait_receive_port( dctx->hport_daemon, &port_id, diff --git a/src/daemon/toks_daemon_signal.c b/src/daemon/toks_daemon_signal.c index 1c7454a..e2127fa 100644 --- a/src/daemon/toks_daemon_signal.c +++ b/src/daemon/toks_daemon_signal.c @@ -11,8 +11,10 @@ #include "toksvc_daemon_impl.h" #include "toksvc_driver_impl.h" -int32_t __stdcall toks_daemon_signal(nt_tty_port_msg * msg) +int32_t __stdcall toks_daemon_signal(struct toks_daemon_ctx * dctx) { + nt_tty_port_msg * msg = &dctx->reply; + /* [not a] ctty signal? */ if (msg->ctlinfo.ctxarg[0]) return NT_STATUS_SUCCESS; diff --git a/src/internal/toksvc_daemon_impl.h b/src/internal/toksvc_daemon_impl.h index a97e327..2e3643d 100644 --- a/src/internal/toksvc_daemon_impl.h +++ b/src/internal/toksvc_daemon_impl.h @@ -15,10 +15,11 @@ enum toks_daemon_opcodes { TOKS_DAEMON_OPCODE_CAP }; -typedef int32_t __stdcall toks_daemon_routine(nt_tty_port_msg *); - +struct toks_daemon_ctx; struct toks_driver_ctx; +typedef int32_t __stdcall toks_daemon_routine(struct toks_daemon_ctx *); + struct toks_daemon_ctx { struct toks_driver_ctx *driver_ctx; @@ -31,11 +32,15 @@ struct toks_daemon_ctx { void * hport_internal_client; void * hevent_internal_client_ready; + + nt_tty_port_msg request; + nt_tty_port_msg reply; }; int32_t __stdcall toks_daemon_init(struct toks_daemon_ctx *, const nt_guid *); int32_t __stdcall toks_daemon_loop(void *); -int32_t __stdcall toks_daemon_connect(nt_tty_port_msg *); -int32_t __stdcall toks_daemon_signal(nt_tty_port_msg *); + +int32_t __stdcall toks_daemon_connect(struct toks_daemon_ctx *); +int32_t __stdcall toks_daemon_signal(struct toks_daemon_ctx *); #endif