From: Hans Leidekker hans@codeweavers.com
--- dlls/wbemprox/Makefile.in | 2 +- dlls/wbemprox/builtin.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/dlls/wbemprox/Makefile.in b/dlls/wbemprox/Makefile.in index 53835c748ff..8c57cf95cdb 100644 --- a/dlls/wbemprox/Makefile.in +++ b/dlls/wbemprox/Makefile.in @@ -1,5 +1,5 @@ MODULE = wbemprox.dll -IMPORTS = winspool version iphlpapi dxgi oleaut32 ole32 advapi32 user32 gdi32 ws2_32 rpcrt4 setupapi +IMPORTS = winspool version iphlpapi oleaut32 ole32 advapi32 user32 gdi32 ws2_32
SOURCES = \ builtin.c \ diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c index 646d93e3978..a3f0d9afcce 100644 --- a/dlls/wbemprox/builtin.c +++ b/dlls/wbemprox/builtin.c @@ -32,7 +32,6 @@ #include "iphlpapi.h" #include "netioapi.h" #include "tlhelp32.h" -#include "d3d10.h" #include "winternl.h" #include "winioctl.h" #include "winsvc.h" @@ -40,7 +39,6 @@ #include "sddl.h" #include "ntsecapi.h" #include "winspool.h" -#include "setupapi.h" #include "ntddstor.h"
#include "wine/debug.h"
From: Hans Leidekker hans@codeweavers.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56859 --- dlls/wbemprox/builtin.c | 24 +++- dlls/wbemprox/class.c | 12 +- dlls/wbemprox/main.c | 14 ++- dlls/wbemprox/query.c | 9 +- dlls/wbemprox/table.c | 202 +++++++++++++++++-------------- dlls/wbemprox/wbemprox_private.h | 10 +- 6 files changed, 153 insertions(+), 118 deletions(-)
diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c index a3f0d9afcce..2e3c3ce041e 100644 --- a/dlls/wbemprox/builtin.c +++ b/dlls/wbemprox/builtin.c @@ -4635,13 +4635,27 @@ void init_table_list( void ) { list_init( &tables[ns] ); for (i = 0; i < builtin_namespaces[ns].table_count; i++) + list_add_tail( &tables[ns], &builtin_namespaces[ns].tables[i].entry ); + table_list[ns] = &tables[ns]; + } +} + +void free_dynamic_tables( void ) +{ + UINT ns; + + for (ns = 0; ns < ARRAY_SIZE(builtin_namespaces); ns++) + { + struct table *table, *next; + + LIST_FOR_EACH_ENTRY_SAFE( table, next, table_list[ns], struct table, entry ) { - struct table *table = &builtin_namespaces[ns].tables[i]; - InitializeCriticalSectionEx( &table->cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO ); - table->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": table.cs" ); - list_add_tail( &tables[ns], &table->entry ); + if (table->flags & TABLE_FLAG_DYNAMIC) + { + list_remove( &table->entry ); + release_table( table ); + } } - table_list[ns] = &tables[ns]; } }
diff --git a/dlls/wbemprox/class.c b/dlls/wbemprox/class.c index 8e585c2f360..49e0201cc53 100644 --- a/dlls/wbemprox/class.c +++ b/dlls/wbemprox/class.c @@ -821,13 +821,21 @@ static HRESULT create_signature_table( IEnumWbemClassObject *iter, enum wbm_name hr = create_signature_columns_and_data( iter, &num_cols, &columns, &row ); if (hr != S_OK) return hr;
- if (!(table = create_table( name, num_cols, columns, 1, 1, row, NULL ))) + if (!(table = alloc_table())) { free_columns( columns, num_cols ); free( row ); return E_OUTOFMEMORY; } - if (!add_table( ns, table )) free_table( table ); /* already exists */ + + table->name = wcsdup( name ); + table->num_cols = num_cols; + table->columns = columns; + table->num_rows = 1; + table->num_rows_allocated = 1; + table->data = row; + table->flags = TABLE_FLAG_DYNAMIC; + if (!add_table( ns, table )) release_table( table ); /* already exists */ return S_OK; }
diff --git a/dlls/wbemprox/main.c b/dlls/wbemprox/main.c index 30363658636..bc081ce1e34 100644 --- a/dlls/wbemprox/main.c +++ b/dlls/wbemprox/main.c @@ -111,11 +111,15 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
switch (fdwReason) { - case DLL_PROCESS_ATTACH: - instance = hinstDLL; - DisableThreadLibraryCalls(hinstDLL); - init_table_list(); - break; + case DLL_PROCESS_ATTACH: + instance = hinstDLL; + DisableThreadLibraryCalls(hinstDLL); + init_table_list(); + break; + case DLL_PROCESS_DETACH: + if (lpvReserved) break; + free_dynamic_tables(); + break; }
return TRUE; diff --git a/dlls/wbemprox/query.c b/dlls/wbemprox/query.c index a6599334f58..ff7be29ed52 100644 --- a/dlls/wbemprox/query.c +++ b/dlls/wbemprox/query.c @@ -54,7 +54,7 @@ HRESULT create_view( enum view_type type, enum wbm_namespace ns, const WCHAR *pa
case VIEW_TYPE_SELECT: { - struct table *table = find_table( ns, class ); + struct table *table = create_table( ns, class ); HRESULT hr;
if (table && (hr = append_table( view, table )) != S_OK) @@ -702,12 +702,9 @@ static HRESULT exec_select_view( struct view *view ) if (!view->table_count) return S_OK;
table = view->table[0]; - if (table->fill) - { - clear_table( table ); - status = table->fill( table, view->cond ); - } + if (table->fill) status = table->fill( table, view->cond ); if (status == FILL_STATUS_FAILED) return WBEM_E_FAILED; + if (!table->num_rows) return S_OK;
len = min( table->num_rows, 16 ); diff --git a/dlls/wbemprox/table.c b/dlls/wbemprox/table.c index 37aa546ad2b..53274eb1b90 100644 --- a/dlls/wbemprox/table.c +++ b/dlls/wbemprox/table.c @@ -311,117 +311,121 @@ void free_row_values( const struct table *table, UINT row ) } }
-void clear_table( struct table *table ) -{ - UINT i; - - if (!table->data) return; - - for (i = 0; i < table->num_rows; i++) free_row_values( table, i ); - if (table->fill) - { - table->num_rows = 0; - table->num_rows_allocated = 0; - free( table->data ); - table->data = NULL; - } -} - void free_columns( struct column *columns, UINT num_cols ) { UINT i; - for (i = 0; i < num_cols; i++) { free( (WCHAR *)columns[i].name ); } free( columns ); }
-void free_table( struct table *table ) +static void free_table( struct table *table ) { - if (!table) return; - assert( table->flags & TABLE_FLAG_DYNAMIC ); + UINT i;
TRACE("destroying %p\n", table);
- clear_table( table ); free( (WCHAR *)table->name ); - free_columns( (struct column *)table->columns, table->num_cols ); + for (i = 0; i < table->num_rows; i++) free_row_values( table, i ); free( table->data ); - - table->cs.DebugInfo->Spare[0] = 0; - DeleteCriticalSection( &table->cs ); + free_columns( (struct column *)table->columns, table->num_cols ); free( table ); }
void release_table( struct table *table ) { - if (!--table->refs) + if (!InterlockedDecrement( &table->refs )) free_table( table ); +} + +struct table *grab_table( struct table *table ) +{ + InterlockedIncrement( &table->refs ); + return table; +} + +struct table *alloc_table( void ) +{ + struct table *table; + if (!(table = calloc( 1, sizeof(*table) ))) return NULL; + list_init( &table->entry ); + table->refs = 1; + return table; +} + +static struct column *dup_columns( const struct column *src, UINT count ) +{ + struct column *dst; + int i; + + if (!(dst = calloc( count, sizeof(*dst) ))) return NULL; + for (i = 0; i < count; i++) { - clear_table( table ); - if (table->flags & TABLE_FLAG_DYNAMIC) + if (!(dst[i].name = wcsdup( src[i].name ))) { - EnterCriticalSection( &table_list_cs ); - list_remove( &table->entry ); - table->removed = TRUE; - LeaveCriticalSection( &table_list_cs ); - - LeaveCriticalSection( &table->cs ); - free_table( table ); - return; + for (; i >= 0; i--) free( (WCHAR *)dst[i].name ); + free( dst); + return NULL; } + dst[i].type = src[i].type; } - LeaveCriticalSection( &table->cs ); + return dst; }
-struct table *grab_table( struct table *table ) +static struct table *dup_table( const struct table *src ) { - EnterCriticalSection( &table->cs ); - if (table->removed) + struct table *dst; + + if (!(dst = alloc_table())) return NULL; + if (!(dst->name = wcsdup( src->name ))) { - LeaveCriticalSection( &table->cs ); + free_table( dst ); return NULL; } - table->refs++; - return table; + if (!(dst->columns = dup_columns( src->columns, src->num_cols ))) + { + free_table( dst ); + return NULL; + } + dst->num_cols = src->num_cols; + if (src->data) + { + UINT size = get_row_size(src) * src->num_rows; + + if (!(dst->data = malloc( size ))) + { + free_table( dst ); + return NULL; + } + memcpy( dst->data, src->data, size ); + dst->num_rows = dst->num_rows_allocated = src->num_rows; + } + dst->fill = src->fill; + + return dst; }
-struct table *find_table( enum wbm_namespace ns, const WCHAR *name ) +struct table *create_table( enum wbm_namespace ns, const WCHAR *name ) { - struct table *table; + struct table *iter, *table;
if (ns == WBEMPROX_NAMESPACE_LAST) return NULL;
- LIST_FOR_EACH_ENTRY( table, table_list[ns], struct table, entry ) + EnterCriticalSection( &table_list_cs ); + + LIST_FOR_EACH_ENTRY( iter, table_list[ns], struct table, entry ) { - if (name && !wcsicmp( table->name, name )) + if (name && !wcsicmp( iter->name, name )) { - TRACE("returning %p\n", table); - return grab_table( table ); + if ((table = dup_table( iter ))) + { + TRACE("returning %p\n", table); + LeaveCriticalSection( &table_list_cs ); + return table; + } } } - return NULL; -}
-struct table *create_table( const WCHAR *name, UINT num_cols, const struct column *columns, - UINT num_rows, UINT num_allocated, BYTE *data, - enum fill_status (*fill)(struct table *, const struct expr *cond) ) -{ - struct table *table; - - if (!(table = malloc( sizeof(*table) ))) return NULL; - table->name = wcsdup( name ); - table->num_cols = num_cols; - table->columns = columns; - table->num_rows = num_rows; - table->num_rows_allocated = num_allocated; - table->data = data; - table->fill = fill; - table->flags = TABLE_FLAG_DYNAMIC; - table->refs = 0; - table->removed = FALSE; - list_init( &table->entry ); - InitializeCriticalSectionEx( &table->cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO ); - table->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": table.cs"); - return table; + LeaveCriticalSection( &table_list_cs ); + return NULL; }
BOOL add_table( enum wbm_namespace ns, struct table *table ) @@ -431,6 +435,7 @@ BOOL add_table( enum wbm_namespace ns, struct table *table ) if (ns == WBEMPROX_NAMESPACE_LAST) return FALSE;
EnterCriticalSection( &table_list_cs ); + LIST_FOR_EACH_ENTRY( iter, table_list[ns], struct table, entry ) { if (!wcsicmp( iter->name, table->name )) @@ -441,8 +446,8 @@ BOOL add_table( enum wbm_namespace ns, struct table *table ) } } list_add_tail( table_list[ns], &table->entry ); - LeaveCriticalSection( &table_list_cs );
+ LeaveCriticalSection( &table_list_cs ); TRACE("added %p\n", table); return TRUE; } @@ -450,45 +455,56 @@ BOOL add_table( enum wbm_namespace ns, struct table *table ) BSTR get_method_name( enum wbm_namespace ns, const WCHAR *class, UINT index ) { struct table *table; - UINT i, count = 0; - BSTR ret;
- if (!(table = find_table( ns, class ))) return NULL; + EnterCriticalSection( &table_list_cs );
- for (i = 0; i < table->num_cols; i++) + LIST_FOR_EACH_ENTRY( table, table_list[ns], struct table, entry ) { - if (table->columns[i].type & COL_FLAG_METHOD) + if (!wcsicmp( table->name, class )) { - if (index == count) + UINT i, count = 0; + for (i = 0; i < table->num_cols; i++) { - ret = SysAllocString( table->columns[i].name ); - release_table( table ); - return ret; + if (table->columns[i].type & COL_FLAG_METHOD) + { + if (index == count++) + { + BSTR ret = SysAllocString( table->columns[i].name ); + LeaveCriticalSection( &table_list_cs ); + return ret; + } + } } - count++; } } - release_table( table ); + + LeaveCriticalSection( &table_list_cs ); return NULL; }
WCHAR *get_first_key_property( enum wbm_namespace ns, const WCHAR *class ) { struct table *table; - WCHAR *ret = NULL; - UINT i;
- if (!(table = find_table( ns, class ))) return NULL; + EnterCriticalSection( &table_list_cs );
- for (i = 0; i < table->num_cols; i++) + LIST_FOR_EACH_ENTRY( table, table_list[ns], struct table, entry ) { - if (table->columns[i].type & COL_FLAG_KEY) + if (!wcsicmp( table->name, class )) { - ret = wcsdup( table->columns[i].name ); - break; + UINT i; + for (i = 0; i < table->num_cols; i++) + { + if (table->columns[i].type & COL_FLAG_KEY) + { + WCHAR *ret = wcsdup( table->columns[i].name ); + LeaveCriticalSection( &table_list_cs ); + return ret; + } + } } }
- release_table( table ); - return ret; + LeaveCriticalSection( &table_list_cs ); + return NULL; } diff --git a/dlls/wbemprox/wbemprox_private.h b/dlls/wbemprox/wbemprox_private.h index 5e585049aa6..632d448b8cd 100644 --- a/dlls/wbemprox/wbemprox_private.h +++ b/dlls/wbemprox/wbemprox_private.h @@ -121,8 +121,6 @@ struct table UINT flags; struct list entry; LONG refs; - CRITICAL_SECTION cs; - BOOL removed; };
struct property @@ -216,17 +214,15 @@ void destroy_view( struct view * ); HRESULT execute_view( struct view * ); struct table *get_view_table( const struct view *, UINT ); void init_table_list( void ); +void free_dynamic_tables( void ); enum wbm_namespace get_namespace_from_string( const WCHAR *namespace ); -struct table *find_table( enum wbm_namespace, const WCHAR * ); +struct table *alloc_table( void ); +struct table *create_table( enum wbm_namespace, const WCHAR * ); struct table *grab_table( struct table * ); void release_table( struct table * ); -struct table *create_table( const WCHAR *, UINT, const struct column *, UINT, UINT, BYTE *, - enum fill_status (*)(struct table *, const struct expr *) ); BOOL add_table( enum wbm_namespace, struct table * ); void free_columns( struct column *, UINT ); void free_row_values( const struct table *, UINT ); -void clear_table( struct table * ); -void free_table( struct table * ); UINT get_type_size( CIMTYPE ); HRESULT eval_cond( const struct table *, UINT, const struct expr *, LONGLONG *, UINT * ); HRESULT get_column_index( const struct table *, const WCHAR *, UINT * );