reactos/reactos/dll/win32/ole32/ifs.c

702 lines
19 KiB
C
Raw Normal View History

/*
* basic interfaces
*
* Copyright 1997 Marcus Meissner
*
* 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
*/
#include "config.h"
#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define COBJMACROS
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"
#include "winerror.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(olemalloc);
/******************************************************************************
* IMalloc32 implementation
*
* NOTES
* For supporting CoRegisterMallocSpy the IMalloc implementation must know if
* a given memory block was allocated with a spy active.
*
*****************************************************************************/
/* set the vtable later */
Sync to Wine-20050628: Robert Shearman <rob@codeweavers.com> - Convert some registry helper functions to use unicode versions of CLSID & registry functions (untested). - Add registry entries for local-only OLE interfaces. - Change IUnknown to local interface. - IUnknown isn't a remotable interface so the stub manager shouldn't need a marshaller for it. - Change the RPC code to use the unicode versions of the CLSID & registry functions. - Don't disconnect proxies flagged with SORFP_NOLIFETIMEMGMT. It makes no sense and only causes trouble for proxies that depend on these proxies being available. - Change some of the registry helper functions to use the unicode versions of the CLSID & registry functions. - Reindent CoGetClassObject and output an error message if the class isn't registered. - Add tests for the touched functions. Dmitry Timoshkov <dmitry@codeweavers.com> - Make remaining OLE interface vtables const. Richard Cohen <richard@daijobu.co.uk> - Base FileMonikerImpl_Save() on XP. - Correct handling of Unicode strings & multibyte locales. - More error checking. - Change ERR to WARN. - Match Windows quick & dirty estimate for GetSizeMax(). Stefan Huehner <stefan@huehner.org> - Fix some more -Wstrict-prototypes warnings. Mike Hearn <mike@navi.cx> - Add some tracing to the IRemUnknown RpcProxyBuffer implementation. Eric Pouech <pouech-eric@wanadoo.fr> - Const correctness fixes. Richard Cohen <richard@daijobu.co.uk> - IEnum::Clone shouldn't do a Reset. Marcus Meissner <marcus@jet.franken.de> - Removed CLSID_CompositeMoniker (conflicting with static definition). Alexandre Julliard <julliard@winehq.org> - Sort entry points alphabetically. svn path=/trunk/; revision=17036
2005-08-03 22:31:39 +00:00
static const IMallocVtbl VT_IMalloc32;
typedef struct {
Sync to Wine-20050628: Robert Shearman <rob@codeweavers.com> - Convert some registry helper functions to use unicode versions of CLSID & registry functions (untested). - Add registry entries for local-only OLE interfaces. - Change IUnknown to local interface. - IUnknown isn't a remotable interface so the stub manager shouldn't need a marshaller for it. - Change the RPC code to use the unicode versions of the CLSID & registry functions. - Don't disconnect proxies flagged with SORFP_NOLIFETIMEMGMT. It makes no sense and only causes trouble for proxies that depend on these proxies being available. - Change some of the registry helper functions to use the unicode versions of the CLSID & registry functions. - Reindent CoGetClassObject and output an error message if the class isn't registered. - Add tests for the touched functions. Dmitry Timoshkov <dmitry@codeweavers.com> - Make remaining OLE interface vtables const. Richard Cohen <richard@daijobu.co.uk> - Base FileMonikerImpl_Save() on XP. - Correct handling of Unicode strings & multibyte locales. - More error checking. - Change ERR to WARN. - Match Windows quick & dirty estimate for GetSizeMax(). Stefan Huehner <stefan@huehner.org> - Fix some more -Wstrict-prototypes warnings. Mike Hearn <mike@navi.cx> - Add some tracing to the IRemUnknown RpcProxyBuffer implementation. Eric Pouech <pouech-eric@wanadoo.fr> - Const correctness fixes. Richard Cohen <richard@daijobu.co.uk> - IEnum::Clone shouldn't do a Reset. Marcus Meissner <marcus@jet.franken.de> - Removed CLSID_CompositeMoniker (conflicting with static definition). Alexandre Julliard <julliard@winehq.org> - Sort entry points alphabetically. svn path=/trunk/; revision=17036
2005-08-03 22:31:39 +00:00
const IMallocVtbl *lpVtbl;
DWORD dummy; /* nothing, we are static */
IMallocSpy * pSpy; /* the spy when active */
DWORD SpyedAllocationsLeft; /* number of spyed allocations left */
BOOL SpyReleasePending; /* CoRevokeMallocSpy called with spyed allocations left*/
LPVOID * SpyedBlocks; /* root of the table */
DWORD SpyedBlockTableLength;/* size of the table*/
} _Malloc32;
/* this is the static object instance */
Sync to Wine-20050628: Robert Shearman <rob@codeweavers.com> - Convert some registry helper functions to use unicode versions of CLSID & registry functions (untested). - Add registry entries for local-only OLE interfaces. - Change IUnknown to local interface. - IUnknown isn't a remotable interface so the stub manager shouldn't need a marshaller for it. - Change the RPC code to use the unicode versions of the CLSID & registry functions. - Don't disconnect proxies flagged with SORFP_NOLIFETIMEMGMT. It makes no sense and only causes trouble for proxies that depend on these proxies being available. - Change some of the registry helper functions to use the unicode versions of the CLSID & registry functions. - Reindent CoGetClassObject and output an error message if the class isn't registered. - Add tests for the touched functions. Dmitry Timoshkov <dmitry@codeweavers.com> - Make remaining OLE interface vtables const. Richard Cohen <richard@daijobu.co.uk> - Base FileMonikerImpl_Save() on XP. - Correct handling of Unicode strings & multibyte locales. - More error checking. - Change ERR to WARN. - Match Windows quick & dirty estimate for GetSizeMax(). Stefan Huehner <stefan@huehner.org> - Fix some more -Wstrict-prototypes warnings. Mike Hearn <mike@navi.cx> - Add some tracing to the IRemUnknown RpcProxyBuffer implementation. Eric Pouech <pouech-eric@wanadoo.fr> - Const correctness fixes. Richard Cohen <richard@daijobu.co.uk> - IEnum::Clone shouldn't do a Reset. Marcus Meissner <marcus@jet.franken.de> - Removed CLSID_CompositeMoniker (conflicting with static definition). Alexandre Julliard <julliard@winehq.org> - Sort entry points alphabetically. svn path=/trunk/; revision=17036
2005-08-03 22:31:39 +00:00
static _Malloc32 Malloc32 = {&VT_IMalloc32, 0, NULL, 0, 0, NULL, 0};
/* with a spy active all calls from pre to post methods are threadsave */
static CRITICAL_SECTION IMalloc32_SpyCS;
static CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &IMalloc32_SpyCS,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
Sync from Wine-20050830 to Wine-0_9_1: Francois Gouget <fgouget@free.fr> - Assorted spelling fixes. - Fix .spec declarations for functinos with 64bit arguments (reported by winapi_check). Mike Hearn <mh@codeweavers.com> - Robert Shearman <rob@codeweavers.com> Change stub manager to track the number of normal marshals instead of using the state machine so that multiple marshals of the same object and interface work correctly. Robert Shearman <rob@codeweavers.com> - Pass WM_QUIT to outer modal loop. - Fix the return codes during unmarshaling so that it returns failure codes instead of S_FALSE returned from IStream_Read. - Don't fail in CoRegisterClassObject if the class already exists and the REGCLS_MULTIPLEUSE flag is specified. - Fix ref-counting rules to match native DCOM Dlls. - Add exception handling for stubs. - Implement OleRegEnumVerbs. - The [string] attribute is only valid on byte, char and wchar_t types, so replace "unsigned short" by "WCHAR". - Implement OleIsRunning. - Add a stubbed out implementation of IAdviseSink and advise the delegate object to use it. - Initialize out pointer to NULL before access check in IStorage_CreateStorage. - WriteClassStg should return E_INVALIDARG if pstg is NULL instead of asserting. - ReadClassStg should return E_INVALIDARG if pstg is NULL instead of crashing and a NULL pclsid should cause it to return the same value. - Make the interfaces that should be supported by the data cache explicit so their is no confusion in this file as to what it should be implementing and what this object should implement. - Delegate some IOleObject methods to the server IOleObject if it is running. - Implement some IRunningObject functions that actually start the server and initialize it. - Remove redunant braces. - Compact multi-line comments that fit into one line. - Remove comments that state the obvious. - Remove extra brackets that are redundant because the -> operator binds tighter than &. - Change "this" to "This" to make code more like other interface implementations. - Remove redundant comparisons with NULL for pointers. - Re-arrange some functions and vtables so we don't have declarations for all of the functions in the file. - Fix a trace to refer to the object ID rather than the legacy MID. - Fix the error case of CoMarshalInterThreadInterface to release the stream. - Move all 16-bit functions to an appropriate 16-bit file. - Implement OLE object notifications, making sure to cope with the case of the advise holder not being created because no notifications are needed. - Implement a Stop function and use this to properly implement IOleObject_Close, IAdviseSink_OnClose and the destructor. - We shouldn't pass the application name into CreateProcess because the value stored in the registry could include arguments. - Extend COM_OpenKeyForCLSID to open a subkey and return an HRESULT. - Fix up the callers and reorganize CoGetClassObject to split out the inproc code into another function. Alex Villacís Lasso <a_villacis@palosanto.com> - Add NULL check for sinkInterface in DataCache_GetAdvise. - Add missing ! to fix a reversed condition check in OleCreateDefaultHandler, in order to match intent in comment. Vincent Béron <vberon@mecano.gme.usherb.ca> - Use the proper calling convention for 2 16-bit functions. Alexandre Julliard <julliard@winehq.org> - We are no longer generating .spec.c files. - Use a more portable scheme for storing the name of a critical section. - Fixed some traces to use the right printf format and avoid typecasts. - Removed unused debug channels. - We are no longer generating .dbg.c files. Richard Cohen <richard@daijobu.co.uk> - Relax the share mode validation for transacted storage, with a test. Eric Pouech <eric.pouech@wanadoo.fr> - Fixes for function prototypes without arguments. Michael Jung <mjung@iss.tu-darmstadt.de> - Added tracing to CoCreateInstance. Markus Amsler <markus.amsler@oribi.org> - Improve c2man Documented-Total count. svn path=/trunk/; revision=19370
2005-11-20 15:01:10 +00:00
0, 0, { (DWORD_PTR)(__FILE__ ": IMalloc32_SpyCS") }
};
static CRITICAL_SECTION IMalloc32_SpyCS = { &critsect_debug, -1, 0, 0, 0, 0 };
/* resize the old table */
static int SetSpyedBlockTableLength ( DWORD NewLength )
{
LPVOID *NewSpyedBlocks;
if (!Malloc32.SpyedBlocks) NewSpyedBlocks = LocalAlloc(LMEM_ZEROINIT, NewLength * sizeof(PVOID));
else NewSpyedBlocks = LocalReAlloc(Malloc32.SpyedBlocks, NewLength * sizeof(PVOID), LMEM_ZEROINIT);
if (NewSpyedBlocks) {
Malloc32.SpyedBlocks = NewSpyedBlocks;
Malloc32.SpyedBlockTableLength = NewLength;
}
return NewSpyedBlocks != NULL;
}
/* add a location to the table */
static int AddMemoryLocation(LPVOID * pMem)
{
LPVOID * Current;
/* allocate the table if not already allocated */
if (!Malloc32.SpyedBlockTableLength) {
if (!SetSpyedBlockTableLength(0x1000)) return 0;
}
/* find a free location */
Current = Malloc32.SpyedBlocks;
while (*Current) {
Current++;
if (Current >= Malloc32.SpyedBlocks + Malloc32.SpyedBlockTableLength) {
/* no more space in table, grow it */
DWORD old_length = Malloc32.SpyedBlockTableLength;
if (!SetSpyedBlockTableLength( Malloc32.SpyedBlockTableLength + 0x1000 )) return 0;
Current = Malloc32.SpyedBlocks + old_length;
}
};
/* put the location in our table */
*Current = pMem;
Malloc32.SpyedAllocationsLeft++;
/*TRACE("%lu\n",Malloc32.SpyedAllocationsLeft);*/
return 1;
}
static int RemoveMemoryLocation(LPCVOID pMem)
{
LPVOID * Current;
/* allocate the table if not already allocated */
if (!Malloc32.SpyedBlockTableLength) {
if (!SetSpyedBlockTableLength(0x1000)) return 0;
}
Current = Malloc32.SpyedBlocks;
/* find the location */
while (*Current != pMem) {
Current++;
if (Current >= Malloc32.SpyedBlocks + Malloc32.SpyedBlockTableLength) return 0; /* not found */
}
/* location found */
Malloc32.SpyedAllocationsLeft--;
/*TRACE("%lu\n",Malloc32.SpyedAllocationsLeft);*/
*Current = NULL;
return 1;
}
/******************************************************************************
* IMalloc32_QueryInterface [VTABLE]
*/
static HRESULT WINAPI IMalloc_fnQueryInterface(LPMALLOC iface,REFIID refiid,LPVOID *obj) {
TRACE("(%s,%p)\n",debugstr_guid(refiid),obj);
if (IsEqualIID(&IID_IUnknown,refiid) || IsEqualIID(&IID_IMalloc,refiid)) {
*obj = (LPMALLOC)&Malloc32;
return S_OK;
}
return E_NOINTERFACE;
}
/******************************************************************************
* IMalloc32_AddRefRelease [VTABLE]
*/
static ULONG WINAPI IMalloc_fnAddRefRelease (LPMALLOC iface) {
return 1;
}
/******************************************************************************
* IMalloc32_Alloc [VTABLE]
*/
static LPVOID WINAPI IMalloc_fnAlloc(LPMALLOC iface, DWORD cb) {
LPVOID addr;
TRACE("(%d)\n",cb);
if(Malloc32.pSpy) {
DWORD preAllocResult;
EnterCriticalSection(&IMalloc32_SpyCS);
preAllocResult = IMallocSpy_PreAlloc(Malloc32.pSpy, cb);
if ((cb != 0) && (preAllocResult == 0)) {
/* PreAlloc can force Alloc to fail, but not if cb == 0 */
TRACE("returning null\n");
LeaveCriticalSection(&IMalloc32_SpyCS);
return NULL;
}
}
addr = HeapAlloc(GetProcessHeap(),0,cb);
if(Malloc32.pSpy) {
addr = IMallocSpy_PostAlloc(Malloc32.pSpy, addr);
if (addr) AddMemoryLocation(addr);
LeaveCriticalSection(&IMalloc32_SpyCS);
}
TRACE("--(%p)\n",addr);
return addr;
}
/******************************************************************************
* IMalloc32_Realloc [VTABLE]
*/
static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) {
LPVOID pNewMemory;
TRACE("(%p,%d)\n",pv,cb);
if(Malloc32.pSpy) {
LPVOID pRealMemory;
BOOL fSpyed;
EnterCriticalSection(&IMalloc32_SpyCS);
fSpyed = RemoveMemoryLocation(pv);
cb = IMallocSpy_PreRealloc(Malloc32.pSpy, pv, cb, &pRealMemory, fSpyed);
/* check if can release the spy */
if(Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) {
IMallocSpy_Release(Malloc32.pSpy);
Malloc32.SpyReleasePending = FALSE;
Malloc32.pSpy = NULL;
}
if (0==cb) {
/* PreRealloc can force Realloc to fail */
LeaveCriticalSection(&IMalloc32_SpyCS);
return NULL;
}
pv = pRealMemory;
}
if (!pv) pNewMemory = HeapAlloc(GetProcessHeap(),0,cb);
else if (cb) pNewMemory = HeapReAlloc(GetProcessHeap(),0,pv,cb);
else {
HeapFree(GetProcessHeap(),0,pv);
pNewMemory = NULL;
}
if(Malloc32.pSpy) {
pNewMemory = IMallocSpy_PostRealloc(Malloc32.pSpy, pNewMemory, TRUE);
if (pNewMemory) AddMemoryLocation(pNewMemory);
LeaveCriticalSection(&IMalloc32_SpyCS);
}
TRACE("--(%p)\n",pNewMemory);
return pNewMemory;
}
/******************************************************************************
* IMalloc32_Free [VTABLE]
*/
static VOID WINAPI IMalloc_fnFree(LPMALLOC iface,LPVOID pv) {
BOOL fSpyed = 0;
TRACE("(%p)\n",pv);
if(Malloc32.pSpy) {
EnterCriticalSection(&IMalloc32_SpyCS);
fSpyed = RemoveMemoryLocation(pv);
pv = IMallocSpy_PreFree(Malloc32.pSpy, pv, fSpyed);
}
HeapFree(GetProcessHeap(),0,pv);
if(Malloc32.pSpy) {
IMallocSpy_PostFree(Malloc32.pSpy, fSpyed);
/* check if can release the spy */
if(Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) {
IMallocSpy_Release(Malloc32.pSpy);
Malloc32.SpyReleasePending = FALSE;
Malloc32.pSpy = NULL;
}
LeaveCriticalSection(&IMalloc32_SpyCS);
}
}
/******************************************************************************
* IMalloc32_GetSize [VTABLE]
*
* NOTES
* FIXME returns:
* win95: size allocated (4 byte boundarys)
* win2k: size originally requested !!! (allocated on 8 byte boundarys)
*/
static DWORD WINAPI IMalloc_fnGetSize(LPMALLOC iface,LPVOID pv) {
DWORD cb;
BOOL fSpyed = 0;
TRACE("(%p)\n",pv);
if(Malloc32.pSpy) {
EnterCriticalSection(&IMalloc32_SpyCS);
pv = IMallocSpy_PreGetSize(Malloc32.pSpy, pv, fSpyed);
}
cb = HeapSize(GetProcessHeap(),0,pv);
if(Malloc32.pSpy) {
cb = IMallocSpy_PostGetSize(Malloc32.pSpy, cb, fSpyed);
LeaveCriticalSection(&IMalloc32_SpyCS);
}
return cb;
}
/******************************************************************************
* IMalloc32_DidAlloc [VTABLE]
*/
static INT WINAPI IMalloc_fnDidAlloc(LPMALLOC iface,LPVOID pv) {
BOOL fSpyed = 0;
int didAlloc;
TRACE("(%p)\n",pv);
if(Malloc32.pSpy) {
EnterCriticalSection(&IMalloc32_SpyCS);
pv = IMallocSpy_PreDidAlloc(Malloc32.pSpy, pv, fSpyed);
}
didAlloc = -1;
if(Malloc32.pSpy) {
didAlloc = IMallocSpy_PostDidAlloc(Malloc32.pSpy, pv, fSpyed, didAlloc);
LeaveCriticalSection(&IMalloc32_SpyCS);
}
return didAlloc;
}
/******************************************************************************
* IMalloc32_HeapMinimize [VTABLE]
*/
static VOID WINAPI IMalloc_fnHeapMinimize(LPMALLOC iface) {
TRACE("()\n");
if(Malloc32.pSpy) {
EnterCriticalSection(&IMalloc32_SpyCS);
IMallocSpy_PreHeapMinimize(Malloc32.pSpy);
}
if(Malloc32.pSpy) {
IMallocSpy_PostHeapMinimize(Malloc32.pSpy);
LeaveCriticalSection(&IMalloc32_SpyCS);
}
}
Sync to Wine-20050628: Robert Shearman <rob@codeweavers.com> - Convert some registry helper functions to use unicode versions of CLSID & registry functions (untested). - Add registry entries for local-only OLE interfaces. - Change IUnknown to local interface. - IUnknown isn't a remotable interface so the stub manager shouldn't need a marshaller for it. - Change the RPC code to use the unicode versions of the CLSID & registry functions. - Don't disconnect proxies flagged with SORFP_NOLIFETIMEMGMT. It makes no sense and only causes trouble for proxies that depend on these proxies being available. - Change some of the registry helper functions to use the unicode versions of the CLSID & registry functions. - Reindent CoGetClassObject and output an error message if the class isn't registered. - Add tests for the touched functions. Dmitry Timoshkov <dmitry@codeweavers.com> - Make remaining OLE interface vtables const. Richard Cohen <richard@daijobu.co.uk> - Base FileMonikerImpl_Save() on XP. - Correct handling of Unicode strings & multibyte locales. - More error checking. - Change ERR to WARN. - Match Windows quick & dirty estimate for GetSizeMax(). Stefan Huehner <stefan@huehner.org> - Fix some more -Wstrict-prototypes warnings. Mike Hearn <mike@navi.cx> - Add some tracing to the IRemUnknown RpcProxyBuffer implementation. Eric Pouech <pouech-eric@wanadoo.fr> - Const correctness fixes. Richard Cohen <richard@daijobu.co.uk> - IEnum::Clone shouldn't do a Reset. Marcus Meissner <marcus@jet.franken.de> - Removed CLSID_CompositeMoniker (conflicting with static definition). Alexandre Julliard <julliard@winehq.org> - Sort entry points alphabetically. svn path=/trunk/; revision=17036
2005-08-03 22:31:39 +00:00
static const IMallocVtbl VT_IMalloc32 =
{
IMalloc_fnQueryInterface,
IMalloc_fnAddRefRelease,
IMalloc_fnAddRefRelease,
IMalloc_fnAlloc,
IMalloc_fnRealloc,
IMalloc_fnFree,
IMalloc_fnGetSize,
IMalloc_fnDidAlloc,
IMalloc_fnHeapMinimize
};
/******************************************************************************
* IMallocSpy implementation
*****************************************************************************/
/* set the vtable later */
Sync to Wine-20050628: Robert Shearman <rob@codeweavers.com> - Convert some registry helper functions to use unicode versions of CLSID & registry functions (untested). - Add registry entries for local-only OLE interfaces. - Change IUnknown to local interface. - IUnknown isn't a remotable interface so the stub manager shouldn't need a marshaller for it. - Change the RPC code to use the unicode versions of the CLSID & registry functions. - Don't disconnect proxies flagged with SORFP_NOLIFETIMEMGMT. It makes no sense and only causes trouble for proxies that depend on these proxies being available. - Change some of the registry helper functions to use the unicode versions of the CLSID & registry functions. - Reindent CoGetClassObject and output an error message if the class isn't registered. - Add tests for the touched functions. Dmitry Timoshkov <dmitry@codeweavers.com> - Make remaining OLE interface vtables const. Richard Cohen <richard@daijobu.co.uk> - Base FileMonikerImpl_Save() on XP. - Correct handling of Unicode strings & multibyte locales. - More error checking. - Change ERR to WARN. - Match Windows quick & dirty estimate for GetSizeMax(). Stefan Huehner <stefan@huehner.org> - Fix some more -Wstrict-prototypes warnings. Mike Hearn <mike@navi.cx> - Add some tracing to the IRemUnknown RpcProxyBuffer implementation. Eric Pouech <pouech-eric@wanadoo.fr> - Const correctness fixes. Richard Cohen <richard@daijobu.co.uk> - IEnum::Clone shouldn't do a Reset. Marcus Meissner <marcus@jet.franken.de> - Removed CLSID_CompositeMoniker (conflicting with static definition). Alexandre Julliard <julliard@winehq.org> - Sort entry points alphabetically. svn path=/trunk/; revision=17036
2005-08-03 22:31:39 +00:00
static const IMallocSpyVtbl VT_IMallocSpy;
typedef struct {
Sync to Wine-20050628: Robert Shearman <rob@codeweavers.com> - Convert some registry helper functions to use unicode versions of CLSID & registry functions (untested). - Add registry entries for local-only OLE interfaces. - Change IUnknown to local interface. - IUnknown isn't a remotable interface so the stub manager shouldn't need a marshaller for it. - Change the RPC code to use the unicode versions of the CLSID & registry functions. - Don't disconnect proxies flagged with SORFP_NOLIFETIMEMGMT. It makes no sense and only causes trouble for proxies that depend on these proxies being available. - Change some of the registry helper functions to use the unicode versions of the CLSID & registry functions. - Reindent CoGetClassObject and output an error message if the class isn't registered. - Add tests for the touched functions. Dmitry Timoshkov <dmitry@codeweavers.com> - Make remaining OLE interface vtables const. Richard Cohen <richard@daijobu.co.uk> - Base FileMonikerImpl_Save() on XP. - Correct handling of Unicode strings & multibyte locales. - More error checking. - Change ERR to WARN. - Match Windows quick & dirty estimate for GetSizeMax(). Stefan Huehner <stefan@huehner.org> - Fix some more -Wstrict-prototypes warnings. Mike Hearn <mike@navi.cx> - Add some tracing to the IRemUnknown RpcProxyBuffer implementation. Eric Pouech <pouech-eric@wanadoo.fr> - Const correctness fixes. Richard Cohen <richard@daijobu.co.uk> - IEnum::Clone shouldn't do a Reset. Marcus Meissner <marcus@jet.franken.de> - Removed CLSID_CompositeMoniker (conflicting with static definition). Alexandre Julliard <julliard@winehq.org> - Sort entry points alphabetically. svn path=/trunk/; revision=17036
2005-08-03 22:31:39 +00:00
const IMallocSpyVtbl *lpVtbl;
Sync to Wine-20050725: Robert Shearman <rob@codeweavers.com> - Marshal return value from IRemUnknown_RemQueryInterface. - We should be starting with 1 reference. - IRpcStubBuffer_Disconnect can be called more than once. - Silence now noisy error messages caused by changes in the way we call ipid_to_stubmanager. Move the error message to the one place it is needed. - By-pass the RPC runtime if possible when calling an STA by posting a message directly to the apartment window for it to process. Fixes a deadlock in InstallShield caused by having to create a thread when freeing an object that comes from an STA apartment. Added tests that fail without this fix. - Hack around broken state management so InstallShield works. - Delete the stub manager outside of the apartment critical section because the deletion may require the object to re-enter the apartment. - Always query for the correct stub interface, otherwise we will be pointing to the completely wrong object when a proxy does a queryinterface. - Remove assumption that the stub buffer will handle the lifetime of the object. Alex Villacis Lasso <a_villacis@palosanto.com> - Initialize RegisteredClass properly in CoRegisterClassObject to prevent crash in CoRevokeClassObject when accessing (uninitialized) pMarshalledData. Mike McCormack <mike@codeweavers.com> - Fix gcc 4.0 -Wpointer-sign warnings. Vitaly Lipatov <lav@etersoft.ru> - Added some documentation. Stefan Huehner <stefan@huehner.org> - Fix some missing-declarations warnings. Marcus Meissner <meissner@suse.de> - 16bit interfaces are cdecl, so drop the WINAPI. - 16bit COM interfaces are cdecl, not WINAPI. - OleInitializeWOW gets 2 arguments. - Added OleSetMenuDescriptor16 stub. Marcus Meissner <marcus@jet.franken.de> - Implemented IsValidInterface16, CoMemAlloc. Added debug to HGLOBALLockBytes16_QueryInterface. svn path=/trunk/; revision=17332
2005-08-12 17:19:46 +00:00
LONG ref;
} _MallocSpy;
/* this is the static object instance */
Sync to Wine-20050628: Robert Shearman <rob@codeweavers.com> - Convert some registry helper functions to use unicode versions of CLSID & registry functions (untested). - Add registry entries for local-only OLE interfaces. - Change IUnknown to local interface. - IUnknown isn't a remotable interface so the stub manager shouldn't need a marshaller for it. - Change the RPC code to use the unicode versions of the CLSID & registry functions. - Don't disconnect proxies flagged with SORFP_NOLIFETIMEMGMT. It makes no sense and only causes trouble for proxies that depend on these proxies being available. - Change some of the registry helper functions to use the unicode versions of the CLSID & registry functions. - Reindent CoGetClassObject and output an error message if the class isn't registered. - Add tests for the touched functions. Dmitry Timoshkov <dmitry@codeweavers.com> - Make remaining OLE interface vtables const. Richard Cohen <richard@daijobu.co.uk> - Base FileMonikerImpl_Save() on XP. - Correct handling of Unicode strings & multibyte locales. - More error checking. - Change ERR to WARN. - Match Windows quick & dirty estimate for GetSizeMax(). Stefan Huehner <stefan@huehner.org> - Fix some more -Wstrict-prototypes warnings. Mike Hearn <mike@navi.cx> - Add some tracing to the IRemUnknown RpcProxyBuffer implementation. Eric Pouech <pouech-eric@wanadoo.fr> - Const correctness fixes. Richard Cohen <richard@daijobu.co.uk> - IEnum::Clone shouldn't do a Reset. Marcus Meissner <marcus@jet.franken.de> - Removed CLSID_CompositeMoniker (conflicting with static definition). Alexandre Julliard <julliard@winehq.org> - Sort entry points alphabetically. svn path=/trunk/; revision=17036
2005-08-03 22:31:39 +00:00
static _MallocSpy MallocSpy = {&VT_IMallocSpy, 0};
/******************************************************************************
* IMalloc32_QueryInterface [VTABLE]
*/
static HRESULT WINAPI IMallocSpy_fnQueryInterface(LPMALLOCSPY iface,REFIID refiid,LPVOID *obj)
{
TRACE("(%s,%p)\n",debugstr_guid(refiid),obj);
if (IsEqualIID(&IID_IUnknown,refiid) || IsEqualIID(&IID_IMallocSpy,refiid)) {
*obj = (LPMALLOC)&MallocSpy;
return S_OK;
}
return E_NOINTERFACE;
}
/******************************************************************************
* IMalloc32_AddRef [VTABLE]
*/
static ULONG WINAPI IMallocSpy_fnAddRef (LPMALLOCSPY iface)
{
_MallocSpy *This = (_MallocSpy *)iface;
ULONG ref = InterlockedIncrement(&This->ref);
TRACE ("(%p)->(count=%u)\n", This, ref - 1);
return ref;
}
/******************************************************************************
* IMalloc32_AddRelease [VTABLE]
*
* NOTES
* Our MallocSpy is static. If the count reaches 0 we dump the leaks
*/
static ULONG WINAPI IMallocSpy_fnRelease (LPMALLOCSPY iface)
{
_MallocSpy *This = (_MallocSpy *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE ("(%p)->(count=%u)\n", This, ref + 1);
if (!ref) {
/* our allocation list MUST be empty here */
}
return ref;
}
static ULONG WINAPI IMallocSpy_fnPreAlloc(LPMALLOCSPY iface, ULONG cbRequest)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%u)\n", This, cbRequest);
return cbRequest;
}
static PVOID WINAPI IMallocSpy_fnPostAlloc(LPMALLOCSPY iface, void* pActual)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%p)\n", This, pActual);
return pActual;
}
static PVOID WINAPI IMallocSpy_fnPreFree(LPMALLOCSPY iface, void* pRequest, BOOL fSpyed)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%p %u)\n", This, pRequest, fSpyed);
return pRequest;
}
static void WINAPI IMallocSpy_fnPostFree(LPMALLOCSPY iface, BOOL fSpyed)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%u)\n", This, fSpyed);
}
static ULONG WINAPI IMallocSpy_fnPreRealloc(LPMALLOCSPY iface, void* pRequest, ULONG cbRequest, void** ppNewRequest, BOOL fSpyed)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%p %u %u)\n", This, pRequest, cbRequest, fSpyed);
*ppNewRequest = pRequest;
return cbRequest;
}
static PVOID WINAPI IMallocSpy_fnPostRealloc(LPMALLOCSPY iface, void* pActual, BOOL fSpyed)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%p %u)\n", This, pActual, fSpyed);
return pActual;
}
static PVOID WINAPI IMallocSpy_fnPreGetSize(LPMALLOCSPY iface, void* pRequest, BOOL fSpyed)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%p %u)\n", This, pRequest, fSpyed);
return pRequest;
}
static ULONG WINAPI IMallocSpy_fnPostGetSize(LPMALLOCSPY iface, ULONG cbActual, BOOL fSpyed)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%u %u)\n", This, cbActual, fSpyed);
return cbActual;
}
static PVOID WINAPI IMallocSpy_fnPreDidAlloc(LPMALLOCSPY iface, void* pRequest, BOOL fSpyed)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%p %u)\n", This, pRequest, fSpyed);
return pRequest;
}
static int WINAPI IMallocSpy_fnPostDidAlloc(LPMALLOCSPY iface, void* pRequest, BOOL fSpyed, int fActual)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->(%p %u %u)\n", This, pRequest, fSpyed, fActual);
return fActual;
}
static void WINAPI IMallocSpy_fnPreHeapMinimize(LPMALLOCSPY iface)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->()\n", This);
}
static void WINAPI IMallocSpy_fnPostHeapMinimize(LPMALLOCSPY iface)
{
_MallocSpy *This = (_MallocSpy *)iface;
TRACE ("(%p)->()\n", This);
}
Sync to Wine-20050628: Robert Shearman <rob@codeweavers.com> - Convert some registry helper functions to use unicode versions of CLSID & registry functions (untested). - Add registry entries for local-only OLE interfaces. - Change IUnknown to local interface. - IUnknown isn't a remotable interface so the stub manager shouldn't need a marshaller for it. - Change the RPC code to use the unicode versions of the CLSID & registry functions. - Don't disconnect proxies flagged with SORFP_NOLIFETIMEMGMT. It makes no sense and only causes trouble for proxies that depend on these proxies being available. - Change some of the registry helper functions to use the unicode versions of the CLSID & registry functions. - Reindent CoGetClassObject and output an error message if the class isn't registered. - Add tests for the touched functions. Dmitry Timoshkov <dmitry@codeweavers.com> - Make remaining OLE interface vtables const. Richard Cohen <richard@daijobu.co.uk> - Base FileMonikerImpl_Save() on XP. - Correct handling of Unicode strings & multibyte locales. - More error checking. - Change ERR to WARN. - Match Windows quick & dirty estimate for GetSizeMax(). Stefan Huehner <stefan@huehner.org> - Fix some more -Wstrict-prototypes warnings. Mike Hearn <mike@navi.cx> - Add some tracing to the IRemUnknown RpcProxyBuffer implementation. Eric Pouech <pouech-eric@wanadoo.fr> - Const correctness fixes. Richard Cohen <richard@daijobu.co.uk> - IEnum::Clone shouldn't do a Reset. Marcus Meissner <marcus@jet.franken.de> - Removed CLSID_CompositeMoniker (conflicting with static definition). Alexandre Julliard <julliard@winehq.org> - Sort entry points alphabetically. svn path=/trunk/; revision=17036
2005-08-03 22:31:39 +00:00
static void MallocSpyDumpLeaks(void) {
TRACE("leaks: %u\n", Malloc32.SpyedAllocationsLeft);
}
Sync to Wine-20050628: Robert Shearman <rob@codeweavers.com> - Convert some registry helper functions to use unicode versions of CLSID & registry functions (untested). - Add registry entries for local-only OLE interfaces. - Change IUnknown to local interface. - IUnknown isn't a remotable interface so the stub manager shouldn't need a marshaller for it. - Change the RPC code to use the unicode versions of the CLSID & registry functions. - Don't disconnect proxies flagged with SORFP_NOLIFETIMEMGMT. It makes no sense and only causes trouble for proxies that depend on these proxies being available. - Change some of the registry helper functions to use the unicode versions of the CLSID & registry functions. - Reindent CoGetClassObject and output an error message if the class isn't registered. - Add tests for the touched functions. Dmitry Timoshkov <dmitry@codeweavers.com> - Make remaining OLE interface vtables const. Richard Cohen <richard@daijobu.co.uk> - Base FileMonikerImpl_Save() on XP. - Correct handling of Unicode strings & multibyte locales. - More error checking. - Change ERR to WARN. - Match Windows quick & dirty estimate for GetSizeMax(). Stefan Huehner <stefan@huehner.org> - Fix some more -Wstrict-prototypes warnings. Mike Hearn <mike@navi.cx> - Add some tracing to the IRemUnknown RpcProxyBuffer implementation. Eric Pouech <pouech-eric@wanadoo.fr> - Const correctness fixes. Richard Cohen <richard@daijobu.co.uk> - IEnum::Clone shouldn't do a Reset. Marcus Meissner <marcus@jet.franken.de> - Removed CLSID_CompositeMoniker (conflicting with static definition). Alexandre Julliard <julliard@winehq.org> - Sort entry points alphabetically. svn path=/trunk/; revision=17036
2005-08-03 22:31:39 +00:00
static const IMallocSpyVtbl VT_IMallocSpy =
{
IMallocSpy_fnQueryInterface,
IMallocSpy_fnAddRef,
IMallocSpy_fnRelease,
IMallocSpy_fnPreAlloc,
IMallocSpy_fnPostAlloc,
IMallocSpy_fnPreFree,
IMallocSpy_fnPostFree,
IMallocSpy_fnPreRealloc,
IMallocSpy_fnPostRealloc,
IMallocSpy_fnPreGetSize,
IMallocSpy_fnPostGetSize,
IMallocSpy_fnPreDidAlloc,
IMallocSpy_fnPostDidAlloc,
IMallocSpy_fnPreHeapMinimize,
IMallocSpy_fnPostHeapMinimize
};
/******************************************************************************
* CoGetMalloc [OLE32.@]
*
* Retrieves the current IMalloc interface for the process.
*
* PARAMS
* dwMemContext [I]
* lpMalloc [O] Address where memory allocator object will be stored.
*
* RETURNS
* Success: S_OK.
* Failure: HRESULT code.
*/
HRESULT WINAPI CoGetMalloc(DWORD dwMemContext, LPMALLOC *lpMalloc)
{
*lpMalloc = (LPMALLOC)&Malloc32;
return S_OK;
}
/***********************************************************************
* CoTaskMemAlloc [OLE32.@]
*
* Allocates memory using the current process memory allocator.
*
* PARAMS
* size [I] Size of the memory block to allocate.
*
* RETURNS
* Success: Pointer to newly allocated memory block.
* Failure: NULL.
*/
LPVOID WINAPI CoTaskMemAlloc(ULONG size)
{
return IMalloc_Alloc((LPMALLOC)&Malloc32,size);
}
/***********************************************************************
* CoTaskMemFree [OLE32.@]
*
* Frees memory allocated from the current process memory allocator.
*
* PARAMS
* ptr [I] Memory block to free.
*
* RETURNS
* Nothing.
*/
VOID WINAPI CoTaskMemFree(LPVOID ptr)
{
IMalloc_Free((LPMALLOC)&Malloc32, ptr);
}
/***********************************************************************
* CoTaskMemRealloc [OLE32.@]
*
* Allocates memory using the current process memory allocator.
*
* PARAMS
* pvOld [I] Pointer to old memory block.
* size [I] Size of the new memory block.
*
* RETURNS
* Success: Pointer to newly allocated memory block.
* Failure: NULL.
*/
LPVOID WINAPI CoTaskMemRealloc(LPVOID pvOld, ULONG size)
{
return IMalloc_Realloc((LPMALLOC)&Malloc32, pvOld, size);
}
/***********************************************************************
* CoRegisterMallocSpy [OLE32.@]
*
* Registers an object that receives notifications on memory allocations and
* frees.
*
* PARAMS
* pMallocSpy [I] New spy object.
*
* RETURNS
* Success: S_OK.
* Failure: HRESULT code.
*
* NOTES
* if a mallocspy is already registered, we can't do it again since
* only the spy knows, how to free a memory block
*/
HRESULT WINAPI CoRegisterMallocSpy(LPMALLOCSPY pMallocSpy)
{
IMallocSpy* pSpy;
HRESULT hres = E_INVALIDARG;
TRACE("\n");
/* HACK TO ACTIVATE OUT SPY */
if (pMallocSpy == (LPVOID)-1) pMallocSpy =(IMallocSpy*)&MallocSpy;
if(Malloc32.pSpy) return CO_E_OBJISREG;
EnterCriticalSection(&IMalloc32_SpyCS);
if (SUCCEEDED(IUnknown_QueryInterface(pMallocSpy, &IID_IMallocSpy, (LPVOID*)&pSpy))) {
Malloc32.pSpy = pSpy;
hres = S_OK;
}
LeaveCriticalSection(&IMalloc32_SpyCS);
return hres;
}
/***********************************************************************
* CoRevokeMallocSpy [OLE32.@]
*
* Revokes a previousl registered object that receives notifications on memory
* allocations and frees.
*
* PARAMS
* pMallocSpy [I] New spy object.
*
* RETURNS
* Success: S_OK.
* Failure: HRESULT code.
*
* NOTES
* we can't revoke a malloc spy as long as memory blocks allocated with
* the spy are active since only the spy knows how to free them
*/
HRESULT WINAPI CoRevokeMallocSpy(void)
{
HRESULT hres = S_OK;
TRACE("\n");
EnterCriticalSection(&IMalloc32_SpyCS);
/* if it's our spy it's time to dump the leaks */
if (Malloc32.pSpy == (IMallocSpy*)&MallocSpy) {
MallocSpyDumpLeaks();
}
if (Malloc32.SpyedAllocationsLeft) {
TRACE("SpyReleasePending with %u allocations left\n", Malloc32.SpyedAllocationsLeft);
Malloc32.SpyReleasePending = TRUE;
hres = E_ACCESSDENIED;
} else {
IMallocSpy_Release(Malloc32.pSpy);
Malloc32.pSpy = NULL;
}
LeaveCriticalSection(&IMalloc32_SpyCS);
return S_OK;
}
/******************************************************************************
* IsValidInterface [OLE32.@]
*
* Determines whether a pointer is a valid interface.
*
* PARAMS
* punk [I] Interface to be tested.
*
* RETURNS
* TRUE, if the passed pointer is a valid interface, or FALSE otherwise.
*/
BOOL WINAPI IsValidInterface(LPUNKNOWN punk)
{
return !(
IsBadReadPtr(punk,4) ||
IsBadReadPtr(punk->lpVtbl,4) ||
IsBadReadPtr(punk->lpVtbl->QueryInterface,9) ||
IsBadCodePtr((FARPROC)punk->lpVtbl->QueryInterface)
);
}