ReactOS  0.4.14-dev-604-gcfdd483
bhook.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS WinSock 2 API
4  * FILE: dll/win32/ws2_32_new/src/bhook.c
5  * PURPOSE: Blocking Hook support for 1.x clients
6  * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <ws2_32.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS *****************************************************************/
17 
18 /*
19  * @implemented
20  */
21 INT
22 WSAAPI
24 {
27  INT ErrorCode;
28  DPRINT("WSACancelBlockingCall\n");
29 
30  /* Call the prolog */
32  if (ErrorCode != ERROR_SUCCESS)
33  {
34  /* Fail */
36  return SOCKET_ERROR;
37  }
38 
39  /* Make sure this isn't a 2.2 client */
40  if (LOBYTE(Process->Version) >= 2)
41  {
42  /* Only valid for 1.x */
44  return SOCKET_ERROR;
45  }
46 
47  /* Cancel the call */
49  if (ErrorCode != ERROR_SUCCESS)
50  {
51  /* Fail */
53  return SOCKET_ERROR;
54  }
55 
56  /* Return success */
57  return ERROR_SUCCESS;
58 }
59 
60 /*
61  * @implemented
62  */
63 BOOL
64 WSAAPI
66 {
69  INT ErrorCode;
70  DPRINT("WSAIsBlocking\n");
71 
72  /* Call the prolog */
74  if (ErrorCode != ERROR_SUCCESS)
75  {
76  /* Fail unless its because we're busy */
77  if (ErrorCode != WSAEINPROGRESS) return FALSE;
78  }
79 
80  /* Return the value from the thread */
81  return Thread->Blocking;
82 }
83 
84 /*
85  * @implemented
86  */
87 FARPROC
88 WSAAPI
90 {
93  INT ErrorCode;
94  DPRINT("WSASetBlockingHook: %p\n", lpBlockFunc);
95 
96  /* Call the prolog */
98  if (ErrorCode != ERROR_SUCCESS)
99  {
100  /* Fail */
102  return NULL;
103  }
104 
105  /* Make sure this isn't a 2.2 client */
106  if (LOBYTE(Process->Version) >= 2)
107  {
108  /* Only valid for 1.x */
110  return NULL;
111  }
112 
113  /* Make sure the pointer is safe */
114  if (IsBadCodePtr(lpBlockFunc))
115  {
116  /* Invalid pointer */
118  return NULL;
119  }
120 
121  /* Set the blocking hook and return the previous one */
122  return WsThreadSetBlockingHook(Thread, lpBlockFunc);
123 }
124 
125 /*
126  * @implemented
127  */
128 INT
129 WSAAPI
131 {
134  INT ErrorCode;
135  DPRINT("WSAUnhookBlockingHook\n");
136 
137  /* Call the prolog */
139  if (ErrorCode != ERROR_SUCCESS)
140  {
141  /* Fail */
143  return SOCKET_ERROR;
144  }
145 
146  /* Make sure this isn't a 2.2 client */
147  if (LOBYTE(Process->Version) >= 2)
148  {
149  /* Only valid for 1.x */
151  return SOCKET_ERROR;
152  }
153 
154  /* Set the blocking hook and return the previous one */
156 }
#define SOCKET_ERROR
Definition: winsock.h:333
#define IN
Definition: typedefs.h:38
FARPROC WSAAPI WSASetBlockingHook(IN FARPROC lpBlockFunc)
Definition: bhook.c:89
#define WSAEFAULT
Definition: winerror.h:1945
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LOBYTE(W)
Definition: jmemdos.c:487
#define WSAEINPROGRESS
Definition: winerror.h:1949
int32_t INT
Definition: typedefs.h:56
#define WSAEOPNOTSUPP
Definition: winerror.h:1958
DWORD WSAAPI WsThreadUnhookBlockingHook(IN PWSTHREAD Thread)
Definition: dthread.c:84
BOOL NTAPI IsBadCodePtr(FARPROC lpfn)
Definition: except.c:874
BOOL WSAAPI WSAIsBlocking(VOID)
Definition: bhook.c:65
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
INT WSAAPI WSACancelBlockingCall(VOID)
Definition: bhook.c:23
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define SetLastError(x)
Definition: compat.h:417
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91
#define WSAAPI
Definition: winsock2.h:584
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
INT WSAAPI WSAUnhookBlockingHook(VOID)
Definition: bhook.c:130
DWORD WSAAPI WsThreadCancelBlockingCall(IN PWSTHREAD Thread)
Definition: dthread.c:96
int(* FARPROC)()
Definition: compat.h:28
FARPROC WSAAPI WsThreadSetBlockingHook(IN PWSTHREAD Thread, IN FARPROC BlockingHook)
Definition: dthread.c:60