ReactOS 0.4.15-dev-7842-g558ab78
rawchan.c File Reference
#include "sacdrv.h"
Include dependency graph for rawchan.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI RawChannelCreate (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI RawChannelDestroy (IN PSAC_CHANNEL Channel)
 
FORCEINLINE BOOLEAN ChannelHasNewOBufferData (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI RawChannelORead (IN PSAC_CHANNEL Channel, IN PCHAR Buffer, IN ULONG BufferSize, OUT PULONG ByteCount)
 
NTSTATUS NTAPI RawChannelOEcho (IN PSAC_CHANNEL Channel, IN PCHAR String, IN ULONG Length)
 
NTSTATUS NTAPI RawChannelOWrite2 (IN PSAC_CHANNEL Channel, IN PCHAR String, IN ULONG Size)
 
NTSTATUS NTAPI RawChannelOFlush (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI RawChannelOWrite (IN PSAC_CHANNEL Channel, IN PCHAR String, IN ULONG Length)
 
ULONG NTAPI RawChannelGetIBufferIndex (IN PSAC_CHANNEL Channel)
 
VOID NTAPI RawChannelSetIBufferIndex (IN PSAC_CHANNEL Channel, IN ULONG BufferIndex)
 
NTSTATUS NTAPI RawChannelIRead (IN PSAC_CHANNEL Channel, IN PCHAR Buffer, IN ULONG BufferSize, IN PULONG ReturnBufferSize)
 
NTSTATUS NTAPI RawChannelIBufferIsFull (IN PSAC_CHANNEL Channel, OUT PBOOLEAN BufferStatus)
 
ULONG NTAPI RawChannelIBufferLength (IN PSAC_CHANNEL Channel)
 
WCHAR NTAPI RawChannelIReadLast (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI RawChannelIWrite (IN PSAC_CHANNEL Channel, IN PCHAR Buffer, IN ULONG BufferSize)
 

Function Documentation

◆ ChannelHasNewOBufferData()

FORCEINLINE BOOLEAN ChannelHasNewOBufferData ( IN PSAC_CHANNEL  Channel)

Definition at line 51 of file rawchan.c.

52{
53 return Channel->ChannelHasNewOBufferData;
54}

Referenced by ChanMgrReapChannels(), RawChannelOFlush(), RawChannelORead(), and RawChannelOWrite2().

◆ RawChannelCreate()

NTSTATUS NTAPI RawChannelCreate ( IN PSAC_CHANNEL  Channel)

Definition at line 17 of file rawchan.c.

18{
19 CHECK_PARAMETER(Channel);
20
21 /* Allocate the output buffer */
23 CHECK_ALLOCATION(Channel->OBuffer);
24
25 /* Allocate the input buffer */
27 CHECK_ALLOCATION(Channel->IBuffer);
28
29 /* Reset all flags and return success */
30 Channel->OBufferIndex = 0;
31 Channel->OBufferFirstGoodIndex = 0;
32 Channel->ChannelHasNewIBufferData = FALSE;
33 Channel->ChannelHasNewOBufferData = FALSE;
34 return STATUS_SUCCESS;
35}
#define FALSE
Definition: types.h:117
#define SacAllocatePool(Length, Tag)
Definition: sacdrv.h:24
#define SAC_RAW_IBUFFER_SIZE
Definition: sacdrv.h:164
#define SAC_RAW_OBUFFER_SIZE
Definition: sacdrv.h:163
#define CHECK_ALLOCATION(x)
Definition: sacdrv.h:64
#define CHECK_PARAMETER(x)
Definition: sacdrv.h:54
#define GLOBAL_BLOCK_TAG
Definition: sacdrv.h:142
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by ChannelInitializeVTable().

◆ RawChannelDestroy()

NTSTATUS NTAPI RawChannelDestroy ( IN PSAC_CHANNEL  Channel)

Definition at line 39 of file rawchan.c.

40{
41 CHECK_PARAMETER(Channel);
42
43 /* Free the buffer and then destroy the channel */
44 if (Channel->OBuffer) SacFreePool(Channel->OBuffer);
45 if (Channel->IBuffer) SacFreePool(Channel->IBuffer);
46 return ChannelDestroy(Channel);
47}
NTSTATUS NTAPI ChannelDestroy(IN PSAC_CHANNEL Channel)
Definition: channel.c:77
#define SacFreePool(Pointer)
Definition: sacdrv.h:26

Referenced by ChannelInitializeVTable().

◆ RawChannelGetIBufferIndex()

ULONG NTAPI RawChannelGetIBufferIndex ( IN PSAC_CHANNEL  Channel)

Definition at line 212 of file rawchan.c.

213{
214 ASSERT(Channel);
215 ASSERT(Channel->IBufferIndex < SAC_RAW_IBUFFER_SIZE);
216
217 /* Return the current buffer index */
218 return Channel->IBufferIndex;
219}
#define ASSERT(a)
Definition: mode.c:44

Referenced by RawChannelIBufferIsFull(), RawChannelIBufferLength(), RawChannelIRead(), RawChannelIReadLast(), and RawChannelIWrite().

◆ RawChannelIBufferIsFull()

NTSTATUS NTAPI RawChannelIBufferIsFull ( IN PSAC_CHANNEL  Channel,
OUT PBOOLEAN  BufferStatus 
)

Definition at line 297 of file rawchan.c.

299{
300 CHECK_PARAMETER1(Channel);
301 CHECK_PARAMETER2(BufferStatus);
302
303 /* If the index is beyond the length, the buffer must be full */
304 *BufferStatus = RawChannelGetIBufferIndex(Channel) > SAC_RAW_IBUFFER_SIZE;
305 return STATUS_SUCCESS;
306}
ULONG NTAPI RawChannelGetIBufferIndex(IN PSAC_CHANNEL Channel)
Definition: rawchan.c:212
#define CHECK_PARAMETER2(x)
Definition: sacdrv.h:58
#define CHECK_PARAMETER1(x)
Definition: sacdrv.h:56

Referenced by ChannelInitializeVTable(), and RawChannelIWrite().

◆ RawChannelIBufferLength()

ULONG NTAPI RawChannelIBufferLength ( IN PSAC_CHANNEL  Channel)

Definition at line 310 of file rawchan.c.

311{
312 ASSERT(Channel);
313
314 /* The index is the current length (since we're 0-based) */
315 return RawChannelGetIBufferIndex(Channel);
316}

Referenced by ChannelInitializeVTable().

◆ RawChannelIRead()

NTSTATUS NTAPI RawChannelIRead ( IN PSAC_CHANNEL  Channel,
IN PCHAR  Buffer,
IN ULONG  BufferSize,
IN PULONG  ReturnBufferSize 
)

Definition at line 246 of file rawchan.c.

250{
251 ULONG CopyChars;
252 CHECK_PARAMETER1(Channel);
255
256 /* Assume failure */
257 *ReturnBufferSize = 0;
258
259 /* Check how many bytes are in the buffer */
260 if (Channel->ChannelInputBufferLength(Channel) == 0)
261 {
262 /* Apparently nothing. Make sure the flag indicates so too */
264 }
265 else
266 {
267 /* Use the smallest number of bytes either in the buffer or requested */
268 CopyChars = min(Channel->ChannelInputBufferLength(Channel), BufferSize);
269 ASSERT(CopyChars <= Channel->ChannelInputBufferLength(Channel));
270
271 /* Copy them into the caller's buffer */
272 RtlCopyMemory(Buffer, Channel->IBuffer, CopyChars);
273
274 /* Update the channel's index past the copied (read) bytes */
276 RawChannelGetIBufferIndex(Channel) - CopyChars);
277
278 /* Are there still bytes that haven't been read yet? */
279 if (Channel->ChannelInputBufferLength(Channel))
280 {
281 /* Shift them up in the buffer */
282 RtlMoveMemory(Channel->IBuffer,
283 &Channel->IBuffer[CopyChars],
284 Channel->ChannelInputBufferLength(Channel));
285 }
286
287 /* Return the number of bytes we actually copied */
288 *ReturnBufferSize = CopyChars;
289 }
290
291 /* Return success */
292 return STATUS_SUCCESS;
293}
Definition: bufpool.h:45
#define min(a, b)
Definition: monoChain.cc:55
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:650
VOID NTAPI RawChannelSetIBufferIndex(IN PSAC_CHANNEL Channel, IN ULONG BufferIndex)
Definition: rawchan.c:223
#define CHECK_PARAMETER_WITH_STATUS(Condition, Status)
Definition: sacdrv.h:47
FORCEINLINE BOOLEAN ChannelHasNewIBufferData(IN PSAC_CHANNEL Channel)
Definition: sacdrv.h:1361
_In_ DWORD _In_ DWORD ReturnBufferSize
Definition: setupapi.h:1897
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by ChannelInitializeVTable().

◆ RawChannelIReadLast()

WCHAR NTAPI RawChannelIReadLast ( IN PSAC_CHANNEL  Channel)

Definition at line 320 of file rawchan.c.

321{
322 UCHAR LastChar = 0;
323 ASSERT(Channel);
324
325 /* Check if there's anything to read in the buffer */
326 if (Channel->ChannelInputBufferLength(Channel))
327 {
328 /* Go back one character */
330 RawChannelGetIBufferIndex(Channel) - 1);
331
332 /* Read it, and clear its current value */
333 LastChar = Channel->IBuffer[RawChannelGetIBufferIndex(Channel)];
334 Channel->IBuffer[RawChannelGetIBufferIndex(Channel)] = ANSI_NULL;
335 }
336
337 /* Return the last character */
338 return LastChar;
339}
#define ANSI_NULL
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by ChannelInitializeVTable().

◆ RawChannelIWrite()

NTSTATUS NTAPI RawChannelIWrite ( IN PSAC_CHANNEL  Channel,
IN PCHAR  Buffer,
IN ULONG  BufferSize 
)

Definition at line 343 of file rawchan.c.

346{
348 BOOLEAN IsFull;
349 ULONG Index;
350 CHECK_PARAMETER1(Channel);
353
354 /* First, check if the input buffer still has space */
355 Status = RawChannelIBufferIsFull(Channel, &IsFull);
356 if (!NT_SUCCESS(Status)) return Status;
357 if (IsFull) return STATUS_UNSUCCESSFUL;
358
359 /* Get the current buffer index */
362 {
364 }
365
366 /* Copy the new data */
367 RtlCopyMemory(&Channel->IBuffer[Index], Buffer, BufferSize);
368
369 /* Update the index */
371
372 /* Signal the event, if one was set */
373 if (Channel->Flags & SAC_CHANNEL_FLAG_HAS_NEW_DATA_EVENT)
374 {
375 ChannelSetEvent(Channel, HasNewDataEvent);
376 }
377
378 /* All done */
379 return STATUS_SUCCESS;
380}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI RawChannelIBufferIsFull(IN PSAC_CHANNEL Channel, OUT PBOOLEAN BufferStatus)
Definition: rawchan.c:297
#define ChannelSetEvent(Channel, x)
Definition: sacdrv.h:99
#define SAC_CHANNEL_FLAG_HAS_NEW_DATA_EVENT
Definition: sacdrv.h:171
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by ChannelInitializeVTable().

◆ RawChannelOEcho()

NTSTATUS NTAPI RawChannelOEcho ( IN PSAC_CHANNEL  Channel,
IN PCHAR  String,
IN ULONG  Length 
)

Definition at line 115 of file rawchan.c.

118{
120
121 CHECK_PARAMETER1(Channel);
123
124 if (Length)
125 {
126 Status = ConMgrWriteData(Channel, String, Length);
127 if (NT_SUCCESS(Status)) ConMgrFlushData(Channel);
128 }
129
130 return Status;
131}
NTSTATUS NTAPI ConMgrWriteData(IN PSAC_CHANNEL Channel, IN PVOID Buffer, IN ULONG BufferLength)
Definition: conmgr.c:111
NTSTATUS NTAPI ConMgrFlushData(IN PSAC_CHANNEL Channel)
Definition: conmgr.c:139
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by ChannelInitializeVTable(), and RawChannelOWrite().

◆ RawChannelOFlush()

NTSTATUS NTAPI RawChannelOFlush ( IN PSAC_CHANNEL  Channel)

Definition at line 172 of file rawchan.c.

173{
176 CHAR Dummy;
177 CHECK_PARAMETER1(Channel);
178
179 while (ChannelHasNewOBufferData(Channel))
180 {
181 Status = RawChannelORead(Channel, &Dummy, sizeof(Dummy), &ByteCount);
182 if (!NT_SUCCESS(Status)) return Status;
183
185
186 Status = ConMgrWriteData(Channel, &Dummy, sizeof(Dummy));
187 if (!NT_SUCCESS(Status)) return Status;
188 }
189
190 return ConMgrFlushData(Channel);
191}
FORCEINLINE BOOLEAN ChannelHasNewOBufferData(IN PSAC_CHANNEL Channel)
Definition: rawchan.c:51
NTSTATUS NTAPI RawChannelORead(IN PSAC_CHANNEL Channel, IN PCHAR Buffer, IN ULONG BufferSize, OUT PULONG ByteCount)
Definition: rawchan.c:58
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1099
char CHAR
Definition: xmlstorage.h:175

Referenced by ChannelInitializeVTable().

◆ RawChannelORead()

NTSTATUS NTAPI RawChannelORead ( IN PSAC_CHANNEL  Channel,
IN PCHAR  Buffer,
IN ULONG  BufferSize,
OUT PULONG  ByteCount 
)

Definition at line 58 of file rawchan.c.

62{
64 ULONG NextIndex;
65
66 CHECK_PARAMETER1(Channel);
70
71 *ByteCount = 0;
72
73 if (ChannelHasNewOBufferData(Channel))
74 {
76
77 while (TRUE)
78 {
79 Buffer[(*ByteCount)++] = Channel->OBuffer[Channel->OBufferFirstGoodIndex];
80
81 NextIndex = (Channel->OBufferFirstGoodIndex + 1) & (SAC_OBUFFER_SIZE - 1);
82 Channel->OBufferFirstGoodIndex = NextIndex;
83
84 if (NextIndex == Channel->OBufferIndex)
85 {
86 _InterlockedExchange(&Channel->ChannelHasNewOBufferData, 0);
87 break;
88 }
89
90 ASSERT(*ByteCount > 0);
91
92 if (*ByteCount >= BufferSize) break;
93 }
94 }
95 else
96 {
98 }
99
100 if (Channel->OBufferFirstGoodIndex == Channel->OBufferIndex)
101 {
103 }
104
105 if (ChannelHasNewOBufferData(Channel) == FALSE)
106 {
107 ASSERT(Channel->OBufferFirstGoodIndex == Channel->OBufferIndex);
108 }
109
110 return Status;
111}
#define TRUE
Definition: types.h:120
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)
#define SAC_OBUFFER_SIZE
Definition: sacdrv.h:151
#define CHECK_PARAMETER3(x)
Definition: sacdrv.h:60
#define CHECK_PARAMETER4(x)
Definition: sacdrv.h:62
#define STATUS_NO_DATA_DETECTED
Definition: udferr_usr.h:131

Referenced by ChannelInitializeVTable(), and RawChannelOFlush().

◆ RawChannelOWrite()

NTSTATUS NTAPI RawChannelOWrite ( IN PSAC_CHANNEL  Channel,
IN PCHAR  String,
IN ULONG  Length 
)

Definition at line 195 of file rawchan.c.

198{
199 CHECK_PARAMETER1(Channel);
201
202 if ((ConMgrIsWriteEnabled(Channel)) && (Channel->WriteEnabled))
203 {
204 return RawChannelOEcho(Channel, String, Length);
205 }
206
207 return RawChannelOWrite2(Channel, String, Length);
208}
BOOLEAN NTAPI ConMgrIsWriteEnabled(IN PSAC_CHANNEL Channel)
Definition: conmgr.c:155
NTSTATUS NTAPI RawChannelOWrite2(IN PSAC_CHANNEL Channel, IN PCHAR String, IN ULONG Size)
Definition: rawchan.c:135
NTSTATUS NTAPI RawChannelOEcho(IN PSAC_CHANNEL Channel, IN PCHAR String, IN ULONG Length)
Definition: rawchan.c:115

Referenced by ChannelInitializeVTable().

◆ RawChannelOWrite2()

NTSTATUS NTAPI RawChannelOWrite2 ( IN PSAC_CHANNEL  Channel,
IN PCHAR  String,
IN ULONG  Size 
)

Definition at line 135 of file rawchan.c.

138{
139 BOOLEAN Overflow;
140 ULONG i, NextIndex;
141
142 CHECK_PARAMETER1(Channel);
144
145 Overflow = FALSE;
146
147 for (i = 0; i < Size; i++)
148 {
149 if ((Channel->OBufferIndex == Channel->OBufferFirstGoodIndex) &&
150 ((i) || (ChannelHasNewOBufferData(Channel))))
151 {
152 Overflow = TRUE;
153 }
154
155 ASSERT(Channel->OBufferIndex < SAC_RAW_OBUFFER_SIZE);
156
157 Channel->OBuffer[Channel->OBufferIndex] = String[i];
158
159 NextIndex = (Channel->OBufferIndex + 1) & (SAC_RAW_OBUFFER_SIZE - 1);
160 Channel->OBufferIndex = NextIndex;
161
162 if (Overflow) Channel->OBufferFirstGoodIndex = NextIndex;
163 }
164
165 _InterlockedExchange(&Channel->ChannelHasNewOBufferData, 1);
166
167 return STATUS_SUCCESS;
168}
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
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by RawChannelOWrite().

◆ RawChannelSetIBufferIndex()

VOID NTAPI RawChannelSetIBufferIndex ( IN PSAC_CHANNEL  Channel,
IN ULONG  BufferIndex 
)

Definition at line 223 of file rawchan.c.

225{
227 ASSERT(Channel);
228 ASSERT(Channel->IBufferIndex < SAC_RAW_IBUFFER_SIZE);
229
230 /* Set the new index, and if it's not zero, it means we have data */
231 Channel->IBufferIndex = BufferIndex;
232 _InterlockedExchange(&Channel->ChannelHasNewIBufferData, BufferIndex != 0);
233
234 /* If we have new data, and an event has been registered... */
235 if (!(Channel->IBufferIndex) &&
236 (Channel->Flags & SAC_CHANNEL_FLAG_HAS_NEW_DATA_EVENT))
237 {
238 /* Go ahead and signal it */
239 ChannelClearEvent(Channel, HasNewDataEvent);
241 }
242}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define ChannelClearEvent(Channel, x)
Definition: sacdrv.h:114

Referenced by RawChannelIRead(), RawChannelIReadLast(), and RawChannelIWrite().