wined3d: Avoid the deprecated syntax for SM3 varyings on core profile.
[wine/multimedia.git] / dlls / wer / main.c
blobda44aa7d0d512e5922f2199dba24c37baee96cbd
1 /*
2 * Copyright 2010 Louis Lenders
3 * Copyright 2010 Detlef Riekenberg
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "werapi.h"
28 #include "wine/list.h"
29 #include "wine/unicode.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wer);
34 typedef struct {
35 struct list entry;
36 WER_REPORT_INFORMATION info;
37 WER_REPORT_TYPE reporttype;
38 WCHAR eventtype[1];
39 } report_t;
42 static CRITICAL_SECTION report_table_cs;
43 static CRITICAL_SECTION_DEBUG report_table_cs_debug =
45 0, 0, &report_table_cs,
46 { &report_table_cs_debug.ProcessLocksList, &report_table_cs_debug.ProcessLocksList },
47 0, 0, { (DWORD_PTR)(__FILE__ ": report_table_cs") }
49 static CRITICAL_SECTION report_table_cs = { &report_table_cs_debug, -1, 0, 0, 0, 0 };
51 static struct list report_table = LIST_INIT(report_table);
53 static const WCHAR regpath_exclude[] =
54 {'S','o','f','t','w','a','r','e','\\',
55 'M','i','c','r','o','s','o','f','t','\\',
56 'W','i','n','d','o','w','s',' ','E','r','r','o','r',' ','R','e','p','o','r','t','i','n','g','\\',
57 'E','x','c','l','u','d','e','d','A','p','p','l','i','c','a','t','i','o','n','s',0};
59 /***********************************************************************
60 * Memory allocation helper
63 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
65 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
68 static inline BOOL heap_free(void *mem)
70 return HeapFree(GetProcessHeap(), 0, mem);
73 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
75 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
77 switch (fdwReason)
79 case DLL_WINE_PREATTACH:
80 return FALSE; /* prefer native version */
81 case DLL_PROCESS_ATTACH:
82 DisableThreadLibraryCalls(hinstDLL);
83 break;
86 return TRUE;
89 /***********************************************************************
90 * WerAddExcludedApplication (wer.@)
92 * Add an application to the user specific or the system wide exclusion list
94 * PARAMS
95 * exeName [i] The application name
96 * allUsers [i] for all users (TRUE) or for the current user (FALSE)
98 * RETURNS
99 * Success: S_OK
100 * Failure: A HRESULT error code
103 HRESULT WINAPI WerAddExcludedApplication(PCWSTR exeName, BOOL allUsers)
105 HKEY hkey;
106 DWORD value = 1;
107 LPWSTR bs;
109 TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
110 if (!exeName || !exeName[0])
111 return E_INVALIDARG;
113 bs = strrchrW(exeName, '\\');
114 if (bs) {
115 bs++; /* skip the backslash */
116 if (!bs[0]) {
117 return E_INVALIDARG;
119 } else
120 bs = (LPWSTR) exeName;
122 if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
123 RegSetValueExW(hkey, bs, 0, REG_DWORD, (LPBYTE)&value, sizeof(DWORD));
124 RegCloseKey(hkey);
125 return S_OK;
127 return E_ACCESSDENIED;
130 /***********************************************************************
131 * WerRemoveExcludedApplication (wer.@)
133 * remove an application from the exclusion list
135 * PARAMS
136 * exeName [i] The application name
137 * allUsers [i] for all users (TRUE) or for the current user (FALSE)
139 * RETURNS
140 * Success: S_OK
141 * Failure: A HRESULT error code
144 HRESULT WINAPI WerRemoveExcludedApplication(PCWSTR exeName, BOOL allUsers)
146 HKEY hkey;
147 LPWSTR bs;
148 LONG lres;
150 TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
151 if (!exeName || !exeName[0])
152 return E_INVALIDARG;
154 bs = strrchrW(exeName, '\\');
155 if (bs) {
156 bs++; /* skip the backslash */
157 if (!bs[0]) {
158 return E_INVALIDARG;
160 } else
161 bs = (LPWSTR) exeName;
163 if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
164 lres = RegDeleteValueW(hkey, bs);
165 RegCloseKey(hkey);
166 return lres ? __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND) : S_OK;
168 return E_ACCESSDENIED;
171 /***********************************************************************
172 * WerReportAddDump (wer.@)
174 * Add a dump of dumpType to hReportHandle.
176 * PARAMS
177 * hReportHandle [i] error reporting handle to add the dump
178 * hProcess [i] handle to the regarding process
179 * hThread [o] handle to the regarding thread
180 * dumpType [i] type of the dump
181 * pExceptionParam [o] pointer to a WER_EXCEPTION_INFORMATION
182 * pDumpCustomOptions [o] pointer to a WER_DUMP_CUSTOM_OPTIONS
183 * dwFlags [i] flag to control the heap dump
185 * RETURNS
186 * Success: S_OK
187 * Failure: A HRESULT error code
190 HRESULT WINAPI WerReportAddDump(HREPORT hReportHandle, HANDLE hProcess, HANDLE hThread,
191 WER_DUMP_TYPE dumpType, PWER_EXCEPTION_INFORMATION pExceptionParam,
192 PWER_DUMP_CUSTOM_OPTIONS pDumpCustomOptions, DWORD dwFlags)
194 FIXME("(%p, %p, %p, %d, %p, %p, %u) :stub\n", hReportHandle, hProcess, hThread, dumpType,
195 pExceptionParam, pDumpCustomOptions, dwFlags);
197 return E_NOTIMPL;
200 /***********************************************************************
201 * WerReportAddFile (wer.@)
203 * Add a file to an error report handle.
205 * PARAMS
206 * hreport [i] error reporting handle to add the file
207 * path [i] path to the file to add
208 * type [i] type of the file to add
209 * flags [i] flags for the file
211 * RETURNS
212 * Success: S_OK
213 * Failure: A HRESULT error code
216 HRESULT WINAPI WerReportAddFile(HREPORT hreport, PCWSTR path, WER_FILE_TYPE type, DWORD flags)
218 FIXME("(%p, %s, %d, 0x%x) :stub\n", hreport, debugstr_w(path), type, flags);
220 return S_OK;
223 /***********************************************************************
224 * WerReportCloseHandle (wer.@)
226 * Close an error reporting handle and free associated resources
228 * PARAMS
229 * hreport [i] error reporting handle to close
231 * RETURNS
232 * Success: S_OK
233 * Failure: A HRESULT error code
236 HRESULT WINAPI WerReportCloseHandle(HREPORT hreport)
238 report_t * report = (report_t *) hreport;
239 report_t * cursor;
240 BOOL found = FALSE;
242 TRACE("(%p)\n", hreport);
243 EnterCriticalSection(&report_table_cs);
244 if (report) {
245 LIST_FOR_EACH_ENTRY(cursor, &report_table, report_t, entry)
247 if (cursor == report) {
248 found = TRUE;
249 list_remove(&report->entry);
250 break;
254 LeaveCriticalSection(&report_table_cs);
255 if (!found)
256 return E_INVALIDARG;
258 heap_free(report);
260 return S_OK;
263 /***********************************************************************
264 * WerReportCreate (wer.@)
266 * Create an error report in memory and return a related HANDLE
268 * PARAMS
269 * eventtype [i] a name for the event type
270 * reporttype [i] what type of report should be created
271 * reportinfo [i] NULL or a ptr to a struct with some detailed information
272 * phandle [o] ptr, where the resulting handle should be saved
274 * RETURNS
275 * Success: S_OK
276 * Failure: A HRESULT error code
278 * NOTES
279 * The event type must be registered at microsoft. Predefined types are
280 * "APPCRASH" as the default on Windows, "Crash32" and "Crash64"
283 HRESULT WINAPI WerReportCreate(PCWSTR eventtype, WER_REPORT_TYPE reporttype, PWER_REPORT_INFORMATION reportinfo, HREPORT *phandle)
285 report_t *report;
287 TRACE("(%s, %d, %p, %p)\n", debugstr_w(eventtype), reporttype, reportinfo, phandle);
288 if (reportinfo) {
289 TRACE(".wzFriendlyEventName: %s\n", debugstr_w(reportinfo->wzFriendlyEventName));
290 TRACE(".wzApplicationName: %s\n", debugstr_w(reportinfo->wzApplicationName));
293 if (phandle) *phandle = NULL;
294 if (!eventtype || !eventtype[0] || !phandle) {
295 return E_INVALIDARG;
298 report = heap_alloc_zero(FIELD_OFFSET(report_t, eventtype[lstrlenW(eventtype) + 1]));
299 if (!report)
300 return __HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
302 lstrcpyW(report->eventtype, eventtype);
303 report->reporttype = reporttype;
305 if (reportinfo) {
306 report->info = *reportinfo;
307 } else {
308 FIXME("build report information from scratch for %p\n", report);
311 EnterCriticalSection(&report_table_cs);
312 list_add_head(&report_table, &report->entry);
313 LeaveCriticalSection(&report_table_cs);
315 *phandle = report;
316 TRACE("=> %p\n", report);
317 return S_OK;
320 /***********************************************************************
321 * WerReportSetParameter (wer.@)
323 * Set one of 10 parameter / value pairs for a report handle
325 * PARAMS
326 * hreport [i] error reporting handle to add the parameter
327 * id [i] parameter to set (WER_P0 up to WER_P9)
328 * name [i] optional name of the parameter
329 * value [i] value of the parameter
331 * RETURNS
332 * Success: S_OK
333 * Failure: A HRESULT error code
336 HRESULT WINAPI WerReportSetParameter(HREPORT hreport, DWORD id, PCWSTR name, PCWSTR value)
338 FIXME("(%p, %d, %s, %s) :stub\n", hreport, id, debugstr_w(name), debugstr_w(value));
340 return S_OK;
343 /***********************************************************************
344 * WerReportSubmit (wer.@)
346 * Ask the user for permission and send the error report
347 * then kill or restart the application, when requested
349 * PARAMS
350 * hreport [i] error reporting handle to send
351 * consent [i] current transmit permission
352 * flags [i] flag to select dialog, transmission snd restart options
353 * presult [o] ptr, where the transmission result should be saved
355 * RETURNS
356 * Success: S_OK
357 * Failure: A HRESULT error code
360 HRESULT WINAPI WerReportSubmit(HREPORT hreport, WER_CONSENT consent, DWORD flags, PWER_SUBMIT_RESULT presult)
362 FIXME("(%p, %d, 0x%x, %p) :stub\n", hreport, consent, flags, presult);
364 if(!presult)
365 return E_INVALIDARG;
367 *presult = WerDisabled;
368 return S_OK;
371 /***********************************************************************
372 * WerReportSetUIOption (wer.@)
374 HRESULT WINAPI WerReportSetUIOption(HREPORT hreport, WER_REPORT_UI uitype, PCWSTR value)
376 FIXME("(%p, %d, %s) :stub\n", hreport, uitype, debugstr_w(value));
377 return E_NOTIMPL;