1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/*++
Copyright (c) 1992 Microsoft Corporation
Module Name:
Winsockp.h
Abstract:
Private header file for WOW winsock support.
Author:
David Treadwell (davidtr) 02-Oct-1992
Revision History:
--*/
#include "wow32.h"
#include <winsock.h>
#include <wowwsock.h>
#include "wcall16.h"
#include "wsocktbl.h"
typedef struct _WINSOCK_THREAD_DATA {
VPVOID vIpAddress;
VPHOSTENT16 vHostent;
VPSERVENT16 vServent;
VPPROTOENT16 vProtoent;
VPPROC vBlockingHook;
DWORD ThreadSerialNumber;
DWORD ThreadStartupCount;
WORD ThreadVersion;
} WINSOCK_THREAD_DATA, *PWINSOCK_THREAD_DATA;
extern DWORD WWS32TlsSlot;
extern RTL_CRITICAL_SECTION WWS32CriticalSection;
extern LIST_ENTRY WWS32AsyncContextBlockListHead;
extern WORD WWS32AsyncTaskHandleCounter;
extern LIST_ENTRY WWS32SocketHandleListHead;
extern WORD WWS32SocketHandleCounter;
extern BOOL WWS32SocketHandleCounterWrapped;
extern DWORD WWS32ThreadSerialNumberCounter;
#define WWS32IpAddress \
( ((PWINSOCK_THREAD_DATA)(TlsGetValue( WWS32TlsSlot )))->IpAddress )
#define WWS32vIpAddress \
( ((PWINSOCK_THREAD_DATA)(TlsGetValue( WWS32TlsSlot )))->vIpAddress )
#define WWS32vHostent \
( ((PWINSOCK_THREAD_DATA)(TlsGetValue( WWS32TlsSlot )))->vHostent )
#define WWS32vServent \
( ((PWINSOCK_THREAD_DATA)(TlsGetValue( WWS32TlsSlot )))->vServent )
#define WWS32vProtoent \
( ((PWINSOCK_THREAD_DATA)(TlsGetValue( WWS32TlsSlot )))->vProtoent )
#define WWS32vBlockingHook \
( ((PWINSOCK_THREAD_DATA)(TlsGetValue( WWS32TlsSlot )))->vBlockingHook )
#define WWS32ThreadSerialNumber \
( ((PWINSOCK_THREAD_DATA)(TlsGetValue( WWS32TlsSlot )))->ThreadSerialNumber )
#define WWS32ThreadStartupCount \
( ((PWINSOCK_THREAD_DATA)(TlsGetValue( WWS32TlsSlot )))->ThreadStartupCount )
#define WWS32ThreadVersion \
( ((PWINSOCK_THREAD_DATA)(TlsGetValue( WWS32TlsSlot )))->ThreadVersion )
#define WWS32IsThreadVersion10 ( WWS32ThreadVersion == MAKEWORD(1, 0) )
#define WWS32IsThreadVersion11 ( WWS32ThreadVersion == MAKEWORD(1, 1) )
#define WWS32IsThreadInitialized \
( TlsGetValue( WWS32TlsSlot ) == NULL ? FALSE : TRUE )
typedef struct _WINSOCK_ASYNC_CONTEXT_BLOCK {
LIST_ENTRY ContextBlockListEntry;
HANDLE AsyncTaskHandle32;
HAND16 AsyncTaskHandle16;
VPVOID vBuffer16;
DWORD Buffer16Length;
PVOID Buffer32;
} WINSOCK_ASYNC_CONTEXT_BLOCK, *PWINSOCK_ASYNC_CONTEXT_BLOCK;
typedef struct _WINSOCK_SOCKET_INFO {
LIST_ENTRY GlobalSocketListEntry;
SOCKET SocketHandle32;
DWORD ThreadSerialNumber;
HAND16 SocketHandle16;
} WINSOCK_SOCKET_INFO, *PWINSOCK_SOCKET_INFO;
PFD_SET
AllocateFdSet32 (
IN PFD_SET16 FdSet16
);
INT
ConvertFdSet16To32 (
IN PFD_SET16 FdSet16,
IN PFD_SET FdSet32
);
VOID
ConvertFdSet32To16 (
IN PFD_SET FdSet32,
IN PFD_SET16 FdSet16
);
int PASCAL
WSApSetPostRoutine (
IN PVOID PostRoutine
);
typedef
BOOL
(*PWINSOCK_POST_ROUTINE) (
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
BOOL
WWS32DispatchPostMessage (
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
BOOL
WWS32PostAsyncSelect (
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
BOOL
WWS32PostAsyncGetHost (
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
BOOL
WWS32PostAsyncGetProto (
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
BOOL
WWS32PostAsyncGetServ (
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
PWINSOCK_ASYNC_CONTEXT_BLOCK
WWS32FindAndRemoveAsyncContext (
IN HANDLE AsyncTaskHandle32
);
HAND16
WWS32GetAsyncTaskHandle16 (
VOID
);
VOID
WWS32TaskCleanup(
VOID
);
//
// Message types used by WWS32DispatchPostMessage to dispatch a post
// message call to the appropriate routine.
//
#define WWS32_MESSAGE_ASYNC_SELECT 0
#define WWS32_MESSAGE_ASYNC_GETHOST 1
#define WWS32_MESSAGE_ASYNC_GETPROTO 2
#define WWS32_MESSAGE_ASYNC_GETSERV 3
//
// An arbitrary value that indicates the default blocking hook is in use.
//
#define WWS32_DEFAULT_BLOCKING_HOOK 0xFFFFFFFF
//
// Determine if a pointer is DWORD aligned.
//
#define IS_DWORD_ALIGNED(p) (((DWORD)(p) & (sizeof(DWORD)-1)) == 0)
|