Skip to content

Commit

Permalink
[RPCRT4] Sync with Wine Staging 4.0. CORE-15682
Browse files Browse the repository at this point in the history
  • Loading branch information
AmineKhaldi committed Jan 30, 2019
1 parent bb33692 commit b6fdb56
Show file tree
Hide file tree
Showing 23 changed files with 2,457 additions and 1,084 deletions.
27 changes: 17 additions & 10 deletions dll/win32/rpcrt4/CMakeLists.txt
Expand Up @@ -2,9 +2,21 @@
remove_definitions(-D_WIN32_WINNT=0x502)
add_definitions(-D_WIN32_WINNT=0x600)

add_definitions(
-D__WINESRC__
-D_RPCRT4_
-DCOM_NO_WINDOWS_H
-DMSWMSG)

include_directories(BEFORE ${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
spec2def(rpcrt4.dll rpcrt4.spec ADD_IMPORTLIB)

add_rpc_files(client epm.idl)
add_idl_headers(ndr_types_header ndr_types.idl)

set(IDL_FLAGS ${IDL_FLAGS} -Oicf)
add_rpcproxy_files(ndr_types.idl)
unset(IDL_FLAGS)

list(APPEND SOURCE
cproxy.c
Expand All @@ -29,29 +41,24 @@ list(APPEND SOURCE
precomp.h
${CMAKE_CURRENT_BINARY_DIR}/epm_c.c)

remove_definitions(-D_WIN32_WINNT=0x502)
add_definitions(-D_WIN32_WINNT=0x600)

add_definitions(
-D__WINESRC__
-D_RPCRT4_
-DCOM_NO_WINDOWS_H
-DMSWMSG)

if(MSVC AND NOT ARCH STREQUAL "arm")
add_asm_files(rpcrt4_asm msvc.S)
endif()

add_library(rpcrt4 SHARED
${SOURCE}
ndr_typelib.c
${CMAKE_CURRENT_BINARY_DIR}/ndr_types_p.c
${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c
${rpcrt4_asm}
rpcrt4.rc
${CMAKE_CURRENT_BINARY_DIR}/rpcrt4_stubs.c
${CMAKE_CURRENT_BINARY_DIR}/rpcrt4.def)

set_module_type(rpcrt4 win32dll)
target_link_libraries(rpcrt4 wine uuid ${PSEH_LIB})
add_delay_importlibs(rpcrt4 iphlpapi wininet secur32 user32)
add_delay_importlibs(rpcrt4 iphlpapi wininet secur32 user32 oleaut32)
add_importlibs(rpcrt4 advapi32 advapi32_vista kernel32_vista ws2_32 msvcrt kernel32 ntdll)
add_dependencies(rpcrt4 ndr_types_header)
add_pch(rpcrt4 precomp.h SOURCE)
add_cd_file(TARGET rpcrt4 DESTINATION reactos/system32 FOR all)
118 changes: 39 additions & 79 deletions dll/win32/rpcrt4/cproxy.c
Expand Up @@ -17,8 +17,6 @@
* 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
*
* TODO: Handle non-i386 architectures
*/

#include "config.h"
Expand All @@ -42,21 +40,6 @@

WINE_DEFAULT_DEBUG_CHANNEL(ole);

/* I don't know what MS's std proxy structure looks like,
so this probably doesn't match, but that shouldn't matter */
typedef struct {
IRpcProxyBuffer IRpcProxyBuffer_iface;
LPVOID *PVtbl;
LONG RefCount;
const IID* piid;
LPUNKNOWN pUnkOuter;
IUnknown *base_object; /* must be at offset 0x10 from PVtbl */
IRpcProxyBuffer *base_proxy;
PCInterfaceName name;
LPPSFACTORYBUFFER pPSFactory;
LPRPCCHANNELBUFFER pChannel;
} StdProxyImpl;

static const IRpcProxyBufferVtbl StdProxy_Vtbl;

static inline StdProxyImpl *impl_from_IRpcProxyBuffer(IRpcProxyBuffer *iface)
Expand All @@ -79,7 +62,10 @@ __ASM_GLOBAL_FUNC(call_stubless_func,
"movl 8(%ecx),%edx\n\t" /* info->FormatStringOffset */
"movzwl (%edx,%eax,2),%edx\n\t" /* FormatStringOffset[index] */
"addl 4(%ecx),%edx\n\t" /* info->ProcFormatString + offset */
"movzwl 8(%edx),%eax\n\t" /* arguments size */
"movzbl 1(%edx),%eax\n\t" /* Oi_flags */
"andl $0x08,%eax\n\t" /* Oi_HAS_RPCFLAGS */
"shrl $1,%eax\n\t"
"movzwl 4(%edx,%eax),%eax\n\t" /* arguments size */
"pushl %eax\n\t"
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
"leal 8(%esp),%eax\n\t" /* &This */
Expand Down Expand Up @@ -171,24 +157,43 @@ static inline void init_thunk( struct thunk *thunk, unsigned int index )

extern void call_stubless_func(void);
__ASM_GLOBAL_FUNC(call_stubless_func,
"DCD 0xDEFC\n\t" // _assertfail
"" );
"push {r0-r3}\n\t"
"mov r2, sp\n\t" /* stack_top */
"push {fp,lr}\n\t"
"mov fp, sp\n\t"
"ldr r0, [r0]\n\t" /* This->lpVtbl */
"ldr r0, [r0,#-8]\n\t" /* MIDL_STUBLESS_PROXY_INFO */
"ldr r1, [r0,#8]\n\t" /* info->FormatStringOffset */
"ldrh r1, [r1,ip]\n\t" /* info->FormatStringOffset[index] */
"ldr ip, [r0,#4]\n\t" /* info->ProcFormatString */
"add r1, ip\n\t" /* info->ProcFormatString + offset */
"ldr r0, [r0]\n\t" /* info->pStubDesc */
#ifdef __SOFTFP__
"mov r3, #0\n\t"
#else
"vpush {s0-s15}\n\t" /* store the s0-s15/d0-d7 arguments */
"mov r3, sp\n\t" /* fpu_stack */
#endif
"bl " __ASM_NAME("ndr_client_call") "\n\t"
"mov sp, fp\n\t"
"pop {fp,lr}\n\t"
"add sp, #16\n\t"
"bx lr" );

#include "pshpack1.h"
struct thunk
{
DWORD assertfail;
};
#include "poppack.h"

static const struct thunk thunk_template =
{
{ 0xDEFC } /* _assertfail */
DWORD ldr_ip; /* ldr ip,[pc] */
DWORD ldr_pc; /* ldr pc,[pc] */
DWORD index;
void *func;
};

static inline void init_thunk( struct thunk *thunk, unsigned int index )
{
*thunk = thunk_template;
thunk->ldr_ip = 0xe59fc000; /* ldr ip,[pc] */
thunk->ldr_pc = 0xe59ff000; /* ldr pc,[pc] */
thunk->index = index * sizeof(unsigned short);
thunk->func = call_stubless_func;
}

#else /* __i386__ */
Expand Down Expand Up @@ -233,7 +238,7 @@ static const struct thunk *allocate_block( unsigned int num )
return block;
}

static BOOL fill_stubless_table( IUnknownVtbl *vtbl, DWORD num )
BOOL fill_stubless_table( IUnknownVtbl *vtbl, DWORD num )
{
const void **entry = (const void **)(vtbl + 1);
DWORD i, j;
Expand Down Expand Up @@ -317,9 +322,7 @@ HRESULT StdProxy_Construct(REFIID riid,
return S_OK;
}

static HRESULT WINAPI StdProxy_QueryInterface(LPRPCPROXYBUFFER iface,
REFIID riid,
LPVOID *obj)
HRESULT WINAPI StdProxy_QueryInterface(IRpcProxyBuffer *iface, REFIID riid, void **obj)
{
StdProxyImpl *This = impl_from_IRpcProxyBuffer(iface);
TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
Expand All @@ -340,7 +343,7 @@ static HRESULT WINAPI StdProxy_QueryInterface(LPRPCPROXYBUFFER iface,
return E_NOINTERFACE;
}

static ULONG WINAPI StdProxy_AddRef(LPRPCPROXYBUFFER iface)
ULONG WINAPI StdProxy_AddRef(IRpcProxyBuffer *iface)
{
StdProxyImpl *This = impl_from_IRpcProxyBuffer(iface);
TRACE("(%p)->AddRef()\n",This);
Expand Down Expand Up @@ -370,8 +373,7 @@ static ULONG WINAPI StdProxy_Release(LPRPCPROXYBUFFER iface)
return refs;
}

static HRESULT WINAPI StdProxy_Connect(LPRPCPROXYBUFFER iface,
LPRPCCHANNELBUFFER pChannel)
HRESULT WINAPI StdProxy_Connect(IRpcProxyBuffer *iface, IRpcChannelBuffer *pChannel)
{
StdProxyImpl *This = impl_from_IRpcProxyBuffer(iface);
TRACE("(%p)->Connect(%p)\n",This,pChannel);
Expand All @@ -382,7 +384,7 @@ static HRESULT WINAPI StdProxy_Connect(LPRPCPROXYBUFFER iface,
return S_OK;
}

static VOID WINAPI StdProxy_Disconnect(LPRPCPROXYBUFFER iface)
void WINAPI StdProxy_Disconnect(IRpcProxyBuffer *iface)
{
StdProxyImpl *This = impl_from_IRpcProxyBuffer(iface);
TRACE("(%p)->Disconnect()\n",This);
Expand Down Expand Up @@ -551,45 +553,3 @@ HRESULT WINAPI NdrProxyErrorHandler(DWORD dwExceptionCode)
else
return HRESULT_FROM_WIN32(dwExceptionCode);
}

HRESULT WINAPI
CreateProxyFromTypeInfo( LPTYPEINFO pTypeInfo, LPUNKNOWN pUnkOuter, REFIID riid,
LPRPCPROXYBUFFER *ppProxy, LPVOID *ppv )
{
typedef INT (WINAPI *MessageBoxA)(HWND,LPCSTR,LPCSTR,UINT);
HMODULE hUser32 = LoadLibraryA("user32");
MessageBoxA pMessageBoxA = (void *)GetProcAddress(hUser32, "MessageBoxA");

FIXME("%p %p %s %p %p\n", pTypeInfo, pUnkOuter, debugstr_guid(riid), ppProxy, ppv);
if (pMessageBoxA)
{
pMessageBoxA(NULL,
"The native implementation of OLEAUT32.DLL cannot be used "
"with Wine's RPCRT4.DLL. Remove OLEAUT32.DLL and try again.\n",
"Wine: Unimplemented CreateProxyFromTypeInfo",
0x10);
ExitProcess(1);
}
return E_NOTIMPL;
}

HRESULT WINAPI
CreateStubFromTypeInfo(ITypeInfo *pTypeInfo, REFIID riid, IUnknown *pUnkServer,
IRpcStubBuffer **ppStub )
{
typedef INT (WINAPI *MessageBoxA)(HWND,LPCSTR,LPCSTR,UINT);
HMODULE hUser32 = LoadLibraryA("user32");
MessageBoxA pMessageBoxA = (void *)GetProcAddress(hUser32, "MessageBoxA");

FIXME("%p %s %p %p\n", pTypeInfo, debugstr_guid(riid), pUnkServer, ppStub);
if (pMessageBoxA)
{
pMessageBoxA(NULL,
"The native implementation of OLEAUT32.DLL cannot be used "
"with Wine's RPCRT4.DLL. Remove OLEAUT32.DLL and try again.\n",
"Wine: Unimplemented CreateProxyFromTypeInfo",
0x10);
ExitProcess(1);
}
return E_NOTIMPL;
}
2 changes: 1 addition & 1 deletion dll/win32/rpcrt4/cpsf.c
Expand Up @@ -279,7 +279,7 @@ HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll,
/* register clsid to point to module */
strcpyW( keyname, clsidW );
strcatW( keyname, clsid );
len = GetModuleFileNameW(hDll, module, sizeof(module)/sizeof(WCHAR));
len = GetModuleFileNameW(hDll, module, ARRAY_SIZE(module));
if (len && len < sizeof(module)) {
TRACE("registering CLSID %s => %s\n", debugstr_w(clsid), debugstr_w(module));
if (RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key) == ERROR_SUCCESS) {
Expand Down
30 changes: 30 additions & 0 deletions dll/win32/rpcrt4/cpsf.h
Expand Up @@ -21,9 +21,36 @@
#ifndef __WINE_CPSF_H
#define __WINE_CPSF_H

typedef struct
{
IRpcProxyBuffer IRpcProxyBuffer_iface;
void **PVtbl;
LONG RefCount;
const IID *piid;
IUnknown *pUnkOuter;
/* offset of base_object from PVtbl must match assembly thunks; see
* fill_delegated_proxy_table() */
IUnknown *base_object;
IRpcProxyBuffer *base_proxy;
PCInterfaceName name;
IPSFactoryBuffer *pPSFactory;
IRpcChannelBuffer *pChannel;
} StdProxyImpl;

typedef struct
{
IUnknownVtbl *base_obj;
IRpcStubBuffer *base_stub;
CStdStubBuffer stub_buffer;
} cstdstubbuffer_delegating_t;

HRESULT StdProxy_Construct(REFIID riid, LPUNKNOWN pUnkOuter, const ProxyFileInfo *ProxyInfo,
int Index, LPPSFACTORYBUFFER pPSFactory, LPRPCPROXYBUFFER *ppProxy,
LPVOID *ppvObj) DECLSPEC_HIDDEN;
HRESULT WINAPI StdProxy_QueryInterface(IRpcProxyBuffer *iface, REFIID iid, void **obj) DECLSPEC_HIDDEN;
ULONG WINAPI StdProxy_AddRef(IRpcProxyBuffer *iface) DECLSPEC_HIDDEN;
HRESULT WINAPI StdProxy_Connect(IRpcProxyBuffer *iface, IRpcChannelBuffer *channel) DECLSPEC_HIDDEN;
void WINAPI StdProxy_Disconnect(IRpcProxyBuffer *iface) DECLSPEC_HIDDEN;

HRESULT CStdStubBuffer_Construct(REFIID riid, LPUNKNOWN pUnkServer, PCInterfaceName name,
CInterfaceStubVtbl *vtbl, LPPSFACTORYBUFFER pPSFactory,
Expand All @@ -41,5 +68,8 @@ extern const IRpcStubBufferVtbl CStdStubBuffer_Delegating_Vtbl DECLSPEC_HIDDEN;
BOOL fill_delegated_proxy_table(IUnknownVtbl *vtbl, DWORD num) DECLSPEC_HIDDEN;
HRESULT create_proxy(REFIID iid, IUnknown *pUnkOuter, IRpcProxyBuffer **pproxy, void **ppv) DECLSPEC_HIDDEN;
HRESULT create_stub(REFIID iid, IUnknown *pUnk, IRpcStubBuffer **ppstub) DECLSPEC_HIDDEN;
BOOL fill_stubless_table(IUnknownVtbl *vtbl, DWORD num) DECLSPEC_HIDDEN;
IUnknownVtbl *get_delegating_vtbl(DWORD num_methods) DECLSPEC_HIDDEN;
void release_delegating_vtbl(IUnknownVtbl *vtbl) DECLSPEC_HIDDEN;

#endif /* __WINE_CPSF_H */
25 changes: 15 additions & 10 deletions dll/win32/rpcrt4/cstub.c
Expand Up @@ -50,13 +50,6 @@ static LONG WINAPI stub_filter(EXCEPTION_POINTERS *eptr)
return EXCEPTION_EXECUTE_HANDLER;
}

typedef struct
{
IUnknownVtbl *base_obj;
IRpcStubBuffer *base_stub;
CStdStubBuffer stub_buffer;
} cstdstubbuffer_delegating_t;

static inline cstdstubbuffer_delegating_t *impl_from_delegating( IRpcStubBuffer *iface )
{
return CONTAINING_RECORD((void *)iface, cstdstubbuffer_delegating_t, stub_buffer);
Expand Down Expand Up @@ -175,11 +168,23 @@ typedef struct
static const BYTE opcodes[16] = { 0x48, 0x8b, 0x49, 0x20, 0x48, 0x8b, 0x01,
0xff, 0xa0, 0, 0, 0, 0, 0x48, 0x8d, 0x36 };
#elif defined(__arm__)

static const DWORD opcodes[] =
{
0xe52d4004, /* push {r4} */
0xe5900010, /* ldr r0, [r0, #16] */
0xe5904000, /* ldr r4, [r0] */
0xe59fc008, /* ldr ip, [pc, #8] */
0xe08cc004, /* add ip, ip, r4 */
0xe49d4004, /* pop {r4} */
0xe59cf000 /* ldr pc, [ip] */
};

typedef struct
{
DWORD opcodes[ARRAY_SIZE(opcodes)];
DWORD offset;
} vtbl_method_t;
static const BYTE opcodes[1];

#else

Expand Down Expand Up @@ -267,7 +272,7 @@ BOOL fill_delegated_proxy_table(IUnknownVtbl *vtbl, DWORD num)
return TRUE;
}

static IUnknownVtbl *get_delegating_vtbl(DWORD num_methods)
IUnknownVtbl *get_delegating_vtbl(DWORD num_methods)
{
IUnknownVtbl *ret;

Expand Down Expand Up @@ -303,7 +308,7 @@ static IUnknownVtbl *get_delegating_vtbl(DWORD num_methods)
return ret;
}

static void release_delegating_vtbl(IUnknownVtbl *vtbl)
void release_delegating_vtbl(IUnknownVtbl *vtbl)
{
ref_counted_vtbl *table = (ref_counted_vtbl*)((DWORD *)vtbl - 1);

Expand Down
2 changes: 0 additions & 2 deletions dll/win32/rpcrt4/ndr_contexthandle.c
Expand Up @@ -23,8 +23,6 @@
#include "rpc_assoc.h"
#include "rpcndr.h"

#include "wine/rpcfc.h"

#include "wine/debug.h"
#include "wine/list.h"

Expand Down

0 comments on commit b6fdb56

Please sign in to comment.