36b824b02bc2a7cbd60ed9febad29dc46f99eb99
[reactos.git] / reactos / dll / win32 / rpcrt4 / rpcrt4_ros.diff
1 diff -prudN e:\Wine\dlls\rpcrt4/epm_towers.h e:\reactos\dll\win32\rpcrt4/epm_towers.h
2 --- e:\Wine\dlls\rpcrt4/epm_towers.h 2011-09-16 23:22:37.031828000 +0100
3 +++ e:\reactos\dll\win32\rpcrt4/epm_towers.h 2013-01-25 14:13:03.257632500 +0100
4 @@ -19,7 +19,7 @@
5 *
6 */
7
8 -#include "epm.h"
9 +#include <epm_c.h>
10
11 #define EPM_PROTOCOL_DNET_NSP 0x04
12 #define EPM_PROTOCOL_OSI_TP4 0x05
13 diff -prudN e:\Wine\dlls\rpcrt4/ndr_marshall.c e:\reactos\dll\win32\rpcrt4/ndr_marshall.c
14 --- e:\Wine\dlls\rpcrt4/ndr_marshall.c 2012-04-02 20:39:58.270363100 +0100
15 +++ e:\reactos\dll\win32\rpcrt4/ndr_marshall.c 2013-12-06 20:04:02.897835300 +0100
16 @@ -1211,7 +1211,7 @@ static unsigned char * EmbeddedPointerMa
17 unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
18 unsigned char *saved_memory = pStubMsg->Memory;
19
20 - pStubMsg->Memory = pMemory;
21 + pStubMsg->Memory = membase;
22 PointerMarshall(pStubMsg, bufptr, *(unsigned char**)memptr, info+4);
23 pStubMsg->Memory = saved_memory;
24 }
25 @@ -1365,7 +1365,7 @@ static void EmbeddedPointerBufferSize(PM
26 unsigned char *memptr = membase + *(const SHORT*)&info[0];
27 unsigned char *saved_memory = pStubMsg->Memory;
28
29 - pStubMsg->Memory = pMemory;
30 + pStubMsg->Memory = membase;
31 PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);
32 pStubMsg->Memory = saved_memory;
33 }
34 diff -prudN e:\Wine\dlls\rpcrt4/rpc_epmap.c e:\reactos\dll\win32\rpcrt4/rpc_epmap.c
35 --- e:\Wine\dlls\rpcrt4/rpc_epmap.c 2013-03-02 14:18:00.736492500 +0100
36 +++ e:\reactos\dll\win32\rpcrt4/rpc_epmap.c 2013-12-06 20:28:21.361553600 +0100
37 @@ -162,7 +169,7 @@ static RPC_STATUS get_epm_handle_server(
38
39 static LONG WINAPI rpc_filter(EXCEPTION_POINTERS *__eptr)
40 {
41 - switch (GetExceptionCode())
42 + switch (__eptr->ExceptionRecord->ExceptionCode)
43 {
44 case EXCEPTION_ACCESS_VIOLATION:
45 case EXCEPTION_ILLEGAL_INSTRUCTION:
46 diff -prudN e:\Wine\dlls\rpcrt4/rpc_server.c e:\reactos\dll\win32\rpcrt4/rpc_server.c
47 --- e:\Wine\dlls\rpcrt4/rpc_server.c 2012-12-09 09:57:02.680308600 +0100
48 +++ e:\reactos\dll\win32\rpcrt4/rpc_server.c 2013-12-06 23:50:04.564226300 +0100
49 @@ -1075,8 +1077,10 @@ void RPCRT4_destroy_all_protseqs(void)
50 EnterCriticalSection(&server_cs);
51 LIST_FOR_EACH_ENTRY_SAFE(cps, cursor2, &protseqs, RpcServerProtseq, entry)
52 {
53 +#ifndef __REACTOS__
54 if (listen_count != 0)
55 RPCRT4_sync_with_server_thread(cps);
56 +#endif
57 destroy_serverprotoseq(cps);
58 }
59 LeaveCriticalSection(&server_cs);
60 diff -prudN e:\Wine\dlls\rpcrt4/rpc_transport.c e:\reactos\dll\win32\rpcrt4/rpc_transport.c
61 --- e:\Wine\dlls\rpcrt4/rpc_transport.c 2013-12-06 20:10:59.302378700 +0100
62 +++ e:\reactos\dll\win32\rpcrt4/rpc_transport.c 2013-12-06 23:39:38.664465200 +0100
63 @@ -111,31 +115,41 @@ typedef struct _RpcConnection_np
64 {
65 RpcConnection common;
66 HANDLE pipe;
67 - HANDLE listen_thread;
68 + OVERLAPPED ovl;
69 BOOL listening;
70 } RpcConnection_np;
71
72 static RpcConnection *rpcrt4_conn_np_alloc(void)
73 {
74 RpcConnection_np *npc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcConnection_np));
75 + if (npc)
76 + {
77 + npc->pipe = NULL;
78 + memset(&npc->ovl, 0, sizeof(npc->ovl));
79 + npc->listening = FALSE;
80 + }
81 return &npc->common;
82 }
83
84 -static DWORD CALLBACK listen_thread(void *arg)
85 +static RPC_STATUS rpcrt4_conn_listen_pipe(RpcConnection_np *npc)
86 {
87 - RpcConnection_np *npc = arg;
88 + if (npc->listening)
89 + return RPC_S_OK;
90 +
91 + npc->listening = TRUE;
92 for (;;)
93 {
94 - if (ConnectNamedPipe(npc->pipe, NULL))
95 + if (ConnectNamedPipe(npc->pipe, &npc->ovl))
96 return RPC_S_OK;
97
98 switch(GetLastError())
99 {
100 case ERROR_PIPE_CONNECTED:
101 + SetEvent(npc->ovl.hEvent);
102 + return RPC_S_OK;
103 + case ERROR_IO_PENDING:
104 + /* will be completed in rpcrt4_protseq_np_wait_for_new_connection */
105 return RPC_S_OK;
106 - case ERROR_HANDLES_CLOSED:
107 - /* connection closed during listen */
108 - return RPC_S_NO_CONTEXT_AVAILABLE;
109 case ERROR_NO_DATA_DETECTED:
110 /* client has disconnected, retry */
111 DisconnectNamedPipe( npc->pipe );
112 @@ -148,28 +162,12 @@ static DWORD CALLBACK listen_thread(void
113 }
114 }
115
116 -static RPC_STATUS rpcrt4_conn_listen_pipe(RpcConnection_np *npc)
117 -{
118 - if (npc->listening)
119 - return RPC_S_OK;
120 -
121 - npc->listening = TRUE;
122 - npc->listen_thread = CreateThread(NULL, 0, listen_thread, npc, 0, NULL);
123 - if (!npc->listen_thread)
124 - {
125 - npc->listening = FALSE;
126 - ERR("Couldn't create listen thread (error was %d)\n", GetLastError());
127 - return RPC_S_OUT_OF_RESOURCES;
128 - }
129 - return RPC_S_OK;
130 -}
131 -
132 static RPC_STATUS rpcrt4_conn_create_pipe(RpcConnection *Connection, LPCSTR pname)
133 {
134 RpcConnection_np *npc = (RpcConnection_np *) Connection;
135 TRACE("listening on %s\n", pname);
136
137 - npc->pipe = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX,
138 + npc->pipe = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
139 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE,
140 PIPE_UNLIMITED_INSTANCES,
141 RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL);
142 @@ -181,6 +179,9 @@ static RPC_STATUS rpcrt4_conn_create_pip
143 return RPC_S_CANT_CREATE_ENDPOINT;
144 }
145
146 + memset(&npc->ovl, 0, sizeof(npc->ovl));
147 + npc->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
148 +
149 /* Note: we don't call ConnectNamedPipe here because it must be done in the
150 * server thread as the thread must be alertable */
151 return RPC_S_OK;
152 @@ -227,6 +228,9 @@ static RPC_STATUS rpcrt4_conn_open_pipe(
153 if (err == ERROR_PIPE_BUSY) {
154 TRACE("connection failed, error=%x\n", err);
155 return RPC_S_SERVER_TOO_BUSY;
156 + } else if (err == ERROR_BAD_NETPATH) {
157 + TRACE("connection failed, error=%x\n", err);
158 + return RPC_S_SERVER_UNAVAILABLE;
159 }
160 if (!wait || !WaitNamedPipeA(pname, NMPWAIT_WAIT_FOREVER)) {
161 err = GetLastError();
162 @@ -236,9 +240,11 @@ static RPC_STATUS rpcrt4_conn_open_pipe(
163 }
164
165 /* success */
166 + memset(&npc->ovl, 0, sizeof(npc->ovl));
167 /* pipe is connected; change to message-read mode. */
168 dwMode = PIPE_READMODE_MESSAGE;
169 SetNamedPipeHandleState(pipe, &dwMode, NULL, NULL);
170 + npc->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
171 npc->pipe = pipe;
172
173 return RPC_S_OK;
174 @@ -306,18 +312,32 @@ static RPC_STATUS rpcrt4_protseq_ncalrpc
175 static RPC_STATUS rpcrt4_ncacn_np_open(RpcConnection* Connection)
176 {
177 RpcConnection_np *npc = (RpcConnection_np *) Connection;
178 - static const char prefix[] = "\\\\.";
179 + static const char prefix[] = "\\\\";
180 + static const char local[] =".";
181 RPC_STATUS r;
182 LPSTR pname;
183 + INT size;
184
185 /* already connected? */
186 if (npc->pipe)
187 return RPC_S_OK;
188
189 /* protseq=ncacn_np: named pipes */
190 - pname = I_RpcAllocate(strlen(prefix) + strlen(Connection->Endpoint) + 1);
191 - strcat(strcpy(pname, prefix), Connection->Endpoint);
192 - r = rpcrt4_conn_open_pipe(Connection, pname, FALSE);
193 + size = strlen(prefix);
194 + if (Connection->NetworkAddr == NULL || strlen(Connection->NetworkAddr) == 0)
195 + size += strlen(local);
196 + else
197 + size += strlen(Connection->NetworkAddr);
198 + size += strlen(Connection->Endpoint) + 1;
199 +
200 + pname = I_RpcAllocate(size);
201 + strcpy(pname, prefix);
202 + if (Connection->NetworkAddr == NULL || strlen(Connection->NetworkAddr) == 0)
203 + strcat(pname, local);
204 + else
205 + strcat(pname, Connection->NetworkAddr);
206 + strcat(pname, Connection->Endpoint);
207 + r = rpcrt4_conn_open_pipe(Connection, pname, TRUE);
208 I_RpcFree(pname);
209
210 return r;
211 @@ -366,9 +386,9 @@ static void rpcrt4_conn_np_handoff(RpcCo
212 * to the child, then reopen the server binding to continue listening */
213
214 new_npc->pipe = old_npc->pipe;
215 - new_npc->listen_thread = old_npc->listen_thread;
216 + new_npc->ovl = old_npc->ovl;
217 old_npc->pipe = 0;
218 - old_npc->listen_thread = 0;
219 + memset(&old_npc->ovl, 0, sizeof(old_npc->ovl));
220 old_npc->listening = FALSE;
221 }
222
223 @@ -413,11 +433,17 @@ static int rpcrt4_conn_np_read(RpcConnec
224 char *buf = buffer;
225 BOOL ret = TRUE;
226 unsigned int bytes_left = count;
227 + OVERLAPPED ovl;
228 +
229 + ZeroMemory(&ovl, sizeof(ovl));
230 + ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
231
232 while (bytes_left)
233 {
234 DWORD bytes_read;
235 - ret = ReadFile(npc->pipe, buf, bytes_left, &bytes_read, NULL);
236 + ret = ReadFile(npc->pipe, buf, bytes_left, &bytes_read, &ovl);
237 + if (!ret && GetLastError() == ERROR_IO_PENDING)
238 + ret = GetOverlappedResult(npc->pipe, &ovl, &bytes_read, TRUE);
239 if (!ret && GetLastError() == ERROR_MORE_DATA)
240 ret = TRUE;
241 if (!ret || !bytes_read)
242 @@ -425,6 +451,7 @@ static int rpcrt4_conn_np_read(RpcConnec
243 bytes_left -= bytes_read;
244 buf += bytes_read;
245 }
246 + CloseHandle(ovl.hEvent);
247 return ret ? count : -1;
248 }
249
250 @@ -435,16 +462,23 @@ static int rpcrt4_conn_np_write(RpcConne
251 const char *buf = buffer;
252 BOOL ret = TRUE;
253 unsigned int bytes_left = count;
254 + OVERLAPPED ovl;
255 +
256 + ZeroMemory(&ovl, sizeof(ovl));
257 + ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
258
259 while (bytes_left)
260 {
261 DWORD bytes_written;
262 - ret = WriteFile(npc->pipe, buf, bytes_left, &bytes_written, NULL);
263 + ret = WriteFile(npc->pipe, buf, bytes_left, &bytes_written, &ovl);
264 + if (!ret && GetLastError() == ERROR_IO_PENDING)
265 + ret = GetOverlappedResult(npc->pipe, &ovl, &bytes_written, TRUE);
266 if (!ret || !bytes_written)
267 break;
268 bytes_left -= bytes_written;
269 buf += bytes_written;
270 }
271 + CloseHandle(ovl.hEvent);
272 return ret ? count : -1;
273 }
274
275 @@ -456,9 +490,9 @@ static int rpcrt4_conn_np_close(RpcConne
276 CloseHandle(npc->pipe);
277 npc->pipe = 0;
278 }
279 - if (npc->listen_thread) {
280 - CloseHandle(npc->listen_thread);
281 - npc->listen_thread = 0;
282 + if (npc->ovl.hEvent) {
283 + CloseHandle(npc->ovl.hEvent);
284 + npc->ovl.hEvent = 0;
285 }
286 return 0;
287 }
288 @@ -662,7 +696,7 @@ static void *rpcrt4_protseq_np_get_wait_
289 conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
290 while (conn) {
291 rpcrt4_conn_listen_pipe(conn);
292 - if (conn->listen_thread)
293 + if (conn->ovl.hEvent)
294 (*count)++;
295 conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
296 }
297 @@ -683,7 +717,7 @@ static void *rpcrt4_protseq_np_get_wait_
298 *count = 1;
299 conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
300 while (conn) {
301 - if ((objs[*count] = conn->listen_thread))
302 + if ((objs[*count] = conn->ovl.hEvent))
303 (*count)++;
304 conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
305 }
306 @@ -730,18 +764,12 @@ static int rpcrt4_protseq_np_wait_for_ne
307 EnterCriticalSection(&protseq->cs);
308 conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
309 while (conn) {
310 - if (b_handle == conn->listen_thread) break;
311 + if (b_handle == conn->ovl.hEvent) break;
312 conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
313 }
314 cconn = NULL;
315 if (conn)
316 - {
317 - DWORD exit_code;
318 - if (GetExitCodeThread(conn->listen_thread, &exit_code) && exit_code == RPC_S_OK)
319 - RPCRT4_SpawnConnection(&cconn, &conn->common);
320 - CloseHandle(conn->listen_thread);
321 - conn->listen_thread = 0;
322 - }
323 + RPCRT4_SpawnConnection(&cconn, &conn->common);
324 else
325 ERR("failed to locate connection for handle %p\n", b_handle);
326 LeaveCriticalSection(&protseq->cs);
327 diff -prudN e:\Wine\dlls\rpcrt4/rpcrt4.spec e:\reactos\dll\win32\rpcrt4/rpcrt4.spec
328 --- e:\Wine\dlls\rpcrt4/rpcrt4.spec 2012-09-09 19:47:53.677232900 +0100
329 +++ e:\reactos\dll\win32\rpcrt4/rpcrt4.spec 2013-12-06 20:29:09.804227500 +0100
330 @@ -266,7 +266,7 @@
331 @ stdcall NdrRangeUnmarshall(ptr ptr ptr long)
332 @ stub NdrRpcSmClientAllocate
333 @ stub NdrRpcSmClientFree
334 -@ stub NdrRpcSmSetClientToOsf
335 +@ stdcall NdrRpcSmSetClientToOsf(ptr)
336 @ stub NdrRpcSsDefaultAllocate
337 @ stub NdrRpcSsDefaultFree
338 @ stub NdrRpcSsDisableAllocate