ReactOS  0.4.15-dev-509-g96a357b
ports.h File Reference

Go to the source code of this file.

Classes

struct  _PORT_SET
 

Typedefs

typedef struct _PORT_SET PORT_SET
 
typedef struct _PORT_SETPPORT_SET
 

Functions

NTSTATUS PortsStartup (PPORT_SET PortSet, UINT StartingPort, UINT PortsToManage)
 
VOID PortsShutdown (PPORT_SET PortSet)
 
VOID DeallocatePort (PPORT_SET PortSet, ULONG Port)
 
BOOLEAN AllocatePort (PPORT_SET PortSet, ULONG Port)
 
ULONG AllocateAnyPort (PPORT_SET PortSet)
 
ULONG AllocatePortFromRange (PPORT_SET PortSet, ULONG Lowest, ULONG Highest)
 

Typedef Documentation

◆ PORT_SET

◆ PPORT_SET

Function Documentation

◆ AllocateAnyPort()

ULONG AllocateAnyPort ( PPORT_SET  PortSet)

Definition at line 69 of file ports.c.

69  {
70  ULONG AllocatedPort;
71  KIRQL OldIrql;
72 
73  KeAcquireSpinLock( &PortSet->Lock, &OldIrql );
74  AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, 0 );
75  if( AllocatedPort != (ULONG)-1 ) {
76  RtlSetBit( &PortSet->ProtoBitmap, AllocatedPort );
77  AllocatedPort += PortSet->StartingPort;
78  KeReleaseSpinLock( &PortSet->Lock, OldIrql );
79  return htons(AllocatedPort);
80  }
81  KeReleaseSpinLock( &PortSet->Lock, OldIrql );
82 
83  return -1;
84 }
UINT StartingPort
Definition: ports.h:16
NTSYSAPI VOID NTAPI RtlSetBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:304
RTL_BITMAP ProtoBitmap
Definition: ports.h:14
KSPIN_LOCK Lock
Definition: ports.h:18
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSYSAPI ULONG WINAPI RtlFindClearBits(PCRTL_BITMAP, ULONG, ULONG)
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
#define htons(x)
Definition: module.h:213

◆ AllocatePort()

BOOLEAN AllocatePort ( PPORT_SET  PortSet,
ULONG  Port 
)

Definition at line 47 of file ports.c.

47  {
48  BOOLEAN Clear;
49  KIRQL OldIrql;
50 
51  Port = htons(Port);
52 
53  if ((Port < PortSet->StartingPort) ||
54  (Port >= PortSet->StartingPort + PortSet->PortsToOversee))
55  {
56  return FALSE;
57  }
58 
59  Port -= PortSet->StartingPort;
60 
61  KeAcquireSpinLock( &PortSet->Lock, &OldIrql );
62  Clear = RtlAreBitsClear( &PortSet->ProtoBitmap, Port, 1 );
63  if( Clear ) RtlSetBits( &PortSet->ProtoBitmap, Port, 1 );
64  KeReleaseSpinLock( &PortSet->Lock, OldIrql );
65 
66  return Clear;
67 }
CPPORT Port[4]
Definition: headless.c:34
UINT StartingPort
Definition: ports.h:16
RTL_BITMAP ProtoBitmap
Definition: ports.h:14
KSPIN_LOCK Lock
Definition: ports.h:18
UCHAR KIRQL
Definition: env_spec_w32.h:591
UINT PortsToOversee
Definition: ports.h:17
unsigned char BOOLEAN
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
NTSYSAPI void WINAPI RtlSetBits(PRTL_BITMAP, ULONG, ULONG)
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
NTSYSAPI BOOLEAN WINAPI RtlAreBitsClear(PCRTL_BITMAP, ULONG, ULONG)
void Clear(USHORT Window)
Definition: hardware.c:684
#define htons(x)
Definition: module.h:213

Referenced by TCPAllocatePort(), and UDPAllocatePort().

◆ AllocatePortFromRange()

ULONG AllocatePortFromRange ( PPORT_SET  PortSet,
ULONG  Lowest,
ULONG  Highest 
)

Definition at line 86 of file ports.c.

86  {
87  ULONG AllocatedPort;
88  KIRQL OldIrql;
89 
90  if ((Lowest < PortSet->StartingPort) ||
91  (Highest >= PortSet->StartingPort + PortSet->PortsToOversee))
92  {
93  return -1;
94  }
95 
96  Lowest -= PortSet->StartingPort;
97  Highest -= PortSet->StartingPort;
98 
99  KeAcquireSpinLock( &PortSet->Lock, &OldIrql );
100  AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, Lowest );
101  if( AllocatedPort != (ULONG)-1 && AllocatedPort <= Highest) {
102  RtlSetBit( &PortSet->ProtoBitmap, AllocatedPort );
103  AllocatedPort += PortSet->StartingPort;
104  KeReleaseSpinLock( &PortSet->Lock, OldIrql );
105  return htons(AllocatedPort);
106  }
107  KeReleaseSpinLock( &PortSet->Lock, OldIrql );
108 
109  return -1;
110 }
UINT StartingPort
Definition: ports.h:16
NTSYSAPI VOID NTAPI RtlSetBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:304
RTL_BITMAP ProtoBitmap
Definition: ports.h:14
KSPIN_LOCK Lock
Definition: ports.h:18
UCHAR KIRQL
Definition: env_spec_w32.h:591
UINT PortsToOversee
Definition: ports.h:17
NTSYSAPI ULONG WINAPI RtlFindClearBits(PCRTL_BITMAP, ULONG, ULONG)
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
#define htons(x)
Definition: module.h:213

Referenced by TCPAllocatePort(), and UDPAllocatePort().

◆ DeallocatePort()

VOID DeallocatePort ( PPORT_SET  PortSet,
ULONG  Port 
)

Definition at line 35 of file ports.c.

35  {
36  KIRQL OldIrql;
37 
38  Port = htons(Port);
39  ASSERT(Port >= PortSet->StartingPort);
40  ASSERT(Port < PortSet->StartingPort + PortSet->PortsToOversee);
41 
42  KeAcquireSpinLock( &PortSet->Lock, &OldIrql );
43  RtlClearBits( &PortSet->ProtoBitmap, Port - PortSet->StartingPort, 1 );
44  KeReleaseSpinLock( &PortSet->Lock, OldIrql );
45 }
CPPORT Port[4]
Definition: headless.c:34
UINT StartingPort
Definition: ports.h:16
RTL_BITMAP ProtoBitmap
Definition: ports.h:14
KSPIN_LOCK Lock
Definition: ports.h:18
UCHAR KIRQL
Definition: env_spec_w32.h:591
UINT PortsToOversee
Definition: ports.h:17
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
NTSYSAPI void WINAPI RtlClearBits(PRTL_BITMAP, ULONG, ULONG)
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define htons(x)
Definition: module.h:213

Referenced by TCPFreePort(), and UDPFreePort().

◆ PortsShutdown()

VOID PortsShutdown ( PPORT_SET  PortSet)

Definition at line 31 of file ports.c.

31  {
33 }
#define PORT_SET_TAG
Definition: tags.h:26
PVOID ProtoBitBuffer
Definition: ports.h:15
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by TCPShutdown(), and UDPShutdown().

◆ PortsStartup()

NTSTATUS PortsStartup ( PPORT_SET  PortSet,
UINT  StartingPort,
UINT  PortsToManage 
)

Definition at line 13 of file ports.c.

15  {
16  PortSet->StartingPort = StartingPort;
17  PortSet->PortsToOversee = PortsToManage;
18 
19  PortSet->ProtoBitBuffer =
21  PORT_SET_TAG );
22  if(!PortSet->ProtoBitBuffer) return STATUS_INSUFFICIENT_RESOURCES;
24  PortSet->ProtoBitBuffer,
25  PortSet->PortsToOversee );
26  RtlClearAllBits( &PortSet->ProtoBitmap );
27  KeInitializeSpinLock( &PortSet->Lock );
28  return STATUS_SUCCESS;
29 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UINT StartingPort
Definition: ports.h:16
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
RTL_BITMAP ProtoBitmap
Definition: ports.h:14
KSPIN_LOCK Lock
Definition: ports.h:18
UINT PortsToOversee
Definition: ports.h:17
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
#define PORT_SET_TAG
Definition: tags.h:26
PVOID ProtoBitBuffer
Definition: ports.h:15
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSYSAPI void WINAPI RtlClearAllBits(PRTL_BITMAP)
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by TCPStartup(), and UDPStartup().