ReactOS 0.4.16-dev-334-g4d9f67c
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: dll/win32/ws2help/apc.c
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
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
42WahCloseApcHelper(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
59WahCloseThread(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
88INT
90WahQueueUserApc(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
116DWORD
117WINAPI
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 NO_ERROR
Definition: dderror.h:5
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define GetCurrentProcess()
Definition: compat.h:759
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
DWORD WINAPI QueueUserAPC(IN PAPCFUNC pfnAPC, IN HANDLE hThread, IN ULONG_PTR dwData)
Definition: thread.c:959
DWORD WINAPI WahOpenCurrentThread(IN HANDLE ApcHelperHandle, OUT LPWSATHREADID ThreadId)
Definition: apc.c:118
#define APCH
Definition: apc.c:14
DWORD WINAPI WahCloseThread(IN HANDLE ApcHelperHandle, IN LPWSATHREADID ThreadId)
Definition: apc.c:59
INT WINAPI WahQueueUserApc(IN HANDLE ApcHelperHandle, IN LPWSATHREADID ThreadId, IN LPWSAUSERAPC ApcRoutine, IN PVOID ApcContext OPTIONAL)
Definition: apc.c:90
DWORD WINAPI WahCloseApcHelper(IN HANDLE ApcHelperHandle)
Definition: apc.c:42
DWORD WINAPI WahOpenApcHelper(OUT PHANDLE ApcHelperHandle)
Definition: apc.c:20
#define WS2HELP_PROLOG()
Definition: precomp.h:47
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:727
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:726
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define DWORD_PTR
Definition: treelist.c:76
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1148
#define WINAPI
Definition: msvc.h:6
#define DUPLICATE_SAME_ACCESS