ReactOS 0.4.15-dev-6042-g2eb6700
handle.c
Go to the documentation of this file.
1/*
2 * Implementation of the Microsoft Installer (msi.dll)
3 *
4 * Copyright 2002-2004 Mike McCormack for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#define COBJMACROS
22
23#include <stdarg.h>
24
25#include "windef.h"
26#include "winbase.h"
27#include "winreg.h"
28#include "shlwapi.h"
29#include "wine/debug.h"
30#include "msi.h"
31#include "msiquery.h"
32
33#include "msipriv.h"
34#include "winemsi_s.h"
35
37
40{
41 0, 0, &MSI_handle_cs,
44 0, 0, { (DWORD_PTR)(__FILE__ ": MSI_handle_cs") }
45};
46static CRITICAL_SECTION MSI_handle_cs = { &MSI_handle_cs_debug, -1, 0, 0, 0, 0 };
47
50{
51 0, 0, &MSI_object_cs,
54 0, 0, { (DWORD_PTR)(__FILE__ ": MSI_object_cs") }
55};
56static CRITICAL_SECTION MSI_object_cs = { &MSI_object_cs_debug, -1, 0, 0, 0, 0 };
57
58typedef struct msi_handle_info_t
59{
61 union {
64 } u;
67
69static unsigned int msihandletable_size = 0;
70
72{
78}
79
81{
82 UINT i;
83
84 /* find a slot */
85 for(i=0; i<msihandletable_size; i++)
86 if( !msihandletable[i].u.obj && !msihandletable[i].u.rem )
87 break;
89 {
91 int newsize;
92 if (msihandletable_size == 0)
93 {
94 newsize = 256;
95 p = msi_alloc_zero(newsize * sizeof(*p));
96 }
97 else
98 {
99 newsize = msihandletable_size * 2;
100 p = msi_realloc(msihandletable, newsize * sizeof(*p));
101 if (p) memset(p + msihandletable_size, 0, (newsize - msihandletable_size) * sizeof(*p));
102 }
103 if (!p)
104 return 0;
106 msihandletable_size = newsize;
107 }
108 return i + 1;
109}
110
112{
115
117
119 if (ret)
120 {
121 entry = &msihandletable[ ret - 1 ];
123 entry->u.obj = obj;
124 entry->dwThreadId = GetCurrentThreadId();
125 entry->remote = FALSE;
126 }
127
129
130 TRACE( "%p -> %lu\n", obj, ret );
131
132 return ret;
133}
134
136{
139
141
143 if (ret)
144 {
145 entry = &msihandletable[ ret - 1 ];
146 entry->u.rem = remote;
147 entry->dwThreadId = GetCurrentThreadId();
148 entry->remote = TRUE;
149 }
150
152
153 TRACE( "%lu -> %lu\n", remote, ret );
154
155 return ret;
156}
157
159{
161
163 handle--;
165 goto out;
166 if( msihandletable[handle].remote)
167 goto out;
168 if( !msihandletable[handle].u.obj )
169 goto out;
170 if( msihandletable[handle].u.obj->magic != MSIHANDLE_MAGIC )
171 goto out;
172 if( type && (msihandletable[handle].u.obj->type != type) )
173 goto out;
176
177out:
179
180 return ret;
181}
182
184{
185 MSIHANDLE ret = 0;
186
188 handle--;
190 goto out;
191 if( !msihandletable[handle].remote)
192 goto out;
194
195out:
197
198 return ret;
199}
200
202{
204
206 if( info )
207 {
208 info->magic = MSIHANDLE_MAGIC;
209 info->type = type;
210 info->refcount = 1;
211 info->destructor = destroy;
212 }
213
214 return info;
215}
216
218{
219 if( !info )
220 return;
221
222 if( info->magic != MSIHANDLE_MAGIC )
223 {
224 ERR("Invalid handle!\n");
225 return;
226 }
227
228 InterlockedIncrement(&info->refcount);
229}
230
232{
234}
235
237{
239}
240
242{
243 int ret;
244
245 if( !info )
246 return -1;
247
248 if( info->magic != MSIHANDLE_MAGIC )
249 {
250 ERR("Invalid handle!\n");
251 return -1;
252 }
253
254 ret = InterlockedDecrement( &info->refcount );
255 if( ret==0 )
256 {
257 if( info->destructor )
258 info->destructor( info );
259 msi_free( info );
260 TRACE("object %p destroyed\n", info);
261 }
262
263 return ret;
264}
265
266/***********************************************************
267 * MsiCloseHandle [MSI.@]
268 */
270{
273
274 TRACE( "%lu\n", handle );
275
276 if (!handle)
277 return ERROR_SUCCESS;
278
280
281 handle--;
283 goto out;
284
285 if (msihandletable[handle].remote)
286 {
287 remote_CloseHandle( msihandletable[handle].u.rem );
288 }
289 else
290 {
292 if( !info )
293 goto out;
294
295 if( info->magic != MSIHANDLE_MAGIC )
296 {
297 ERR("Invalid handle!\n");
298 goto out;
299 }
300 }
301
305
307
308 TRACE( "handle %lu destroyed\n", handle + 1 );
309out:
311 if( info )
313
314 return ret;
315}
316
317/***********************************************************
318 * MsiCloseAllHandles [MSI.@]
319 *
320 * Closes all handles owned by the current thread
321 *
322 * RETURNS:
323 * The number of handles closed
324 */
326{
327 UINT i, n=0;
328
329 TRACE("\n");
330
332 for(i=0; i<msihandletable_size; i++)
333 {
335 {
337 MsiCloseHandle( i+1 );
339 n++;
340 }
341 }
343
344 return n;
345}
346
348{
349 return MsiCloseHandle(handle);
350}
void destroy(_Tp *__pointer)
Definition: _construct.h:278
#define __cdecl
Definition: accygwin.h:79
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ERR(fmt,...)
Definition: debug.h:110
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
static CRITICAL_SECTION_DEBUG MSI_object_cs_debug
Definition: handle.c:49
void msiobj_lock(MSIOBJECTHDR *info)
Definition: handle.c:231
static CRITICAL_SECTION MSI_object_cs
Definition: handle.c:48
static unsigned int msihandletable_size
Definition: handle.c:69
static MSIHANDLE alloc_handle_table_entry(void)
Definition: handle.c:80
void * alloc_msiobject(UINT type, UINT size, msihandledestructor destroy)
Definition: handle.c:201
UINT __cdecl s_remote_CloseHandle(MSIHANDLE handle)
Definition: handle.c:347
static CRITICAL_SECTION_DEBUG MSI_handle_cs_debug
Definition: handle.c:39
MSIHANDLE alloc_msihandle(MSIOBJECTHDR *obj)
Definition: handle.c:111
MSIHANDLE msi_get_remote(MSIHANDLE handle)
Definition: handle.c:183
void msiobj_addref(MSIOBJECTHDR *info)
Definition: handle.c:217
struct msi_handle_info_t msi_handle_info
void msi_free_handle_table(void)
Definition: handle.c:71
UINT WINAPI MsiCloseHandle(MSIHANDLE handle)
Definition: handle.c:269
static CRITICAL_SECTION MSI_handle_cs
Definition: handle.c:38
MSIHANDLE alloc_msi_remote_handle(MSIHANDLE remote)
Definition: handle.c:135
int msiobj_release(MSIOBJECTHDR *info)
Definition: handle.c:241
void * msihandle2msiinfo(MSIHANDLE handle, UINT type)
Definition: handle.c:158
void msiobj_unlock(MSIOBJECTHDR *info)
Definition: handle.c:236
static msi_handle_info * msihandletable
Definition: handle.c:68
UINT WINAPI MsiCloseAllHandles(void)
Definition: handle.c:325
DWORD dwThreadId
Definition: fdebug.c:31
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat p
Definition: glext.h:8902
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
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 * u
Definition: glfuncs.h:240
uint32_t entry
Definition: isohybrid.c:63
static void * msi_realloc(void *mem, size_t len) __WINE_ALLOC_SIZE(2)
Definition: msipriv.h:1154
static void * msi_alloc_zero(size_t len) __WINE_ALLOC_SIZE(1)
Definition: msipriv.h:1148
static void msi_free(void *mem)
Definition: msipriv.h:1159
#define MSIHANDLE_MAGIC
Definition: msipriv.h:736
VOID(* msihandledestructor)(MSIOBJECTHDR *)
Definition: msipriv.h:73
unsigned int UINT
Definition: ndis.h:50
static FILE * out
Definition: regtests2xml.c:44
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY ProcessLocksList
Definition: winbase.h:883
DWORD dwThreadId
Definition: handle.c:65
MSIHANDLE rem
Definition: handle.c:63
union msi_handle_info_t::@488 u
MSIOBJECTHDR * obj
Definition: handle.c:62
#define DWORD_PTR
Definition: treelist.c:76
int ret
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define WINAPI
Definition: msvc.h:6
unsigned long MSIHANDLE
Definition: winemsi.idl:27