Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * basic interfaces |
| 3 | * |
| 4 | * Copyright 1997 Marcus Meissner |
| 5 | */ |
| 6 | |
| 7 | #include <ctype.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 10 | #include <assert.h> |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 11 | #include "winerror.h" |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 12 | #include "ldt.h" |
| 13 | #include "heap.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 14 | #include "wine/winbase16.h" |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 15 | #include "wine/obj_base.h" |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 16 | #include "local.h" |
| 17 | #include "module.h" |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 18 | #include "debugtools.h" |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 19 | |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 20 | #include "ifs.h" |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 21 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 22 | DEFAULT_DEBUG_CHANNEL(relay) |
| 23 | |
François Gouget | d604eb1 | 1998-12-18 16:00:03 +0000 | [diff] [blame] | 24 | /* --- IUnknown implementation */ |
| 25 | |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 26 | typedef struct |
| 27 | { |
| 28 | /* IUnknown fields */ |
| 29 | ICOM_VTABLE(IUnknown)* lpvtbl; |
| 30 | DWORD ref; |
| 31 | } IUnknownImpl; |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 32 | |
| 33 | /****************************************************************************** |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 34 | * IUnknown_AddRef [VTABLE:IUNKNOWN.1] |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 35 | */ |
François Gouget | d604eb1 | 1998-12-18 16:00:03 +0000 | [diff] [blame] | 36 | static ULONG WINAPI IUnknown_fnAddRef(LPUNKNOWN iface) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 37 | ICOM_THIS(IUnknownImpl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 38 | TRACE("(%p)->AddRef()\n",This); |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 39 | return ++(This->ref); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 40 | } |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 41 | |
| 42 | /****************************************************************************** |
| 43 | * IUnknown_Release [VTABLE:IUNKNOWN.2] |
| 44 | */ |
François Gouget | d604eb1 | 1998-12-18 16:00:03 +0000 | [diff] [blame] | 45 | static ULONG WINAPI IUnknown_fnRelease(LPUNKNOWN iface) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 46 | ICOM_THIS(IUnknownImpl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 47 | TRACE("(%p)->Release()\n",This); |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 48 | if (!--(This->ref)) { |
| 49 | HeapFree(GetProcessHeap(),0,This); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 50 | return 0; |
| 51 | } |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 52 | return This->ref; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 55 | /****************************************************************************** |
| 56 | * IUnknown_QueryInterface [VTABLE:IUNKNOWN.0] |
| 57 | */ |
François Gouget | d604eb1 | 1998-12-18 16:00:03 +0000 | [diff] [blame] | 58 | static HRESULT WINAPI IUnknown_fnQueryInterface(LPUNKNOWN iface,REFIID refiid,LPVOID *obj) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 59 | ICOM_THIS(IUnknownImpl,iface); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 60 | char xrefiid[50]; |
| 61 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 62 | WINE_StringFromCLSID((LPCLSID)refiid,xrefiid); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 63 | TRACE("(%p)->QueryInterface(%s,%p)\n",This,xrefiid,obj); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 64 | |
| 65 | if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 66 | *obj = This; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 67 | return 0; |
| 68 | } |
| 69 | return OLE_E_ENUM_NOMORE; |
| 70 | } |
| 71 | |
Paul Quinn | 2305f3c | 1999-05-22 11:41:38 +0000 | [diff] [blame] | 72 | static ICOM_VTABLE(IUnknown) uvt = |
| 73 | { |
| 74 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE |
François Gouget | d604eb1 | 1998-12-18 16:00:03 +0000 | [diff] [blame] | 75 | IUnknown_fnQueryInterface, |
| 76 | IUnknown_fnAddRef, |
| 77 | IUnknown_fnRelease |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 80 | /****************************************************************************** |
| 81 | * IUnknown_Constructor [INTERNAL] |
| 82 | */ |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 83 | LPUNKNOWN |
| 84 | IUnknown_Constructor() { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 85 | IUnknownImpl* unk; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 86 | |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 87 | unk = (IUnknownImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IUnknownImpl)); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 88 | unk->lpvtbl = &uvt; |
| 89 | unk->ref = 1; |
François Gouget | d604eb1 | 1998-12-18 16:00:03 +0000 | [diff] [blame] | 90 | return (LPUNKNOWN)unk; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 93 | |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 94 | /* --- IMalloc16 implementation */ |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 95 | |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 96 | |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 97 | typedef struct |
| 98 | { |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 99 | /* IUnknown fields */ |
| 100 | ICOM_VTABLE(IMalloc16)* lpvtbl; |
| 101 | DWORD ref; |
| 102 | /* IMalloc16 fields */ |
| 103 | /* Gmm, I think one is not enough, we should probably manage a list of |
| 104 | * heaps |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 105 | */ |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 106 | HGLOBAL16 heap; |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 107 | } IMalloc16Impl; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 108 | |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 109 | /****************************************************************************** |
| 110 | * IMalloc16_QueryInterface [COMPOBJ.500] |
| 111 | */ |
Francois Gouget | 93217c6 | 1999-02-10 06:42:03 +0000 | [diff] [blame] | 112 | HRESULT WINAPI IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *obj) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 113 | ICOM_THIS(IMalloc16Impl,iface); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 114 | char xrefiid[50]; |
| 115 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 116 | WINE_StringFromCLSID((LPCLSID)refiid,xrefiid); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 117 | TRACE("(%p)->QueryInterface(%s,%p)\n",This,xrefiid,obj); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 118 | if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) || |
| 119 | !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc)) |
| 120 | ) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 121 | *obj = This; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | return OLE_E_ENUM_NOMORE; |
| 125 | } |
| 126 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 127 | /****************************************************************************** |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 128 | * IMalloc16_AddRef [COMPOBJ.501] |
| 129 | */ |
Francois Gouget | 93217c6 | 1999-02-10 06:42:03 +0000 | [diff] [blame] | 130 | ULONG WINAPI IMalloc16_fnAddRef(IMalloc16* iface) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 131 | ICOM_THIS(IMalloc16Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 132 | TRACE("(%p)->AddRef()\n",This); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 133 | return 1; /* cannot be freed */ |
| 134 | } |
| 135 | |
| 136 | /****************************************************************************** |
| 137 | * IMalloc16_Release [COMPOBJ.502] |
| 138 | */ |
Francois Gouget | 93217c6 | 1999-02-10 06:42:03 +0000 | [diff] [blame] | 139 | ULONG WINAPI IMalloc16_fnRelease(IMalloc16* iface) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 140 | ICOM_THIS(IMalloc16Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 141 | TRACE("(%p)->Release()\n",This); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 142 | return 1; /* cannot be freed */ |
| 143 | } |
| 144 | |
| 145 | /****************************************************************************** |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 146 | * IMalloc16_Alloc [COMPOBJ.503] |
| 147 | */ |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 148 | LPVOID WINAPI IMalloc16_fnAlloc(IMalloc16* iface,DWORD cb) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 149 | ICOM_THIS(IMalloc16Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 150 | TRACE("(%p)->Alloc(%ld)\n",This,cb); |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 151 | return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(This->heap,LOCAL_Alloc(This->heap,0,cb)); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 154 | /****************************************************************************** |
| 155 | * IMalloc16_Realloc [COMPOBJ.504] |
| 156 | */ |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 157 | LPVOID WINAPI IMalloc16_fnRealloc(IMalloc16* iface,LPVOID pv,DWORD cb) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 158 | ICOM_THIS(IMalloc16Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 159 | TRACE("(%p)->Realloc(%p,%ld)\n",This,pv,cb); |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 160 | return (LPVOID)PTR_SEG_OFF_TO_SEGPTR(This->heap,LOCAL_ReAlloc(This->heap,0,LOWORD(pv),cb)); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 161 | } |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 162 | |
| 163 | /****************************************************************************** |
| 164 | * IMalloc16_Free [COMPOBJ.505] |
| 165 | */ |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 166 | VOID WINAPI IMalloc16_fnFree(IMalloc16* iface,LPVOID pv) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 167 | ICOM_THIS(IMalloc16Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 168 | TRACE("(%p)->Free(%p)\n",This,pv); |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 169 | LOCAL_Free(This->heap,LOWORD(pv)); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 172 | /****************************************************************************** |
| 173 | * IMalloc16_GetSize [COMPOBJ.506] |
| 174 | */ |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 175 | DWORD WINAPI IMalloc16_fnGetSize(const IMalloc16* iface,LPVOID pv) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 176 | ICOM_CTHIS(IMalloc16Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 177 | TRACE("(%p)->GetSize(%p)\n",This,pv); |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 178 | return LOCAL_Size(This->heap,LOWORD(pv)); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 181 | /****************************************************************************** |
| 182 | * IMalloc16_DidAlloc [COMPOBJ.507] |
| 183 | */ |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 184 | INT16 WINAPI IMalloc16_fnDidAlloc(const IMalloc16* iface,LPVOID pv) { |
| 185 | ICOM_CTHIS(IMalloc16,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 186 | TRACE("(%p)->DidAlloc(%p)\n",This,pv); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 187 | return (INT16)-1; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 188 | } |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 189 | |
| 190 | /****************************************************************************** |
| 191 | * IMalloc16_HeapMinimize [COMPOBJ.508] |
| 192 | */ |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 193 | LPVOID WINAPI IMalloc16_fnHeapMinimize(IMalloc16* iface) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 194 | ICOM_THIS(IMalloc16Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 195 | TRACE("(%p)->HeapMinimize()\n",This); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 196 | return NULL; |
| 197 | } |
| 198 | |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 199 | static ICOM_VTABLE(IMalloc16)* msegvt16 = NULL; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 200 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 201 | /****************************************************************************** |
| 202 | * IMalloc16_Constructor [VTABLE] |
| 203 | */ |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 204 | LPMALLOC16 |
| 205 | IMalloc16_Constructor() { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 206 | IMalloc16Impl* This; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 207 | HMODULE16 hcomp = GetModuleHandle16("COMPOBJ"); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 208 | |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 209 | This = (IMalloc16Impl*)SEGPTR_NEW(IMalloc16Impl); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 210 | if (!msegvt16) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 211 | This->lpvtbl = msegvt16 = SEGPTR_NEW(ICOM_VTABLE(IMalloc16)); |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 212 | |
Francois Gouget | 93217c6 | 1999-02-10 06:42:03 +0000 | [diff] [blame] | 213 | #define VTENT(x) msegvt16->fn##x = (void*)WIN32_GetProcAddress16(hcomp,"IMalloc16_"#x);assert(msegvt16->fn##x) |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 214 | VTENT(QueryInterface); |
| 215 | VTENT(AddRef); |
| 216 | VTENT(Release); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 217 | VTENT(Alloc); |
| 218 | VTENT(Realloc); |
| 219 | VTENT(Free); |
| 220 | VTENT(GetSize); |
| 221 | VTENT(DidAlloc); |
| 222 | VTENT(HeapMinimize); |
| 223 | msegvt16 = (ICOM_VTABLE(IMalloc16)*)SEGPTR_GET(msegvt16); |
| 224 | #undef VTENT |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 225 | } |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 226 | This->ref = 1; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 227 | /* FIXME: implement multiple heaps */ |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 228 | This->heap = GlobalAlloc16(GMEM_MOVEABLE,64000); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 229 | LocalInit16(This->heap,0,64000); |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 230 | return (LPMALLOC16)SEGPTR_GET(This); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 233 | |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 234 | /* --- IMalloc32 implementation */ |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 235 | |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 236 | typedef struct |
| 237 | { |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 238 | /* IUnknown fields */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 239 | ICOM_VTABLE(IMalloc)* lpvtbl; |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 240 | DWORD ref; |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 241 | } IMalloc32Impl; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 242 | |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 243 | /****************************************************************************** |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 244 | * IMalloc32_QueryInterface [VTABLE] |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 245 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 246 | static HRESULT WINAPI IMalloc_fnQueryInterface(LPMALLOC iface,REFIID refiid,LPVOID *obj) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 247 | ICOM_THIS(IMalloc32Impl,iface); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 248 | char xrefiid[50]; |
| 249 | |
| 250 | WINE_StringFromCLSID((LPCLSID)refiid,xrefiid); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 251 | TRACE("(%p)->QueryInterface(%s,%p)\n",This,xrefiid,obj); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 252 | if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) || |
| 253 | !memcmp(&IID_IMalloc,refiid,sizeof(IID_IMalloc)) |
| 254 | ) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 255 | *obj = This; |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 256 | return S_OK; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 257 | } |
| 258 | return OLE_E_ENUM_NOMORE; |
| 259 | } |
| 260 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 261 | /****************************************************************************** |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 262 | * IMalloc32_AddRef [VTABLE] |
| 263 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 264 | static ULONG WINAPI IMalloc_fnAddRef(LPMALLOC iface) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 265 | ICOM_THIS(IMalloc32Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 266 | TRACE("(%p)->AddRef()\n",This); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 267 | return 1; /* cannot be freed */ |
| 268 | } |
| 269 | |
| 270 | /****************************************************************************** |
| 271 | * IMalloc32_Release [VTABLE] |
| 272 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 273 | static ULONG WINAPI IMalloc_fnRelease(LPMALLOC iface) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 274 | ICOM_THIS(IMalloc32Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 275 | TRACE("(%p)->Release()\n",This); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 276 | return 1; /* cannot be freed */ |
| 277 | } |
| 278 | |
| 279 | /****************************************************************************** |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 280 | * IMalloc32_Alloc [VTABLE] |
| 281 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 282 | static LPVOID WINAPI IMalloc_fnAlloc(LPMALLOC iface,DWORD cb) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 283 | ICOM_THIS(IMalloc32Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 284 | TRACE("(%p)->Alloc(%ld)\n",This,cb); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 285 | return HeapAlloc(GetProcessHeap(),0,cb); |
| 286 | } |
| 287 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 288 | /****************************************************************************** |
| 289 | * IMalloc32_Realloc [VTABLE] |
| 290 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 291 | static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 292 | ICOM_THIS(IMalloc32Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 293 | TRACE("(%p)->Realloc(%p,%ld)\n",This,pv,cb); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 294 | return HeapReAlloc(GetProcessHeap(),0,pv,cb); |
| 295 | } |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 296 | |
| 297 | /****************************************************************************** |
| 298 | * IMalloc32_Free [VTABLE] |
| 299 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 300 | static VOID WINAPI IMalloc_fnFree(LPMALLOC iface,LPVOID pv) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 301 | ICOM_THIS(IMalloc32Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 302 | TRACE("(%p)->Free(%p)\n",This,pv); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 303 | HeapFree(GetProcessHeap(),0,pv); |
| 304 | } |
| 305 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 306 | /****************************************************************************** |
| 307 | * IMalloc32_GetSize [VTABLE] |
| 308 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 309 | static DWORD WINAPI IMalloc_fnGetSize(const IMalloc* iface,LPVOID pv) { |
| 310 | ICOM_CTHIS(IMalloc,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 311 | TRACE("(%p)->GetSize(%p)\n",This,pv); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 312 | return HeapSize(GetProcessHeap(),0,pv); |
| 313 | } |
| 314 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 315 | /****************************************************************************** |
| 316 | * IMalloc32_DidAlloc [VTABLE] |
| 317 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 318 | static INT WINAPI IMalloc_fnDidAlloc(const IMalloc* iface,LPVOID pv) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 319 | ICOM_CTHIS(IMalloc32Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 320 | TRACE("(%p)->DidAlloc(%p)\n",This,pv); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 321 | return -1; |
| 322 | } |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 323 | |
| 324 | /****************************************************************************** |
| 325 | * IMalloc32_HeapMinimize [VTABLE] |
| 326 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 327 | static LPVOID WINAPI IMalloc_fnHeapMinimize(LPMALLOC iface) { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 328 | ICOM_THIS(IMalloc32Impl,iface); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 329 | TRACE("(%p)->HeapMinimize()\n",This); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 330 | return NULL; |
| 331 | } |
| 332 | |
Paul Quinn | 2305f3c | 1999-05-22 11:41:38 +0000 | [diff] [blame] | 333 | static ICOM_VTABLE(IMalloc) VT_IMalloc32 = |
| 334 | { |
| 335 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 336 | IMalloc_fnQueryInterface, |
| 337 | IMalloc_fnAddRef, |
| 338 | IMalloc_fnRelease, |
| 339 | IMalloc_fnAlloc, |
| 340 | IMalloc_fnRealloc, |
| 341 | IMalloc_fnFree, |
| 342 | IMalloc_fnGetSize, |
| 343 | IMalloc_fnDidAlloc, |
| 344 | IMalloc_fnHeapMinimize |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 345 | }; |
| 346 | |
Matthew Becker | 7517534 | 1998-10-18 14:39:06 +0000 | [diff] [blame] | 347 | /****************************************************************************** |
| 348 | * IMalloc32_Constructor [VTABLE] |
| 349 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 350 | LPMALLOC |
| 351 | IMalloc_Constructor() { |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 352 | IMalloc32Impl* This; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 353 | |
Francois Gouget | 452db3f | 1999-02-17 15:57:24 +0000 | [diff] [blame] | 354 | This = (IMalloc32Impl*)HeapAlloc(GetProcessHeap(),0,sizeof(IMalloc32Impl)); |
| 355 | This->lpvtbl = &VT_IMalloc32; |
| 356 | This->ref = 1; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 357 | return (LPMALLOC)This; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 358 | } |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 359 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 360 | /**************************************************************************** |
| 361 | * API Functions |
| 362 | */ |
Matthew Becker | b05264f | 1998-10-11 14:21:42 +0000 | [diff] [blame] | 363 | |
| 364 | /****************************************************************************** |
| 365 | * IsValidInterface32 [OLE32.78] |
| 366 | * |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 367 | * RETURNS |
| 368 | * True, if the passed pointer is a valid interface |
| 369 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 370 | BOOL WINAPI IsValidInterface( |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 371 | LPUNKNOWN punk /* [in] interface to be tested */ |
| 372 | ) { |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 373 | return !( |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 374 | IsBadReadPtr(punk,4) || |
| 375 | IsBadReadPtr(punk->lpvtbl,4) || |
| 376 | IsBadReadPtr(punk->lpvtbl->fnQueryInterface,9) || |
| 377 | IsBadCodePtr(punk->lpvtbl->fnQueryInterface) |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 378 | ); |
| 379 | } |