2024-04-12 10:36:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995 - 1997 Microsoft Corporation.
|
|
|
|
* Module Name:
|
|
|
|
* CreatePipeEx.NT.cpp
|
|
|
|
* Abstract:
|
|
|
|
* CreatePipe-like function that lets one or both handles be overlapped
|
|
|
|
* Author:
|
|
|
|
* Dave Hart Summer 1997
|
|
|
|
* Revision History:
|
|
|
|
* J Reece Wilson 2022: Updated default size to match Linux's 16 page assumption
|
|
|
|
* Renamed MyCreatePipeEx to CreatePipeEx
|
|
|
|
* Now using Au atomics
|
|
|
|
* Added second parameter check
|
|
|
|
* J Reece Wilson 202[2/3]: Rewritten in C++
|
|
|
|
* J Reece Wilson 2024: Widening
|
|
|
|
*
|
|
|
|
* License:
|
|
|
|
* MICROSOFT LIMITED PUBLIC LICENSE version 1.1
|
|
|
|
*/
|
2022-05-05 10:26:21 +00:00
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
|
|
|
|
static AuUInt32 gPipeSerialNumber;
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
CreatePipeEx(
|
|
|
|
OUT LPHANDLE lpReadPipe,
|
|
|
|
OUT LPHANDLE lpWritePipe,
|
|
|
|
IN LPSECURITY_ATTRIBUTES lpPipeAttributes,
|
|
|
|
IN DWORD nSize,
|
|
|
|
DWORD dwReadMode,
|
|
|
|
DWORD dwWriteMode
|
|
|
|
)
|
|
|
|
{
|
|
|
|
HANDLE ReadPipeHandle, WritePipeHandle;
|
|
|
|
DWORD dwError;
|
2024-04-09 22:39:00 +00:00
|
|
|
wchar_t sPipeNameBuffer[MAX_PATH];
|
2022-05-05 10:26:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Only one valid OpenMode flag - FILE_FLAG_OVERLAPPED
|
|
|
|
//
|
|
|
|
|
|
|
|
if ((dwReadMode | dwWriteMode) & (~FILE_FLAG_OVERLAPPED))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check output arguments are non-null
|
|
|
|
//
|
|
|
|
|
|
|
|
if (!lpReadPipe || !lpWritePipe)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set the default pipe size
|
|
|
|
//
|
|
|
|
|
|
|
|
if (nSize == 0)
|
|
|
|
{
|
|
|
|
nSize = 16 * AuHwInfo::GetPageSize();
|
|
|
|
}
|
|
|
|
|
2024-04-09 22:39:00 +00:00
|
|
|
swprintf(sPipeNameBuffer,
|
|
|
|
L"\\\\.\\Pipe\\AuroraProcessCStandardStream.%08x.%08x",
|
2022-05-05 10:26:21 +00:00
|
|
|
GetCurrentProcessId(),
|
2024-04-12 10:36:32 +00:00
|
|
|
AuAtomicAdd(&gPipeSerialNumber, 1u));
|
2022-05-05 10:26:21 +00:00
|
|
|
|
2024-04-12 10:36:32 +00:00
|
|
|
ReadPipeHandle = CreateNamedPipeW(sPipeNameBuffer,
|
2024-04-09 22:39:00 +00:00
|
|
|
PIPE_ACCESS_INBOUND | dwReadMode,
|
|
|
|
PIPE_TYPE_BYTE | PIPE_WAIT,
|
|
|
|
1, // Number of pipes
|
|
|
|
nSize, // Out buffer size
|
|
|
|
nSize, // In buffer size
|
|
|
|
120 * 1000, // Timeout in ms
|
2024-04-12 10:36:32 +00:00
|
|
|
lpPipeAttributes);
|
2022-05-05 10:26:21 +00:00
|
|
|
|
|
|
|
if (!ReadPipeHandle)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2024-04-09 22:39:00 +00:00
|
|
|
WritePipeHandle = Aurora::Win32Open2(sPipeNameBuffer,
|
|
|
|
GENERIC_WRITE,
|
|
|
|
0, // No sharing
|
|
|
|
lpPipeAttributes,
|
|
|
|
OPEN_EXISTING,
|
2024-04-12 10:36:32 +00:00
|
|
|
dwWriteMode,
|
|
|
|
NULL);
|
2022-05-05 10:26:21 +00:00
|
|
|
|
|
|
|
if (INVALID_HANDLE_VALUE == WritePipeHandle)
|
|
|
|
{
|
|
|
|
dwError = GetLastError();
|
|
|
|
CloseHandle(ReadPipeHandle);
|
|
|
|
SetLastError(dwError);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lpReadPipe = ReadPipeHandle;
|
|
|
|
*lpWritePipe = WritePipeHandle;
|
|
|
|
return TRUE;
|
|
|
|
}
|