ReactOS 0.4.15-dev-7674-gc0b4db1
NpfsHelpers.c File Reference
#include <kmt_test.h>
#include "npfs.h"
Include dependency graph for NpfsHelpers.c:

Go to the source code of this file.

Macros

#define ok_eq_print_(value, expected, spec, FileAndLine)    KmtOk((value) == (expected), FileAndLine, #value " = " spec ", expected " spec "\n", value, expected)
 
#define ok_eq_ulong_(value, expected)   ok_eq_print_(value, expected, "%lu", FileAndLine)
 
#define ok_eq_ulonglong_(value, expected)   ok_eq_print_(value, expected, "%I64u", FileAndLine)
 
#define ok_eq_ulongptr_(value, expected)   ok_eq_print_(value, (ULONG_PTR)(expected), "%lu", FileAndLine)
 
#define ok_eq_hex_(value, expected)   ok_eq_print_(value, expected, "0x%08lx", FileAndLine)
 

Functions

NTSTATUS NpCreatePipeEx (OUT PHANDLE ServerHandle, IN PCWSTR PipePath, IN ULONG ReadMode, IN ULONG CompletionMode, IN ULONG NamedPipeType, IN ULONG ShareAccess, IN ULONG MaximumInstances, IN ULONG InboundQuota, IN ULONG OutboundQuota, IN ACCESS_MASK DesiredAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PLARGE_INTEGER DefaultTimeout OPTIONAL)
 
NTSTATUS NpCreatePipe (OUT PHANDLE ServerHandle, PCWSTR PipePath, ULONG ReadMode, ULONG CompletionMode, ULONG NamedPipeType, ULONG NamedPipeConfiguration, ULONG MaximumInstances, ULONG InboundQuota, ULONG OutboundQuota)
 
NTSTATUS NpOpenPipeEx (OUT PHANDLE ClientHandle, IN PCWSTR PipePath, IN ACCESS_MASK DesiredAccess, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions)
 
NTSTATUS NpOpenPipe (OUT PHANDLE ClientHandle, IN PCWSTR PipePath, IN ULONG NamedPipeConfiguration)
 
NTSTATUS NpControlPipe (IN HANDLE ServerHandle, IN ULONG FsControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength)
 
NTSTATUS NpWaitPipe (IN PCWSTR PipeName, IN PLARGE_INTEGER Timeout)
 
NTSTATUS NpReadPipe (IN HANDLE PipeHandle, OUT PVOID Buffer, IN ULONG BufferSize, OUT PULONG_PTR BytesRead)
 
NTSTATUS NpWritePipe (IN HANDLE PipeHandle, IN const VOID *Buffer, IN ULONG BufferSize, OUT PULONG_PTR BytesWritten)
 
static BOOLEAN CheckBuffer (PVOID Buffer, SIZE_T Size, UCHAR Value)
 
VOID NpCheckServerPipe_ (IN HANDLE ServerHandle, IN ULONG ReadMode, IN ULONG CompletionMode, IN ULONG NamedPipeType, IN ULONG NamedPipeConfiguration, IN ULONG MaximumInstances, IN ULONG CurrentInstances, IN ULONG InboundQuota, IN ULONG ReadDataAvailable, IN ULONG OutboundQuota, IN ULONG WriteQuotaAvailable, IN ULONG NamedPipeState, IN PCSTR FileAndLine)
 
VOID NpCheckClientPipe_ (IN HANDLE ClientHandle, IN ULONG ReadMode, IN ULONG CompletionMode, IN ULONG NamedPipeType, IN ULONG NamedPipeConfiguration, IN ULONG MaximumInstances, IN ULONG CurrentInstances, IN ULONG InboundQuota, IN ULONG ReadDataAvailable, IN ULONG OutboundQuota, IN ULONG WriteQuotaAvailable, IN ULONG NamedPipeState, IN PCSTR FileAndLine)
 
VOID NpQueryPipe_ (IN HANDLE PipeHandle, IN NTSTATUS ExpectedStatus, IN PCSTR FileAndLine)
 
static VOID NTAPI PipeWorkerThread (IN PVOID ThreadContext)
 
VOID StartWorkerThread (OUT PTHREAD_CONTEXT Context)
 
VOID FinishWorkerThread (IN PTHREAD_CONTEXT Context)
 
BOOLEAN WaitForWork (IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
 
BOOLEAN TriggerWork (IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
 

Variables

static KSTART_ROUTINE PipeWorkerThread
 

Macro Definition Documentation

◆ ok_eq_hex_

#define ok_eq_hex_ (   value,
  expected 
)    ok_eq_print_(value, expected, "0x%08lx", FileAndLine)

Definition at line 443 of file NpfsHelpers.c.

◆ ok_eq_print_

#define ok_eq_print_ (   value,
  expected,
  spec,
  FileAndLine 
)     KmtOk((value) == (expected), FileAndLine, #value " = " spec ", expected " spec "\n", value, expected)

Definition at line 434 of file NpfsHelpers.c.

◆ ok_eq_ulong_

#define ok_eq_ulong_ (   value,
  expected 
)    ok_eq_print_(value, expected, "%lu", FileAndLine)

Definition at line 436 of file NpfsHelpers.c.

◆ ok_eq_ulonglong_

#define ok_eq_ulonglong_ (   value,
  expected 
)    ok_eq_print_(value, expected, "%I64u", FileAndLine)

Definition at line 437 of file NpfsHelpers.c.

◆ ok_eq_ulongptr_

#define ok_eq_ulongptr_ (   value,
  expected 
)    ok_eq_print_(value, (ULONG_PTR)(expected), "%lu", FileAndLine)

Definition at line 439 of file NpfsHelpers.c.

Function Documentation

◆ CheckBuffer()

static BOOLEAN CheckBuffer ( PVOID  Buffer,
SIZE_T  Size,
UCHAR  Value 
)
static

Definition at line 417 of file NpfsHelpers.c.

421{
422 PUCHAR Array = Buffer;
423 SIZE_T i;
424
425 for (i = 0; i < Size; i++)
426 if (Array[i] != Value)
427 {
428 trace("Expected %x, found %x at offset %lu\n", Value, Array[i], (ULONG)i);
429 return FALSE;
430 }
431 return TRUE;
432}
#define trace
Definition: atltest.h:70
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG_PTR SIZE_T
Definition: typedefs.h:80
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by NpQueryPipe_().

◆ FinishWorkerThread()

VOID FinishWorkerThread ( IN PTHREAD_CONTEXT  Context)

Definition at line 685 of file NpfsHelpers.c.

687{
688 KmtFinishThread(Context->Thread, &Context->ThreadDoneEvent);
689}
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)

Referenced by TestConnect(), and TestReadWrite().

◆ NpCheckClientPipe_()

VOID NpCheckClientPipe_ ( IN HANDLE  ClientHandle,
IN ULONG  ReadMode,
IN ULONG  CompletionMode,
IN ULONG  NamedPipeType,
IN ULONG  NamedPipeConfiguration,
IN ULONG  MaximumInstances,
IN ULONG  CurrentInstances,
IN ULONG  InboundQuota,
IN ULONG  ReadDataAvailable,
IN ULONG  OutboundQuota,
IN ULONG  WriteQuotaAvailable,
IN ULONG  NamedPipeState,
IN PCSTR  FileAndLine 
)

Definition at line 520 of file NpfsHelpers.c.

538{
542 FILE_PIPE_LOCAL_INFORMATION PipeLocalInfo;
543 FILE_PIPE_REMOTE_INFORMATION PipeRemoteInfo;
544
546 RtlFillMemory(&PipeInfo, sizeof(PipeInfo), 0x55);
547 Status = ZwQueryInformationFile(ClientHandle,
549 &PipeInfo,
550 sizeof(PipeInfo),
555 ok_eq_ulong_(PipeInfo.ReadMode, ReadMode);
556 ok_eq_ulong_(PipeInfo.CompletionMode, CompletionMode);
557
559 RtlFillMemory(&PipeLocalInfo, sizeof(PipeLocalInfo), 0x55);
560 Status = ZwQueryInformationFile(ClientHandle,
562 &PipeLocalInfo,
563 sizeof(PipeLocalInfo),
567 ok_eq_ulongptr_(IoStatusBlock.Information, sizeof(PipeLocalInfo));
568 ok_eq_ulong_(PipeLocalInfo.NamedPipeType, NamedPipeType);
569 ok_eq_ulong_(PipeLocalInfo.NamedPipeConfiguration, NamedPipeConfiguration);
570 ok_eq_ulong_(PipeLocalInfo.MaximumInstances, MaximumInstances);
571 ok_eq_ulong_(PipeLocalInfo.CurrentInstances, CurrentInstances);
572 ok_eq_ulong_(PipeLocalInfo.InboundQuota, InboundQuota);
573 ok_eq_ulong_(PipeLocalInfo.ReadDataAvailable, ReadDataAvailable);
574 ok_eq_ulong_(PipeLocalInfo.OutboundQuota, OutboundQuota);
575 ok_eq_ulong_(PipeLocalInfo.WriteQuotaAvailable, WriteQuotaAvailable);
576 ok_eq_ulong_(PipeLocalInfo.NamedPipeState, NamedPipeState);
578
580 RtlFillMemory(&PipeRemoteInfo, sizeof(PipeRemoteInfo), 0x55);
581 Status = ZwQueryInformationFile(ClientHandle,
583 &PipeRemoteInfo,
584 sizeof(PipeRemoteInfo),
590 ok_eq_ulong_(PipeRemoteInfo.MaximumCollectionCount, 0x55555555UL);
591}
#define ok_eq_ulongptr_(value, expected)
Definition: NpfsHelpers.c:439
#define ok_eq_hex_(value, expected)
Definition: NpfsHelpers.c:443
#define ok_eq_ulonglong_(value, expected)
Definition: NpfsHelpers.c:437
#define ok_eq_ulong_(value, expected)
Definition: NpfsHelpers.c:436
LONG NTSTATUS
Definition: precomp.h:26
@ FilePipeLocalInformation
Definition: from_kernel.h:85
@ FilePipeInformation
Definition: from_kernel.h:84
Status
Definition: gdiplustypes.h:25
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
#define ULL(a, b)
Definition: format_msg.c:27
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_PIPE_CLIENT_END
Definition: iotypes.h:84
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:672
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG NamedPipeConfiguration
Definition: pipe.c:43
LARGE_INTEGER CollectDataTime
Definition: iotypes.h:5916
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_opt_ PWDF_USB_PIPE_INFORMATION PipeInfo
Definition: wdfusb.h:2543

◆ NpCheckServerPipe_()

VOID NpCheckServerPipe_ ( IN HANDLE  ServerHandle,
IN ULONG  ReadMode,
IN ULONG  CompletionMode,
IN ULONG  NamedPipeType,
IN ULONG  NamedPipeConfiguration,
IN ULONG  MaximumInstances,
IN ULONG  CurrentInstances,
IN ULONG  InboundQuota,
IN ULONG  ReadDataAvailable,
IN ULONG  OutboundQuota,
IN ULONG  WriteQuotaAvailable,
IN ULONG  NamedPipeState,
IN PCSTR  FileAndLine 
)

Definition at line 446 of file NpfsHelpers.c.

464{
468 FILE_PIPE_LOCAL_INFORMATION PipeLocalInfo;
469 FILE_PIPE_REMOTE_INFORMATION PipeRemoteInfo;
470
472 RtlFillMemory(&PipeInfo, sizeof(PipeInfo), 0x55);
473 Status = ZwQueryInformationFile(ServerHandle,
475 &PipeInfo,
476 sizeof(PipeInfo),
481 ok_eq_ulong_(PipeInfo.ReadMode, ReadMode);
482 ok_eq_ulong_(PipeInfo.CompletionMode, CompletionMode);
483
485 RtlFillMemory(&PipeLocalInfo, sizeof(PipeLocalInfo), 0x55);
486 Status = ZwQueryInformationFile(ServerHandle,
488 &PipeLocalInfo,
489 sizeof(PipeLocalInfo),
493 ok_eq_ulongptr_(IoStatusBlock.Information, sizeof(PipeLocalInfo));
494 ok_eq_ulong_(PipeLocalInfo.NamedPipeType, NamedPipeType);
495 ok_eq_ulong_(PipeLocalInfo.NamedPipeConfiguration, NamedPipeConfiguration);
496 ok_eq_ulong_(PipeLocalInfo.MaximumInstances, MaximumInstances);
497 ok_eq_ulong_(PipeLocalInfo.CurrentInstances, CurrentInstances);
498 ok_eq_ulong_(PipeLocalInfo.InboundQuota, InboundQuota);
499 ok_eq_ulong_(PipeLocalInfo.ReadDataAvailable, ReadDataAvailable);
500 ok_eq_ulong_(PipeLocalInfo.OutboundQuota, OutboundQuota);
501 ok_eq_ulong_(PipeLocalInfo.WriteQuotaAvailable, WriteQuotaAvailable);
502 ok_eq_ulong_(PipeLocalInfo.NamedPipeState, NamedPipeState);
504
506 RtlFillMemory(&PipeRemoteInfo, sizeof(PipeRemoteInfo), 0x55);
507 Status = ZwQueryInformationFile(ServerHandle,
509 &PipeRemoteInfo,
510 sizeof(PipeRemoteInfo),
516 ok_eq_ulong_(PipeRemoteInfo.MaximumCollectionCount, 0x55555555UL);
517}
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85

◆ NpControlPipe()

NTSTATUS NpControlPipe ( IN HANDLE  ServerHandle,
IN ULONG  FsControlCode,
IN PVOID  InputBuffer,
IN ULONG  InputBufferLength 
)

Definition at line 208 of file NpfsHelpers.c.

213{
216
218 Status = ZwFsControlFile(ServerHandle,
219 NULL,
220 NULL,
221 NULL,
226 NULL,
227 0);
228 if (Status == STATUS_PENDING)
229 {
230 Status = ZwWaitForSingleObject(ServerHandle,
231 FALSE,
232 NULL);
235 }
236 if (NT_SUCCESS(Status))
237 {
240 }
241 else
242 {
243 ok_eq_hex(IoStatusBlock.Status, 0x55555555UL);
244 ok_eq_ulongptr(IoStatusBlock.Information, 0x5555555555555555ULL);
245 }
246 return Status;
247}
#define ok_eq_hex(value, expected)
Definition: apitest.h:76
#define ok_eq_ulongptr(value, expected)
Definition: apitest.h:70
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG FsControlCode
Definition: fltkernel.h:1370
NTSYSAPI NTSTATUS NTAPI ZwFsControlFile(IN HANDLE DeviceHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferSize, OUT PVOID OutputBuffer, IN ULONG OutputBufferSize)
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:322
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953

Referenced by NpWaitPipe().

◆ NpCreatePipe()

NTSTATUS NpCreatePipe ( OUT PHANDLE  ServerHandle,
PCWSTR  PipePath,
ULONG  ReadMode,
ULONG  CompletionMode,
ULONG  NamedPipeType,
ULONG  NamedPipeConfiguration,
ULONG  MaximumInstances,
ULONG  InboundQuota,
ULONG  OutboundQuota 
)

Definition at line 86 of file NpfsHelpers.c.

96{
98 LARGE_INTEGER DefaultTimeout;
99
100 if (NamedPipeConfiguration == FILE_PIPE_INBOUND)
102 else if (NamedPipeConfiguration == FILE_PIPE_OUTBOUND)
104 else if (NamedPipeConfiguration == FILE_PIPE_FULL_DUPLEX)
106 else
107 {
108 ASSERTMSG("Invalid NamedPipeConfiguration parameter value!\n", FALSE);
110 }
111
112 DefaultTimeout.QuadPart = -50 * 1000 * 10;
113
114 return NpCreatePipeEx(ServerHandle,
115 PipePath,
116 ReadMode,
117 CompletionMode,
118 NamedPipeType,
120 MaximumInstances,
121 InboundQuota,
122 OutboundQuota,
126 &DefaultTimeout);
127}
NTSTATUS NpCreatePipeEx(OUT PHANDLE ServerHandle, IN PCWSTR PipePath, IN ULONG ReadMode, IN ULONG CompletionMode, IN ULONG NamedPipeType, IN ULONG ShareAccess, IN ULONG MaximumInstances, IN ULONG InboundQuota, IN ULONG OutboundQuota, IN ACCESS_MASK DesiredAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PLARGE_INTEGER DefaultTimeout OPTIONAL)
Definition: NpfsHelpers.c:12
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT ShareAccess
Definition: create.c:4147
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_OPEN_IF
Definition: from_kernel.h:56
#define FILE_PIPE_FULL_DUPLEX
Definition: iotypes.h:83
#define FILE_PIPE_OUTBOUND
Definition: iotypes.h:82
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define GENERIC_WRITE
Definition: nt_native.h:90
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:480

◆ NpCreatePipeEx()

NTSTATUS NpCreatePipeEx ( OUT PHANDLE  ServerHandle,
IN PCWSTR  PipePath,
IN ULONG  ReadMode,
IN ULONG  CompletionMode,
IN ULONG  NamedPipeType,
IN ULONG  ShareAccess,
IN ULONG  MaximumInstances,
IN ULONG  InboundQuota,
IN ULONG  OutboundQuota,
IN ACCESS_MASK  DesiredAccess,
IN ULONG  Disposition,
IN ULONG  CreateOptions,
IN PLARGE_INTEGER DefaultTimeout  OPTIONAL 
)

Definition at line 12 of file NpfsHelpers.c.

26{
32
37 NULL,
38 NULL);
39
40 Params.NamedPipeType = NamedPipeType;
41 Params.ReadMode = ReadMode;
42 Params.CompletionMode = CompletionMode;
43 Params.MaximumInstances = MaximumInstances;
44 Params.InboundQuota = InboundQuota;
45 Params.OutboundQuota = OutboundQuota;
46 if (DefaultTimeout)
47 {
48 Params.DefaultTimeout.QuadPart = DefaultTimeout->QuadPart;
49 Params.TimeoutSpecified = TRUE;
50 }
51 else
52 {
53 Params.DefaultTimeout.QuadPart = 0;
54 Params.TimeoutSpecified = FALSE;
55 }
56
58 Status = IoCreateFile(ServerHandle,
62 NULL, /* AllocationSize */
63 0, /* FileAttributes */
67 NULL, /* EaBuffer */
68 0, /* EaLength */
70 &Params,
71 0);
72 if (NT_SUCCESS(Status))
73 {
76 }
77 else
78 {
79 ok_eq_hex(IoStatusBlock.Status, 0x55555555UL);
80 ok_eq_ulongptr(IoStatusBlock.Information, 0x5555555555555555ULL);
81 }
82 return Status;
83}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define FILE_CREATED
Definition: nt_native.h:770
NTSTATUS NTAPI IoCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options)
Definition: file.c:3010
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:118
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64
@ CreateFileTypeNamedPipe
Definition: iotypes.h:536

Referenced by NpCreatePipe().

◆ NpOpenPipe()

NTSTATUS NpOpenPipe ( OUT PHANDLE  ClientHandle,
IN PCWSTR  PipePath,
IN ULONG  NamedPipeConfiguration 
)

Definition at line 180 of file NpfsHelpers.c.

184{
186
187 if (NamedPipeConfiguration == FILE_PIPE_INBOUND)
189 else if (NamedPipeConfiguration == FILE_PIPE_OUTBOUND)
191 else if (NamedPipeConfiguration == FILE_PIPE_FULL_DUPLEX)
193 else
194 {
195 ASSERTMSG("Invalid NamedPipeConfiguration parameter value!\n", FALSE);
197 }
198
199 return NpOpenPipeEx(ClientHandle,
200 PipePath,
203 FILE_OPEN,
205}
NTSTATUS NpOpenPipeEx(OUT PHANDLE ClientHandle, IN PCWSTR PipePath, IN ACCESS_MASK DesiredAccess, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions)
Definition: NpfsHelpers.c:130
#define FILE_OPEN
Definition: from_kernel.h:54
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477

Referenced by ConnectPipe().

◆ NpOpenPipeEx()

NTSTATUS NpOpenPipeEx ( OUT PHANDLE  ClientHandle,
IN PCWSTR  PipePath,
IN ACCESS_MASK  DesiredAccess,
IN ULONG  ShareAccess,
IN ULONG  Disposition,
IN ULONG  CreateOptions 
)

Definition at line 130 of file NpfsHelpers.c.

137{
142
145 &ObjectName,
147 NULL,
148 NULL);
149
151 Status = IoCreateFile(ClientHandle,
155 NULL, /* AllocationSize */
156 0, /* FileAttributes */
160 NULL, /* EaBuffer */
161 0, /* EaLength */
163 NULL,
164 0);
165 if (NT_SUCCESS(Status))
166 {
167 ok(Status != STATUS_PENDING, "IoCreateFile returned pending\n");
170 }
171 else
172 {
173 ok_eq_hex(IoStatusBlock.Status, 0x55555555UL);
174 ok_eq_ulongptr(IoStatusBlock.Information, 0x5555555555555555ULL);
175 }
176 return Status;
177}
#define ok(value,...)
Definition: atltest.h:57
#define FILE_OPENED
Definition: nt_native.h:769
@ CreateFileTypeNone
Definition: iotypes.h:535

Referenced by ConnectPipe(), and NpOpenPipe().

◆ NpQueryPipe_()

VOID NpQueryPipe_ ( IN HANDLE  PipeHandle,
IN NTSTATUS  ExpectedStatus,
IN PCSTR  FileAndLine 
)

Definition at line 594 of file NpfsHelpers.c.

598{
602 FILE_PIPE_LOCAL_INFORMATION PipeLocalInfo;
603 FILE_PIPE_REMOTE_INFORMATION PipeRemoteInfo;
604
605 ASSERT(!NT_SUCCESS(ExpectedStatus));
606
608 RtlFillMemory(&PipeInfo, sizeof(PipeInfo), 0x55);
609 Status = ZwQueryInformationFile(PipeHandle,
611 &PipeInfo,
612 sizeof(PipeInfo),
614 ok_eq_hex_(Status, ExpectedStatus);
615 ok_bool_true(CheckBuffer(&IoStatusBlock, sizeof(IoStatusBlock), 0x55), "CheckBuffer returned");
616 ok_bool_true(CheckBuffer(&PipeInfo, sizeof(PipeInfo), 0x55), "CheckBuffer returned");
617
619 RtlFillMemory(&PipeLocalInfo, sizeof(PipeLocalInfo), 0x55);
620 Status = ZwQueryInformationFile(PipeHandle,
622 &PipeLocalInfo,
623 sizeof(PipeLocalInfo),
625 ok_eq_hex_(Status, ExpectedStatus);
626 ok_bool_true(CheckBuffer(&IoStatusBlock, sizeof(IoStatusBlock), 0x55), "CheckBuffer returned");
627 ok_bool_true(CheckBuffer(&PipeLocalInfo, sizeof(PipeLocalInfo), 0x55), "CheckBuffer returned");
628
630 RtlFillMemory(&PipeRemoteInfo, sizeof(PipeRemoteInfo), 0x55);
631 Status = ZwQueryInformationFile(PipeHandle,
633 &PipeRemoteInfo,
634 sizeof(PipeRemoteInfo),
636 ok_eq_hex_(Status, ExpectedStatus);
637 ok_bool_true(CheckBuffer(&IoStatusBlock, sizeof(IoStatusBlock), 0x55), "CheckBuffer returned");
638 ok_bool_true(CheckBuffer(&PipeRemoteInfo, sizeof(PipeRemoteInfo), 0x55), "CheckBuffer returned");
639}
static BOOLEAN CheckBuffer(PVOID Buffer, SIZE_T Size, UCHAR Value)
Definition: NpfsHelpers.c:417
#define ok_bool_true(value, desc)
Definition: apitest.h:77
static HANDLE PipeHandle
Definition: dhcpcsvc.c:22
#define ASSERT(a)
Definition: mode.c:44

◆ NpReadPipe()

NTSTATUS NpReadPipe ( IN HANDLE  PipeHandle,
OUT PVOID  Buffer,
IN ULONG  BufferSize,
OUT PULONG_PTR  BytesRead 
)

Definition at line 322 of file NpfsHelpers.c.

327{
330 BOOLEAN PendingReturned = FALSE;
331
333 Status = ZwReadFile(PipeHandle,
334 NULL,
335 NULL,
336 NULL,
338 Buffer,
340 NULL,
341 NULL);
342 if (Status == STATUS_PENDING)
343 {
344 Status = ZwWaitForSingleObject(PipeHandle,
345 FALSE,
346 NULL);
349 PendingReturned = TRUE;
350 }
351 if (NT_SUCCESS(Status))
352 {
355 }
356 else
357 {
358 if (PendingReturned)
359 {
362 }
363 else
364 {
365 ok_eq_hex(IoStatusBlock.Status, 0x55555555UL);
366 ok_eq_ulongptr(IoStatusBlock.Information, 0x5555555555555555ULL);
367 }
368 *BytesRead = 0;
369 }
370 return Status;
371}
unsigned char BOOLEAN
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by ReadPipe().

◆ NpWaitPipe()

NTSTATUS NpWaitPipe ( IN PCWSTR  PipeName,
IN PLARGE_INTEGER  Timeout 
)

Definition at line 250 of file NpfsHelpers.c.

253{
255 HANDLE RootHandle;
259 PFILE_PIPE_WAIT_FOR_BUFFER WaitForBuffer;
260 ULONG NameLength;
262
264 &RootDirectoryName,
266 NULL,
267 NULL);
268
270 Status = IoCreateFile(&RootHandle,
274 NULL,
275 0,
277 FILE_OPEN,
279 NULL,
280 0,
282 NULL,
283 0);
284 if (!NT_SUCCESS(Status))
285 {
286 ok_eq_hex(IoStatusBlock.Status, 0x55555555UL);
287 ok_eq_ulongptr(IoStatusBlock.Information, 0x5555555555555555ULL);
288 return Status;
289 }
290 ok(Status != STATUS_PENDING, "IoCreateFile returned pending\n");
293
294 NameLength = (ULONG)(wcslen(PipeName) * sizeof(WCHAR));
296 Name[NameLength / sizeof(WCHAR)]);
297 WaitForBuffer = ExAllocatePoolWithTag(NonPagedPool, BufferSize, 'WPmK');
298 if (WaitForBuffer == NULL)
300
301 if (Timeout)
302 {
303 WaitForBuffer->Timeout.QuadPart = Timeout->QuadPart;
304 WaitForBuffer->TimeoutSpecified = TRUE;
305 }
306 else
307 {
308 WaitForBuffer->Timeout.QuadPart = 0;
309 WaitForBuffer->TimeoutSpecified = FALSE;
310 }
311 WaitForBuffer->NameLength = NameLength;
312 RtlCopyMemory(WaitForBuffer->Name, PipeName, NameLength);
313 Status = NpControlPipe(RootHandle,
315 WaitForBuffer,
316 BufferSize);
317 ExFreePoolWithTag(WaitForBuffer, 'WPmK');
318 return Status;
319}
NTSTATUS NpControlPipe(IN HANDLE ServerHandle, IN ULONG FsControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength)
Definition: NpfsHelpers.c:208
#define BufferSize
Definition: mmc.h:75
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define DEVICE_NAMED_PIPE
Definition: npfs.h:11
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
static ULONG Timeout
Definition: ping.c:61
#define FSCTL_PIPE_WAIT
Definition: winioctl.h:199
LARGE_INTEGER Timeout
Definition: winioctl.h:457
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ NpWritePipe()

NTSTATUS NpWritePipe ( IN HANDLE  PipeHandle,
IN const VOID Buffer,
IN ULONG  BufferSize,
OUT PULONG_PTR  BytesWritten 
)

Definition at line 374 of file NpfsHelpers.c.

379{
382
384 Status = ZwWriteFile(PipeHandle,
385 NULL,
386 NULL,
387 NULL,
389 (PVOID)Buffer,
391 NULL,
392 NULL);
393 if (Status == STATUS_PENDING)
394 {
395 Status = ZwWaitForSingleObject(PipeHandle,
396 FALSE,
397 NULL);
400 }
401 if (NT_SUCCESS(Status))
402 {
405 }
406 else
407 {
408 ok_eq_hex(IoStatusBlock.Status, 0x55555555UL);
409 ok_eq_ulongptr(IoStatusBlock.Information, 0x5555555555555555ULL);
410 *BytesWritten = 0;
411 }
412 return Status;
413}
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960

Referenced by WritePipe().

◆ PipeWorkerThread()

static VOID NTAPI PipeWorkerThread ( IN PVOID  ThreadContext)
static

Definition at line 645 of file NpfsHelpers.c.

647{
648 PTHREAD_CONTEXT Context = ThreadContext;
649 PVOID WaitEvents[2] = { &Context->ThreadDoneEvent,
650 &Context->StartWorkEvent };
652
653 while (TRUE)
654 {
656 WaitEvents,
657 WaitAny,
658 Executive,
660 FALSE,
661 NULL,
662 NULL);
663 if (Status == STATUS_WAIT_0)
664 break;
666
667 Context->Work(Context);
668
669 KeSetEvent(&Context->WorkCompleteEvent, IO_NO_INCREMENT, TRUE);
670 }
671}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define KernelMode
Definition: asm.h:34
@ WaitAny
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
#define STATUS_WAIT_0
Definition: ntstatus.h:237
#define STATUS_WAIT_1
Definition: ntstatus.h:71
#define IO_NO_INCREMENT
Definition: iotypes.h:598
@ Executive
Definition: ketypes.h:415

◆ StartWorkerThread()

VOID StartWorkerThread ( OUT PTHREAD_CONTEXT  Context)

Definition at line 674 of file NpfsHelpers.c.

676{
679 KeInitializeEvent(&Context->WorkCompleteEvent, NotificationEvent, TRUE);
680
682}
static KSTART_ROUTINE PipeWorkerThread
Definition: NpfsHelpers.c:641
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
@ NotificationEvent
@ SynchronizationEvent

Referenced by TestConnect(), and TestReadWrite().

◆ TriggerWork()

BOOLEAN TriggerWork ( IN PTHREAD_CONTEXT  Context,
IN ULONG  MilliSeconds 
)

Definition at line 710 of file NpfsHelpers.c.

713{
715
716 Status = KeWaitForSingleObject(&Context->WorkCompleteEvent,
717 Executive,
719 FALSE,
720 NULL);
722 KeClearEvent(&Context->WorkCompleteEvent);
723 KeSetEvent(&Context->StartWorkEvent, IO_NO_INCREMENT, TRUE);
724 return WaitForWork(Context, MilliSeconds);
725}
BOOLEAN WaitForWork(IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
Definition: NpfsHelpers.c:692
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22

Referenced by CheckConnectPipe(), CheckListenPipe(), CheckReadPipe(), and CheckWritePipe().

◆ WaitForWork()

BOOLEAN WaitForWork ( IN PTHREAD_CONTEXT  Context,
IN ULONG  MilliSeconds 
)

Definition at line 692 of file NpfsHelpers.c.

695{
698
699 Timeout.QuadPart = -10 * 1000 * (LONGLONG)MilliSeconds;
700 Status = KeWaitForSingleObject(&Context->WorkCompleteEvent,
701 Executive,
703 FALSE,
704 &Timeout);
705 ok(Status == STATUS_SUCCESS || Status == STATUS_TIMEOUT, "Wait status %lx\n", Status);
706 return Status != STATUS_TIMEOUT;
707}
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
int64_t LONGLONG
Definition: typedefs.h:68

Referenced by TestConnect(), TestReadWrite(), and TriggerWork().

Variable Documentation

◆ PipeWorkerThread

KSTART_ROUTINE PipeWorkerThread
static

Definition at line 641 of file NpfsHelpers.c.

Referenced by StartWorkerThread().