From 1e8ae763c6b3dfb6afbe2204f708c98330135712 Mon Sep 17 00:00:00 2001 From: David Mason Date: Tue, 21 May 2024 15:37:26 -0700 Subject: [PATCH 1/2] 8 fix for ipc --- src/native/eventpipe/ds-ipc-pal-namedpipe.c | 23 +++++++++++++++++++++ src/native/eventpipe/ds-ipc-pal-socket.c | 5 +++++ src/native/eventpipe/ds-ipc-pal.h | 3 +++ src/native/eventpipe/ds-ipc.c | 6 +++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/native/eventpipe/ds-ipc-pal-namedpipe.c b/src/native/eventpipe/ds-ipc-pal-namedpipe.c index 6802d5aa28d42f..81babd02541474 100644 --- a/src/native/eventpipe/ds-ipc-pal-namedpipe.c +++ b/src/native/eventpipe/ds-ipc-pal-namedpipe.c @@ -187,6 +187,25 @@ ds_ipc_free (DiagnosticsIpc *ipc) ep_rt_object_free (ipc); } +void +ds_ipc_reset (DiagnosticsIpc *ipc) +{ + if (!ipc) + return; + + if (ipc->pipe != INVALID_HANDLE_VALUE) { + CloseHandle (ipc->pipe); + ipc->pipe = INVALID_HANDLE_VALUE; + } + + if (ipc->overlap.hEvent != INVALID_HANDLE_VALUE) { + CloseHandle (ipc->overlap.hEvent); + ipc->overlap.hEvent = INVALID_HANDLE_VALUE; + } + + ipc->is_listening = false; +} + int32_t ds_ipc_poll ( DiagnosticsIpcPollHandle *poll_handles_data, @@ -206,6 +225,10 @@ ds_ipc_poll ( // SERVER EP_ASSERT (poll_handles_data [i].ipc->mode == DS_IPC_CONNECTION_MODE_LISTEN); handles [i] = poll_handles_data [i].ipc->overlap.hEvent; + if (handles [i] == INVALID_HANDLE_VALUE) { + // Invalid handle, wait will fail. Signal error + poll_handles_data [i].events = DS_IPC_POLL_EVENTS_ERR; + } } else { // CLIENT bool success = true; diff --git a/src/native/eventpipe/ds-ipc-pal-socket.c b/src/native/eventpipe/ds-ipc-pal-socket.c index 742de3f90a7aa2..adde8807952981 100644 --- a/src/native/eventpipe/ds-ipc-pal-socket.c +++ b/src/native/eventpipe/ds-ipc-pal-socket.c @@ -1061,6 +1061,11 @@ ds_ipc_free (DiagnosticsIpc *ipc) ep_rt_object_free (ipc); } +void +ds_ipc_reset (DiagnosticsIpc *ipc) +{ +} + int32_t ds_ipc_poll ( DiagnosticsIpcPollHandle *poll_handles_data, diff --git a/src/native/eventpipe/ds-ipc-pal.h b/src/native/eventpipe/ds-ipc-pal.h index 8ffd202b6b5185..c51b02f24c8339 100644 --- a/src/native/eventpipe/ds-ipc-pal.h +++ b/src/native/eventpipe/ds-ipc-pal.h @@ -35,6 +35,9 @@ ds_ipc_alloc ( void ds_ipc_free (DiagnosticsIpc *ipc); +void +ds_ipc_reset (DiagnosticsIpc *ipc); + // Poll // Parameters: // - IpcPollHandle * poll_handles_data: Array of IpcPollHandles to poll diff --git a/src/native/eventpipe/ds-ipc.c b/src/native/eventpipe/ds-ipc.c index 063b98b84aef86..373ff289c83d82 100644 --- a/src/native/eventpipe/ds-ipc.c +++ b/src/native/eventpipe/ds-ipc.c @@ -850,7 +850,11 @@ listen_port_reset ( ds_ipc_error_callback_func callback) { EP_ASSERT (object != NULL); - return; +#ifdef _WIN32 + DiagnosticsListenPort *listen_port = (DiagnosticsListenPort *)object; + ds_ipc_reset (listen_port->port.ipc); + ds_ipc_listen (listen_port->port.ipc, callback); +#endif // _WIN32 } static DiagnosticsPortVtable listen_port_vtable = { From 5d3e336e9b34067ec03643d5ebaeddfedd7ac518 Mon Sep 17 00:00:00 2001 From: David Mason Date: Tue, 21 May 2024 17:36:52 -0700 Subject: [PATCH 2/2] Update ds-ipc-pal-namedpipe.c --- src/native/eventpipe/ds-ipc-pal-namedpipe.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/native/eventpipe/ds-ipc-pal-namedpipe.c b/src/native/eventpipe/ds-ipc-pal-namedpipe.c index 81babd02541474..f3a0584eeb8967 100644 --- a/src/native/eventpipe/ds-ipc-pal-namedpipe.c +++ b/src/native/eventpipe/ds-ipc-pal-namedpipe.c @@ -194,15 +194,17 @@ ds_ipc_reset (DiagnosticsIpc *ipc) return; if (ipc->pipe != INVALID_HANDLE_VALUE) { + DisconnectNamedPipe (ipc->pipe); CloseHandle (ipc->pipe); ipc->pipe = INVALID_HANDLE_VALUE; } if (ipc->overlap.hEvent != INVALID_HANDLE_VALUE) { CloseHandle (ipc->overlap.hEvent); - ipc->overlap.hEvent = INVALID_HANDLE_VALUE; } + memset(&ipc->overlap, 0, sizeof(OVERLAPPED)); // clear the overlapped objects state + ipc->overlap.hEvent = INVALID_HANDLE_VALUE; ipc->is_listening = false; }