@joebigelow / wix-1 / commits / 8cfd711f

Update Burn to use pipeutil for low-level pipe operations

Rob Mensching committed Jan 11, 2024 at 00:00 UTC 8cfd711f775e8501836162538998b5b6d8efbf89
8 files changed +86 -328
src/burn/engine/burnpipe.cpp
+41 -276
@@ -2,34 +2,9 @@
2
3 #include "precomp.h"
4
5 -static const DWORD PIPE_64KB = 64 * 1024;
6 -static const DWORD PIPE_WAIT_FOR_CONNECTION = 100; // wait a 10th of a second,
7 -static const DWORD PIPE_RETRY_FOR_CONNECTION = 1800; // for up to 3 minutes.
5 +static const LPCWSTR CACHE_PIPE_NAME_FORMAT_STRING = L"%ls.Cache";
6 +static const LPCWSTR LOGGING_PIPE_NAME_FORMAT_STRING = L"%ls.Log";
7
9 -static const LPCWSTR PIPE_NAME_FORMAT_STRING = L"\\\\.\\pipe\\%ls";
10 -static const LPCWSTR CACHE_PIPE_NAME_FORMAT_STRING = L"\\\\.\\pipe\\%ls.Cache";
11 -static const LPCWSTR LOGGING_PIPE_NAME_FORMAT_STRING = L"\\\\.\\pipe\\%ls.Log";
12 -
13 -static HRESULT AllocatePipeMessage(
14 - __in DWORD dwMessage,
15 - __in_bcount_opt(cbData) LPVOID pvData,
16 - __in SIZE_T cbData,
17 - __out_bcount(cb) LPVOID* ppvMessage,
18 - __out SIZE_T* pcbMessage
19 - );
20 -static void FreePipeMessage(
21 - __in BURN_PIPE_MESSAGE *pMsg
22 - );
23 -static HRESULT WritePipeMessage(
24 - __in HANDLE hPipe,
25 - __in DWORD dwMessage,
26 - __in_bcount_opt(cbData) LPVOID pvData,
27 - __in SIZE_T cbData
28 - );
29 -static HRESULT GetPipeMessage(
30 - __in HANDLE hPipe,
31 - __in BURN_PIPE_MESSAGE* pMsg
32 - );
8 static HRESULT ChildPipeConnected(
9 __in HANDLE hPipe,
10 __in_z LPCWSTR wzSecret,
@@ -37,7 +12,6 @@ static HRESULT ChildPipeConnected(
12 );
13
14
40 -
15 /*******************************************************************
16 PipeConnectionInitialize - initialize pipe connection data.
17
@@ -60,9 +34,9 @@ void PipeConnectionUninitialize(
34 __in BURN_PIPE_CONNECTION* pConnection
35 )
36 {
63 - ReleaseFileHandle(pConnection->hLoggingPipe);
64 - ReleaseFileHandle(pConnection->hCachePipe);
65 - ReleaseFileHandle(pConnection->hPipe);
37 + ReleasePipeHandle(pConnection->hLoggingPipe);
38 + ReleasePipeHandle(pConnection->hCachePipe);
39 + ReleasePipeHandle(pConnection->hPipe);
40 ReleaseHandle(pConnection->hProcess);
41 ReleaseStr(pConnection->sczSecret);
42 ReleaseStr(pConnection->sczName);
@@ -71,7 +45,7 @@ void PipeConnectionUninitialize(
45 }
46
47 /*******************************************************************
74 - PipeSendMessage -
48 + PipeSendMessage -
49
50 *******************************************************************/
51 extern "C" HRESULT PipeSendMessage(
@@ -87,7 +61,7 @@ extern "C" HRESULT PipeSendMessage(
61 HRESULT hr = S_OK;
62 BURN_PIPE_RESULT result = { };
63
90 - hr = WritePipeMessage(hPipe, dwMessage, pvData, cbData);
64 + hr = PipeWriteMessage(hPipe, dwMessage, pvData, cbData);
65 ExitOnFailure(hr, "Failed to write send message to pipe.");
66
67 hr = PipePumpMessages(hPipe, pfnCallback, pvContext, &result);
@@ -100,7 +74,7 @@ LExit:
74 }
75
76 /*******************************************************************
103 - PipePumpMessages -
77 + PipePumpMessages -
78
79 *******************************************************************/
80 extern "C" HRESULT PipePumpMessages(
@@ -111,15 +85,15 @@ extern "C" HRESULT PipePumpMessages(
85 )
86 {
87 HRESULT hr = S_OK;
114 - BURN_PIPE_MESSAGE msg = { };
88 + PIPE_MESSAGE msg = { };
89 SIZE_T iData = 0;
90 LPSTR sczMessage = NULL;
91 DWORD dwResult = 0;
92
93 // Pump messages from child process.
120 - while (S_OK == (hr = GetPipeMessage(hPipe, &msg)))
94 + while (S_OK == (hr = PipeReadMessage(hPipe, &msg)))
95 {
122 - switch (msg.dwMessage)
96 + switch (msg.dwMessageType)
97 {
98 case BURN_PIPE_MESSAGE_TYPE_LOG:
99 iData = 0;
@@ -166,15 +140,15 @@ extern "C" HRESULT PipePumpMessages(
140 {
141 hr = E_INVALIDARG;
142 }
169 - ExitOnFailure(hr, "Failed to process message: %u", msg.dwMessage);
143 + ExitOnFailure(hr, "Failed to process message: %u", msg.dwMessageType);
144 break;
145 }
146
147 // post result
174 - hr = WritePipeMessage(hPipe, static_cast<DWORD>(BURN_PIPE_MESSAGE_TYPE_COMPLETE), &dwResult, sizeof(dwResult));
148 + hr = PipeWriteMessage(hPipe, static_cast<DWORD>(BURN_PIPE_MESSAGE_TYPE_COMPLETE), &dwResult, sizeof(dwResult));
149 ExitOnFailure(hr, "Failed to post result to child process.");
150
177 - FreePipeMessage(&msg);
151 + ReleasePipeMessage(&msg);
152 }
153 ExitOnFailure(hr, "Failed to get message over pipe");
154
@@ -185,13 +159,13 @@ extern "C" HRESULT PipePumpMessages(
159
160 LExit:
161 ReleaseStr(sczMessage);
188 - FreePipeMessage(&msg);
162 + ReleasePipeMessage(&msg);
163
164 return hr;
165 }
166
167 /*******************************************************************
194 - PipeCreateNameAndSecret -
168 + PipeCreateNameAndSecret -
169
170 *******************************************************************/
171 extern "C" HRESULT PipeCreateNameAndSecret(
@@ -247,7 +221,7 @@ extern "C" HRESULT PipeCreatePipes(
221 HRESULT hr = S_OK;
222 PSECURITY_DESCRIPTOR psd = NULL;
223 SECURITY_ATTRIBUTES sa = { };
250 - LPWSTR sczFullPipeName = NULL;
224 + LPWSTR sczPipeName = NULL;
225 HANDLE hPipe = INVALID_HANDLE_VALUE;
226 HANDLE hCachePipe = INVALID_HANDLE_VALUE;
227 HANDLE hLoggingPipe = INVALID_HANDLE_VALUE;
@@ -269,37 +243,24 @@ extern "C" HRESULT PipeCreatePipes(
243 }
244
245 // Create the pipe.
272 - hr = StrAllocFormatted(&sczFullPipeName, PIPE_NAME_FORMAT_STRING, pConnection->sczName);
273 - ExitOnFailure(hr, "Failed to allocate full name of pipe: %ls", pConnection->sczName);
274 -
275 - // TODO: consider using overlapped IO to do waits on the pipe and still be able to cancel and such.
276 - hPipe = ::CreateNamedPipeW(sczFullPipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, PIPE_64KB, PIPE_64KB, 1, psd ? &sa : NULL);
277 - if (INVALID_HANDLE_VALUE == hPipe)
278 - {
279 - ExitWithLastError(hr, "Failed to create pipe: %ls", sczFullPipeName);
280 - }
246 + hr = PipeCreate(pConnection->sczName, psd ? &sa : NULL, &hPipe);
247 + ExitOnFailure(hr, "Failed to create pipe: %ls", pConnection->sczName);
248
249 if (fCompanion)
250 {
251 // Create the cache pipe.
285 - hr = StrAllocFormatted(&sczFullPipeName, CACHE_PIPE_NAME_FORMAT_STRING, pConnection->sczName);
252 + hr = StrAllocFormatted(&sczPipeName, CACHE_PIPE_NAME_FORMAT_STRING, pConnection->sczName);
253 ExitOnFailure(hr, "Failed to allocate full name of cache pipe: %ls", pConnection->sczName);
254
288 - hCachePipe = ::CreateNamedPipeW(sczFullPipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, PIPE_64KB, PIPE_64KB, 1, NULL);
289 - if (INVALID_HANDLE_VALUE == hCachePipe)
290 - {
291 - ExitWithLastError(hr, "Failed to create cache pipe: %ls", sczFullPipeName);
292 - }
255 + hr = PipeCreate(sczPipeName, NULL, &hCachePipe);
256 + ExitOnFailure(hr, "Failed to create cache pipe: %ls", sczPipeName);
257
258 // Create the logging pipe.
295 - hr = StrAllocFormatted(&sczFullPipeName, LOGGING_PIPE_NAME_FORMAT_STRING, pConnection->sczName);
259 + hr = StrAllocFormatted(&sczPipeName, LOGGING_PIPE_NAME_FORMAT_STRING, pConnection->sczName);
260 ExitOnFailure(hr, "Failed to allocate full name of logging pipe: %ls", pConnection->sczName);
261
298 - hLoggingPipe = ::CreateNamedPipeW(sczFullPipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, PIPE_64KB, PIPE_64KB, 1, NULL);
299 - if (INVALID_HANDLE_VALUE == hLoggingPipe)
300 - {
301 - ExitWithLastError(hr, "Failed to create logging pipe: %ls", sczFullPipeName);
302 - }
262 + hr = PipeCreate(sczPipeName, NULL, &hLoggingPipe);
263 + ExitOnFailure(hr, "Failed to create logging pipe: %ls", sczPipeName);
264 }
265
266 pConnection->hLoggingPipe = hLoggingPipe;
@@ -312,10 +273,10 @@ extern "C" HRESULT PipeCreatePipes(
273 hPipe = INVALID_HANDLE_VALUE;
274
275 LExit:
315 - ReleaseFileHandle(hLoggingPipe);
316 - ReleaseFileHandle(hCachePipe);
317 - ReleaseFileHandle(hPipe);
318 - ReleaseStr(sczFullPipeName);
276 + ReleasePipeHandle(hLoggingPipe);
277 + ReleasePipeHandle(hCachePipe);
278 + ReleasePipeHandle(hPipe);
279 + ReleaseStr(sczPipeName);
280
281 if (psd)
282 {
@@ -326,7 +287,7 @@ LExit:
287 }
288
289 /*******************************************************************
329 - PipeWaitForChildConnect -
290 + PipeWaitForChildConnect -
291
292 *******************************************************************/
293 extern "C" HRESULT PipeWaitForChildConnect(
@@ -343,58 +304,10 @@ extern "C" HRESULT PipeWaitForChildConnect(
304 for (DWORD i = 0; i < countof(hPipes) && INVALID_HANDLE_VALUE != hPipes[i]; ++i)
305 {
306 HANDLE hPipe = hPipes[i];
346 - DWORD dwPipeState = PIPE_READMODE_BYTE | PIPE_NOWAIT;
307
348 - // Temporarily make the pipe non-blocking so we will not get stuck in ::ConnectNamedPipe() forever
349 - // if the child decides not to show up.
350 - if (!::SetNamedPipeHandleState(hPipe, &dwPipeState, NULL, NULL))
351 - {
352 - ExitWithLastError(hr, "Failed to set pipe to non-blocking.");
353 - }
354 -
355 - // Loop for a while waiting for a connection from child process.
356 - DWORD cRetry = 0;
357 - do
358 - {
359 - if (!::ConnectNamedPipe(hPipe, NULL))
360 - {
361 - DWORD er = ::GetLastError();
362 - if (ERROR_PIPE_CONNECTED == er)
363 - {
364 - hr = S_OK;
365 - break;
366 - }
367 - else if (ERROR_PIPE_LISTENING == er)
368 - {
369 - if (cRetry < PIPE_RETRY_FOR_CONNECTION)
370 - {
371 - hr = HRESULT_FROM_WIN32(er);
372 - }
373 - else
374 - {
375 - hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT);
376 - break;
377 - }
378 -
379 - ++cRetry;
380 - ::Sleep(PIPE_WAIT_FOR_CONNECTION);
381 - }
382 - else
383 - {
384 - hr = HRESULT_FROM_WIN32(er);
385 - break;
386 - }
387 - }
388 - } while (HRESULT_FROM_WIN32(ERROR_PIPE_LISTENING) == hr);
308 + hr = PipeServerWaitForClientConnect(hPipe);
309 ExitOnRootFailure(hr, "Failed to wait for child to connect to pipe.");
310
391 - // Put the pipe back in blocking mode.
392 - dwPipeState = PIPE_READMODE_BYTE | PIPE_WAIT;
393 - if (!::SetNamedPipeHandleState(hPipe, &dwPipeState, NULL, NULL))
394 - {
395 - ExitWithLastError(hr, "Failed to reset pipe to blocking.");
396 - }
397 -
311 // Prove we are the one that created the elevated process by passing the secret.
312 hr = FileWriteHandle(hPipe, reinterpret_cast<LPCBYTE>(&cbSecret), sizeof(cbSecret));
313 ExitOnFailure(hr, "Failed to write secret length to pipe.");
@@ -422,7 +335,7 @@ LExit:
335 }
336
337 /*******************************************************************
425 - PipeTerminateLoggingPipe -
338 + PipeTerminateLoggingPipe -
339
340 *******************************************************************/
341 extern "C" HRESULT PipeTerminateLoggingPipe(
@@ -438,7 +351,7 @@ extern "C" HRESULT PipeTerminateLoggingPipe(
351 hr = BuffWriteNumber(&pbData, &cbData, dwParentExitCode);
352 ExitOnFailure(hr, "Failed to write exit code to message buffer.");
353
441 - hr = WritePipeMessage(hLoggingPipe, static_cast<DWORD>(BURN_PIPE_MESSAGE_TYPE_COMPLETE), pbData, cbData);
354 + hr = PipeWriteMessage(hLoggingPipe, static_cast<DWORD>(BURN_PIPE_MESSAGE_TYPE_COMPLETE), pbData, cbData);
355 ExitOnFailure(hr, "Failed to post complete message to logging pipe.");
356
357 LExit:
@@ -448,7 +361,7 @@ LExit:
361 }
362
363 /*******************************************************************
451 - PipeTerminateChildProcess -
364 + PipeTerminateChildProcess -
365
366 *******************************************************************/
367 extern "C" HRESULT PipeTerminateChildProcess(
@@ -472,11 +385,11 @@ extern "C" HRESULT PipeTerminateChildProcess(
385 // Send the messages.
386 if (INVALID_HANDLE_VALUE != pConnection->hCachePipe)
387 {
475 - hr = WritePipeMessage(pConnection->hCachePipe, static_cast<DWORD>(BURN_PIPE_MESSAGE_TYPE_TERMINATE), pbData, cbData);
388 + hr = PipeWriteMessage(pConnection->hCachePipe, static_cast<DWORD>(BURN_PIPE_MESSAGE_TYPE_TERMINATE), pbData, cbData);
389 ExitOnFailure(hr, "Failed to post terminate message to child process cache thread.");
390 }
391
479 - hr = WritePipeMessage(pConnection->hPipe, static_cast<DWORD>(BURN_PIPE_MESSAGE_TYPE_TERMINATE), pbData, cbData);
392 + hr = PipeWriteMessage(pConnection->hPipe, static_cast<DWORD>(BURN_PIPE_MESSAGE_TYPE_TERMINATE), pbData, cbData);
393 ExitOnFailure(hr, "Failed to post terminate message to child process.");
394
395 // If we were able to get a handle to the other process, wait for it to exit.
@@ -532,28 +445,7 @@ extern "C" HRESULT PipeChildConnect(
445 LPWSTR sczPipeName = NULL;
446
447 // Try to connect to the parent.
535 - hr = StrAllocFormatted(&sczPipeName, PIPE_NAME_FORMAT_STRING, pConnection->sczName);
536 - ExitOnFailure(hr, "Failed to allocate name of parent pipe.");
537 -
538 - hr = E_UNEXPECTED;
539 - for (DWORD cRetry = 0; FAILED(hr) && cRetry < PIPE_RETRY_FOR_CONNECTION; ++cRetry)
540 - {
541 - pConnection->hPipe = ::CreateFileW(sczPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
542 - if (INVALID_HANDLE_VALUE == pConnection->hPipe)
543 - {
544 - hr = HRESULT_FROM_WIN32(::GetLastError());
545 - if (E_FILENOTFOUND == hr) // if the pipe isn't created, call it a timeout waiting on the parent.
546 - {
547 - hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT);
548 - }
549 -
550 - ::Sleep(PIPE_WAIT_FOR_CONNECTION);
551 - }
552 - else // we have a connection, go with it.
553 - {
554 - hr = S_OK;
555 - }
556 - }
448 + hr = PipeClientConnect(pConnection->sczName, &pConnection->hPipe);
449 ExitOnRootFailure(hr, "Failed to open parent pipe: %ls", sczPipeName)
450
451 // Verify the parent and notify it that the child connected.
@@ -566,11 +458,8 @@ extern "C" HRESULT PipeChildConnect(
458 hr = StrAllocFormatted(&sczPipeName, CACHE_PIPE_NAME_FORMAT_STRING, pConnection->sczName);
459 ExitOnFailure(hr, "Failed to allocate name of parent cache pipe.");
460
569 - pConnection->hCachePipe = ::CreateFileW(sczPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
570 - if (INVALID_HANDLE_VALUE == pConnection->hCachePipe)
571 - {
572 - ExitWithLastError(hr, "Failed to open parent cache pipe: %ls", sczPipeName)
573 - }
461 + hr = PipeClientConnect(sczPipeName, &pConnection->hCachePipe);
462 + ExitOnFailure(hr, "Failed to open parent cache pipe: %ls", sczPipeName)
463
464 // Verify the parent and notify it that the child connected.
465 hr = ChildPipeConnected(pConnection->hCachePipe, pConnection->sczSecret, &pConnection->dwProcessId);
@@ -580,11 +469,8 @@ extern "C" HRESULT PipeChildConnect(
469 hr = StrAllocFormatted(&sczPipeName, LOGGING_PIPE_NAME_FORMAT_STRING, pConnection->sczName);
470 ExitOnFailure(hr, "Failed to allocate name of parent logging pipe.");
471
583 - pConnection->hLoggingPipe = ::CreateFileW(sczPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
584 - if (INVALID_HANDLE_VALUE == pConnection->hLoggingPipe)
585 - {
586 - ExitWithLastError(hr, "Failed to open parent logging pipe: %ls", sczPipeName)
587 - }
472 + hr = PipeClientConnect(sczPipeName, &pConnection->hLoggingPipe);
473 + ExitOnFailure(hr, "Failed to open parent cache pipe: %ls", sczPipeName)
474
475 // Verify the parent and notify it that the child connected.
476 hr = ChildPipeConnected(pConnection->hLoggingPipe, pConnection->sczSecret, &pConnection->dwProcessId);
@@ -600,127 +486,6 @@ LExit:
486 return hr;
487 }
488
603 -
604 -static HRESULT AllocatePipeMessage(
605 - __in DWORD dwMessage,
606 - __in_bcount_opt(cbData) LPVOID pvData,
607 - __in SIZE_T cbData,
608 - __out_bcount(cb) LPVOID* ppvMessage,
609 - __out SIZE_T* pcbMessage
610 - )
611 -{
612 - HRESULT hr = S_OK;
613 - LPVOID pv = NULL;
614 - size_t cb = 0;
615 - DWORD dwcbData = 0;
616 -
617 - // If no data was provided, ensure the count of bytes is zero.
618 - if (!pvData)
619 - {
620 - cbData = 0;
621 - }
622 - else if (MAXDWORD < cbData)
623 - {
624 - ExitWithRootFailure(hr, E_INVALIDDATA, "Pipe message is too large.");
625 - }
626 -
627 - hr = ::SizeTAdd(sizeof(dwMessage) + sizeof(dwcbData), cbData, &cb);
628 - ExitOnRootFailure(hr, "Failed to calculate total pipe message size");
629 -
630 - dwcbData = (DWORD)cbData;
631 -
632 - // Allocate the message.
633 - pv = MemAlloc(cb, FALSE);
634 - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for message.");
635 -
636 - memcpy_s(pv, cb, &dwMessage, sizeof(dwMessage));
637 - memcpy_s(static_cast<BYTE*>(pv) + sizeof(dwMessage), cb - sizeof(dwMessage), &dwcbData, sizeof(dwcbData));
638 - if (dwcbData)
639 - {
640 - memcpy_s(static_cast<BYTE*>(pv) + sizeof(dwMessage) + sizeof(dwcbData), cb - sizeof(dwMessage) - sizeof(dwcbData), pvData, dwcbData);
641 - }
642 -
643 - *pcbMessage = cb;
644 - *ppvMessage = pv;
645 - pv = NULL;
646 -
647 -LExit:
648 - ReleaseMem(pv);
649 - return hr;
650 -}
651 -
652 -static void FreePipeMessage(
653 - __in BURN_PIPE_MESSAGE *pMsg
654 - )
655 -{
656 - if (pMsg->fAllocatedData)
657 - {
658 - ReleaseNullMem(pMsg->pvData);
659 - pMsg->fAllocatedData = FALSE;
660 - }
661 -}
662 -
663 -static HRESULT WritePipeMessage(
664 - __in HANDLE hPipe,
665 - __in DWORD dwMessage,
666 - __in_bcount_opt(cbData) LPVOID pvData,
667 - __in SIZE_T cbData
668 - )
669 -{
670 - HRESULT hr = S_OK;
671 - LPVOID pv = NULL;
672 - SIZE_T cb = 0;
673 -
674 - hr = AllocatePipeMessage(dwMessage, pvData, cbData, &pv, &cb);
675 - ExitOnFailure(hr, "Failed to allocate message to write.");
676 -
677 - // Write the message.
678 - hr = FileWriteHandle(hPipe, reinterpret_cast<LPCBYTE>(pv), cb);
679 - ExitOnFailure(hr, "Failed to write message type to pipe.");
680 -
681 -LExit:
682 - ReleaseMem(pv);
683 - return hr;
684 -}
685 -
686 -static HRESULT GetPipeMessage(
687 - __in HANDLE hPipe,
688 - __in BURN_PIPE_MESSAGE* pMsg
689 - )
690 -{
691 - HRESULT hr = S_OK;
692 - BYTE pbMessageAndByteCount[sizeof(DWORD) + sizeof(DWORD)] = { };
693 -
694 - hr = FileReadHandle(hPipe, pbMessageAndByteCount, sizeof(pbMessageAndByteCount));
695 - if (HRESULT_FROM_WIN32(ERROR_BROKEN_PIPE) == hr)
696 - {
697 - memset(pbMessageAndByteCount, 0, sizeof(pbMessageAndByteCount));
698 - hr = S_FALSE;
699 - }
700 - ExitOnFailure(hr, "Failed to read message from pipe.");
701 -
702 - pMsg->dwMessage = *(DWORD*)(pbMessageAndByteCount);
703 - pMsg->cbData = *(DWORD*)(pbMessageAndByteCount + sizeof(DWORD));
704 - if (pMsg->cbData)
705 - {
706 - pMsg->pvData = MemAlloc(pMsg->cbData, FALSE);
707 - ExitOnNull(pMsg->pvData, hr, E_OUTOFMEMORY, "Failed to allocate data for message.");
708 -
709 - hr = FileReadHandle(hPipe, reinterpret_cast<LPBYTE>(pMsg->pvData), pMsg->cbData);
710 - ExitOnFailure(hr, "Failed to read data for message.");
711 -
712 - pMsg->fAllocatedData = TRUE;
713 - }
714 -
715 -LExit:
716 - if (!pMsg->fAllocatedData && pMsg->pvData)
717 - {
718 - MemFree(pMsg->pvData);
719 - }
720 -
721 - return hr;
722 -}
723 -
489 static HRESULT ChildPipeConnected(
490 __in HANDLE hPipe,
491 __in_z LPCWSTR wzSecret,
src/burn/engine/burnpipe.h
+1 -10
@@ -25,15 +25,6 @@ typedef enum _BURN_PIPE_MESSAGE_TYPE : DWORD
25 BURN_PIPE_MESSAGE_TYPE_TERMINATE = 0xF0000003,
26 } BURN_PIPE_MESSAGE_TYPE;
27
28 -typedef struct _BURN_PIPE_MESSAGE
29 -{
30 - DWORD dwMessage;
31 - DWORD cbData;
32 -
33 - BOOL fAllocatedData;
34 - LPVOID pvData;
35 -} BURN_PIPE_MESSAGE;
36 -
28 typedef struct _BURN_PIPE_RESULT
29 {
30 DWORD dwResult;
@@ -42,7 +33,7 @@ typedef struct _BURN_PIPE_RESULT
33
34
35 typedef HRESULT (*PFN_PIPE_MESSAGE_CALLBACK)(
45 - __in BURN_PIPE_MESSAGE* pMsg,
36 + __in PIPE_MESSAGE* pMsg,
37 __in_opt LPVOID pvContext,
38 __out DWORD* pdwResult
39 );
src/burn/engine/elevation.cpp
+27 -27
@@ -129,43 +129,43 @@ static HRESULT WaitForElevatedChildCacheThread(
129 __in DWORD dwExpectedExitCode
130 );
131 static HRESULT ProcessApplyInitializeMessages(
132 - __in BURN_PIPE_MESSAGE* pMsg,
132 + __in PIPE_MESSAGE* pMsg,
133 __in_opt LPVOID pvContext,
134 __out DWORD* pdwResult
135 );
136 static HRESULT ProcessBurnCacheMessages(
137 - __in BURN_PIPE_MESSAGE* pMsg,
137 + __in PIPE_MESSAGE* pMsg,
138 __in LPVOID pvContext,
139 __out DWORD* pdwResult
140 );
141 static HRESULT ProcessGenericExecuteMessages(
142 - __in BURN_PIPE_MESSAGE* pMsg,
142 + __in PIPE_MESSAGE* pMsg,
143 __in LPVOID pvContext,
144 __out DWORD* pdwResult
145 );
146 static HRESULT ProcessMsiPackageMessages(
147 - __in BURN_PIPE_MESSAGE* pMsg,
147 + __in PIPE_MESSAGE* pMsg,
148 __in_opt LPVOID pvContext,
149 __out DWORD* pdwResult
150 );
151 static HRESULT ProcessLaunchApprovedExeMessages(
152 - __in BURN_PIPE_MESSAGE* pMsg,
152 + __in PIPE_MESSAGE* pMsg,
153 __in_opt LPVOID pvContext,
154 __out DWORD* pdwResult
155 );
156 static HRESULT ProcessProgressRoutineMessage(
157 - __in BURN_PIPE_MESSAGE* pMsg,
157 + __in PIPE_MESSAGE* pMsg,
158 __in LPPROGRESS_ROUTINE pfnProgress,
159 __in LPVOID pvContext,
160 __out DWORD* pdwResult
161 );
162 static HRESULT ProcessElevatedChildMessage(
163 - __in BURN_PIPE_MESSAGE* pMsg,
163 + __in PIPE_MESSAGE* pMsg,
164 __in_opt LPVOID pvContext,
165 __out DWORD* pdwResult
166 );
167 static HRESULT ProcessElevatedChildCacheMessage(
168 - __in BURN_PIPE_MESSAGE* pMsg,
168 + __in PIPE_MESSAGE* pMsg,
169 __in_opt LPVOID pvContext,
170 __out DWORD* pdwResult
171 );
@@ -1739,7 +1739,7 @@ LExit:
1739 }
1740
1741 static HRESULT ProcessApplyInitializeMessages(
1742 - __in BURN_PIPE_MESSAGE* pMsg,
1742 + __in PIPE_MESSAGE* pMsg,
1743 __in_opt LPVOID pvContext,
1744 __out DWORD* pdwResult
1745 )
@@ -1752,7 +1752,7 @@ static HRESULT ProcessApplyInitializeMessages(
1752 HRESULT hrBA = S_OK;
1753
1754 // Process the message.
1755 - switch (pMsg->dwMessage)
1755 + switch (pMsg->dwMessageType)
1756 {
1757 case BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE_PAUSE_AU_BEGIN:
1758 pContext->fPauseCompleteNeeded = TRUE;
@@ -1801,7 +1801,7 @@ LExit:
1801 }
1802
1803 static HRESULT ProcessBurnCacheMessages(
1804 - __in BURN_PIPE_MESSAGE* pMsg,
1804 + __in PIPE_MESSAGE* pMsg,
1805 __in LPVOID pvContext,
1806 __out DWORD* pdwResult
1807 )
@@ -1813,7 +1813,7 @@ static HRESULT ProcessBurnCacheMessages(
1813 BOOL fProgressRoutine = FALSE;
1814
1815 // Process the message.
1816 - switch (pMsg->dwMessage)
1816 + switch (pMsg->dwMessageType)
1817 {
1818 case BURN_ELEVATION_MESSAGE_TYPE_BURN_CACHE_BEGIN:
1819 // read message parameters
@@ -1872,7 +1872,7 @@ LExit:
1872 }
1873
1874 static HRESULT ProcessGenericExecuteMessages(
1875 - __in BURN_PIPE_MESSAGE* pMsg,
1875 + __in PIPE_MESSAGE* pMsg,
1876 __in LPVOID pvContext,
1877 __out DWORD* pdwResult
1878 )
@@ -1885,7 +1885,7 @@ static HRESULT ProcessGenericExecuteMessages(
1885 LPWSTR* rgwzFiles = NULL;
1886 GENERIC_EXECUTE_MESSAGE message = { };
1887
1888 - if (BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE == pMsg->dwMessage)
1888 + if (BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE == pMsg->dwMessageType)
1889 {
1890 hr = ProcessExecuteActionCompleteMessage((BYTE*)pMsg->pvData, pMsg->cbData, &pContext->restart, pdwResult);
1891 ExitOnFailure(hr, "Failed to process BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE message.");
@@ -1897,7 +1897,7 @@ static HRESULT ProcessGenericExecuteMessages(
1897 ExitOnFailure(hr, "Failed to allowed results.");
1898
1899 // Process the message.
1900 - switch (pMsg->dwMessage)
1900 + switch (pMsg->dwMessageType)
1901 {
1902 case BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_PROGRESS:
1903 message.type = GENERIC_EXECUTE_MESSAGE_PROGRESS;
@@ -1979,7 +1979,7 @@ LExit:
1979 }
1980
1981 static HRESULT ProcessMsiPackageMessages(
1982 - __in BURN_PIPE_MESSAGE* pMsg,
1982 + __in PIPE_MESSAGE* pMsg,
1983 __in_opt LPVOID pvContext,
1984 __out DWORD* pdwResult
1985 )
@@ -1993,7 +1993,7 @@ static HRESULT ProcessMsiPackageMessages(
1993 LPWSTR sczMessage = NULL;
1994 BOOL fRestartManager = FALSE;
1995
1996 - if (BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE == pMsg->dwMessage)
1996 + if (BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE == pMsg->dwMessageType)
1997 {
1998 hr = ProcessExecuteActionCompleteMessage((BYTE*)pMsg->pvData, pMsg->cbData, &pContext->restart, pdwResult);
1999 ExitOnFailure(hr, "Failed to process BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE message.");
@@ -2024,7 +2024,7 @@ static HRESULT ProcessMsiPackageMessages(
2024 ExitOnFailure(hr, "Failed to read UI flags.");
2025
2026 // Process the rest of the message.
2027 - switch (pMsg->dwMessage)
2027 + switch (pMsg->dwMessageType)
2028 {
2029 case BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_PROGRESS:
2030 // read message parameters
@@ -2093,7 +2093,7 @@ LExit:
2093 }
2094
2095 static HRESULT ProcessLaunchApprovedExeMessages(
2096 - __in BURN_PIPE_MESSAGE* pMsg,
2096 + __in PIPE_MESSAGE* pMsg,
2097 __in_opt LPVOID pvContext,
2098 __out DWORD* pdwResult
2099 )
@@ -2104,7 +2104,7 @@ static HRESULT ProcessLaunchApprovedExeMessages(
2104 DWORD dwProcessId = 0;
2105
2106 // Process the message.
2107 - switch (pMsg->dwMessage)
2107 + switch (pMsg->dwMessageType)
2108 {
2109 case BURN_ELEVATION_MESSAGE_TYPE_LAUNCH_APPROVED_EXE_PROCESSID:
2110 // read message parameters
@@ -2126,7 +2126,7 @@ LExit:
2126 }
2127
2128 static HRESULT ProcessProgressRoutineMessage(
2129 - __in BURN_PIPE_MESSAGE* pMsg,
2129 + __in PIPE_MESSAGE* pMsg,
2130 __in LPPROGRESS_ROUTINE pfnProgress,
2131 __in LPVOID pvContext,
2132 __out DWORD* pdwResult
@@ -2156,7 +2156,7 @@ LExit:
2156 }
2157
2158 static HRESULT ProcessElevatedChildMessage(
2159 - __in BURN_PIPE_MESSAGE* pMsg,
2159 + __in PIPE_MESSAGE* pMsg,
2160 __in_opt LPVOID pvContext,
2161 __out DWORD* pdwResult
2162 )
@@ -2167,7 +2167,7 @@ static HRESULT ProcessElevatedChildMessage(
2167 BOOTSTRAPPER_APPLY_RESTART restart = BOOTSTRAPPER_APPLY_RESTART_NONE;
2168 BOOL fSendRestart = FALSE;
2169
2170 - switch (pMsg->dwMessage)
2170 + switch (pMsg->dwMessageType)
2171 {
2172 case BURN_ELEVATION_MESSAGE_TYPE_BEGIN_MSI_TRANSACTION:
2173 hrResult = OnMsiBeginTransaction(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
@@ -2263,7 +2263,7 @@ static HRESULT ProcessElevatedChildMessage(
2263 break;
2264
2265 default:
2266 - ExitWithRootFailure(hr, E_INVALIDARG, "Unexpected elevated message sent to child process, msg: %u", pMsg->dwMessage);
2266 + ExitWithRootFailure(hr, E_INVALIDARG, "Unexpected elevated message sent to child process, msg: %u", pMsg->dwMessageType);
2267 }
2268
2269 if (fSendRestart)
@@ -2279,7 +2279,7 @@ LExit:
2279 }
2280
2281 static HRESULT ProcessElevatedChildCacheMessage(
2282 - __in BURN_PIPE_MESSAGE* pMsg,
2282 + __in PIPE_MESSAGE* pMsg,
2283 __in_opt LPVOID pvContext,
2284 __out DWORD* pdwResult
2285 )
@@ -2288,7 +2288,7 @@ static HRESULT ProcessElevatedChildCacheMessage(
2288 BURN_ELEVATION_CHILD_MESSAGE_CONTEXT* pContext = static_cast<BURN_ELEVATION_CHILD_MESSAGE_CONTEXT*>(pvContext);
2289 HRESULT hrResult = S_OK;
2290
2291 - switch (pMsg->dwMessage)
2291 + switch (pMsg->dwMessageType)
2292 {
2293 case BURN_ELEVATION_MESSAGE_TYPE_CACHE_PREPARE_PACKAGE:
2294 hrResult = OnCachePreparePackage(pContext->pCache, pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
@@ -2313,7 +2313,7 @@ static HRESULT ProcessElevatedChildCacheMessage(
2313
2314 default:
2315 hr = E_INVALIDARG;
2316 - ExitOnRootFailure(hr, "Unexpected elevated cache message sent to child process, msg: %u", pMsg->dwMessage);
2316 + ExitOnRootFailure(hr, "Unexpected elevated cache message sent to child process, msg: %u", pMsg->dwMessageType);
2317 }
2318
2319 *pdwResult = (DWORD)hrResult;
src/burn/engine/embedded.cpp
+5 -5
@@ -14,7 +14,7 @@ struct BURN_EMBEDDED_CALLBACK_CONTEXT
14 // internal function declarations
15
16 static HRESULT ProcessEmbeddedMessages(
17 - __in BURN_PIPE_MESSAGE* pMsg,
17 + __in PIPE_MESSAGE* pMsg,
18 __in_opt LPVOID pvContext,
19 __out DWORD* pdwResult
20 );
@@ -36,7 +36,7 @@ static HRESULT OnEmbeddedProgress(
36 // function definitions
37
38 /*******************************************************************
39 - EmbeddedRunBundle -
39 + EmbeddedRunBundle -
40
41 *******************************************************************/
42 extern "C" HRESULT EmbeddedRunBundle(
@@ -108,7 +108,7 @@ LExit:
108 // internal function definitions
109
110 static HRESULT ProcessEmbeddedMessages(
111 - __in BURN_PIPE_MESSAGE* pMsg,
111 + __in PIPE_MESSAGE* pMsg,
112 __in_opt LPVOID pvContext,
113 __out DWORD* pdwResult
114 )
@@ -118,7 +118,7 @@ static HRESULT ProcessEmbeddedMessages(
118 DWORD dwResult = 0;
119
120 // Process the message.
121 - switch (pMsg->dwMessage)
121 + switch (pMsg->dwMessageType)
122 {
123 case BURN_EMBEDDED_MESSAGE_TYPE_ERROR:
124 hr = OnEmbeddedErrorMessage(pContext->pfnGenericMessageHandler, pContext->pvContext, static_cast<BYTE*>(pMsg->pvData), pMsg->cbData, &dwResult);
@@ -131,7 +131,7 @@ static HRESULT ProcessEmbeddedMessages(
131 break;
132
133 default:
134 - LogStringLine(REPORT_DEBUG, "Unexpected embedded message received from child process, msg: %u", pMsg->dwMessage);
134 + LogStringLine(REPORT_DEBUG, "Unexpected embedded message received from child process, msg: %u", pMsg->dwMessageType);
135 dwResult = (DWORD)E_NOTIMPL;
136 }
137
src/burn/engine/externalengine.cpp
+2 -2
@@ -9,7 +9,7 @@ static HRESULT CopyStringToExternal(
9 __inout SIZE_T* pcchBuffer
10 );
11 static HRESULT ProcessUnknownEmbeddedMessages(
12 - __in BURN_PIPE_MESSAGE* /*pMsg*/,
12 + __in PIPE_MESSAGE* /*pMsg*/,
13 __in_opt LPVOID /*pvContext*/,
14 __out DWORD* pdwResult
15 );
@@ -877,7 +877,7 @@ static HRESULT CopyStringToExternal(
877 }
878
879 static HRESULT ProcessUnknownEmbeddedMessages(
880 - __in BURN_PIPE_MESSAGE* /*pMsg*/,
880 + __in PIPE_MESSAGE* /*pMsg*/,
881 __in_opt LPVOID /*pvContext*/,
882 __out DWORD* pdwResult
883 )
src/burn/engine/precomp.h
+1
@@ -38,6 +38,7 @@
38 #include <memutil.h>
39 #include <osutil.h>
40 #include <pathutil.h>
41 +#include <pipeutil.h>
42 #include <polcutil.h>
43 #include <procutil.h>
44 #include <queutil.h>
src/burn/test/BurnUnitTest/ElevationTest.cpp
+8 -8
@@ -16,12 +16,12 @@ static DWORD CALLBACK ElevateTest_ThreadProc(
16 __in LPVOID lpThreadParameter
17 );
18 static HRESULT ProcessParentMessages(
19 - __in BURN_PIPE_MESSAGE* pMsg,
19 + __in PIPE_MESSAGE* pMsg,
20 __in_opt LPVOID pvContext,
21 __out DWORD* pdwResult
22 );
23 static HRESULT ProcessChildMessages(
24 - __in BURN_PIPE_MESSAGE* pMsg,
24 + __in PIPE_MESSAGE* pMsg,
25 __in_opt LPVOID pvContext,
26 __out DWORD* pdwResult
27 );
@@ -155,7 +155,7 @@ LExit:
155 }
156
157 static HRESULT ProcessParentMessages(
158 - __in BURN_PIPE_MESSAGE* pMsg,
158 + __in PIPE_MESSAGE* pMsg,
159 __in_opt LPVOID /*pvContext*/,
160 __out DWORD* pdwResult
161 )
@@ -164,7 +164,7 @@ static HRESULT ProcessParentMessages(
164 HRESULT hrResult = E_INVALIDDATA;
165
166 // Process the message.
167 - switch (pMsg->dwMessage)
167 + switch (pMsg->dwMessageType)
168 {
169 case TEST_CHILD_SENT_MESSAGE_ID:
170 if (sizeof(TEST_MESSAGE_DATA) == pMsg->cbData && 0 == memcmp(TEST_MESSAGE_DATA, pMsg->pvData, sizeof(TEST_MESSAGE_DATA)))
@@ -175,7 +175,7 @@ static HRESULT ProcessParentMessages(
175
176 default:
177 hr = E_INVALIDARG;
178 - ExitOnRootFailure(hr, "Unexpected elevated message sent to parent process, msg: %u", pMsg->dwMessage);
178 + ExitOnRootFailure(hr, "Unexpected elevated message sent to parent process, msg: %u", pMsg->dwMessageType);
179 }
180
181 *pdwResult = static_cast<DWORD>(hrResult);
@@ -185,7 +185,7 @@ LExit:
185 }
186
187 static HRESULT ProcessChildMessages(
188 - __in BURN_PIPE_MESSAGE* pMsg,
188 + __in PIPE_MESSAGE* pMsg,
189 __in_opt LPVOID pvContext,
190 __out DWORD* pdwResult
191 )
@@ -195,7 +195,7 @@ static HRESULT ProcessChildMessages(
195 DWORD dwResult = 0;
196
197 // Process the message.
198 - switch (pMsg->dwMessage)
198 + switch (pMsg->dwMessageType)
199 {
200 case TEST_PARENT_SENT_MESSAGE_ID:
201 // send test message
@@ -205,7 +205,7 @@ static HRESULT ProcessChildMessages(
205
206 default:
207 hr = E_INVALIDARG;
208 - ExitOnRootFailure(hr, "Unexpected elevated message sent to child process, msg: %u", pMsg->dwMessage);
208 + ExitOnRootFailure(hr, "Unexpected elevated message sent to child process, msg: %u", pMsg->dwMessageType);
209 }
210
211 *pdwResult = dwResult;
src/burn/test/BurnUnitTest/precomp.h
+1
@@ -24,6 +24,7 @@
24 #include <logutil.h>
25 #include <memutil.h>
26 #include <pathutil.h>
27 +#include <pipeutil.h>
28 #include <polcutil.h>
29 #include <regutil.h>
30 #include <resrutil.h>