ReactOS  0.4.14-dev-317-g96040ec
lock.c File Reference
#include "afd.h"
Include dependency graph for lock.c:

Go to the source code of this file.

Functions

PVOID GetLockedData (PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
PVOID LockRequest (PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
 
VOID UnlockRequest (PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
PAFD_WSABUF LockBuffers (PAFD_WSABUF Buf, UINT Count, PVOID AddressBuf, PINT AddressLen, BOOLEAN Write, BOOLEAN LockAddress, KPROCESSOR_MODE LockMode)
 
VOID UnlockBuffers (PAFD_WSABUF Buf, UINT Count, BOOL Address)
 
PAFD_HANDLE LockHandles (PAFD_HANDLE HandleArray, UINT HandleCount)
 
VOID UnlockHandles (PAFD_HANDLE HandleArray, UINT HandleCount)
 
BOOLEAN SocketAcquireStateLock (PAFD_FCB FCB)
 
VOID SocketStateUnlock (PAFD_FCB FCB)
 
NTSTATUS NTAPI UnlockAndMaybeComplete (PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
 
NTSTATUS LostSocket (PIRP Irp)
 
NTSTATUS QueueUserModeIrp (PAFD_FCB FCB, PIRP Irp, UINT Function)
 
NTSTATUS LeaveIrpUntilLater (PAFD_FCB FCB, PIRP Irp, UINT Function)
 

Function Documentation

◆ GetLockedData()

PVOID GetLockedData ( PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 13 of file lock.c.

14 {
15  ASSERT(Irp->MdlAddress);
16  ASSERT(Irp->Tail.Overlay.DriverContext[0]);
17 
19 
20  return Irp->Tail.Overlay.DriverContext[0];
21 }
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157

Referenced by CleanupPendingIrp(), LockRequest(), PacketSocketRecvComplete(), PacketSocketSendComplete(), ReceiveActivity(), ReceiveComplete(), SatisfyPacketRecvRequest(), and SendComplete().

◆ LeaveIrpUntilLater()

NTSTATUS LeaveIrpUntilLater ( PAFD_FCB  FCB,
PIRP  Irp,
UINT  Function 
)

Definition at line 433 of file lock.c.

433  {
435 
437 
439 
440  return Status;
441 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:397
Status
Definition: gdiplustypes.h:24

Referenced by AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdPacketSocketReadData(), AfdStreamSocketConnect(), and AfdWaitForListen().

◆ LockBuffers()

PAFD_WSABUF LockBuffers ( PAFD_WSABUF  Buf,
UINT  Count,
PVOID  AddressBuf,
PINT  AddressLen,
BOOLEAN  Write,
BOOLEAN  LockAddress,
KPROCESSOR_MODE  LockMode 
)

Definition at line 205 of file lock.c.

208  {
209  UINT i;
210  /* Copy the buffer array so we don't lose it */
211  UINT Lock = LockAddress ? 2 : 0;
212  UINT Size = (sizeof(AFD_WSABUF) + sizeof(AFD_MAPBUF)) * (Count + Lock);
214  BOOLEAN LockFailed = FALSE;
215  PAFD_MAPBUF MapBuf;
216 
217  AFD_DbgPrint(MID_TRACE,("Called(%p)\n", NewBuf));
218 
219  if( NewBuf ) {
220  RtlZeroMemory(NewBuf, Size);
221 
222  MapBuf = (PAFD_MAPBUF)(NewBuf + Count + Lock);
223 
224  _SEH2_TRY {
225  RtlCopyMemory( NewBuf, Buf, sizeof(AFD_WSABUF) * Count );
226  if( LockAddress ) {
227  if (AddressBuf && AddressLen) {
228  NewBuf[Count].buf = AddressBuf;
229  NewBuf[Count].len = *AddressLen;
230  NewBuf[Count + 1].buf = (PVOID)AddressLen;
231  NewBuf[Count + 1].len = sizeof(*AddressLen);
232  }
233  Count += 2;
234  }
236  AFD_DbgPrint(MIN_TRACE,("Access violation copying buffer info "
237  "from userland (%p %p)\n",
238  Buf, AddressLen));
240  _SEH2_YIELD(return NULL);
241  } _SEH2_END;
242 
243  for( i = 0; i < Count; i++ ) {
244  AFD_DbgPrint(MID_TRACE,("Locking buffer %u (%p:%u)\n",
245  i, NewBuf[i].buf, NewBuf[i].len));
246 
247  if( NewBuf[i].buf && NewBuf[i].len ) {
248  MapBuf[i].Mdl = IoAllocateMdl( NewBuf[i].buf,
249  NewBuf[i].len,
250  FALSE,
251  FALSE,
252  NULL );
253  } else {
254  MapBuf[i].Mdl = NULL;
255  continue;
256  }
257 
258  AFD_DbgPrint(MID_TRACE,("NewMdl @ %p\n", MapBuf[i].Mdl));
259 
260  if( MapBuf[i].Mdl ) {
261  AFD_DbgPrint(MID_TRACE,("Probe and lock pages\n"));
262  _SEH2_TRY {
263  MmProbeAndLockPages( MapBuf[i].Mdl, LockMode,
266  LockFailed = TRUE;
267  } _SEH2_END;
268  AFD_DbgPrint(MID_TRACE,("MmProbeAndLock finished\n"));
269 
270  if( LockFailed ) {
271  AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
272  IoFreeMdl( MapBuf[i].Mdl );
273  MapBuf[i].Mdl = NULL;
275  return NULL;
276  }
277  } else {
279  return NULL;
280  }
281  }
282  }
283 
284  AFD_DbgPrint(MID_TRACE,("Leaving %p\n", NewBuf));
285 
286  return NewBuf;
287 }
UINT len
Definition: shared.h:17
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
PCHAR buf
Definition: shared.h:18
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define TAG_AFD_WSA_BUFFER
Definition: afd.h:54
static BOOL Write(PBYTE Address, PBYTE Data, SIZE_T Size)
Definition: vmhorizon.c:15
_SEH2_TRY
Definition: create.c:4250
ULONG LockMode
Definition: env_spec_w32.cpp:8
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 AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
struct _AFD_WSABUF AFD_WSABUF
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
struct _AFD_MAPBUF * PAFD_MAPBUF
PMDL Mdl
Definition: afd.h:107
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
GLenum GLsizei len
Definition: glext.h:6722
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
_SEH2_END
Definition: create.c:4424
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
unsigned int UINT
Definition: ndis.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdPacketSocketReadData(), and AfdPacketSocketWriteData().

◆ LockHandles()

PAFD_HANDLE LockHandles ( PAFD_HANDLE  HandleArray,
UINT  HandleCount 
)

Definition at line 310 of file lock.c.

310  {
311  UINT i;
313 
315  HandleCount * sizeof(AFD_HANDLE),
317 
318  for( i = 0; FileObjects && i < HandleCount; i++ ) {
319  FileObjects[i].Status = 0;
320  FileObjects[i].Events = HandleArray[i].Events;
321  FileObjects[i].Handle = 0;
322  if( !HandleArray[i].Handle ) continue;
323  if( NT_SUCCESS(Status) ) {
325  ( (PVOID)HandleArray[i].Handle,
327  NULL,
328  KernelMode,
329  (PVOID*)&FileObjects[i].Handle,
330  NULL );
331  }
332 
333  if( !NT_SUCCESS(Status) )
334  {
335  AFD_DbgPrint(MIN_TRACE,("Failed to reference handles (0x%x)\n", Status));
336  FileObjects[i].Handle = 0;
337  }
338  }
339 
340  if( !NT_SUCCESS(Status) ) {
341  UnlockHandles( FileObjects, HandleCount );
342  return NULL;
343  }
344 
345  return FileObjects;
346 }
NTSTATUS Status
Definition: shared.h:52
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
LONG NTSTATUS
Definition: precomp.h:26
#define TAG_AFD_POLL_HANDLE
Definition: afd.h:47
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
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
ULONG Events
Definition: shared.h:51
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
unsigned int UINT
Definition: ndis.h:50
#define MIN_TRACE
Definition: debug.h:14
SOCKET Handle
Definition: shared.h:50
return STATUS_SUCCESS
Definition: btrfs.c:2938
VOID UnlockHandles(PAFD_HANDLE HandleArray, UINT HandleCount)
Definition: lock.c:348

Referenced by AfdSelect().

◆ LockRequest()

PVOID LockRequest ( PIRP  Irp,
PIO_STACK_LOCATION  IrpSp,
BOOLEAN  Output,
KPROCESSOR_MODE LockMode 
)

Definition at line 24 of file lock.c.

27  {
28  BOOLEAN LockFailed = FALSE;
29 
30  ASSERT(!Irp->MdlAddress);
31 
32  switch (IrpSp->MajorFunction)
33  {
36  ASSERT(IrpSp->Parameters.DeviceIoControl.Type3InputBuffer);
37  ASSERT(IrpSp->Parameters.DeviceIoControl.InputBufferLength);
38 
39 
40  Irp->MdlAddress =
41  IoAllocateMdl( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer,
42  IrpSp->Parameters.DeviceIoControl.InputBufferLength,
43  FALSE,
44  FALSE,
45  NULL );
46  if( Irp->MdlAddress ) {
47  _SEH2_TRY {
48  MmProbeAndLockPages( Irp->MdlAddress, Irp->RequestorMode, IoModifyAccess );
50  LockFailed = TRUE;
51  } _SEH2_END;
52 
53  if( LockFailed ) {
54  AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
55  IoFreeMdl( Irp->MdlAddress );
56  Irp->MdlAddress = NULL;
57  return NULL;
58  }
59 
60  /* The mapped address goes in index 1 */
61  Irp->Tail.Overlay.DriverContext[1] = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
62  if (!Irp->Tail.Overlay.DriverContext[1])
63  {
64  AFD_DbgPrint(MIN_TRACE,("Failed to get mapped address\n"));
65  MmUnlockPages(Irp->MdlAddress);
66  IoFreeMdl( Irp->MdlAddress );
67  Irp->MdlAddress = NULL;
68  return NULL;
69  }
70 
71  /* The allocated address goes in index 0 */
72  Irp->Tail.Overlay.DriverContext[0] = ExAllocatePoolWithTag(NonPagedPool,
73  MmGetMdlByteCount(Irp->MdlAddress),
75 
76  if (!Irp->Tail.Overlay.DriverContext[0])
77  {
78  AFD_DbgPrint(MIN_TRACE,("Failed to allocate memory\n"));
79  MmUnlockPages(Irp->MdlAddress);
80  IoFreeMdl( Irp->MdlAddress );
81  Irp->MdlAddress = NULL;
82  return NULL;
83  }
84 
85  RtlCopyMemory(Irp->Tail.Overlay.DriverContext[0],
86  Irp->Tail.Overlay.DriverContext[1],
87  MmGetMdlByteCount(Irp->MdlAddress));
88 
89  /* If we don't want a copy back, we zero the mapped address pointer */
90  if (!Output)
91  {
92  Irp->Tail.Overlay.DriverContext[1] = NULL;
93  }
94 
95  /* We're using a user-mode buffer directly */
96  if (LockMode != NULL)
97  {
98  *LockMode = UserMode;
99  }
100  }
101  else return NULL;
102  break;
103 
104  case IRP_MJ_READ:
105  case IRP_MJ_WRITE:
106  ASSERT(Irp->UserBuffer);
107 
108  Irp->MdlAddress =
109  IoAllocateMdl(Irp->UserBuffer,
111  IrpSp->Parameters.Read.Length : IrpSp->Parameters.Write.Length,
112  FALSE,
113  FALSE,
114  NULL );
115  if( Irp->MdlAddress ) {
116  PAFD_RECV_INFO AfdInfo;
117 
118  _SEH2_TRY {
119  MmProbeAndLockPages( Irp->MdlAddress, Irp->RequestorMode, IoModifyAccess );
121  LockFailed = TRUE;
122  } _SEH2_END;
123 
124  if( LockFailed ) {
125  AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
126  IoFreeMdl( Irp->MdlAddress );
127  Irp->MdlAddress = NULL;
128  return NULL;
129  }
130 
131  /* We need to create the info struct that AFD expects for all send/recv requests */
133  sizeof(AFD_RECV_INFO) + sizeof(AFD_WSABUF),
135 
136  if (!AfdInfo)
137  {
138  AFD_DbgPrint(MIN_TRACE,("Failed to allocate memory\n"));
139  MmUnlockPages(Irp->MdlAddress);
140  IoFreeMdl( Irp->MdlAddress );
141  Irp->MdlAddress = NULL;
142  return NULL;
143  }
144 
145  /* We'll append the buffer array to this struct */
146  AfdInfo->BufferArray = (PAFD_WSABUF)(AfdInfo + 1);
147  AfdInfo->BufferCount = 1;
148 
149  /* Setup the default flags values */
150  AfdInfo->AfdFlags = 0;
151  AfdInfo->TdiFlags = 0;
152 
153  /* Now build the buffer array */
154  AfdInfo->BufferArray[0].buf = MmGetSystemAddressForMdl(Irp->MdlAddress);
155  AfdInfo->BufferArray[0].len = MmGetMdlByteCount(Irp->MdlAddress);
156 
157  /* Store the struct where AFD expects */
158  Irp->Tail.Overlay.DriverContext[0] = AfdInfo;
159 
160  /* Don't copy anything out */
161  Irp->Tail.Overlay.DriverContext[1] = NULL;
162 
163  /* We're using a placeholder buffer that we allocated */
164  if (LockMode != NULL)
165  {
166  *LockMode = KernelMode;
167  }
168  }
169  else return NULL;
170  break;
171 
172  default:
173  ASSERT(FALSE);
174  return NULL;
175  }
176 
177  return GetLockedData(Irp, IrpSp);
178 }
UINT len
Definition: shared.h:17
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
PCHAR buf
Definition: shared.h:18
ULONG AfdFlags
Definition: shared.h:87
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
_SEH2_TRY
Definition: create.c:4250
ULONG LockMode
Definition: env_spec_w32.cpp:8
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
PAFD_WSABUF BufferArray
Definition: shared.h:85
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
PVOID GetLockedData(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:13
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG TdiFlags
Definition: shared.h:88
ULONG BufferCount
Definition: shared.h:86
Definition: arc.h:85
struct _AFD_WSABUF * PAFD_WSABUF
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
_SEH2_END
Definition: create.c:4424
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define MmGetMdlByteCount(_Mdl)
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define MmGetSystemAddressForMdl(Mdl)
#define MIN_TRACE
Definition: debug.h:14
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

Referenced by AfdBindSocket(), AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdDisconnect(), AfdEnumEvents(), AfdEventSelect(), AfdGetInfo(), AfdGetTdiHandles(), AfdListenSocket(), AfdPacketSocketReadData(), AfdPacketSocketWriteData(), AfdSetConnectData(), AfdSetConnectDataSize(), AfdSetConnectOptions(), AfdSetConnectOptionsSize(), AfdSetContext(), AfdSetDisconnectData(), AfdSetDisconnectDataSize(), AfdSetDisconnectOptions(), AfdSetDisconnectOptionsSize(), AfdSetInfo(), AfdStreamSocketConnect(), MimeProtocol_LockRequest(), PersistMoniker_Load(), Protocol_Continue(), Protocol_LockRequest(), Protocol_Start(), ProtocolEmul_LockRequest(), test_binding(), test_BindToStorage(), test_download(), test_submit(), and thread_proc().

◆ LostSocket()

NTSTATUS LostSocket ( PIRP  Irp)

Definition at line 387 of file lock.c.

387  {
389  AFD_DbgPrint(MIN_TRACE,("Called.\n"));
390  Irp->IoStatus.Information = 0;
391  Irp->IoStatus.Status = Status;
392  if ( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
394  return Status;
395 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define IoCompleteRequest
Definition: irp.c:1240
VOID UnlockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:180
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define MIN_TRACE
Definition: debug.h:14
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by AfdAccept(), AfdBindSocket(), AfdCleanupSocket(), AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdDisconnect(), AfdEnumEvents(), AfdEventSelect(), AfdGetConnectData(), AfdGetConnectOptions(), AfdGetContext(), AfdGetContextSize(), AfdGetDisconnectData(), AfdGetDisconnectOptions(), AfdGetInfo(), AfdGetPeerName(), AfdGetSockName(), AfdGetTdiHandles(), AfdListenSocket(), AfdPacketSocketReadData(), AfdPacketSocketWriteData(), AfdSetConnectData(), AfdSetConnectDataSize(), AfdSetConnectOptions(), AfdSetConnectOptionsSize(), AfdSetContext(), AfdSetDisconnectData(), AfdSetDisconnectDataSize(), AfdSetDisconnectOptions(), AfdSetDisconnectOptionsSize(), AfdSetInfo(), AfdStreamSocketConnect(), AfdWaitForListen(), and SatisfyAccept().

◆ QueueUserModeIrp()

NTSTATUS QueueUserModeIrp ( PAFD_FCB  FCB,
PIRP  Irp,
UINT  Function 
)

Definition at line 397 of file lock.c.

398 {
400 
401  /* Add the IRP to the queue in all cases (so AfdCancelHandler will work properly) */
402  InsertTailList( &FCB->PendingIrpList[Function],
403  &Irp->Tail.Overlay.ListEntry );
404 
405  /* Acquire the cancel spin lock and check the cancel bit */
406  IoAcquireCancelSpinLock(&Irp->CancelIrql);
407  if (!Irp->Cancel)
408  {
409  /* We are not cancelled; we're good to go so
410  * set the cancel routine, release the cancel spin lock,
411  * mark the IRP as pending, and
412  * return STATUS_PENDING to the caller
413  */
415  IoReleaseCancelSpinLock(Irp->CancelIrql);
418  }
419  else
420  {
421  /* We were already cancelled before we were able to register our cancel routine
422  * so we are to call the cancel routine ourselves right here to cancel the IRP
423  * (which handles all the stuff we do above) and return STATUS_CANCELLED to the caller
424  */
426  Irp);
428  }
429 
430  return Status;
431 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define InsertTailList(ListHead, Entry)
IoSetCancelRoutine(Irp, CancelRoutine)
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
IoMarkIrpPending(Irp)
DRIVER_CANCEL AfdCancelHandler
Definition: afd.h:304

Referenced by AfdConnectedSocketWriteData(), AfdDisconnect(), AfdPacketSocketWriteData(), AfdStreamSocketConnect(), and LeaveIrpUntilLater().

◆ SocketAcquireStateLock()

◆ SocketStateUnlock()

◆ UnlockAndMaybeComplete()

NTSTATUS NTAPI UnlockAndMaybeComplete ( PAFD_FCB  FCB,
NTSTATUS  Status,
PIRP  Irp,
UINT  Information 
)

Definition at line 375 of file lock.c.

376  {
377  Irp->IoStatus.Status = Status;
378  Irp->IoStatus.Information = Information;
379  if ( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
383  return Status;
384 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
IoSetCancelRoutine(Irp, CancelRoutine)
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
VOID UnlockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:180
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
Iosb Information
Definition: create.c:4377

Referenced by AfdAccept(), AfdBindSocket(), AfdCancelHandler(), AfdCleanupSocket(), AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdDisconnect(), AfdEnumEvents(), AfdEventSelect(), AfdGetConnectData(), AfdGetConnectOptions(), AfdGetContext(), AfdGetContextSize(), AfdGetDisconnectData(), AfdGetDisconnectOptions(), AfdGetInfo(), AfdGetPeerName(), AfdGetSockName(), AfdGetTdiHandles(), AfdListenSocket(), AfdPacketSocketReadData(), AfdPacketSocketWriteData(), AfdSetConnectData(), AfdSetConnectDataSize(), AfdSetConnectOptions(), AfdSetConnectOptionsSize(), AfdSetContext(), AfdSetDisconnectData(), AfdSetDisconnectDataSize(), AfdSetDisconnectOptions(), AfdSetDisconnectOptionsSize(), AfdSetInfo(), AfdStreamSocketConnect(), AfdWaitForListen(), and SatisfyAccept().

◆ UnlockBuffers()

VOID UnlockBuffers ( PAFD_WSABUF  Buf,
UINT  Count,
BOOL  Address 
)

Definition at line 289 of file lock.c.

289  {
290  UINT Lock = Address ? 2 : 0;
291  PAFD_MAPBUF Map = (PAFD_MAPBUF)(Buf + Count + Lock);
292  UINT i;
293 
294  if( !Buf ) return;
295 
296  for( i = 0; i < Count + Lock; i++ ) {
297  if( Map[i].Mdl ) {
298  MmUnlockPages( Map[i].Mdl );
299  IoFreeMdl( Map[i].Mdl );
300  Map[i].Mdl = NULL;
301  }
302  }
303 
305  Buf = NULL;
306 }
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
#define TAG_AFD_WSA_BUFFER
Definition: afd.h:54
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
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
struct _AFD_MAPBUF * PAFD_MAPBUF
PMDL Mdl
Definition: afd.h:107
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
unsigned int UINT
Definition: ndis.h:50
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by AfdConnectedSocketReadData(), AfdConnectedSocketWriteData(), AfdPacketSocketReadData(), AfdPacketSocketWriteData(), CleanupPendingIrp(), PacketSocketRecvComplete(), PacketSocketSendComplete(), ReceiveActivity(), ReceiveComplete(), and SendComplete().

◆ UnlockHandles()

VOID UnlockHandles ( PAFD_HANDLE  HandleArray,
UINT  HandleCount 
)

Definition at line 348 of file lock.c.

348  {
349  UINT i;
350 
351  for( i = 0; i < HandleCount; i++ ) {
352  if( HandleArray[i].Handle )
353  ObDereferenceObject( (PVOID)HandleArray[i].Handle );
354  }
355 
357  HandleArray = NULL;
358 }
#define TAG_AFD_POLL_HANDLE
Definition: afd.h:47
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
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
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned int UINT
Definition: ndis.h:50
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by LockHandles(), and SignalSocket().

◆ UnlockRequest()

VOID UnlockRequest ( PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 180 of file lock.c.

181 {
182  ASSERT(Irp->MdlAddress);
183  ASSERT(Irp->Tail.Overlay.DriverContext[0]);
184 
186 
187  /* Check if we need to copy stuff back */
188  if (Irp->Tail.Overlay.DriverContext[1] != NULL)
189  {
190  RtlCopyMemory(Irp->Tail.Overlay.DriverContext[1],
191  Irp->Tail.Overlay.DriverContext[0],
192  MmGetMdlByteCount(Irp->MdlAddress));
193  }
194 
195  ExFreePoolWithTag(Irp->Tail.Overlay.DriverContext[0], TAG_AFD_DATA_BUFFER);
196  MmUnlockPages( Irp->MdlAddress );
197  IoFreeMdl( Irp->MdlAddress );
198  Irp->MdlAddress = NULL;
199 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
smooth NULL
Definition: ftsmooth.c:416
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define MmGetMdlByteCount(_Mdl)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by AfdConnectedSocketWriteData(), AfdDisconnect(), AfdPacketSocketWriteData(), DisconnectComplete(), ListenComplete(), LostSocket(), MimeProtocol_UnlockRequest(), PacketSocketRecvComplete(), PacketSocketSendComplete(), Protocol_UnlockRequest(), ProtocolEmul_UnlockRequest(), ReceiveActivity(), ReceiveComplete(), SatisfyPreAccept(), SendComplete(), SignalSocket(), StreamSocketConnectComplete(), test_binding(), test_BindToObject(), test_BindToStorage(), test_download(), test_submit(), test_URLDownloadToFile(), and UnlockAndMaybeComplete().