- Add some definitions to NDK

- Prettify/document CreatePipe and correct some mistakes, use 120 second timeout like on NT and send FILE_PIPE flags instead of weird BOOLEAN values from hell.

svn path=/trunk/; revision=19065
This commit is contained in:
Alex Ionescu 2005-11-08 20:53:53 +00:00
parent 7f3dd627ae
commit 4e84f04716
3 changed files with 97 additions and 73 deletions

View file

@ -37,6 +37,7 @@ extern POBJECT_TYPE NTSYSAPI IoDriverObjectType;
#define FILE_DOES_NOT_EXIST 0x00000005 #define FILE_DOES_NOT_EXIST 0x00000005
/* Pipe Flags */ /* Pipe Flags */
#define FILE_PIPE_BYTE_STREAM_TYPE 0x00000000
#define FILE_PIPE_BYTE_STREAM_MODE 0x00000000 #define FILE_PIPE_BYTE_STREAM_MODE 0x00000000
#define FILE_PIPE_MESSAGE_MODE 0x00000001 #define FILE_PIPE_MESSAGE_MODE 0x00000001
#define FILE_PIPE_QUEUE_OPERATION 0x00000000 #define FILE_PIPE_QUEUE_OPERATION 0x00000000

View file

@ -1181,6 +1181,15 @@ RtlIsTextUnicode(
ULONG *Flags ULONG *Flags
); );
NTSYSAPI
BOOLEAN
NTAPI
RtlPrefixString(
PCANSI_STRING String1,
PCANSI_STRING String2,
BOOLEAN CaseInsensitive
);
NTSYSAPI NTSYSAPI
BOOLEAN BOOLEAN
NTAPI NTAPI

View file

@ -17,14 +17,16 @@
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
ULONG ProcessPipeId = 0; LONG ProcessPipeId = 0;
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
/* /*
* @implemented * @implemented
*/ */
BOOL STDCALL CreatePipe(PHANDLE hReadPipe, BOOL
STDCALL
CreatePipe(PHANDLE hReadPipe,
PHANDLE hWritePipe, PHANDLE hWritePipe,
LPSECURITY_ATTRIBUTES lpPipeAttributes, LPSECURITY_ATTRIBUTES lpPipeAttributes,
DWORD nSize) DWORD nSize)
@ -37,38 +39,47 @@ BOOL STDCALL CreatePipe(PHANDLE hReadPipe,
NTSTATUS Status; NTSTATUS Status;
HANDLE ReadPipeHandle; HANDLE ReadPipeHandle;
HANDLE WritePipeHandle; HANDLE WritePipeHandle;
ULONG PipeId; LONG PipeId;
ULONG Attributes; ULONG Attributes;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL; PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
DefaultTimeout.QuadPart = -300000000; /* 30 seconds */ /* Set the timeout to 120 seconds */
DefaultTimeout.QuadPart = -1200000000;
PipeId = (ULONG)InterlockedIncrement((LONG*)&ProcessPipeId); /* Use default buffer size if desired */
if (!nSize) nSize = 0x1000;
/* Increase the Pipe ID */
PipeId = InterlockedIncrement(&ProcessPipeId);
/* Create the pipe name */
swprintf(Buffer, swprintf(Buffer,
L"\\\\.\\PIPE\\Win32Pipes.%08x.%08x", L"\\\\.\\PIPE\\Win32Pipes.%08x.%08x",
NtCurrentTeb()->Cid.UniqueProcess, NtCurrentTeb()->Cid.UniqueProcess,
PipeId); PipeId);
RtlInitUnicodeString (&PipeName, RtlInitUnicodeString(&PipeName, Buffer);
Buffer);
/* Always use case insensitive */
Attributes = OBJ_CASE_INSENSITIVE; Attributes = OBJ_CASE_INSENSITIVE;
/* Check if we got attributes */
if (lpPipeAttributes) if (lpPipeAttributes)
{ {
/* Use the attributes' SD instead */
SecurityDescriptor = lpPipeAttributes->lpSecurityDescriptor; SecurityDescriptor = lpPipeAttributes->lpSecurityDescriptor;
if (lpPipeAttributes->bInheritHandle)
Attributes |= OBJ_INHERIT; /* Set OBJ_INHERIT if requested */
if (lpPipeAttributes->bInheritHandle) Attributes |= OBJ_INHERIT;
} }
/* use default buffer size if desired */ /* Initialize the attributes */
if (nSize == 0)
nSize = 0x1000;
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&PipeName, &PipeName,
Attributes, Attributes,
NULL, NULL,
SecurityDescriptor); SecurityDescriptor);
/* Create the named pipe */
Status = NtCreateNamedPipeFile(&ReadPipeHandle, Status = NtCreateNamedPipeFile(&ReadPipeHandle,
FILE_GENERIC_READ |FILE_WRITE_ATTRIBUTES | SYNCHRONIZE, FILE_GENERIC_READ |FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
&ObjectAttributes, &ObjectAttributes,
@ -76,35 +87,38 @@ BOOL STDCALL CreatePipe(PHANDLE hReadPipe,
FILE_SHARE_WRITE, FILE_SHARE_WRITE,
FILE_CREATE, FILE_CREATE,
FILE_SYNCHRONOUS_IO_NONALERT, FILE_SYNCHRONOUS_IO_NONALERT,
FALSE, FILE_PIPE_BYTE_STREAM_TYPE,
FALSE, FILE_PIPE_BYTE_STREAM_MODE,
FALSE, FILE_PIPE_BYTE_STREAM_MODE,
1, 1,
nSize, nSize,
nSize, nSize,
&DefaultTimeout); &DefaultTimeout);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* Convert error and fail */
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
return FALSE; return FALSE;
} }
/* Now try opening it for write access */
Status = NtOpenFile(&WritePipeHandle, Status = NtOpenFile(&WritePipeHandle,
FILE_GENERIC_WRITE | SYNCHRONIZE, FILE_GENERIC_WRITE | SYNCHRONIZE,
&ObjectAttributes, &ObjectAttributes,
&StatusBlock, &StatusBlock,
FILE_SHARE_READ, FILE_SHARE_READ,
FILE_SYNCHRONOUS_IO_NONALERT); FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* Convert error and fail */
NtClose(ReadPipeHandle); NtClose(ReadPipeHandle);
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
return FALSE; return FALSE;
} }
/* Return both handles */
*hReadPipe = ReadPipeHandle; *hReadPipe = ReadPipeHandle;
*hWritePipe = WritePipeHandle; *hWritePipe = WritePipeHandle;
return TRUE; return TRUE;
} }