From ab47cca2fb7779e5f24c9738990f296fd46e5839 Mon Sep 17 00:00:00 2001 From: Detlef Riekenberg Date: Mon, 1 Nov 2010 23:08:45 +0100 Subject: [PATCH] wer: Implement WerReportCreate and WerReportCloseHandle. --- dlls/wer/main.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++--- dlls/wer/tests/main.c | 3 -- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/dlls/wer/main.c b/dlls/wer/main.c index 289d01e84ac..539eac44ebf 100644 --- a/dlls/wer/main.c +++ b/dlls/wer/main.c @@ -23,10 +23,44 @@ #include "windef.h" #include "winbase.h" #include "werapi.h" +#include "wine/list.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(wer); +typedef struct { + struct list entry; + WER_REPORT_INFORMATION info; + WER_REPORT_TYPE reporttype; + WCHAR eventtype[1]; +} report_t; + + +static CRITICAL_SECTION report_table_cs; +static CRITICAL_SECTION_DEBUG report_table_cs_debug = +{ + 0, 0, &report_table_cs, + { &report_table_cs_debug.ProcessLocksList, &report_table_cs_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": report_table_cs") } +}; +static CRITICAL_SECTION report_table_cs = { &report_table_cs_debug, -1, 0, 0, 0, 0 }; + +static struct list report_table = LIST_INIT(report_table); + +/*********************************************************************** + * Memory alloccation helper + */ + +static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len) +{ + return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len); +} + +static inline BOOL heap_free(void *mem) +{ + return HeapFree(GetProcessHeap(), 0, mem); +} + HRESULT WINAPI WerAddExcludedApplication(PCWSTR exeName, BOOL allUsers) { FIXME("(%s, %d) stub\n",debugstr_w(exeName), allUsers); @@ -86,9 +120,29 @@ HRESULT WINAPI WerRemoveExcludedApplication(PCWSTR exeName, BOOL allUsers) */ HRESULT WINAPI WerReportCloseHandle(HREPORT hreport) { - FIXME("(%p) :stub\n", hreport); + report_t * report = (report_t *) hreport; + report_t * cursor; + BOOL found = FALSE; + + TRACE("(%p)\n", hreport); + EnterCriticalSection(&report_table_cs); + if (report) { + LIST_FOR_EACH_ENTRY(cursor, &report_table, report_t, entry) + { + if (cursor == report) { + found = TRUE; + list_remove(&report->entry); + break; + } + } + } + LeaveCriticalSection(&report_table_cs); + if (!found) + return E_INVALIDARG; - return E_NOTIMPL; + heap_free(report); + + return S_OK; } /*********************************************************************** @@ -113,8 +167,10 @@ HRESULT WINAPI WerReportCloseHandle(HREPORT hreport) */ HRESULT WINAPI WerReportCreate(PCWSTR eventtype, WER_REPORT_TYPE reporttype, PWER_REPORT_INFORMATION reportinfo, HREPORT *phandle) { + report_t *report; + DWORD len; - FIXME("(%s, %d, %p, %p) :stub\n", debugstr_w(eventtype), reporttype, reportinfo, phandle); + TRACE("(%s, %d, %p, %p)\n", debugstr_w(eventtype), reporttype, reportinfo, phandle); if (reportinfo) { TRACE(".wzFriendlyEventName: %s\n", debugstr_w(reportinfo->wzFriendlyEventName)); TRACE(".wzApplicationName: %s\n", debugstr_w(reportinfo->wzApplicationName)); @@ -125,7 +181,28 @@ HRESULT WINAPI WerReportCreate(PCWSTR eventtype, WER_REPORT_TYPE reporttype, PWE return E_INVALIDARG; } - return E_NOTIMPL; + len = lstrlenW(eventtype) + 1; + + report = heap_alloc_zero(len * sizeof(WCHAR) + sizeof(report_t)); + if (!report) + return __HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); + + lstrcpyW(report->eventtype, eventtype); + report->reporttype = reporttype; + + if (reportinfo) { + report->info = *reportinfo; + } else { + FIXME("build report information from scratch for %p\n", report); + } + + EnterCriticalSection(&report_table_cs); + list_add_head(&report_table, &report->entry); + LeaveCriticalSection(&report_table_cs); + + *phandle = report; + TRACE("=> %p\n", report); + return S_OK; } /*********************************************************************** diff --git a/dlls/wer/tests/main.c b/dlls/wer/tests/main.c index a4317897f8a..f63b7bd561a 100644 --- a/dlls/wer/tests/main.c +++ b/dlls/wer/tests/main.c @@ -111,7 +111,6 @@ static void test_WerReportCloseHandle(void) report = (void *) 0xdeadbeef; hr = WerReportCreate(appcrash, WerReportCritical, NULL, &report); - todo_wine ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report); if (!report) { @@ -143,8 +142,6 @@ static void test_WerReportCreate(void) report = (void *) 0xdeadbeef; /* test a simple valid case */ hr = WerReportCreate(appcrash, WerReportCritical, NULL, &report); - - todo_wine ok(hr == S_OK, "got 0x%x and %p (expected S_OK)\n", hr, report); if (!report) { -- 2.11.4.GIT