ReactOS  0.4.14-dev-98-gb0d4763
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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
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
#define trace
Definition: atltest.h:70
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

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 
545  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
546  RtlFillMemory(&PipeInfo, sizeof(PipeInfo), 0x55);
547  Status = ZwQueryInformationFile(ClientHandle,
548  &IoStatusBlock,
549  &PipeInfo,
550  sizeof(PipeInfo),
555  ok_eq_ulong_(PipeInfo.ReadMode, ReadMode);
556  ok_eq_ulong_(PipeInfo.CompletionMode, CompletionMode);
557 
558  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
559  RtlFillMemory(&PipeLocalInfo, sizeof(PipeLocalInfo), 0x55);
560  Status = ZwQueryInformationFile(ClientHandle,
561  &IoStatusBlock,
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 
579  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
580  RtlFillMemory(&PipeRemoteInfo, sizeof(PipeRemoteInfo), 0x55);
581  Status = ZwQueryInformationFile(ClientHandle,
582  &IoStatusBlock,
583  &PipeRemoteInfo,
584  sizeof(PipeRemoteInfo),
589  ok_eq_ulonglong_(PipeRemoteInfo.CollectDataTime.QuadPart, 0ULL);
590  ok_eq_ulong_(PipeRemoteInfo.MaximumCollectionCount, 0x55555555UL);
591 }
ULONG NamedPipeConfiguration
Definition: pipe.c:43
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_PIPE_CLIENT_END
Definition: iotypes.h:84
LARGE_INTEGER CollectDataTime
Definition: iotypes.h:5560
#define ok_eq_ulong_(value, expected)
Definition: NpfsHelpers.c:436
#define ULL(a, b)
Definition: format_msg.c:27
_In_ PUSBD_PIPE_INFORMATION PipeInfo
Definition: hubbusif.h:294
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:679
#define ok_eq_ulonglong_(value, expected)
Definition: NpfsHelpers.c:437
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define ok_eq_ulongptr_(value, expected)
Definition: NpfsHelpers.c:439
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define ok_eq_hex_(value, expected)
Definition: NpfsHelpers.c:443
LONGLONG QuadPart
Definition: typedefs.h:112

◆ 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 
471  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
472  RtlFillMemory(&PipeInfo, sizeof(PipeInfo), 0x55);
473  Status = ZwQueryInformationFile(ServerHandle,
474  &IoStatusBlock,
475  &PipeInfo,
476  sizeof(PipeInfo),
481  ok_eq_ulong_(PipeInfo.ReadMode, ReadMode);
482  ok_eq_ulong_(PipeInfo.CompletionMode, CompletionMode);
483 
484  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
485  RtlFillMemory(&PipeLocalInfo, sizeof(PipeLocalInfo), 0x55);
486  Status = ZwQueryInformationFile(ServerHandle,
487  &IoStatusBlock,
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 
505  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
506  RtlFillMemory(&PipeRemoteInfo, sizeof(PipeRemoteInfo), 0x55);
507  Status = ZwQueryInformationFile(ServerHandle,
508  &IoStatusBlock,
509  &PipeRemoteInfo,
510  sizeof(PipeRemoteInfo),
515  ok_eq_ulonglong_(PipeRemoteInfo.CollectDataTime.QuadPart, 0ULL);
516  ok_eq_ulong_(PipeRemoteInfo.MaximumCollectionCount, 0x55555555UL);
517 }
ULONG NamedPipeConfiguration
Definition: pipe.c:43
LONG NTSTATUS
Definition: precomp.h:26
LARGE_INTEGER CollectDataTime
Definition: iotypes.h:5560
#define ok_eq_ulong_(value, expected)
Definition: NpfsHelpers.c:436
#define ULL(a, b)
Definition: format_msg.c:27
_In_ PUSBD_PIPE_INFORMATION PipeInfo
Definition: hubbusif.h:294
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:679
#define ok_eq_ulonglong_(value, expected)
Definition: NpfsHelpers.c:437
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define ok_eq_ulongptr_(value, expected)
Definition: NpfsHelpers.c:439
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define ok_eq_hex_(value, expected)
Definition: NpfsHelpers.c:443
LONGLONG QuadPart
Definition: typedefs.h:112

◆ 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 
217  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
218  Status = ZwFsControlFile(ServerHandle,
219  NULL,
220  NULL,
221  NULL,
222  &IoStatusBlock,
224  InputBuffer,
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 }
LONG NTSTATUS
Definition: precomp.h:26
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
CHAR InputBuffer[80]
Definition: conmgr.c:33
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)
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG FsControlCode
Definition: fltkernel.h:1369
#define ok_eq_hex(value, expected)
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593

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,
119  ShareAccess,
120  MaximumInstances,
121  InboundQuota,
122  OutboundQuota,
124  FILE_OPEN_IF,
126  &DefaultTimeout);
127 }
#define FILE_OPEN_IF
Definition: from_kernel.h:56
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 FILE_SHARE_WRITE
Definition: nt_native.h:681
_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:4157
#define FILE_SHARE_READ
Definition: compat.h:125
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define GENERIC_WRITE
Definition: nt_native.h:90
#define GENERIC_READ
Definition: compat.h:124
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_PIPE_OUTBOUND
Definition: iotypes.h:82
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:466
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
#define FILE_PIPE_FULL_DUPLEX
Definition: iotypes.h:83
LONGLONG QuadPart
Definition: typedefs.h:112

◆ 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 
33  RtlInitUnicodeString(&ObjectName, PipePath);
35  &ObjectName,
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 
57  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
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:35
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:62
_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:4157
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
LARGE_INTEGER DefaultTimeout
Definition: iotypes.h:790
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
Status
Definition: gdiplustypes.h:24
_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 DesiredAccess
Definition: create.c:4157
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#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:3009
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ok_eq_hex(value, expected)
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
LONGLONG QuadPart
Definition: typedefs.h:112

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,
202  ShareAccess,
203  FILE_OPEN,
205 }
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
_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:4157
#define FILE_SHARE_READ
Definition: compat.h:125
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:463
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define GENERIC_WRITE
Definition: nt_native.h:90
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 GENERIC_READ
Definition: compat.h:124
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_PIPE_OUTBOUND
Definition: iotypes.h:82
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
#define FILE_PIPE_FULL_DUPLEX
Definition: iotypes.h:83

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 
143  RtlInitUnicodeString(&ObjectName, PipePath);
145  &ObjectName,
147  NULL,
148  NULL);
149 
150  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
151  Status = IoCreateFile(ClientHandle,
154  &IoStatusBlock,
155  NULL, /* AllocationSize */
156  0, /* FileAttributes */
157  ShareAccess,
158  Disposition,
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 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:62
_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:4157
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
Status
Definition: gdiplustypes.h:24
#define ok(value,...)
Definition: atltest.h:57
_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 DesiredAccess
Definition: create.c:4157
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
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:3009
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ok_eq_hex(value, expected)
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

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 
607  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
608  RtlFillMemory(&PipeInfo, sizeof(PipeInfo), 0x55);
609  Status = ZwQueryInformationFile(PipeHandle,
610  &IoStatusBlock,
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 
618  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
619  RtlFillMemory(&PipeLocalInfo, sizeof(PipeLocalInfo), 0x55);
620  Status = ZwQueryInformationFile(PipeHandle,
621  &IoStatusBlock,
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 
629  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
630  RtlFillMemory(&PipeRemoteInfo, sizeof(PipeRemoteInfo), 0x55);
631  Status = ZwQueryInformationFile(PipeHandle,
632  &IoStatusBlock,
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 }
LONG NTSTATUS
Definition: precomp.h:26
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
static BOOLEAN CheckBuffer(PVOID Buffer, SIZE_T Size, UCHAR Value)
Definition: NpfsHelpers.c:417
_In_ PUSBD_PIPE_INFORMATION PipeInfo
Definition: hubbusif.h:294
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define ok_eq_hex_(value, expected)
Definition: NpfsHelpers.c:443

◆ 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 
332  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
333  Status = ZwReadFile(PipeHandle,
334  NULL,
335  NULL,
336  NULL,
337  &IoStatusBlock,
338  Buffer,
339  BufferSize,
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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define BufferSize
Definition: classpnp.h:419
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define ok_eq_hex(value, expected)
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

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 
269  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
270  Status = IoCreateFile(&RootHandle,
273  &IoStatusBlock,
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 = 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 }
LARGE_INTEGER Timeout
Definition: winioctl.h:457
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
#define DEVICE_NAMED_PIPE
Definition: npfs.h:11
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
smooth NULL
Definition: ftsmooth.c:416
#define FSCTL_PIPE_WAIT
Definition: winioctl.h:199
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define BufferSize
Definition: classpnp.h:419
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define SYNCHRONIZE
Definition: nt_native.h:61
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
static ULONG Timeout
Definition: ping.c:61
#define ok(value,...)
Definition: atltest.h:57
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
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:3009
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ok_eq_hex(value, expected)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
NTSTATUS NpControlPipe(IN HANDLE ServerHandle, IN ULONG FsControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength)
Definition: NpfsHelpers.c:208
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LONGLONG QuadPart
Definition: typedefs.h:112
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ 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 
383  RtlFillMemory(&IoStatusBlock, sizeof(IoStatusBlock), 0x55);
384  Status = ZwWriteFile(PipeHandle,
385  NULL,
386  NULL,
387  NULL,
388  &IoStatusBlock,
389  (PVOID)Buffer,
390  BufferSize,
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_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
LONG NTSTATUS
Definition: precomp.h:26
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define BufferSize
Definition: classpnp.h:419
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define ok_eq_hex(value, expected)
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593

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,
659  KernelMode,
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 TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define STATUS_WAIT_1
Definition: ntstatus.h:71
#define STATUS_WAIT_0
Definition: ntstatus.h:223
smooth NULL
Definition: ftsmooth.c:416
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ StartWorkerThread()

VOID StartWorkerThread ( OUT PTHREAD_CONTEXT  Context)

Definition at line 674 of file NpfsHelpers.c.

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

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,
718  KernelMode,
719  FALSE,
720  NULL);
722  KeClearEvent(&Context->WorkCompleteEvent);
723  KeSetEvent(&Context->StartWorkEvent, IO_NO_INCREMENT, TRUE);
724  return WaitForWork(Context, MilliSeconds);
725 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
smooth NULL
Definition: ftsmooth.c:416
Status
Definition: gdiplustypes.h:24
#define IO_NO_INCREMENT
Definition: iotypes.h:566
BOOLEAN WaitForWork(IN PTHREAD_CONTEXT Context, IN ULONG MilliSeconds)
Definition: NpfsHelpers.c:692
#define ok_eq_hex(value, expected)
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2966

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,
702  KernelMode,
703  FALSE,
704  &Timeout);
705  ok(Status == STATUS_SUCCESS || Status == STATUS_TIMEOUT, "Wait status %lx\n", Status);
706  return Status != STATUS_TIMEOUT;
707 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
int64_t LONGLONG
Definition: typedefs.h:66
Status
Definition: gdiplustypes.h:24
static ULONG Timeout
Definition: ping.c:61
#define ok(value,...)
Definition: atltest.h:57
return STATUS_SUCCESS
Definition: btrfs.c:2966

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

Variable Documentation

◆ PipeWorkerThread

KSTART_ROUTINE PipeWorkerThread
static

Definition at line 641 of file NpfsHelpers.c.

Referenced by StartWorkerThread().