ReactOS  0.4.13-dev-99-g7e18b6d
apc.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS WinSock 2 DLL
4  * FILE: include/ws2_32.h
5  * PURPOSE: WinSock 2 DLL header
6  */
7 
8 /* INCLUDES ******************************************************************/
9 
10 #include "precomp.h"
11 
12 /* DATA **********************************************************************/
13 
14 #define APCH (HANDLE)'SOR '
15 
16 /* FUNCTIONS *****************************************************************/
17 
18 DWORD
19 WINAPI
20 WahOpenApcHelper(OUT PHANDLE ApcHelperHandle)
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 }
39 
40 DWORD
41 WINAPI
42 WahCloseApcHelper(IN HANDLE ApcHelperHandle)
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 }
56 
57 DWORD
58 WINAPI
59 WahCloseThread(IN HANDLE ApcHelperHandle,
60  IN LPWSATHREADID ThreadId)
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 }
87 
88 INT
89 WINAPI
90 WahQueueUserApc(IN HANDLE ApcHelperHandle,
91  IN LPWSATHREADID ThreadId,
92  IN LPWSAUSERAPC ApcRoutine,
94 {
95  /* Validate params */
96  if ((ApcHelperHandle != APCH) ||
97  (!ThreadId) ||
98  (!ThreadId->ThreadHandle) ||
99  (!ApcRoutine))
100  {
101  /* Invalid parameters */
103  }
104 
105  /* Queue the APC */
106  if (QueueUserAPC(ApcRoutine, ThreadId->ThreadHandle, (ULONG_PTR)ApcContext))
107  {
108  /* Return success */
109  return ERROR_SUCCESS;
110  }
111 
112  /* Fail */
113  return GetLastError();
114 }
115 
116 DWORD
117 WINAPI
119  OUT LPWSATHREADID ThreadId)
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 }
151 
152 /* EOF */
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define IN
Definition: typedefs.h:38
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:719
#define CloseHandle
Definition: compat.h:398
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DWORD_PTR
Definition: treelist.c:76
VOID WINAPI ApcRoutine(PVOID Context, PIO_STATUS_BLOCK IoStatus, ULONG Reserved)
Definition: apc.c:12
DWORD WINAPI WahOpenCurrentThread(IN HANDLE ApcHelperHandle, OUT LPWSATHREADID ThreadId)
Definition: apc.c:118
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define NO_ERROR
Definition: dderror.h:5
int32_t INT
Definition: typedefs.h:56
DWORD WINAPI WahCloseApcHelper(IN HANDLE ApcHelperHandle)
Definition: apc.c:42
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:910
INT WINAPI WahQueueUserApc(IN HANDLE ApcHelperHandle, IN LPWSATHREADID ThreadId, IN LPWSAUSERAPC ApcRoutine, IN PVOID ApcContext OPTIONAL)
Definition: apc.c:90
#define DUPLICATE_SAME_ACCESS
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1178
smooth NULL
Definition: ftsmooth.c:416
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
#define WINAPI
Definition: msvc.h:8
DWORD WINAPI WahCloseThread(IN HANDLE ApcHelperHandle, IN LPWSATHREADID ThreadId)
Definition: apc.c:59
unsigned long DWORD
Definition: ntddk_ex.h:95
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
#define OUT
Definition: typedefs.h:39
#define APCH
Definition: apc.c:14
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
DWORD WINAPI WahOpenApcHelper(OUT PHANDLE ApcHelperHandle)
Definition: apc.c:20
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
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68