ReactOS  0.4.14-dev-614-gbfd8a84
ws2help.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _WSH_HANDLE
 
struct  _WSH_HASH_TABLE
 
struct  _WSH_SEARCH_TABLE
 
struct  _WSH_HANDLE_TABLE
 

Typedefs

typedef struct _WSH_HANDLE WSH_HANDLE
 
typedef struct _WSH_HANDLEPWAH_HANDLE
 
typedef struct _WSH_HASH_TABLE WSH_HASH_TABLE
 
typedef struct _WSH_HASH_TABLEPWAH_HASH_TABLE
 
typedef struct _WSH_SEARCH_TABLE WSH_SEARCH_TABLE
 
typedef struct _WSH_SEARCH_TABLEPWAH_SEARCH_TABLE
 
typedef struct _WSH_HANDLE_TABLE WSH_HANDLE_TABLE
 
typedef struct _WSH_HANDLE_TABLEPWAH_HANDLE_TABLE
 
typedef BOOL(WINAPIPWAH_HANDLE_ENUMERATE_PROC) (IN PVOID Context, IN PWAH_HANDLE Handle)
 

Functions

PWAH_HANDLE WINAPI WahReferenceContextByHandle (IN PWAH_HANDLE_TABLE Table, IN HANDLE Handle)
 
DWORD WINAPI WahRemoveHandleContext (IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE Handle)
 
DWORD WINAPI WahCloseSocketHandle (IN HANDLE HelperHandle, IN SOCKET Socket)
 
DWORD WINAPI WahOpenCurrentThread (IN HANDLE HelperHandle, OUT LPWSATHREADID ThreadId)
 
DWORD WINAPI WahCloseApcHelper (IN HANDLE HelperHandle)
 
DWORD WINAPI WahCloseThread (IN HANDLE HelperHandle, IN LPWSATHREADID ThreadId)
 
DWORD WINAPI WahCloseHandleHelper (IN HANDLE HelperHandle)
 
DWORD WINAPI WahCloseNotificationHandleHelper (IN HANDLE HelperHandle)
 
DWORD WINAPI WahOpenNotificationHandleHelper (OUT PHANDLE HelperHandle)
 
DWORD WINAPI WahCreateNotificationHandle (IN HANDLE HelperHandle, OUT PHANDLE NotificationHelperHandle)
 
INT WINAPI WahWaitForNotification (IN HANDLE NotificationHelperHandle, IN HANDLE lpNotificationHandle, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
 
INT WINAPI WahNotifyAllProcesses (IN HANDLE NotificationHelperHandle)
 
BOOL WINAPI WahEnumerateHandleContexts (IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE_ENUMERATE_PROC Callback, IN PVOID Context)
 
DWORD WINAPI WahCreateHandleContextTable (OUT PWAH_HANDLE_TABLE *Table)
 
DWORD WINAPI WahDestroyHandleContextTable (IN PWAH_HANDLE_TABLE Table)
 
PWAH_HANDLE WINAPI WahInsertHandleContext (IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE Handle)
 
DWORD WINAPI WahOpenApcHelper (OUT PHANDLE ApcHelperHandle)
 

Typedef Documentation

◆ PWAH_HANDLE

◆ PWAH_HANDLE_ENUMERATE_PROC

typedef BOOL(WINAPI * PWAH_HANDLE_ENUMERATE_PROC) (IN PVOID Context, IN PWAH_HANDLE Handle)

Definition at line 44 of file ws2help.h.

◆ PWAH_HANDLE_TABLE

◆ PWAH_HASH_TABLE

◆ PWAH_SEARCH_TABLE

◆ WSH_HANDLE

◆ WSH_HANDLE_TABLE

◆ WSH_HASH_TABLE

◆ WSH_SEARCH_TABLE

Function Documentation

◆ WahCloseApcHelper()

DWORD WINAPI WahCloseApcHelper ( IN HANDLE  HelperHandle)

Definition at line 42 of file apc.c.

43 {
45 
46  /* Enter the prolog, make sure we're initialized */
48  if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
49 
50  /* Validate handle */
51  if (ApcHelperHandle != APCH) return ERROR_INVALID_PARAMETER;
52 
53  /* return */
54  return ERROR_SUCCESS;
55 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WS2HELP_PROLOG()
Definition: precomp.h:47
unsigned long DWORD
Definition: ntddk_ex.h:95
#define APCH
Definition: apc.c:14

Referenced by WsProcDelete().

◆ WahCloseHandleHelper()

DWORD WINAPI WahCloseHandleHelper ( IN HANDLE  HelperHandle)

Definition at line 86 of file handle.c.

87 {
89  PWAH_HELPER_CONTEXT Context = HelperHandle;
90 
91  /* Enter the prolog, make sure we're initialized */
93  if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
94 
95  /* Validate the handle */
96  if (!Context) return ERROR_INVALID_PARAMETER;
97 
98  /* Queue an APC to exit the thread */
99  if (QueueUserAPC(ExitThreadApc, Context->ThreadHandle, (ULONG_PTR)Context))
100  {
101  /* Done */
102  return ERROR_SUCCESS;
103  }
104  else
105  {
106  /* We failed somewhere */
107  return ERROR_GEN_FAILURE;
108  }
109 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define WS2HELP_PROLOG()
Definition: precomp.h:47
DWORD WINAPI QueueUserAPC(IN PAPCFUNC pfnAPC, IN HANDLE hThread, IN ULONG_PTR dwData)
Definition: thread.c:947
VOID CALLBACK ExitThreadApc(ULONG_PTR Context)
Definition: handle.c:69
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_GEN_FAILURE
Definition: winerror.h:134

Referenced by WsProcDelete().

◆ WahCloseNotificationHandleHelper()

DWORD WINAPI WahCloseNotificationHandleHelper ( IN HANDLE  HelperHandle)

Definition at line 22 of file notify.c.

23 {
25 
26  /* Enter the prolog, make sure we're initialized */
28  if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
29 
30  /* Validate handle */
31  if (HelperHandle != HANH) return ERROR_INVALID_PARAMETER;
32 
33  /* return */
34  return ERROR_SUCCESS;
35 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WS2HELP_PROLOG()
Definition: precomp.h:47
#define HANH
Definition: notify.c:14
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by WsProcDelete().

◆ WahCloseSocketHandle()

DWORD WINAPI WahCloseSocketHandle ( IN HANDLE  HelperHandle,
IN SOCKET  Socket 
)

Definition at line 113 of file handle.c.

115 {
117  PWAH_HELPER_CONTEXT Context = HelperHandle;
118 
119  /* Enter the prolog, make sure we're initialized */
121  if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
122 
123  /* Validate the handle */
124  if (!(Context) || (Socket == INVALID_SOCKET) || !(Socket))
125  {
126  /* Invalid handle and/or socket */
128  }
129 
130  /* Just close the handle and return */
131  CloseHandle((HANDLE)Socket);
132  return ERROR_SUCCESS;
133 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WS2HELP_PROLOG()
Definition: precomp.h:47
#define INVALID_SOCKET
Definition: winsock.h:332
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI CloseHandle(IN HANDLE hObject)
Definition: handle.c:129

Referenced by WsProcDetachSocket().

◆ WahCloseThread()

DWORD WINAPI WahCloseThread ( IN HANDLE  HelperHandle,
IN LPWSATHREADID  ThreadId 
)

Definition at line 59 of file apc.c.

61 {
63 
64  /* Enter the prolog, make sure we're initialized */
66  if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
67 
68  /* Validate handles */
69  if ((ApcHelperHandle != APCH) || (!ThreadId) || (!ThreadId->ThreadHandle))
70  {
71  /* Invalid helper/thread handles */
73  }
74 
75  /* Close the thread handle */
76  if (CloseHandle(ThreadId->ThreadHandle))
77  {
78  /* Clear the structure */
79  ThreadId->ThreadHandle = NULL;
80  ThreadId->Reserved = 0;
81  return NO_ERROR;
82  }
83 
84  /* return */
85  return GetLastError();
86 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define CloseHandle
Definition: compat.h:406
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define NO_ERROR
Definition: dderror.h:5
#define WS2HELP_PROLOG()
Definition: precomp.h:47
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define APCH
Definition: apc.c:14

Referenced by WsThreadDelete().

◆ WahCreateHandleContextTable()

DWORD WINAPI WahCreateHandleContextTable ( OUT PWAH_HANDLE_TABLE Table)

Definition at line 189 of file context.c.

190 {
192  PWAH_HANDLE_TABLE LocalTable;
193  DWORD i;
194 
195  /* Enter the prolog, make sure we're initialized */
197  if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
198 
199  /* Assume NULL */
200  *Table = NULL;
201 
202  /* Allocate enough tables */
203  LocalTable = HeapAlloc(GlobalHeap,
204  0,
206  SearchTables[gHandleToIndexMask + 1]));
207 
208  /* Make sure it was allocated */
209  if (!LocalTable) return WSA_NOT_ENOUGH_MEMORY;
210 
211  /* Set the mask for the table */
212  LocalTable->Mask = gHandleToIndexMask;
213 
214  /* Now initialize every table */
215  for (i = 0; i <= gHandleToIndexMask; i++)
216  {
217  /* No hash table yet */
218  LocalTable->SearchTables[i].HashTable = NULL;
219 
220  /* Set the current count */
221  LocalTable->SearchTables[i].CurrentCount = &LocalTable->SearchTables[i].Count1;
222 
223  /* Initialize the counts */
224  LocalTable->SearchTables[i].Count1 = 1;
225  LocalTable->SearchTables[i].Count2 = 0;
226 
227  /* Set expanding state and spin count */
228  LocalTable->SearchTables[i].Expanding = FALSE;
229  LocalTable->SearchTables[i].SpinCount = gdwSpinCount;
230 
231  /* Initialize the lock */
233  SearchTables[i].Lock,
234  gdwSpinCount);
235  }
236 
237  /* Return pointer */
238  *Table = LocalTable;
239 
240  /* Return success */
241  return ERROR_SUCCESS;
242 }
volatile PLONG CurrentCount
Definition: ws2help.h:27
ASMGENDATA Table[]
Definition: genincdata.c:61
BOOL WINAPI InitializeCriticalSectionAndSpinCount(OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount)
Definition: synch.c:765
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
volatile PWAH_HASH_TABLE HashTable
Definition: ws2help.h:26
#define WS2HELP_PROLOG()
Definition: precomp.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
smooth NULL
Definition: ftsmooth.c:416
WSH_SEARCH_TABLE SearchTables[1]
Definition: ws2help.h:38
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WSA_NOT_ENOUGH_MEMORY
Definition: winsock2.h:593
DWORD gHandleToIndexMask
Definition: context.c:19
#define VOID
Definition: acefi.h:82
HANDLE GlobalHeap
Definition: dllmain.c:19
DWORD gdwSpinCount
Definition: context.c:18
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254

Referenced by WsSockStartup().

◆ WahCreateNotificationHandle()

DWORD WINAPI WahCreateNotificationHandle ( IN HANDLE  HelperHandle,
OUT PHANDLE  NotificationHelperHandle 
)

Definition at line 39 of file notify.c.

41 {
42  UNREFERENCED_PARAMETER(HelperHandle);
43  UNREFERENCED_PARAMETER(NotificationHelperHandle);
44  return 0;
45 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323

◆ WahDestroyHandleContextTable()

DWORD WINAPI WahDestroyHandleContextTable ( IN PWAH_HANDLE_TABLE  Table)

Definition at line 246 of file context.c.

247 {
248  DWORD i;
249 
250  /* Make sure the table is valid */
251  if (!Table)
252  {
253  /* No valid table */
255  }
256 
257  /* Loop each search table */
258  for (i = 0; i <= Table->Mask; i++)
259  {
260  /* Check if there's a table here */
261  if (Table->SearchTables[i].HashTable)
262  {
263  /* Free it */
264  HeapFree(GlobalHeap, 0, Table->SearchTables[i].HashTable);
265  }
266 
267  /* Delete the lock */
268  DeleteCriticalSection(&Table->SearchTables[i].Lock);
269  }
270 
271  /* Delete the table */
273 
274  /* Return success */
275  return ERROR_SUCCESS;
276 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
ASMGENDATA Table[]
Definition: genincdata.c:61
#define ERROR_SUCCESS
Definition: deptool.c:10
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
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE GlobalHeap
Definition: dllmain.c:19
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by WsSockCleanup().

◆ WahEnumerateHandleContexts()

BOOL WINAPI WahEnumerateHandleContexts ( IN PWAH_HANDLE_TABLE  Table,
IN PWAH_HANDLE_ENUMERATE_PROC  Callback,
IN PVOID  Context 
)

Definition at line 280 of file context.c.

283 {
284  DWORD i, j;
285  PWAH_SEARCH_TABLE SearchTable;
288  BOOL GoOn = TRUE;
289 
290  /* Loop the table */
291  for (i = 0; i <= Table->Mask; i++)
292  {
293  /* Get the Search table */
294  SearchTable = &Table->SearchTables[i];
295 
296  /* Lock it */
297  AcquireWriteLock(SearchTable);
298 
299  /* Mark us as expanding and wait for everyone */
300  SearchTable->Expanding = TRUE;
301  TryWaitForReaders(SearchTable);
302 
303  /* Get the hash table */
304  HashTable = SearchTable->HashTable;
305 
306  /* Make sure it exists */
307  if (HashTable)
308  {
309  /* Loop every handle in it */
310  for (j = 0; j < HashTable->Size; j++)
311  {
312  /* Get this handle */
313  Handle = HashTable->Handles[j];
314  if (!Handle) continue;
315 
316  /* Call the callback proc */
317  GoOn = Callback(Context, Handle);
318  if (!GoOn) break;
319  }
320  }
321 
322  /* Disable the expansion bit and release the lock */
323  SearchTable->Expanding = FALSE;
324  ReleaseWriteLock(SearchTable);
325 
326  /* Check again if we should leave */
327  if (!GoOn) break;
328  }
329 
330  /* return */
331  return GoOn;
332 }
ASMGENDATA Table[]
Definition: genincdata.c:61
#define TRUE
Definition: types.h:120
Definition: hash.c:67
volatile PWAH_HASH_TABLE HashTable
Definition: ws2help.h:26
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
unsigned int BOOL
Definition: ntddk_ex.h:94
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 GLint GLint j
Definition: glfuncs.h:250
static __inline VOID TryWaitForReaders(IN PWAH_SEARCH_TABLE Table)
Definition: context.c:144
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ReleaseWriteLock(t)
Definition: context.c:43
LPFNPSPCALLBACK Callback
Definition: desk.c:111
#define AcquireWriteLock(t)
Definition: context.c:40

Referenced by WsProcDelete().

◆ WahInsertHandleContext()

PWAH_HANDLE WINAPI WahInsertHandleContext ( IN PWAH_HANDLE_TABLE  Table,
IN PWAH_HANDLE  Handle 
)

Definition at line 336 of file context.c.

338 {
339  PWAH_HANDLE *HashHandle, OldHandle;
340  PVLONG Count;
342  DWORD HandleCount, i;
343  PWAH_SEARCH_TABLE SearchTable;
344 
345  /* Get the current Search Table */
346  SearchTable = WSH_SEARCH_TABLE_FROM_HANDLE(Handle->Handle, Table);
347 
348  /* Start loop */
349  do
350  {
351  /* Get reader lock */
352  AcquireReadLock(SearchTable, &Count);
353 
354  /* Get the hash table */
355  HashTable = SearchTable->HashTable;
356 
357  /* Make sure we are not expanding, and that the table is there */
358  if (!(SearchTable->Expanding) && (HashTable))
359  {
360  /* Get the hash handle */
361  HashHandle = &WSH_HASH_FROM_HANDLE(Handle->Handle, HashTable);
362 
363  /* Do the insert */
364  if (InterlockedCompareExchangePointer((PVOID*)HashHandle,
365  Handle,
366  NULL) == NULL)
367  {
368  /* Success, release the reader lock */
369  ReleaseReadLock(SearchTable, Count);
370 
371  /* Save old handle */
372  OldHandle = Handle;
373  break;
374  }
375  }
376 
377  /* Release the read lock since we're done with it now */
378  ReleaseReadLock(SearchTable, Count);
379 
380  /* We need the writer lock to expand/create the table */
381  AcquireWriteLock(SearchTable);
382 
383  /* Mark the table in use */
384  SearchTable->Expanding = TRUE;
385 
386  /* Wait for all the readers to finish */
387  TryWaitForReaders(SearchTable);
388 
389  /* Start loop */
390  do
391  {
392  /* Get the hash table again */
393  HashTable = SearchTable->HashTable;
394 
395  /* Check if exists now */
396  if (HashTable)
397  {
398  /* It does! Do what we wanted to do earlier. Get the hash... */
399  HashHandle = &WSH_HASH_FROM_HANDLE(Handle->Handle, HashTable);
400 
401  /* Check if it doesn't exist */
402  if (!(*HashHandle))
403  {
404  /* Write it (no need for interlock, we have the RW lock) */
405  OldHandle = Handle;
406  *HashHandle = Handle;
407  break;
408  }
409  else if ((*HashHandle)->Handle == Handle->Handle)
410  {
411  /* Handle matches, write it (see comment above) */
412  OldHandle = *HashHandle;
413  *HashHandle = Handle;
414  break;
415  }
416 
417  /* No go, we need to expand the table. Remember the size now */
418  HandleCount = HashTable->Size;
419  }
420  else
421  {
422  /* Table is empty, we have to create it */
423  HandleCount = 0;
424  }
425 
426 ExpandTable:
427  /* Find a free prime */
428  for (i = 0; HandleCount >= SockPrimes[i]; i++);
429 
430  /* Check if we found one */
431  if (SockPrimes[i] != 0xFFFFFFFF)
432  {
433  /* Use the prime */
434  HandleCount = SockPrimes[i];
435  }
436  else
437  {
438  /* No primes left. Table is quite large, so simply double it */
439  HandleCount *= 2;
440  }
441 
442  /* Allocate the table */
444  0,
446  Handles[HandleCount]));
447 
448  /* Hopefully we have one now */
449  if (NewHashTable)
450  {
451  /* Set its size */
452  NewHashTable->Size = HandleCount;
453 
454  /* Initialize it */
455  RtlZeroMemory(NewHashTable->Handles, HandleCount * sizeof(PVOID));
456 
457  /* Insert us first */
459 
460  /* Now check if our old table had entries in it */
461  if (HashTable)
462  {
463  /* We need to move them */
464  for (i = 0; i < HashTable->Size; i++)
465  {
466  /* Make sure the hash handle exists */
467  if (HashTable->Handles[i])
468  {
469  /* Get it */
470  HashHandle = &WSH_HASH_FROM_HANDLE(HashTable->
471  Handles[i]->Handle,
472  NewHashTable);
473 
474  /* Check if it has a value */
475  if (!(*HashHandle))
476  {
477  /* It's empty, so just write the handle */
478  *HashHandle = HashTable->Handles[i];
479  }
480  else
481  {
482  /* Not empty :/... that implies a collision */
484  goto ExpandTable;
485  }
486  }
487  }
488 
489  /* Write the new hash table */
490  SearchTable->HashTable = NewHashTable;
491 
492  /* Wait for everyone to be done with it, then free it */
493  TryWaitForReaders(SearchTable);
495  }
496  else
497  {
498  /* It was empty, nothing to worry about */
499  SearchTable->HashTable = NewHashTable;
500  }
501 
502  /* Save the old handle */
503  OldHandle = Handle;
504  }
505  else
506  {
507  /* There was no old handle */
508  OldHandle = Handle;
509  }
510  } while (0);
511 
512  /* Mark us as free, and release the write lock */
513  SearchTable->Expanding = FALSE;
514  ReleaseWriteLock(SearchTable);
515  break;
516  } while (1);
517 
518  /* Return the old handle */
519  return OldHandle;
520 }
ASMGENDATA Table[]
Definition: genincdata.c:61
#define TRUE
Definition: types.h:120
Definition: hash.c:67
VLONG * PVLONG
Definition: context.c:29
static __inline VOID AcquireReadLock(IN PWAH_SEARCH_TABLE Table, IN PVLONG *Count)
Definition: context.c:50
#define WSH_HASH_FROM_HANDLE(h, hs)
Definition: context.c:37
volatile PWAH_HASH_TABLE HashTable
Definition: ws2help.h:26
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
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
CONST DWORD SockPrimes[]
Definition: context.c:21
#define WSH_SEARCH_TABLE_FROM_HANDLE(h, t)
Definition: context.c:34
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
smooth NULL
Definition: ftsmooth.c:416
static __inline VOID TryWaitForReaders(IN PWAH_SEARCH_TABLE Table)
Definition: context.c:144
_In_ HANDLE Handle
Definition: extypes.h:390
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE GlobalHeap
Definition: dllmain.c:19
struct HashTable * NewHashTable(void)
Definition: hash.c:77
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ReleaseWriteLock(t)
Definition: context.c:43
#define HeapFree(x, y, z)
Definition: compat.h:402
#define AcquireWriteLock(t)
Definition: context.c:40
static __inline VOID ReleaseReadLock(IN PWAH_SEARCH_TABLE Table, IN PVLONG Count)
Definition: context.c:75

Referenced by WsSockAssociateHandle().

◆ WahNotifyAllProcesses()

INT WINAPI WahNotifyAllProcesses ( IN HANDLE  NotificationHelperHandle)

Definition at line 67 of file notify.c.

68 {
69  UNREFERENCED_PARAMETER(NotificationHelperHandle);
70  return 0;
71 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323

◆ WahOpenApcHelper()

DWORD WINAPI WahOpenApcHelper ( OUT PHANDLE  ApcHelperHandle)

Definition at line 20 of file apc.c.

21 {
23 
24  /* Enter the prolog, make sure we're initialized */
26  if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
27 
28  /* Validate handle */
29  if (!ApcHelperHandle) return ERROR_INVALID_PARAMETER;
30 
31  /*
32  * Return a bogus handle ("ROS")
33  * Historical note:(MS sends "CKM", which probably stands for "Keith Moore"
34  * (KM), one of the core architects of Winsock 2.2 from Microsoft.
35  */
36  *ApcHelperHandle = APCH;
37  return ERROR_SUCCESS;
38 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WS2HELP_PROLOG()
Definition: precomp.h:47
unsigned long DWORD
Definition: ntddk_ex.h:95
#define APCH
Definition: apc.c:14

Referenced by WsProcOpenAsyncHelperDevice().

◆ WahOpenCurrentThread()

DWORD WINAPI WahOpenCurrentThread ( IN HANDLE  HelperHandle,
OUT LPWSATHREADID  ThreadId 
)

Definition at line 118 of file apc.c.

120 {
121  HANDLE ProcessHandle, ThreadHandle;
122 
123  /* Validate params */
124  if ((ApcHelperHandle != APCH) || (!ThreadId))
125  {
126  /* Invalid parameters */
128  }
129 
130  /* Get the process/thread handles */
132  ThreadHandle = GetCurrentThread();
133 
134  /* Duplicate the handle */
136  ThreadHandle,
138  &ThreadId->ThreadHandle,
139  0,
140  FALSE,
142  {
143  /* Save the thread handle and return */
144  ThreadId->Reserved = (DWORD_PTR)ThreadHandle;
145  return ERROR_SUCCESS;
146  }
147 
148  /* Fail */
149  return GetLastError();
150 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DWORD_PTR
Definition: treelist.c:76
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define DUPLICATE_SAME_ACCESS
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1148
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
#define APCH
Definition: apc.c:14
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149

Referenced by WsThreadInitialize().

◆ WahOpenNotificationHandleHelper()

DWORD WINAPI WahOpenNotificationHandleHelper ( OUT PHANDLE  HelperHandle)

Definition at line 49 of file notify.c.

50 {
52 
53  /* Enter the prolog, make sure we're initialized */
55  if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
56 
57  /* Validate handle */
58  if (!HelperHandle) return ERROR_INVALID_PARAMETER;
59 
60  /* Return a bogus handle ("ROS2") */
61  *HelperHandle = HANH;
62  return ERROR_SUCCESS;
63 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WS2HELP_PROLOG()
Definition: precomp.h:47
#define HANH
Definition: notify.c:14
unsigned long DWORD
Definition: ntddk_ex.h:95

◆ WahReferenceContextByHandle()

PWAH_HANDLE WINAPI WahReferenceContextByHandle ( IN PWAH_HANDLE_TABLE  Table,
IN HANDLE  Handle 
)

Definition at line 524 of file context.c.

526 {
527  PWAH_HANDLE HashHandle;
528  PWAH_SEARCH_TABLE SearchTable;
530  PVLONG Count;
531 
532  /* Get the current Search Table */
533  SearchTable = WSH_SEARCH_TABLE_FROM_HANDLE(Handle, Table);
534 
535  /* Lock it */
536  AcquireReadLock(SearchTable, &Count);
537 
538  /* Get the hash table and handle */
539  HashTable = SearchTable->HashTable;
540 
541  /* Check if it's valid, and if it's the one we want */
542  if ((HashTable) &&
543  (HashHandle = WSH_HASH_FROM_HANDLE(Handle, HashTable)) &&
544  (HashHandle->Handle == Handle))
545  {
546  /* Reference the handle */
547  InterlockedIncrement(&HashHandle->RefCount);
548  }
549  else
550  {
551  /* Invalid handle */
552  HashHandle = NULL;
553  }
554 
555  /* Release the lock */
556  ReleaseReadLock(SearchTable, Count);
557 
558  /* Return */
559  return HashHandle;
560 }
ASMGENDATA Table[]
Definition: genincdata.c:61
Definition: hash.c:67
VLONG * PVLONG
Definition: context.c:29
static __inline VOID AcquireReadLock(IN PWAH_SEARCH_TABLE Table, IN PVLONG *Count)
Definition: context.c:50
#define WSH_HASH_FROM_HANDLE(h, hs)
Definition: context.c:37
volatile PWAH_HASH_TABLE HashTable
Definition: ws2help.h:26
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define WSH_SEARCH_TABLE_FROM_HANDLE(h, t)
Definition: context.c:34
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
LONG RefCount
Definition: ws2help.h:14
#define InterlockedIncrement
Definition: armddk.h:53
HANDLE Handle
Definition: ws2help.h:15
static __inline VOID ReleaseReadLock(IN PWAH_SEARCH_TABLE Table, IN PVLONG Count)
Definition: context.c:75

Referenced by WsSockGetSocket(), and WsSockGetSocketNoExport().

◆ WahRemoveHandleContext()

DWORD WINAPI WahRemoveHandleContext ( IN PWAH_HANDLE_TABLE  Table,
IN PWAH_HANDLE  Handle 
)

Definition at line 564 of file context.c.

566 {
567  PWAH_HANDLE *HashHandle;
568  PWAH_SEARCH_TABLE SearchTable;
571 
572  /* Get the current Search Table */
573  SearchTable = WSH_SEARCH_TABLE_FROM_HANDLE(Handle->Handle, Table);
574 
575  /* Lock it */
576  AcquireWriteLock(SearchTable);
577 
578  /* Get the hash table and handle */
579  HashTable = SearchTable->HashTable;
580  HashHandle = &WSH_HASH_FROM_HANDLE(Handle->Handle, HashTable);
581 
582  /* Make sure we have a handle, and write the new pointer */
583  if (HashHandle && (InterlockedCompareExchangePointer((PVOID*)HashHandle,
584  NULL,
585  Handle) == Handle))
586  {
587  /* Wait for everyone to be done with it */
588  TryWaitForReaders(SearchTable);
589  }
590  else
591  {
592  /* Invalid handle */
594  }
595 
596  /* Release the lock */
597  ReleaseWriteLock(SearchTable);
598 
599  /* Return */
600  return ErrorCode;
601 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
ASMGENDATA Table[]
Definition: genincdata.c:61
Definition: hash.c:67
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WSH_HASH_FROM_HANDLE(h, hs)
Definition: context.c:37
volatile PWAH_HASH_TABLE HashTable
Definition: ws2help.h:26
#define WSH_SEARCH_TABLE_FROM_HANDLE(h, t)
Definition: context.c:34
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
smooth NULL
Definition: ftsmooth.c:416
static __inline VOID TryWaitForReaders(IN PWAH_SEARCH_TABLE Table)
Definition: context.c:144
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ReleaseWriteLock(t)
Definition: context.c:43
#define AcquireWriteLock(t)
Definition: context.c:40

Referenced by WsProcDetachSocket(), and WsSockDisassociateHandle().

◆ WahWaitForNotification()

INT WINAPI WahWaitForNotification ( IN HANDLE  NotificationHelperHandle,
IN HANDLE  lpNotificationHandle,
IN LPWSAOVERLAPPED  lpOverlapped,
IN LPWSAOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine 
)

Definition at line 75 of file notify.c.

79 {
80  UNREFERENCED_PARAMETER(NotificationHelperHandle);
81  UNREFERENCED_PARAMETER(lpNotificationHandle);
83  UNREFERENCED_PARAMETER(lpCompletionRoutine);
84  return 0;
85 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90