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