ReactOS 0.4.15-dev-7934-g1dc8d80
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
34DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
35
37
39{
40 WCHAR buf[512];
42 return SysAllocString(buf);
43}
44
46{
47 BSTR ret;
50 return ret;
51}
52
53#define MIN_BLOCK_SIZE 128
54#define ARENA_FREE_FILLER 0xaa
55
57{
58 return MIN_BLOCK_SIZE << block;
59}
60
62{
63 memset(heap, 0, sizeof(*heap));
64 list_init(&heap->custom_blocks);
65}
66
68{
69 struct list *list;
70 void *tmp;
71
72 size = (size+3)&~3;
73
74 if(!heap->block_cnt) {
75 if(!heap->blocks) {
76 heap->blocks = heap_alloc(sizeof(void*));
77 if(!heap->blocks)
78 return NULL;
79 }
80
81 tmp = heap_alloc(block_size(0));
82 if(!tmp)
83 return NULL;
84
85 heap->blocks[0] = tmp;
86 heap->block_cnt = 1;
87 }
88
89 if(heap->offset + size <= block_size(heap->last_block)) {
90 tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
91 heap->offset += size;
92 return tmp;
93 }
94
95 if(size <= block_size(heap->last_block+1)) {
96 if(heap->last_block+1 == heap->block_cnt) {
97 tmp = heap_realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*));
98 if(!tmp)
99 return NULL;
100
101 heap->blocks = tmp;
102 heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt));
103 if(!heap->blocks[heap->block_cnt])
104 return NULL;
105
106 heap->block_cnt++;
107 }
108
109 heap->last_block++;
110 heap->offset = size;
111 return heap->blocks[heap->last_block];
112 }
113
114 list = heap_alloc(size + sizeof(struct list));
115 if(!list)
116 return NULL;
117
118 list_add_head(&heap->custom_blocks, list);
119 return list+1;
120}
121
123{
124 void *ret;
125
126 if(mem == (BYTE*)heap->blocks[heap->last_block] + heap->offset-size
127 && heap->offset+inc < block_size(heap->last_block)) {
128 heap->offset += inc;
129 return mem;
130 }
131
133 if(ret) /* FIXME: avoid copying for custom blocks */
134 memcpy(ret, mem, size);
135 return ret;
136}
137
139{
140 struct list *tmp;
141
142 if(!heap)
143 return;
144
145 while((tmp = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
146 list_remove(tmp);
147 heap_free(tmp);
148 }
149
150 if(WARN_ON(heap)) {
151 DWORD i;
152
153 for(i=0; i < heap->block_cnt; i++)
155 }
156
157 heap->last_block = heap->offset = 0;
158 heap->mark = FALSE;
159}
160
162{
163 DWORD i;
164
166
167 for(i=0; i < heap->block_cnt; i++)
168 heap_free(heap->blocks[i]);
169 heap_free(heap->blocks);
170
172}
173
175{
176 if(heap->mark)
177 return NULL;
178
179 heap->mark = TRUE;
180 return heap;
181}
182
184{
185 *ppv = NULL;
186
188 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
189 *ppv = iface;
190 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
191 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
192 *ppv = iface;
193 }
194
195 if(*ppv) {
196 IUnknown_AddRef((IUnknown*)*ppv);
197 return S_OK;
198 }
199
200 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
201 return E_NOINTERFACE;
202}
203
205{
206 TRACE("(%p)\n", iface);
207 return 2;
208}
209
211{
212 TRACE("(%p)\n", iface);
213 return 1;
214}
215
217{
218 TRACE("(%p)->(%x)\n", iface, fLock);
219 return S_OK;
220}
221
222static const IClassFactoryVtbl VBScriptFactoryVtbl = {
228};
229
231
232static const IClassFactoryVtbl VBScriptRegExpFactoryVtbl = {
238};
239
241
242/******************************************************************
243 * DllMain (vbscript.@)
244 */
245BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
246{
247 TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
248
249 switch(fdwReason)
250 {
251 case DLL_WINE_PREATTACH:
252 return FALSE; /* prefer native version */
255 vbscript_hinstance = hInstDLL;
256 break;
258 if (lpv) break;
260 }
261
262 return TRUE;
263}
264
265/***********************************************************************
266 * DllGetClassObject (vbscript.@)
267 */
269{
270 if(IsEqualGUID(&CLSID_VBScript, rclsid)) {
271 TRACE("(CLSID_VBScript %s %p)\n", debugstr_guid(riid), ppv);
272 return IClassFactory_QueryInterface(&VBScriptFactory, riid, ppv);
273 }else if(IsEqualGUID(&CLSID_VBScriptRegExp, rclsid)) {
274 TRACE("(CLSID_VBScriptRegExp %s %p)\n", debugstr_guid(riid), ppv);
275 return IClassFactory_QueryInterface(&VBScriptRegExpFactory, riid, ppv);
276 }
277
278 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
280}
281
282/***********************************************************************
283 * DllCanUnloadNow (vbscript.@)
284 */
286{
287 return S_FALSE;
288}
289
290/***********************************************************************
291 * DllRegisterServer (vbscript.@)
292 */
294{
295 TRACE("()\n");
297}
298
299/***********************************************************************
300 * DllUnregisterServer (vbscript.@)
301 */
303{
304 TRACE("()\n");
306}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:71
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:33
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
static void list_init(struct list_entry *head)
Definition: list.h:51
const GUID IID_IUnknown
const GUID IID_IClassFactory
#define FIXME(fmt,...)
Definition: debug.h:111
Definition: list.h:37
const CLSID CLSID_VBScript
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
OLECHAR * BSTR
Definition: compat.h:2293
#define WINE_DECLARE_DEBUG_CHANNEL(x)
Definition: compat.h:45
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: vbscript.c:930
#define VBS_UNKNOWN_RUNTIME_ERROR
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define debugstr_guid
Definition: kernel32.h:35
#define GUID_NULL
Definition: ks.h:106
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define WARN_ON(c)
Definition: module.h:257
const CLSID CLSID_VBScriptRegExp
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
#define list
Definition: rosglue.h:35
HRESULT __wine_unregister_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:110
HRESULT __wine_register_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:98
__WINE_SERVER_LIST_INLINE struct list * list_next(const struct list *list, const struct list *elem)
Definition: list.h:115
static HANDLE heap
Definition: heap.c:65
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
Definition: mem.c:156
uint32_t ULONG
Definition: typedefs.h:59
HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: vbregexp.c:1618
void release_regexp_typelib(void)
Definition: vbregexp.c:1634
#define FACILITY_VBS
Definition: vbscript.h:378
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
BSTR get_vbscript_string(int id)
Definition: vbscript_main.c:38
HRESULT WINAPI DllRegisterServer(void)
void heap_pool_init(heap_pool_t *heap)
Definition: vbscript_main.c:61
heap_pool_t * heap_pool_mark(heap_pool_t *heap)
void * heap_pool_alloc(heap_pool_t *heap, size_t size)
Definition: vbscript_main.c:67
static IClassFactory VBScriptFactory
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
void * heap_pool_grow(heap_pool_t *heap, void *mem, DWORD size, DWORD inc)
static HINSTANCE vbscript_hinstance
Definition: vbscript_main.c:36
#define ARENA_FREE_FILLER
Definition: vbscript_main.c:54
BSTR get_vbscript_error_string(HRESULT error)
Definition: vbscript_main.c:45
HRESULT WINAPI DllUnregisterServer(void)
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
static DWORD block_size(DWORD block)
Definition: vbscript_main.c:56
void heap_pool_free(heap_pool_t *heap)
void heap_pool_clear(heap_pool_t *heap)
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
#define MIN_BLOCK_SIZE
Definition: vbscript_main.c:53
static const IClassFactoryVtbl VBScriptRegExpFactoryVtbl
HRESULT WINAPI DllCanUnloadNow(void)
static const IClassFactoryVtbl VBScriptFactoryVtbl
static IClassFactory VBScriptRegExpFactory
int ret
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
#define E_NOINTERFACE
Definition: winerror.h:2364
#define HRESULT_FACILITY(hr)
Definition: winerror.h:79
#define HRESULT_CODE(hr)
Definition: winerror.h:76
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:2663
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
static unsigned int block
Definition: xmlmemory.c:101
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193