ReactOS 0.4.15-dev-7924-g5949c20
chanmgr.c File Reference
#include "sacdrv.h"
Include dependency graph for chanmgr.c:

Go to the source code of this file.

Macros

#define MAX_REF_COUNT   100
 
#define CHANNEL_SLOT_IS_IN_USE(x)   (ChannelRefCount[(x)] > 0)
 

Functions

FORCEINLINE PSAC_CHANNEL ChannelFromIndex (IN ULONG Index)
 
FORCEINLINE LONG ChannelGetReferenceCount (IN LONG Index)
 
FORCEINLINE LONG ChannelReferenceByIndex (IN LONG Index)
 
FORCEINLINE LONG ChannelReferenceByIndexWithLock (IN LONG Index)
 
FORCEINLINE LONG ChannelDereferenceByIndex (IN LONG Index)
 
FORCEINLINE VOID ChannelDereferenceByIndexWithLock (IN LONG Index)
 
FORCEINLINE VOID ChannelDereferenceToZeroByIndex (IN LONG Index)
 
FORCEINLINE VOID ChannelReferenceToOneByIndex (IN LONG Index)
 
FORCEINLINE VOID ChannelReferenceToOneByIndexWithLock (IN LONG Index)
 
NTSTATUS NTAPI ChanMgrInitialize (VOID)
 
NTSTATUS NTAPI ChanMgrShutdown (VOID)
 
NTSTATUS NTAPI ChanMgrGetChannelByName (IN PWCHAR Name, OUT PSAC_CHANNEL *Channel)
 
NTSTATUS NTAPI ChanMgrGetByHandle (IN SAC_CHANNEL_ID ChannelId, OUT PSAC_CHANNEL *TargetChannel)
 
NTSTATUS NTAPI ChanMgrReleaseChannel (IN PSAC_CHANNEL Channel)
 
BOOLEAN NTAPI ChanMgrIsUniqueName (IN PWCHAR ChannelName)
 
NTSTATUS NTAPI ChanMgrReapChannel (IN ULONG ChannelIndex)
 
NTSTATUS NTAPI ChanMgrReapChannels (VOID)
 
NTSTATUS NTAPI ChanMgrCreateChannel (OUT PSAC_CHANNEL *Channel, IN PSAC_CHANNEL_ATTRIBUTES Attributes)
 
NTSTATUS NTAPI ChanMgrGetByHandleAndFileObject (IN SAC_CHANNEL_ID ChannelId, IN PFILE_OBJECT FileObject, OUT PSAC_CHANNEL *TargetChannel)
 
NTSTATUS NTAPI ChanMgrGetChannelIndex (IN PSAC_CHANNEL Channel, IN PLONG ChannelIndex)
 
NTSTATUS NTAPI ChanMgrGetByIndex (IN LONG TargetIndex, IN PSAC_CHANNEL *TargetChannel)
 
NTSTATUS NTAPI ChanMgrGetNextActiveChannel (IN PSAC_CHANNEL CurrentChannel, IN PULONG TargetIndex, OUT PSAC_CHANNEL *TargetChannel)
 
NTSTATUS NTAPI ChanMgrChannelDestroy (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI ChanMgrCloseChannel (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI ChanMgrGetChannelCount (OUT PULONG ChannelCount)
 
NTSTATUS NTAPI ChanMgrIsFull (OUT PBOOLEAN IsFull)
 
NTSTATUS NTAPI ChanMgrCloseChannelsWithFileObject (IN PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI ChanMgrGenerateUniqueCmdName (IN PWCHAR ChannelName)
 

Variables

SAC_CHANNEL_LOCK ChannelCreateLock
 
BOOLEAN ChannelCreateEnabled
 
PSAC_CHANNEL ChannelArray [SAC_MAX_CHANNELS]
 
LONG ChannelRefCount [SAC_MAX_CHANNELS]
 
LONG ChannelReaped [SAC_MAX_CHANNELS]
 
SAC_CHANNEL_LOCK ChannelSlotLock [SAC_MAX_CHANNELS]
 

Macro Definition Documentation

◆ CHANNEL_SLOT_IS_IN_USE

#define CHANNEL_SLOT_IS_IN_USE (   x)    (ChannelRefCount[(x)] > 0)

Definition at line 26 of file chanmgr.c.

◆ MAX_REF_COUNT

#define MAX_REF_COUNT   100

Definition at line 24 of file chanmgr.c.

Function Documentation

◆ ChanMgrChannelDestroy()

NTSTATUS NTAPI ChanMgrChannelDestroy ( IN PSAC_CHANNEL  Channel)

Definition at line 582 of file chanmgr.c.

583{
584 CHECK_PARAMETER1(Channel);
585 CHECK_PARAMETER(ChannelGetReferenceCount(Channel->Index) > 0);
586
587 /* Destroy the channel */
588 return Channel->ChannelDestroy(Channel);
589}
FORCEINLINE LONG ChannelGetReferenceCount(IN LONG Index)
Definition: chanmgr.c:37
#define CHECK_PARAMETER1(x)
Definition: sacdrv.h:56
#define CHECK_PARAMETER(x)
Definition: sacdrv.h:54

◆ ChanMgrCloseChannel()

NTSTATUS NTAPI ChanMgrCloseChannel ( IN PSAC_CHANNEL  Channel)

Definition at line 593 of file chanmgr.c.

594{
596 CHECK_PARAMETER(Channel);
597
598 /* Check if the channel is active */
599 if (ChannelIsActive(Channel))
600 {
601 /* Yep, close it */
602 Status = ChannelClose(Channel);
603 }
604 else
605 {
606 /* Nothing to do */
608 }
609
610 /* Handle the channel close */
611 ConMgrHandleEvent(TRUE, Channel, &Status);
612 return Status;
613}
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ChannelClose(IN PSAC_CHANNEL Channel)
Definition: channel.c:558
BOOLEAN NTAPI ChannelIsActive(IN PSAC_CHANNEL Channel)
Definition: channel.c:250
NTSTATUS NTAPI ConMgrHandleEvent(IN ULONG EventCode, IN PSAC_CHANNEL Channel, OUT PVOID Data)
Definition: conmgr.c:888
#define TRUE
Definition: types.h:120
Status
Definition: gdiplustypes.h:25
#define STATUS_ALREADY_DISCONNECTED
Definition: ntstatus.h:216

Referenced by ChanMgrCloseChannelsWithFileObject(), and ConMgrWorkerProcessEvents().

◆ ChanMgrCloseChannelsWithFileObject()

NTSTATUS NTAPI ChanMgrCloseChannelsWithFileObject ( IN PFILE_OBJECT  FileObject)

Definition at line 682 of file chanmgr.c.

683{
684 PSAC_CHANNEL Channel;
685 ULONG i;
688
689 /* Loop all channels */
690 for (i = 0; i < SAC_MAX_CHANNELS; i++)
691 {
692 /* Try to get this one */
693 Status = ChanMgrGetByIndex(i, &Channel);
694 if (!NT_SUCCESS(Status)) break;
695
696 /* Check if the FO matches, if so, close the channel */
697 if (Channel->FileObject == FileObject) ChanMgrCloseChannel(Channel);
698
699 /* Drop the reference and try the next channel(s) */
700 Status = ChanMgrReleaseChannel(Channel);
701 if (!NT_SUCCESS(Status)) break;
702 }
703
704 /* All done */
705 return Status;
706}
NTSTATUS NTAPI ChanMgrGetByIndex(IN LONG TargetIndex, IN PSAC_CHANNEL *TargetChannel)
Definition: chanmgr.c:496
NTSTATUS NTAPI ChanMgrReleaseChannel(IN PSAC_CHANNEL Channel)
Definition: chanmgr.c:243
NTSTATUS NTAPI ChanMgrCloseChannel(IN PSAC_CHANNEL Channel)
Definition: chanmgr.c:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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 SAC_MAX_CHANNELS
Definition: sacdrv.h:154
PFILE_OBJECT FileObject
Definition: sacdrv.h:440
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550

◆ ChanMgrCreateChannel()

NTSTATUS NTAPI ChanMgrCreateChannel ( OUT PSAC_CHANNEL Channel,
IN PSAC_CHANNEL_ATTRIBUTES  Attributes 
)

Definition at line 345 of file chanmgr.c.

347{
349 PSAC_CHANNEL NewChannel;
350 SAC_CHANNEL_ID ChanId;
351 ULONG i;
352 CHECK_PARAMETER(Channel);
354
355 /* No other channel create attempts can happen */
357
358 /* Is the channel manager initialized? */
360 {
361 /* Nope, bail out */
363 goto ReturnStatus;
364 }
365
366 /* Reap any zombie channels */
368 if (!NT_SUCCESS(Status))
369 {
370 /* Bail out on error */
372 goto ReturnStatus;
373 }
374
375 /* Check if we already have a channel with this name */
376 if (!ChanMgrIsUniqueName(Attributes->NameBuffer))
377 {
378 /* We do, fail */
380 goto ReturnStatus;
381 }
382
383 /* Allocate this channel */
384 NewChannel = SacAllocatePool(sizeof(SAC_CHANNEL), CHANNEL_BLOCK_TAG);
386 RtlZeroMemory(NewChannel, sizeof(SAC_CHANNEL));
387
388 /* Loop channel slots */
389 for (i = 0; i < SAC_MAX_CHANNELS; i++)
390 {
391 /* Find a free spot for it */
392 if (ChannelReaped[i])
393 {
394 /* Free slot found, attempt to use it */
397 if (ChannelArray[i] == NewChannel) break;
398 }
399 }
400
401 /* Did we not find a single free slot? */
402 if (i == SAC_MAX_CHANNELS)
403 {
404 /* Bail out */
405 goto ReturnStatus;
406 }
407
408 /* Create an ID for this channel */
409 RtlZeroMemory(&ChanId, sizeof(ChanId));
411 if (!NT_SUCCESS(Status))
412 {
413 /* Bail out if we couldn't */
414 SAC_DBG(SAC_DBG_INIT, "SAC Create Channel :: Failed to get GUID\n");
415 goto ReturnStatus;
416 }
417
418 /* Now create the channel proper */
419 Status = ChannelCreate(NewChannel, Attributes, ChanId);
420 if (NT_SUCCESS(Status))
421 {
422 /* Set the channel index */
423 _InterlockedExchange(&NewChannel->Index, i);
424
425 /* Add the initial reference to the channel */
427
428 /* Return it to the caller */
429 *Channel = NewChannel;
430
431 /* This slot is now occupied */
432 ASSERT(ChannelReaped[i] == 1);
434 }
435 else
436 {
437 /* We couldn't create it, free the buffer */
438 SacFreePool(NewChannel);
439 }
440
441ReturnStatus:
442 /* Return whatever the operation status was */
444 return Status;
445}
PSAC_CHANNEL ChannelArray[SAC_MAX_CHANNELS]
Definition: chanmgr.c:17
BOOLEAN NTAPI ChanMgrIsUniqueName(IN PWCHAR ChannelName)
Definition: chanmgr.c:282
FORCEINLINE VOID ChannelReferenceToOneByIndexWithLock(IN LONG Index)
Definition: chanmgr.c:109
#define CHANNEL_SLOT_IS_IN_USE(x)
Definition: chanmgr.c:26
NTSTATUS NTAPI ChanMgrReapChannels(VOID)
Definition: chanmgr.c:309
LONG ChannelReaped[SAC_MAX_CHANNELS]
Definition: chanmgr.c:19
BOOLEAN ChannelCreateEnabled
Definition: chanmgr.c:16
NTSTATUS NTAPI ChannelCreate(IN PSAC_CHANNEL Channel, IN PSAC_CHANNEL_ATTRIBUTES Attributes, IN SAC_CHANNEL_ID ChannelId)
Definition: channel.c:457
#define NULL
Definition: types.h:112
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)
#define ASSERT(a)
Definition: mode.c:44
NTKERNELAPI NTSTATUS ExUuidCreate(OUT UUID *Uuid)
Definition: uuid.c:380
#define STATUS_DUPLICATE_NAME
Definition: ntstatus.h:425
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
#define CHECK_PARAMETER2(x)
Definition: sacdrv.h:58
#define SacAllocatePool(Length, Tag)
Definition: sacdrv.h:24
#define CHECK_PARAMETER_WITH_STATUS(Condition, Status)
Definition: sacdrv.h:47
#define ChannelLockCreates()
Definition: sacdrv.h:1330
#define ChannelUnlockCreates()
Definition: sacdrv.h:1331
#define SAC_DBG_INIT
Definition: sacdrv.h:34
#define CHANNEL_BLOCK_TAG
Definition: sacdrv.h:143
#define SacFreePool(Pointer)
Definition: sacdrv.h:26
GUID ChannelGuid
Definition: sacdrv.h:296
LONG Index
Definition: sacdrv.h:426
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes

Referenced by ConMgrInitialize().

◆ ChanMgrGenerateUniqueCmdName()

NTSTATUS NTAPI ChanMgrGenerateUniqueCmdName ( IN PWCHAR  ChannelName)

Definition at line 710 of file chanmgr.c.

711{
713}
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239

◆ ChanMgrGetByHandle()

NTSTATUS NTAPI ChanMgrGetByHandle ( IN SAC_CHANNEL_ID  ChannelId,
OUT PSAC_CHANNEL TargetChannel 
)

Definition at line 202 of file chanmgr.c.

204{
206 ULONG i;
207 PSAC_CHANNEL Channel;
208 CHECK_PARAMETER2(TargetChannel);
209
210 /* Assume failure */
211 *TargetChannel = NULL;
213
214 /* Loop through all channels */
215 for (i = 0; i < SAC_MAX_CHANNELS; i++)
216 {
217 /* Reference this one and check if it's valid */
219 {
220 /* All good, grab it */
221 Channel = ChannelFromIndex(i);
222 ASSERT(Channel != NULL);
223
224 /* Check if the channel ID matches */
225 if (ChannelIsEqual(Channel, &ChannelId))
226 {
227 /* We found it, return it (with a reference held) */
228 *TargetChannel = Channel;
229 return STATUS_SUCCESS;
230 }
231
232 /* Not the one we want, dereference this one and keep going */
234 }
235 }
236
237 /* No channels with this ID were found */
238 return Status;
239}
FORCEINLINE LONG ChannelReferenceByIndexWithLock(IN LONG Index)
Definition: chanmgr.c:60
FORCEINLINE VOID ChannelDereferenceByIndexWithLock(IN LONG Index)
Definition: chanmgr.c:83
FORCEINLINE PSAC_CHANNEL ChannelFromIndex(IN ULONG Index)
Definition: chanmgr.c:30
BOOLEAN NTAPI ChannelIsEqual(IN PSAC_CHANNEL Channel, IN PSAC_CHANNEL_ID ChannelId)
Definition: channel.c:25
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_NOT_FOUND
Definition: shellext.h:72

Referenced by ChanMgrGetByHandleAndFileObject(), ConMgrInitialize(), and ConMgrResetCurrentChannel().

◆ ChanMgrGetByHandleAndFileObject()

NTSTATUS NTAPI ChanMgrGetByHandleAndFileObject ( IN SAC_CHANNEL_ID  ChannelId,
IN PFILE_OBJECT  FileObject,
OUT PSAC_CHANNEL TargetChannel 
)

Definition at line 449 of file chanmgr.c.

452{
454 PSAC_CHANNEL FoundChannel;
455
456 /* Lookup the channel by ID first */
457 Status = ChanMgrGetByHandle(ChannelId, &FoundChannel);
458 if (NT_SUCCESS(Status))
459 {
460 /* We found it, now check if the file object matches */
461 if (FoundChannel->FileObject == FileObject)
462 {
463 /* Yep, return success */
464 *TargetChannel = FoundChannel;
465 }
466 else
467 {
468 /* Nope, drop the reference on the channel */
469 ChanMgrReleaseChannel(FoundChannel);
470
471 /* And return failure */
472 *TargetChannel = NULL;
474 }
475 }
476
477 /* Return if we found it or not */
478 return Status;
479}
NTSTATUS NTAPI ChanMgrGetByHandle(IN SAC_CHANNEL_ID ChannelId, OUT PSAC_CHANNEL *TargetChannel)
Definition: chanmgr.c:202

◆ ChanMgrGetByIndex()

NTSTATUS NTAPI ChanMgrGetByIndex ( IN LONG  TargetIndex,
IN PSAC_CHANNEL TargetChannel 
)

Definition at line 496 of file chanmgr.c.

498{
500 CHECK_PARAMETER1(TargetIndex < SAC_MAX_CHANNELS);
501 CHECK_PARAMETER2(TargetChannel);
502
503 /* Assume failure */
504 *TargetChannel = NULL;
506
507 /* Reference this one and check if it's valid */
508 if (ChannelReferenceByIndexWithLock(TargetIndex) > 0)
509 {
510 /* We found it, return it (with a reference held) */
511 *TargetChannel = ChannelFromIndex(TargetIndex);
512 return STATUS_SUCCESS;
513 }
514
515 /* No channels with this ID were found */
516 return Status;
517}

Referenced by ChanMgrCloseChannelsWithFileObject(), ChanMgrGetChannelCount(), and ChanMgrGetNextActiveChannel().

◆ ChanMgrGetChannelByName()

NTSTATUS NTAPI ChanMgrGetChannelByName ( IN PWCHAR  Name,
OUT PSAC_CHANNEL Channel 
)

Definition at line 152 of file chanmgr.c.

154{
155 NTSTATUS Status, Status1;
156 ULONG i;
158 PWCHAR ChannelName;
161 CHECK_PARAMETER2(Channel);
162
163 /* Assume failure */
164 *Channel = NULL;
166
167 /* Loop through all channels */
168 for (i = 0; i < SAC_MAX_CHANNELS; i++)
169 {
170 /* Reference this one and check if it's valid */
172 {
173 /* All good, grab it */
176
177 /* Get its name */
178 Status1 = ChannelGetName(CurrentChannel, &ChannelName);
179 ASSERT(NT_SUCCESS(Status1));
180
181 /* Check if this is the name that was passed in */
182 Found = wcsicmp(Name, ChannelName);
183 SacFreePool(ChannelName);
184 if (Found)
185 {
186 /* We found it, return it (with a reference held) */
187 *Channel = CurrentChannel;
188 return STATUS_SUCCESS;
189 }
190
191 /* Not the one we want, dereference this one and keep going */
193 }
194 }
195
196 /* No channels with this name were found */
197 return Status;
198}
unsigned char BOOLEAN
return Found
Definition: dirsup.c:1270
NTSTATUS NTAPI ChannelGetName(IN PSAC_CHANNEL Channel, OUT PWCHAR *Name)
Definition: channel.c:297
PSAC_CHANNEL CurrentChannel
Definition: conmgr.c:26
#define wcsicmp
Definition: compat.h:15
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by ChanMgrIsUniqueName().

◆ ChanMgrGetChannelCount()

NTSTATUS NTAPI ChanMgrGetChannelCount ( OUT PULONG  ChannelCount)

Definition at line 617 of file chanmgr.c.

618{
619 ULONG i;
620 PSAC_CHANNEL Channel;
622 CHECK_PARAMETER(ChannelCount);
623
624 /* Assume no channels */
625 *ChannelCount = 0;
626
627 /* Loop every channel */
628 for (i = 0; i < SAC_MAX_CHANNELS; i++)
629 {
630 /* See if this one exists */
631 Status = ChanMgrGetByIndex(i, &Channel);
633 {
634 /* Sanity checks*/
636 ASSERT(Channel != NULL);
637
638 /* It exists -- is it active? Or, does it have output data? */
639 if ((ChannelIsActive(Channel)) ||
640 (!(ChannelIsActive(Channel)) &&
641 (Channel->ChannelHasNewOBufferData)))
642 {
643 /* It's active or has output data, increase the count */
644 ++*ChannelCount;
645 break;
646 }
647
648 /* Drop the reference on this channel and try the next one */
649 Status = ChanMgrReleaseChannel(Channel);
650 if (!NT_SUCCESS(Status)) return Status;
651 }
652 else
653 {
654 /* Channel doesn't exist, nothing wrong with that, keep going */
656 }
657 }
658
659 /* We should always succeed if we get here */
661 return Status;
662}
LONG ChannelHasNewOBufferData
Definition: sacdrv.h:459

Referenced by ChanMgrIsFull().

◆ ChanMgrGetChannelIndex()

NTSTATUS NTAPI ChanMgrGetChannelIndex ( IN PSAC_CHANNEL  Channel,
IN PLONG  ChannelIndex 
)

Definition at line 483 of file chanmgr.c.

485{
486 CHECK_PARAMETER1(Channel);
487 CHECK_PARAMETER2(ChannelIndex);
488
489 /* Just return the index of the channel */
490 *ChannelIndex = ChannelGetIndex(Channel);
491 return STATUS_SUCCESS;
492}
FORCEINLINE LONG ChannelGetIndex(IN PSAC_CHANNEL Channel)
Definition: sacdrv.h:1353

Referenced by ChanMgrGetNextActiveChannel().

◆ ChanMgrGetNextActiveChannel()

NTSTATUS NTAPI ChanMgrGetNextActiveChannel ( IN PSAC_CHANNEL  CurrentChannel,
IN PULONG  TargetIndex,
OUT PSAC_CHANNEL TargetChannel 
)

Definition at line 521 of file chanmgr.c.

524{
526 ULONG i;
527 LONG ChannelIndex, StartIndex;
528 PSAC_CHANNEL FoundChannel;
529 BOOLEAN ChannelFound;
531 CHECK_PARAMETER2(TargetIndex);
532 CHECK_PARAMETER3(TargetChannel);
533
534 /* Get the current channel index */
536 if (!NT_SUCCESS(Status)) return Status;
537
538 /* Assume failure */
539 ChannelFound = FALSE;
540
541 /* Loop through all the possible active channels */
542 StartIndex = (ChannelIndex + 1) % SAC_MAX_CHANNELS;
543 for (i = StartIndex; i != StartIndex; i = (i + 1) % SAC_MAX_CHANNELS)
544 {
545 /* Get the channel and see if it exists*/
546 Status = ChanMgrGetByIndex(i, &FoundChannel);
548 {
549 /* Bail out if we failed for some reason */
550 if (!NT_SUCCESS(Status)) return Status;
551
552 /* It exists -- is it active? Or, does it have output data? */
553 if ((ChannelIsActive(FoundChannel)) ||
554 (!(ChannelIsActive(FoundChannel)) &&
555 (FoundChannel->ChannelHasNewOBufferData)))
556 {
557 /* It's active or has output data, return with it */
558 ChannelFound = TRUE;
559 break;
560 }
561
562 /* Drop the reference on this channel and try the next one */
563 Status = ChanMgrReleaseChannel(FoundChannel);
564 if (!NT_SUCCESS(Status)) return Status;
565 }
566 }
567
568 /* Check if we successfully found a channel */
569 if ((NT_SUCCESS(Status)) && (ChannelFound))
570 {
571 /* Return it and its indexed. Remember we still hold the reference */
572 *TargetIndex = i;
573 *TargetChannel = FoundChannel;
574 }
575
576 /* All done */
577 return Status;
578}
NTSTATUS NTAPI ChanMgrGetChannelIndex(IN PSAC_CHANNEL Channel, IN PLONG ChannelIndex)
Definition: chanmgr.c:483
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define CHECK_PARAMETER3(x)
Definition: sacdrv.h:60

Referenced by ConMgrAdvanceCurrentChannel().

◆ ChanMgrInitialize()

NTSTATUS NTAPI ChanMgrInitialize ( VOID  )

Definition at line 118 of file chanmgr.c.

119{
120 ULONG i;
121
122 /* Initialize the channel lock */
125
126 /* Loop through the channel arrays */
127 for (i = 0; i < SAC_MAX_CHANNELS; i++)
128 {
129 /* Clear and initialize their locks */
132
133 /* Clear their statuses and reference counts */
136 }
137
138 /* All good */
139 return STATUS_SUCCESS;
140}
SAC_CHANNEL_LOCK ChannelSlotLock[SAC_MAX_CHANNELS]
Definition: chanmgr.c:20
SAC_CHANNEL_LOCK ChannelCreateLock
Definition: chanmgr.c:15
LONG ChannelRefCount[SAC_MAX_CHANNELS]
Definition: chanmgr.c:18
FORCEINLINE VOID SacInitializeLock(IN PSAC_CHANNEL_LOCK Lock)
Definition: sacdrv.h:1252

Referenced by InitializeGlobalData().

◆ ChanMgrIsFull()

NTSTATUS NTAPI ChanMgrIsFull ( OUT PBOOLEAN  IsFull)

Definition at line 666 of file chanmgr.c.

667{
669 ULONG Count;
670
671 /* Count the channels */
674
675 /* Return if we hit the limit */
676 *IsFull = (Count == SAC_MAX_CHANNELS);
677 return Status;
678}
NTSTATUS NTAPI ChanMgrGetChannelCount(OUT PULONG ChannelCount)
Definition: chanmgr.c:617
int Count
Definition: noreturn.cpp:7

◆ ChanMgrIsUniqueName()

BOOLEAN NTAPI ChanMgrIsUniqueName ( IN PWCHAR  ChannelName)

Definition at line 282 of file chanmgr.c.

283{
285 BOOLEAN IsUnique = FALSE;
286 PSAC_CHANNEL Channel;
287
288 /* Check if a channel with this name already exists */
289 Status = ChanMgrGetChannelByName(ChannelName, &Channel);
290 if (Status == STATUS_NOT_FOUND) IsUnique = TRUE;
291
292 /* If one did, dereference it, all we wanted was to check uniqueness */
294
295 /* Return if one was found or not */
296 return IsUnique;
297}
NTSTATUS NTAPI ChanMgrGetChannelByName(IN PWCHAR Name, OUT PSAC_CHANNEL *Channel)
Definition: chanmgr.c:152

Referenced by ChanMgrCreateChannel().

◆ ChanMgrReapChannel()

NTSTATUS NTAPI ChanMgrReapChannel ( IN ULONG  ChannelIndex)

Definition at line 301 of file chanmgr.c.

302{
303 /* FIXME: TODO */
305}

Referenced by ChanMgrReapChannels().

◆ ChanMgrReapChannels()

NTSTATUS NTAPI ChanMgrReapChannels ( VOID  )

Definition at line 309 of file chanmgr.c.

310{
311 ULONG i;
313
314 /* Loop all the channels */
315 for (i = 0; i < SAC_MAX_CHANNELS; i++)
316 {
317 /* Lock this index and see if the channel was reaped */
319 if (!ChannelReaped[i])
320 {
321 /* It was not reaped yet, so a channel should still be here */
323 if (ChannelGetReferenceCount(i) <= 0)
324 {
325 /* The channel has no more references, so clear the buffer flags */
328
329 /* And reap it */
331 }
332 }
333
334 /* Release the lock, and move on unless reaping failed */
336 if (!NT_SUCCESS(Status)) break;
337 }
338
339 /* Return reaping status */
340 return Status;
341}
NTSTATUS NTAPI ChanMgrReapChannel(IN ULONG ChannelIndex)
Definition: chanmgr.c:301
FORCEINLINE BOOLEAN ChannelHasNewOBufferData(IN PSAC_CHANNEL Channel)
Definition: rawchan.c:51
#define ChannelSlotUnlock(x)
Definition: sacdrv.h:1339
FORCEINLINE BOOLEAN ChannelHasNewIBufferData(IN PSAC_CHANNEL Channel)
Definition: sacdrv.h:1361

Referenced by ChanMgrCreateChannel().

◆ ChanMgrReleaseChannel()

NTSTATUS NTAPI ChanMgrReleaseChannel ( IN PSAC_CHANNEL  Channel)

Definition at line 243 of file chanmgr.c.

244{
245 LONG Index;
246 ULONG RefCount;
247 PSAC_CHANNEL ThisChannel;
248 CHECK_PARAMETER(Channel);
249
250 /* Get the index of the channel */
251 Index = ChannelGetIndex(Channel);
252
253 /* Drop a reference -- there should still be at least the keepalive left */
256 ASSERT(RefCount > 0);
257
258 /* Do we only have the keep-alive left, and the channel is dead? */
259 if ((RefCount == 1) && !(ChannelIsActive(Channel)))
260 {
261 /* Check if the ??? flag is set, or if there's no output data */
262 ThisChannel = ChannelFromIndex(Index);
263 if (!(ThisChannel->Flags & 1))
264 {
265 /* Nope, we can wipe the references and get rid of it */
267 }
268 else if (!ThisChannel->ChannelHasNewOBufferData)
269 {
270 /* No data, we can wipe the references and get rid of it */
272 }
273 }
274
275 /* We're done, we can unlock the slot now */
277 return STATUS_SUCCESS;
278}
FORCEINLINE VOID ChannelDereferenceToZeroByIndex(IN LONG Index)
Definition: chanmgr.c:92
FORCEINLINE LONG ChannelDereferenceByIndex(IN LONG Index)
Definition: chanmgr.c:72
ULONG Flags
Definition: sacdrv.h:445
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by ChanMgrCloseChannelsWithFileObject(), ChanMgrGetByHandleAndFileObject(), ChanMgrGetChannelCount(), ChanMgrGetNextActiveChannel(), ChanMgrIsUniqueName(), ConMgrSetCurrentChannel(), ConMgrShutdown(), and ConMgrWorkerProcessEvents().

◆ ChanMgrShutdown()

NTSTATUS NTAPI ChanMgrShutdown ( VOID  )

Definition at line 144 of file chanmgr.c.

145{
146 /* FIXME: TODO */
148}

Referenced by FreeGlobalData().

◆ ChannelDereferenceByIndex()

FORCEINLINE LONG ChannelDereferenceByIndex ( IN LONG  Index)

Definition at line 72 of file chanmgr.c.

73{
79}
#define MAX_REF_COUNT
Definition: chanmgr.c:24
long __cdecl _InterlockedDecrement(_Interlocked_operand_ long volatile *_Addend)

Referenced by ChanMgrReleaseChannel(), and ChannelDereferenceByIndexWithLock().

◆ ChannelDereferenceByIndexWithLock()

FORCEINLINE VOID ChannelDereferenceByIndexWithLock ( IN LONG  Index)

◆ ChannelDereferenceToZeroByIndex()

FORCEINLINE VOID ChannelDereferenceToZeroByIndex ( IN LONG  Index)

◆ ChannelFromIndex()

◆ ChannelGetReferenceCount()

◆ ChannelReferenceByIndex()

FORCEINLINE LONG ChannelReferenceByIndex ( IN LONG  Index)

Definition at line 44 of file chanmgr.c.

45{
47 {
53 }
54
56}
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)

Referenced by ChannelReferenceByIndexWithLock().

◆ ChannelReferenceByIndexWithLock()

FORCEINLINE LONG ChannelReferenceByIndexWithLock ( IN LONG  Index)

Definition at line 60 of file chanmgr.c.

61{
62 LONG RefCount;
63
67 return RefCount;
68}
FORCEINLINE LONG ChannelReferenceByIndex(IN LONG Index)
Definition: chanmgr.c:44

Referenced by ChanMgrGetByHandle(), ChanMgrGetByIndex(), and ChanMgrGetChannelByName().

◆ ChannelReferenceToOneByIndex()

FORCEINLINE VOID ChannelReferenceToOneByIndex ( IN LONG  Index)

Definition at line 101 of file chanmgr.c.

Referenced by ChannelReferenceToOneByIndexWithLock().

◆ ChannelReferenceToOneByIndexWithLock()

FORCEINLINE VOID ChannelReferenceToOneByIndexWithLock ( IN LONG  Index)

Definition at line 109 of file chanmgr.c.

110{
114}
FORCEINLINE VOID ChannelReferenceToOneByIndex(IN LONG Index)
Definition: chanmgr.c:101

Referenced by ChanMgrCreateChannel().

Variable Documentation

◆ ChannelArray

◆ ChannelCreateEnabled

BOOLEAN ChannelCreateEnabled

Definition at line 16 of file chanmgr.c.

Referenced by ChanMgrCreateChannel(), and ChanMgrInitialize().

◆ ChannelCreateLock

SAC_CHANNEL_LOCK ChannelCreateLock

Definition at line 15 of file chanmgr.c.

Referenced by ChanMgrInitialize().

◆ ChannelReaped

LONG ChannelReaped[SAC_MAX_CHANNELS]

Definition at line 19 of file chanmgr.c.

Referenced by ChanMgrCreateChannel(), ChanMgrInitialize(), and ChanMgrReapChannels().

◆ ChannelRefCount

◆ ChannelSlotLock