MCPcopy Create free account
hub / github.com/dobin/RedEdr / KernelReaderShutdown

Function KernelReaderShutdown

RedEdr/kernelreader.cpp:93–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91
92
93void KernelReaderShutdown() {
94 // Signal stop
95 if (hStopEventKernel != NULL) {
96 SetEvent(hStopEventKernel);
97 }
98
99 // Cancel any pending synchronous I/O in the reader thread.
100 // The thread may be blocked in ConnectNamedPipe (WaitForClient) or in
101 // ReadFile (ReceiveBatch, which holds pipe_mutex). CancelSynchronousIo
102 // unblocks both cases without trying to acquire the mutex.
103 if (hKernelThreadHandle != NULL) {
104 CancelSynchronousIo(hKernelThreadHandle);
105 }
106
107 // Wait for thread to exit cleanly
108 if (hKernelThreadHandle != NULL) {
109 if (WaitForSingleObject(hKernelThreadHandle, 5000) == WAIT_TIMEOUT) {
110 LOG_A(LOG_WARNING, "KernelReader: Thread did not exit in time, force-terminating");
111 TerminateThread(hKernelThreadHandle, 1);
112 }
113 CloseHandle(hKernelThreadHandle);
114 hKernelThreadHandle = NULL;
115 }
116
117 // Clean up pipe server if the thread left it behind (e.g. cancelled in WaitForClient path)
118 if (kernelPipeServer != NULL) {
119 delete kernelPipeServer;
120 kernelPipeServer = NULL;
121 }
122
123 if (hStopEventKernel != NULL) {
124 CloseHandle(hStopEventKernel);
125 hStopEventKernel = NULL;
126 }
127}
128

Callers 1

ManagerShutdownFunction · 0.85

Calls 1

LOG_AFunction · 0.70

Tested by

no test coverage detected