Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- programs/rpcss/rpcss_main.c | 102 ++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 45 deletions(-)
diff --git a/programs/rpcss/rpcss_main.c b/programs/rpcss/rpcss_main.c index 6d24ccbc07..42749028c3 100644 --- a/programs/rpcss/rpcss_main.c +++ b/programs/rpcss/rpcss_main.c @@ -37,53 +37,60 @@ static WCHAR rpcssW[] = {'R','p','c','S','s',0}; static HANDLE exit_event; static SERVICE_STATUS_HANDLE service_handle;
-static BOOL RPCSS_Initialize(void) +static RPC_STATUS RPCSS_Initialize(void) { - static unsigned short irot_protseq[] = IROT_PROTSEQ; - static unsigned short irot_endpoint[] = IROT_ENDPOINT; - static unsigned short epm_protseq[] = {'n','c','a','c','n','_','n','p',0}; - static unsigned short epm_endpoint[] = {'\','p','i','p','e','\','e','p','m','a','p','p','e','r',0}; - static unsigned short epm_protseq_lrpc[] = {'n','c','a','l','r','p','c',0}; - static unsigned short epm_endpoint_lrpc[] = {'e','p','m','a','p','p','e','r',0}; - RPC_STATUS status; - - WINE_TRACE("\n"); - - status = RpcServerRegisterIf(epm_v3_0_s_ifspec, NULL, NULL); - if (status != RPC_S_OK) - return status; - status = RpcServerRegisterIf(Irot_v0_2_s_ifspec, NULL, NULL); - if (status != RPC_S_OK) - { - RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE); - return FALSE; - } - - status = RpcServerUseProtseqEpW(epm_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT, - epm_endpoint, NULL); - if (status != RPC_S_OK) - goto fail; - - status = RpcServerUseProtseqEpW(epm_protseq_lrpc, RPC_C_PROTSEQ_MAX_REQS_DEFAULT, - epm_endpoint_lrpc, NULL); - if (status != RPC_S_OK) - goto fail; - - status = RpcServerUseProtseqEpW(irot_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT, - irot_endpoint, NULL); - if (status != RPC_S_OK) - goto fail; - - status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE); - if (status != RPC_S_OK) - goto fail; - - return TRUE; + static unsigned short irot_protseq[] = IROT_PROTSEQ; + static unsigned short irot_endpoint[] = IROT_ENDPOINT; + static unsigned short epm_protseq[] = {'n','c','a','c','n','_','n','p',0}; + static unsigned short epm_endpoint[] = {'\','p','i','p','e','\','e','p','m','a','p','p','e','r',0}; + static unsigned short epm_protseq_lrpc[] = {'n','c','a','l','r','p','c',0}; + static unsigned short epm_endpoint_lrpc[] = {'e','p','m','a','p','p','e','r',0}; + static const struct protseq_map + { + unsigned short *protseq; + unsigned short *endpoint; + } protseqs[] = + { + { epm_protseq, epm_endpoint }, + { epm_protseq_lrpc, epm_endpoint_lrpc }, + { irot_protseq, irot_endpoint }, + }; + RPC_IF_HANDLE ifspecs[] = + { + epm_v3_0_s_ifspec, + Irot_v0_2_s_ifspec, + }; + RPC_STATUS status; + int i, j; + + WINE_TRACE("\n"); + + for (i = 0, j = 0; i < ARRAY_SIZE(ifspecs); ++i, j = i) + { + status = RpcServerRegisterIf(ifspecs[i], NULL, NULL); + if (status != RPC_S_OK) + goto fail; + } + + for (i = 0; i < ARRAY_SIZE(protseqs); ++i) + { + status = RpcServerUseProtseqEpW(protseqs[i].protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT, + protseqs[i].endpoint, NULL); + if (status != RPC_S_OK) + goto fail; + } + + status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE); + if (status != RPC_S_OK) + goto fail; + + return RPC_S_OK;
fail: - RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE); - RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, FALSE); - return FALSE; + for (i = 0; i < j; ++i) + RpcServerUnregisterIf(ifspecs[i], NULL, FALSE); + + return status; }
static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context ) @@ -121,10 +128,15 @@ static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv ) { SERVICE_STATUS status; + RPC_STATUS ret;
TRACE( "starting service\n" );
- if (!RPCSS_Initialize()) return; + if ((ret = RPCSS_Initialize())) + { + WARN("Failed to initialize rpc interfaces, status %d.\n", ret); + return; + }
exit_event = CreateEventW( NULL, TRUE, FALSE, NULL );
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- include/wine/irpcss.idl | 33 +++++++++++++++++++++++++++++++++ programs/rpcss/Makefile.in | 3 ++- programs/rpcss/irpcss.idl | 21 +++++++++++++++++++++ programs/rpcss/rpcss_main.c | 12 ++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 include/wine/irpcss.idl create mode 100644 programs/rpcss/irpcss.idl
diff --git a/include/wine/irpcss.idl b/include/wine/irpcss.idl new file mode 100644 index 0000000000..1874e10025 --- /dev/null +++ b/include/wine/irpcss.idl @@ -0,0 +1,33 @@ +/* + * Copyright 2019 Nikolay Sivov for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +import "wtypes.idl"; + +cpp_quote("#define IRPCSS_PROTSEQ {'n','c','a','l','r','p','c',0}") +cpp_quote("#define IRPCSS_ENDPOINT {'i','r','p','c','s','s',0}") + +[ + uuid(85da4974-edc7-40ff-bad4-9c4525a8d044), + version(0.0), +] +interface Irpcss +{ + HRESULT irpcss_get_thread_seq_id( + [in] handle_t handle, + [out] DWORD *sequence_id); +} diff --git a/programs/rpcss/Makefile.in b/programs/rpcss/Makefile.in index 6ccb5e965a..dcc405a944 100644 --- a/programs/rpcss/Makefile.in +++ b/programs/rpcss/Makefile.in @@ -10,4 +10,5 @@ C_SRCS = \
IDL_SRCS = \ epm.idl \ - irot.idl + irot.idl \ + irpcss.idl diff --git a/programs/rpcss/irpcss.idl b/programs/rpcss/irpcss.idl new file mode 100644 index 0000000000..1f346ada82 --- /dev/null +++ b/programs/rpcss/irpcss.idl @@ -0,0 +1,21 @@ +/* + * Copyright 2019 Nikolay Sivov for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#pragma makedep server + +#include "wine/irpcss.idl" diff --git a/programs/rpcss/rpcss_main.c b/programs/rpcss/rpcss_main.c index 42749028c3..6e85ef2c33 100644 --- a/programs/rpcss/rpcss_main.c +++ b/programs/rpcss/rpcss_main.c @@ -28,6 +28,7 @@ #include "winsvc.h" #include "irot.h" #include "epm.h" +#include "irpcss.h"
#include "wine/debug.h"
@@ -37,6 +38,13 @@ static WCHAR rpcssW[] = {'R','p','c','S','s',0}; static HANDLE exit_event; static SERVICE_STATUS_HANDLE service_handle;
+HRESULT __cdecl irpcss_get_thread_seq_id(handle_t h, DWORD *id) +{ + static LONG thread_seq_id; + *id = InterlockedIncrement(&thread_seq_id); + return S_OK; +} + static RPC_STATUS RPCSS_Initialize(void) { static unsigned short irot_protseq[] = IROT_PROTSEQ; @@ -45,6 +53,8 @@ static RPC_STATUS RPCSS_Initialize(void) static unsigned short epm_endpoint[] = {'\','p','i','p','e','\','e','p','m','a','p','p','e','r',0}; static unsigned short epm_protseq_lrpc[] = {'n','c','a','l','r','p','c',0}; static unsigned short epm_endpoint_lrpc[] = {'e','p','m','a','p','p','e','r',0}; + static unsigned short irpcss_protseq[] = IRPCSS_PROTSEQ; + static unsigned short irpcss_endpoint[] = IRPCSS_ENDPOINT; static const struct protseq_map { unsigned short *protseq; @@ -54,11 +64,13 @@ static RPC_STATUS RPCSS_Initialize(void) { epm_protseq, epm_endpoint }, { epm_protseq_lrpc, epm_endpoint_lrpc }, { irot_protseq, irot_endpoint }, + { irpcss_protseq, irpcss_endpoint }, }; RPC_IF_HANDLE ifspecs[] = { epm_v3_0_s_ifspec, Irot_v0_2_s_ifspec, + Irpcss_v0_0_s_ifspec, }; RPC_STATUS status; int i, j;
Signed-off-by: Huw Davies huw@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/ole32/Makefile.in | 1 + dlls/ole32/compobj.c | 18 ++++----- dlls/ole32/compobj_private.h | 5 ++- dlls/ole32/irpcss.idl | 21 ++++++++++ dlls/ole32/moniker.c | 75 ++++++++++++++++++++++++++++++------ dlls/ole32/tests/compobj.c | 27 +++++++++++++ 6 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 dlls/ole32/irpcss.idl
diff --git a/dlls/ole32/Makefile.in b/dlls/ole32/Makefile.in index 6c2f1231f1..32de987a8c 100644 --- a/dlls/ole32/Makefile.in +++ b/dlls/ole32/Makefile.in @@ -48,6 +48,7 @@ RC_SRCS = ole32res.rc IDL_SRCS = \ dcom.idl \ irot.idl \ + irpcss.idl \ ole32_objidl.idl \ ole32_oleidl.idl \ ole32_unknwn.idl diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index 0dc0d39c22..a91067fcb7 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -4027,18 +4027,18 @@ done:
/****************************************************************************** * CoGetCurrentProcess [OLE32.@] - * - * Gets the current process ID. - * - * RETURNS - * The current process ID. - * - * NOTES - * Is DWORD really the correct return type for this function? */ DWORD WINAPI CoGetCurrentProcess(void) { - return GetCurrentProcessId(); + struct oletls *info = COM_CurrentInfo(); + + if (!info) + return 0; + + if (!info->thread_seqid) + info->thread_seqid = rpcss_get_next_seqid(); + + return info->thread_seqid; }
/*********************************************************************** diff --git a/dlls/ole32/compobj_private.h b/dlls/ole32/compobj_private.h index bda1c6bff2..29f94421d1 100644 --- a/dlls/ole32/compobj_private.h +++ b/dlls/ole32/compobj_private.h @@ -165,7 +165,7 @@ struct oletls { struct apartment *apt; IErrorInfo *errorinfo; /* see errorinfo.c */ - IUnknown *state; /* see CoSetState */ + DWORD thread_seqid;/* returned with CoGetCurrentProcess */ DWORD apt_mask; /* apartment mask (+0Ch on x86) */ void *unknown0; DWORD inits; /* number of times CoInitializeEx called */ @@ -178,6 +178,7 @@ struct oletls IUnknown *call_state; /* current call context (+3Ch on x86) */ DWORD unknown2[46]; IUnknown *cancel_object; /* cancel object set by CoSetCancelObject (+F8h on x86) */ + IUnknown *state; /* see CoSetState */ struct list spies; /* Spies installed with CoRegisterInitializeSpy */ DWORD spies_lock; }; @@ -355,4 +356,6 @@ static inline HRESULT copy_formatetc(FORMATETC *dst, const FORMATETC *src) extern HRESULT EnumSTATDATA_Construct(IUnknown *holder, ULONG index, DWORD array_len, STATDATA *data, BOOL copy, IEnumSTATDATA **ppenum) DECLSPEC_HIDDEN;
+extern DWORD rpcss_get_next_seqid(void) DECLSPEC_HIDDEN; + #endif /* __WINE_OLE_COMPOBJ_H */ diff --git a/dlls/ole32/irpcss.idl b/dlls/ole32/irpcss.idl new file mode 100644 index 0000000000..65078167de --- /dev/null +++ b/dlls/ole32/irpcss.idl @@ -0,0 +1,21 @@ +/* + * Copyright 2019 Nikolay Sivov for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#pragma makedep client + +#include "wine/irpcss.idl" diff --git a/dlls/ole32/moniker.c b/dlls/ole32/moniker.c index 82d829d719..f82159d9e1 100644 --- a/dlls/ole32/moniker.c +++ b/dlls/ole32/moniker.c @@ -41,6 +41,7 @@ #include "compobj_private.h" #include "moniker.h" #include "irot.h" +#include "irpcss.h"
WINE_DEFAULT_DEBUG_CHANNEL(ole);
@@ -77,6 +78,7 @@ typedef struct RunningObjectTableImpl
static RunningObjectTableImpl* runningObjectTableInstance = NULL; static IrotHandle irot_handle; +static RPC_BINDING_HANDLE irpcss_handle;
/* define the EnumMonikerImpl structure */ typedef struct EnumMonikerImpl @@ -102,23 +104,30 @@ static inline EnumMonikerImpl *impl_from_IEnumMoniker(IEnumMoniker *iface) static HRESULT EnumMonikerImpl_CreateEnumROTMoniker(InterfaceList *moniker_list, ULONG pos, IEnumMoniker **ppenumMoniker);
+static RPC_BINDING_HANDLE get_rpc_handle(unsigned short *protseq, unsigned short *endpoint) +{ + RPC_BINDING_HANDLE handle = NULL; + RPC_STATUS status; + RPC_WSTR binding; + + status = RpcStringBindingComposeW(NULL, protseq, NULL, endpoint, NULL, &binding); + if (status == RPC_S_OK) + { + status = RpcBindingFromStringBindingW(binding, &handle); + RpcStringFreeW(&binding); + } + + return handle; +} + static IrotHandle get_irot_handle(void) { if (!irot_handle) { - RPC_STATUS status; - RPC_WSTR binding; - IrotHandle new_handle; - unsigned short ncacn_np[] = IROT_PROTSEQ; + unsigned short protseq[] = IROT_PROTSEQ; unsigned short endpoint[] = IROT_ENDPOINT; - status = RpcStringBindingComposeW(NULL, ncacn_np, NULL, endpoint, NULL, &binding); - if (status == RPC_S_OK) - { - status = RpcBindingFromStringBindingW(binding, &new_handle); - RpcStringFreeW(&binding); - } - if (status != RPC_S_OK) - return NULL; + + IrotHandle new_handle = get_rpc_handle(protseq, endpoint); if (InterlockedCompareExchangePointer(&irot_handle, new_handle, NULL)) /* another thread beat us to it */ RpcBindingFree(&new_handle); @@ -126,6 +135,21 @@ static IrotHandle get_irot_handle(void) return irot_handle; }
+static RPC_BINDING_HANDLE get_irpcss_handle(void) +{ + if (!irpcss_handle) + { + unsigned short protseq[] = IROT_PROTSEQ; + unsigned short endpoint[] = IROT_ENDPOINT; + + RPC_BINDING_HANDLE new_handle = get_rpc_handle(protseq, endpoint); + if (InterlockedCompareExchangePointer(&irpcss_handle, new_handle, NULL)) + /* another thread beat us to it */ + RpcBindingFree(&new_handle); + } + return irpcss_handle; +} + static BOOL start_rpcss(void) { static const WCHAR rpcssW[] = {'R','p','c','S','s',0}; @@ -176,6 +200,33 @@ static BOOL start_rpcss(void) return ret; }
+DWORD rpcss_get_next_seqid(void) +{ + DWORD id = 0; + HRESULT hr; + + for (;;) + { + __TRY + { + hr = irpcss_get_thread_seq_id(get_irpcss_handle(), &id); + } + __EXCEPT(rpc_filter) + { + hr = HRESULT_FROM_WIN32(GetExceptionCode()); + } + __ENDTRY + if (hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE)) + { + if (start_rpcss()) + continue; + } + break; + } + + return id; +} + static HRESULT create_stream_on_mip_ro(const InterfaceData *mip, IStream **stream) { HGLOBAL hglobal = GlobalAlloc(0, mip->ulCntData); diff --git a/dlls/ole32/tests/compobj.c b/dlls/ole32/tests/compobj.c index 8412ee45a0..6b15040ebe 100644 --- a/dlls/ole32/tests/compobj.c +++ b/dlls/ole32/tests/compobj.c @@ -3893,6 +3893,31 @@ static void test_implicit_mta(void) CoUninitialize(); }
+static DWORD WINAPI co_get_current_process_thread(void *param) +{ + DWORD *id = param; + + *id = CoGetCurrentProcess(); + return 0; +} + +static void test_CoGetCurrentProcess(void) +{ + DWORD id, id2; + HANDLE thread; + + id = CoGetCurrentProcess(); + ok(!!id && id != GetCurrentProcessId() && id != GetCurrentThreadId(), "Unexpected result %d.\n", id); + + id2 = 0; + thread = CreateThread(NULL, 0, co_get_current_process_thread, &id2, 0, NULL); + ok(thread != NULL, "Failed to create test thread.\n"); + ok(!WaitForSingleObject(thread, 10000), "Wait timed out.\n"); + CloseHandle(thread); + + ok(id2 && id2 != id, "Unexpected id from another thread.\n"); +} + START_TEST(compobj) { init_funcs(); @@ -3949,5 +3974,7 @@ START_TEST(compobj) test_CoGetInstanceFromFile(); test_GlobalOptions(); test_implicit_mta(); + test_CoGetCurrentProcess(); + DeleteFileA( testlib ); }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=59574
Your paranoid android.
=== w8 (32 bit report) ===
ole32: compobj.c:2930: Test failed: PeekMessageA failed: 1400
=== w1064v1809_ar (32 bit report) ===
ole32: compobj.c:2787: Test failed: WaitForSingleObject failed
=== w1064v1809_he (32 bit report) ===
ole32: compobj.c:2928: Test failed: expected message 1024, received none compobj.c:2930: Test failed: PeekMessageA failed: 1400
Signed-off-by: Huw Davies huw@codeweavers.com