ReactOS  0.4.14-dev-293-g2b39b42
vbscript_main.c
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #include "initguid.h"
20 
21 #include "vbscript.h"
22 #include "objsafe.h"
23 #include "mshtmhst.h"
24 #include "rpcproxy.h"
25 #include "vbscript_classes.h"
26 #include "vbsglobal.h"
27 #include "vbsregexp55.h"
28 
29 #include "wine/debug.h"
30 
33 
34 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
35 
37 
38 static ITypeLib *typelib;
40 
41 static REFIID tid_ids[] = {
42 #define XDIID(iface) &DIID_ ## iface,
44 #undef XDIID
45 };
46 
48 {
49  HRESULT hres;
50 
51  if (!typelib) {
52  ITypeLib *tl;
53 
54  static const WCHAR vbscript_dll1W[] = {'v','b','s','c','r','i','p','t','.','d','l','l','\\','1',0};
55 
56  hres = LoadTypeLib(vbscript_dll1W, &tl);
57  if(FAILED(hres)) {
58  ERR("LoadRegTypeLib failed: %08x\n", hres);
59  return hres;
60  }
61 
63  ITypeLib_Release(tl);
64  }
65 
66  if(!typeinfos[tid]) {
67  ITypeInfo *ti;
68 
69  hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
70  if(FAILED(hres)) {
71  ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
72  return hres;
73  }
74 
76  ITypeInfo_Release(ti);
77  }
78 
80  return S_OK;
81 }
82 
83 static void release_typelib(void)
84 {
85  unsigned i;
86 
87  if(!typelib)
88  return;
89 
90  for(i = 0; i < ARRAY_SIZE(typeinfos); i++) {
91  if(typeinfos[i])
92  ITypeInfo_Release(typeinfos[i]);
93  }
94 
95  ITypeLib_Release(typelib);
96 }
97 
98 #define MIN_BLOCK_SIZE 128
99 #define ARENA_FREE_FILLER 0xaa
100 
101 static inline DWORD block_size(DWORD block)
102 {
103  return MIN_BLOCK_SIZE << block;
104 }
105 
107 {
108  memset(heap, 0, sizeof(*heap));
109  list_init(&heap->custom_blocks);
110 }
111 
112 void *heap_pool_alloc(heap_pool_t *heap, size_t size)
113 {
114  struct list *list;
115  void *tmp;
116 
117  size = (size+3)&~3;
118 
119  if(!heap->block_cnt) {
120  if(!heap->blocks) {
121  heap->blocks = heap_alloc(sizeof(void*));
122  if(!heap->blocks)
123  return NULL;
124  }
125 
126  tmp = heap_alloc(block_size(0));
127  if(!tmp)
128  return NULL;
129 
130  heap->blocks[0] = tmp;
131  heap->block_cnt = 1;
132  }
133 
134  if(heap->offset + size <= block_size(heap->last_block)) {
135  tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
136  heap->offset += size;
137  return tmp;
138  }
139 
140  if(size <= block_size(heap->last_block+1)) {
141  if(heap->last_block+1 == heap->block_cnt) {
142  tmp = heap_realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*));
143  if(!tmp)
144  return NULL;
145 
146  heap->blocks = tmp;
147  heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt));
148  if(!heap->blocks[heap->block_cnt])
149  return NULL;
150 
151  heap->block_cnt++;
152  }
153 
154  heap->last_block++;
155  heap->offset = size;
156  return heap->blocks[heap->last_block];
157  }
158 
159  list = heap_alloc(size + sizeof(struct list));
160  if(!list)
161  return NULL;
162 
164  return list+1;
165 }
166 
167 void *heap_pool_grow(heap_pool_t *heap, void *mem, DWORD size, DWORD inc)
168 {
169  void *ret;
170 
171  if(mem == (BYTE*)heap->blocks[heap->last_block] + heap->offset-size
172  && heap->offset+inc < block_size(heap->last_block)) {
173  heap->offset += inc;
174  return mem;
175  }
176 
177  ret = heap_pool_alloc(heap, size+inc);
178  if(ret) /* FIXME: avoid copying for custom blocks */
179  memcpy(ret, mem, size);
180  return ret;
181 }
182 
184 {
185  struct list *tmp;
186 
187  if(!heap)
188  return;
189 
190  while((tmp = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
191  list_remove(tmp);
192  heap_free(tmp);
193  }
194 
195  if(WARN_ON(heap)) {
196  DWORD i;
197 
198  for(i=0; i < heap->block_cnt; i++)
200  }
201 
202  heap->last_block = heap->offset = 0;
203  heap->mark = FALSE;
204 }
205 
207 {
208  DWORD i;
209 
210  heap_pool_clear(heap);
211 
212  for(i=0; i < heap->block_cnt; i++)
213  heap_free(heap->blocks[i]);
214  heap_free(heap->blocks);
215 
216  heap_pool_init(heap);
217 }
218 
220 {
221  if(heap->mark)
222  return NULL;
223 
224  heap->mark = TRUE;
225  return heap;
226 }
227 
229 {
230  *ppv = NULL;
231 
232  if(IsEqualGUID(&IID_IUnknown, riid)) {
233  TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
234  *ppv = iface;
235  }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
236  TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
237  *ppv = iface;
238  }
239 
240  if(*ppv) {
241  IUnknown_AddRef((IUnknown*)*ppv);
242  return S_OK;
243  }
244 
245  FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
246  return E_NOINTERFACE;
247 }
248 
250 {
251  TRACE("(%p)\n", iface);
252  return 2;
253 }
254 
256 {
257  TRACE("(%p)\n", iface);
258  return 1;
259 }
260 
262 {
263  TRACE("(%p)->(%x)\n", iface, fLock);
264  return S_OK;
265 }
266 
267 static const IClassFactoryVtbl VBScriptFactoryVtbl = {
273 };
274 
276 
277 static const IClassFactoryVtbl VBScriptRegExpFactoryVtbl = {
283 };
284 
286 
287 /******************************************************************
288  * DllMain (vbscript.@)
289  */
290 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
291 {
292  TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
293 
294  switch(fdwReason)
295  {
296  case DLL_WINE_PREATTACH:
297  return FALSE; /* prefer native version */
298  case DLL_PROCESS_ATTACH:
299  DisableThreadLibraryCalls(hInstDLL);
300  vbscript_hinstance = hInstDLL;
301  break;
302  case DLL_PROCESS_DETACH:
303  if (lpv) break;
304  release_typelib();
306  }
307 
308  return TRUE;
309 }
310 
311 /***********************************************************************
312  * DllGetClassObject (vbscript.@)
313  */
315 {
316  if(IsEqualGUID(&CLSID_VBScript, rclsid)) {
317  TRACE("(CLSID_VBScript %s %p)\n", debugstr_guid(riid), ppv);
318  return IClassFactory_QueryInterface(&VBScriptFactory, riid, ppv);
319  }else if(IsEqualGUID(&CLSID_VBScriptRegExp, rclsid)) {
320  TRACE("(CLSID_VBScriptRegExp %s %p)\n", debugstr_guid(riid), ppv);
321  return IClassFactory_QueryInterface(&VBScriptRegExpFactory, riid, ppv);
322  }
323 
324  FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
326 }
327 
328 /***********************************************************************
329  * DllCanUnloadNow (vbscript.@)
330  */
332 {
333  return S_FALSE;
334 }
335 
336 /***********************************************************************
337  * DllRegisterServer (vbscript.@)
338  */
340 {
341  TRACE("()\n");
343 }
344 
345 /***********************************************************************
346  * DllUnregisterServer (vbscript.@)
347  */
349 {
350  TRACE("()\n");
352 }
static unsigned int block
Definition: xmlmemory.c:118
static IClassFactory VBScriptRegExpFactory
HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
Definition: vbscript_main.c:47
HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: vbregexp.c:1618
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
static const IClassFactoryVtbl VBScriptFactoryVtbl
HRESULT __wine_register_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:98
static HINSTANCE vbscript_hinstance
Definition: vbscript_main.c:36
void heap_pool_clear(heap_pool_t *heap)
DEFINE_GUID(GUID_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
REFIID riid
Definition: precomp.h:44
#define MIN_BLOCK_SIZE
Definition: vbscript_main.c:98
HRESULT WINAPI DllUnregisterServer(void)
#define REFCLSID
Definition: guiddef.h:117
tid_t
Definition: ieframe.h:311
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT WINAPI DllCanUnloadNow(void)
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
HRESULT WINAPI LoadTypeLib(const OLECHAR *szFile, ITypeLib **pptLib)
Definition: typelib.c:461
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: vbscript.c:861
static void release_typelib(void)
Definition: vbscript_main.c:83
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:2663
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:70
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
const CLSID CLSID_VBScript
HRESULT WINAPI DllRegisterServer(void)
BOOL mark
Definition: jscript.h:65
#define WARN_ON(c)
Definition: module.h:255
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
heap_pool_t * heap_pool_mark(heap_pool_t *heap)
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXME(fmt,...)
Definition: debug.h:110
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
void heap_pool_init(heap_pool_t *heap)
WINE_DEFAULT_DEBUG_CHANNEL(vbscript)
const CLSID CLSID_VBScriptRegExp
#define ARENA_FREE_FILLER
Definition: vbscript_main.c:99
#define debugstr_guid
Definition: kernel32.h:35
#define TID_LIST
Definition: ieframe.h:306
#define DLL_PROCESS_DETACH
Definition: compat.h:119
static REFIID tid_ids[]
Definition: vbscript_main.c:41
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
void * heap_pool_alloc(heap_pool_t *heap, size_t size)
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
HRESULT hres
Definition: protocol.c:465
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
static IClassFactory VBScriptFactory
static const IClassFactoryVtbl VBScriptRegExpFactoryVtbl
void heap_pool_free(heap_pool_t *heap)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static DWORD block_size(DWORD block)
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
HRESULT __wine_unregister_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:110
DWORD offset
Definition: jscript.h:64
struct list custom_blocks
Definition: jscript.h:66
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define GUID_NULL
Definition: ks.h:106
Definition: _list.h:228
static ITypeInfo * typeinfos[LAST_tid]
Definition: vbscript_main.c:39
#define ERR(fmt,...)
Definition: debug.h:109
#define S_OK
Definition: intsafe.h:59
static ITypeLib * typelib
Definition: vbscript_main.c:38
void ** blocks
Definition: jscript.h:61
#define ARRAY_SIZE(a)
Definition: main.h:24
#define list
Definition: rosglue.h:35
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
DWORD last_block
Definition: jscript.h:63
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
void * heap_pool_grow(heap_pool_t *heap, void *mem, DWORD size, DWORD inc)
Definition: mem.c:156
__WINE_SERVER_LIST_INLINE struct list * list_next(const struct list *list, const struct list *elem)
Definition: list.h:115
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
unsigned int ULONG
Definition: retypes.h:1
void release_regexp_typelib(void)
Definition: vbregexp.c:1634
const GUID IID_IClassFactory
#define memset(x, y, z)
Definition: compat.h:39
static TfClientId tid
DWORD block_cnt
Definition: jscript.h:62
WINE_DECLARE_DEBUG_CHANNEL(heap)
static BOOL heap_free(void *mem)
Definition: appwiz.h:75