AuroraRuntime/Source/Processes/CreatePipeEx.NT.cpp
Reece 0a38ffacfa [+] NT: IProcess::AsLoopSource()
[*] NT: Bug fix: our side of the process streams were not marked as FILE_FLAG_OVERLAPPED
[+] CreatePipeEx.NT.cpp
2022-05-05 11:26:21 +01:00

122 lines
3.3 KiB
C++

/******************************************************************************\
* This is a part of the Microsoft Source Code Samples.
* Copyright 1995 - 1997 Microsoft Corporation.
* All rights reserved.
* This source code is only intended as a supplement to
* Microsoft Development Tools and/or WinHelp documentation.
* See these sources for detailed information regarding the
* Microsoft samples programs.
\******************************************************************************/
#include <Source/RuntimeInternal.hpp>
/*++
Copyright (c) 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
--*/
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;
char PipeNameBuffer[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 timeout to 120 seconds
//
//
// Set the default pipe size
//
if (nSize == 0)
{
nSize = 16 * AuHwInfo::GetPageSize();
}
sprintf(PipeNameBuffer,
"\\\\.\\Pipe\\AuroraProcessCStandardStream.%08x.%08x",
GetCurrentProcessId(),
AuAtomicAdd(&gPipeSerialNumber, 1u)
);
ReadPipeHandle = CreateNamedPipeA(
PipeNameBuffer,
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
lpPipeAttributes
);
if (!ReadPipeHandle)
{
return FALSE;
}
WritePipeHandle = CreateFileA(
PipeNameBuffer,
GENERIC_WRITE,
0, // No sharing
lpPipeAttributes,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | dwWriteMode,
NULL // Template file
);
if (INVALID_HANDLE_VALUE == WritePipeHandle)
{
dwError = GetLastError();
CloseHandle(ReadPipeHandle);
SetLastError(dwError);
return FALSE;
}
*lpReadPipe = ReadPipeHandle;
*lpWritePipe = WritePipeHandle;
return TRUE;
}