1 /* 2 * PROJECT: ReactOS kernel-mode tests 3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory 4 * PURPOSE: Kernel-Mode Test Suite NPFS helper declarations 5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org> 6 */ 7 8 #ifndef _KMTEST_NPFS_H_ 9 #define _KMTEST_NPFS_H_ 10 11 #define DEVICE_NAMED_PIPE L"\\Device\\NamedPipe" 12 13 #define BYTE_STREAM FILE_PIPE_BYTE_STREAM_MODE 14 C_ASSERT(FILE_PIPE_BYTE_STREAM_MODE == FILE_PIPE_BYTE_STREAM_TYPE); 15 #define MESSAGE FILE_PIPE_MESSAGE_MODE 16 C_ASSERT(FILE_PIPE_MESSAGE_MODE == FILE_PIPE_MESSAGE_TYPE); 17 #define QUEUE FILE_PIPE_QUEUE_OPERATION 18 #define COMPLETE FILE_PIPE_COMPLETE_OPERATION 19 #define INBOUND FILE_PIPE_INBOUND 20 #define OUTBOUND FILE_PIPE_OUTBOUND 21 #define DUPLEX FILE_PIPE_FULL_DUPLEX 22 23 NTSTATUS 24 NpCreatePipeEx( 25 OUT PHANDLE ServerHandle, 26 IN PCWSTR PipePath, 27 IN ULONG ReadMode, 28 IN ULONG CompletionMode, 29 IN ULONG NamedPipeType, 30 IN ULONG ShareAccess, 31 IN ULONG MaximumInstances, 32 IN ULONG InboundQuota, 33 IN ULONG OutboundQuota, 34 IN ACCESS_MASK DesiredAccess, 35 IN ULONG Disposition, 36 IN ULONG CreateOptions, 37 IN PLARGE_INTEGER DefaultTimeout OPTIONAL); 38 39 NTSTATUS 40 NpCreatePipe( 41 OUT PHANDLE ServerHandle, 42 IN PCWSTR PipePath, 43 IN ULONG ReadMode, 44 IN ULONG CompletionMode, 45 IN ULONG NamedPipeType, 46 IN ULONG NamedPipeConfiguration, 47 IN ULONG MaximumInstances, 48 IN ULONG InboundQuota, 49 IN ULONG OutboundQuota); 50 51 NTSTATUS 52 NpOpenPipeEx( 53 OUT PHANDLE ClientHandle, 54 IN PCWSTR PipePath, 55 IN ACCESS_MASK DesiredAccess, 56 IN ULONG ShareAccess, 57 IN ULONG Disposition, 58 IN ULONG CreateOptions); 59 60 NTSTATUS 61 NpOpenPipe( 62 OUT PHANDLE ClientHandle, 63 IN PCWSTR PipePath, 64 IN ULONG NamedPipeConfiguration); 65 66 NTSTATUS 67 NpControlPipe( 68 IN HANDLE PipeHandle, 69 IN ULONG FsControlCode, 70 IN PVOID InputBuffer, 71 IN ULONG InputBufferLength); 72 73 #define NpListenPipe(ServerHandle) NpControlPipe(ServerHandle, FSCTL_PIPE_LISTEN, NULL, 0) 74 #define NpDisconnectPipe(ServerHandle) NpControlPipe(ServerHandle, FSCTL_PIPE_DISCONNECT, NULL, 0) 75 76 NTSTATUS 77 NpWaitPipe( 78 IN PCWSTR PipeName, 79 IN PLARGE_INTEGER Timeout); 80 81 NTSTATUS 82 NpReadPipe( 83 IN HANDLE PipeHandle, 84 OUT PVOID Buffer, 85 IN ULONG BufferSize, 86 OUT PULONG_PTR BytesRead); 87 88 NTSTATUS 89 NpWritePipe( 90 IN HANDLE PipeHandle, 91 IN const VOID *Buffer, 92 IN ULONG BufferSize, 93 OUT PULONG_PTR BytesWritten); 94 95 #define NpCheckServerPipe(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps) \ 96 NpCheckServerPipe__(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps, __FILE__, __LINE__) 97 98 #define NpCheckServerPipe__(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps, file, line) \ 99 NpCheckServerPipe_(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps, file ":" KMT_STRINGIZE(line)) 100 101 VOID 102 NpCheckServerPipe_( 103 IN HANDLE ServerHandle, 104 /* PipeInformation */ 105 IN ULONG ReadMode, 106 IN ULONG CompletionMode, 107 /* PipeLocalInformation */ 108 IN ULONG NamedPipeType, 109 IN ULONG NamedPipeConfiguration, 110 IN ULONG MaximumInstances, 111 IN ULONG CurrentInstances, 112 IN ULONG InboundQuota, 113 IN ULONG ReadDataAvailable, 114 IN ULONG OutboundQuota, 115 IN ULONG WriteQuotaAvailable, 116 IN ULONG NamedPipeState, 117 /* PipeRemoteInformation */ 118 /* */ 119 IN PCSTR FileAndLine); 120 121 #define NpCheckClientPipe(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps) \ 122 NpCheckClientPipe__(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps, __FILE__, __LINE__) 123 124 #define NpCheckClientPipe__(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps, file, line) \ 125 NpCheckClientPipe_(h, rm, cm, npt, npc, mi, ci, iq, rsa, oq, wqa, nps, file ":" KMT_STRINGIZE(line)) 126 127 VOID 128 NpCheckClientPipe_( 129 IN HANDLE ClientHandle, 130 /* PipeInformation */ 131 IN ULONG ReadMode, 132 IN ULONG CompletionMode, 133 /* PipeLocalInformation */ 134 IN ULONG NamedPipeType, 135 IN ULONG NamedPipeConfiguration, 136 IN ULONG MaximumInstances, 137 IN ULONG CurrentInstances, 138 IN ULONG InboundQuota, 139 IN ULONG ReadDataAvailable, 140 IN ULONG OutboundQuota, 141 IN ULONG WriteQuotaAvailable, 142 IN ULONG NamedPipeState, 143 /* PipeRemoteInformation */ 144 /* */ 145 IN PCSTR FileAndLine); 146 147 #define NpQueryPipe(h, es) \ 148 NpQueryPipe__(h, es, __FILE__, __LINE__) 149 150 #define NpQueryPipe__(h, es, file, line) \ 151 NpQueryPipe_(h, es, file ":" KMT_STRINGIZE(line)) 152 153 VOID 154 NpQueryPipe_( 155 IN HANDLE Handle, 156 IN NTSTATUS ExpectedStatus, 157 IN PCSTR FileAndLine); 158 159 160 struct _THREAD_CONTEXT; 161 typedef VOID (WORK_FUNCTION)(IN OUT struct _THREAD_CONTEXT *); 162 typedef WORK_FUNCTION *PWORK_FUNCTION; 163 164 typedef struct _THREAD_CONTEXT 165 { 166 volatile PWORK_FUNCTION Work; 167 volatile union 168 { 169 struct 170 { 171 PCWSTR PipePath; 172 BOOLEAN ClientSynchronous; 173 HANDLE ClientHandle; 174 NTSTATUS Status; 175 } Connect; 176 struct 177 { 178 HANDLE ServerHandle; 179 NTSTATUS Status; 180 } Listen; 181 struct 182 { 183 HANDLE PipeHandle; 184 PVOID Buffer; 185 ULONG BufferSize; 186 ULONG_PTR BytesTransferred; 187 NTSTATUS Status; 188 } ReadWrite; 189 }; 190 KEVENT ThreadDoneEvent; 191 KEVENT StartWorkEvent; 192 KEVENT WorkCompleteEvent; 193 PKTHREAD Thread; 194 } THREAD_CONTEXT, *PTHREAD_CONTEXT; 195 196 VOID 197 StartWorkerThread( 198 OUT PTHREAD_CONTEXT Context); 199 200 VOID 201 FinishWorkerThread( 202 IN PTHREAD_CONTEXT Context); 203 204 BOOLEAN 205 WaitForWork( 206 IN PTHREAD_CONTEXT Context, 207 IN ULONG MilliSeconds); 208 209 BOOLEAN 210 TriggerWork( 211 IN PTHREAD_CONTEXT Context, 212 IN ULONG MilliSeconds); 213 214 #endif /* !defined _KMTEST_NPFS_H_ */ 215