AuroraRuntime/Source/Processes/AuCreatePipeEx.NT.cpp

106 lines
3.0 KiB
C++
Raw Permalink Normal View History

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
*/
#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;
wchar_t sPipeNameBuffer[MAX_PATH];
//
// 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();
}
swprintf(sPipeNameBuffer,
L"\\\\.\\Pipe\\AuroraProcessCStandardStream.%08x.%08x",
GetCurrentProcessId(),
2024-04-12 10:36:32 +00:00
AuAtomicAdd(&gPipeSerialNumber, 1u));
2024-04-12 10:36:32 +00:00
ReadPipeHandle = CreateNamedPipeW(sPipeNameBuffer,
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);
if (!ReadPipeHandle)
{
return FALSE;
}
WritePipeHandle = Aurora::Win32Open2(sPipeNameBuffer,
GENERIC_WRITE,
0, // No sharing
lpPipeAttributes,
OPEN_EXISTING,
2024-04-12 10:36:32 +00:00
dwWriteMode,
NULL);
if (INVALID_HANDLE_VALUE == WritePipeHandle)
{
dwError = GetLastError();
CloseHandle(ReadPipeHandle);
SetLastError(dwError);
return FALSE;
}
*lpReadPipe = ReadPipeHandle;
*lpWritePipe = WritePipeHandle;
return TRUE;
}