ReactOS 0.4.16-dev-1494-gd054f63
debug.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ntstatus.h"
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "winnls.h"
#include "wingdi.h"
#include "winuser.h"
#include "psapi.h"
#include "werapi.h"
#include "wine/exception.h"
#include "wine/asm.h"
#include "kernelbase.h"
#include "wine/debug.h"
Include dependency graph for debug.c:

Go to the source code of this file.

Classes

struct  _LDR_DATA_TABLE_ENTRY32
 
struct  module_iterator
 
struct  module_push
 

Macros

#define WIN32_NO_STATUS
 
#define PSAPI_VERSION   1 /* avoid K32 function remapping */
 

Typedefs

typedef INT(WINAPIMessageBoxA_funcptr) (HWND, LPCSTR, LPCSTR, UINT)
 
typedef INT(WINAPIMessageBoxW_funcptr) (HWND, LPCWSTR, LPCWSTR, UINT)
 
typedef struct _LDR_DATA_TABLE_ENTRY32 LDR_DATA_TABLE_ENTRY32
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (seh)
 
 WINE_DECLARE_DEBUG_CHANNEL (winedbg)
 
BOOL WINAPI DECLSPEC_HOTPATCH CheckRemoteDebuggerPresent (HANDLE process, BOOL *present)
 
BOOL WINAPI DECLSPEC_HOTPATCH ContinueDebugEvent (DWORD pid, DWORD tid, DWORD status)
 
BOOL WINAPI DECLSPEC_HOTPATCH DebugActiveProcess (DWORD pid)
 
BOOL WINAPI DECLSPEC_HOTPATCH DebugActiveProcessStop (DWORD pid)
 
void WINAPI DECLSPEC_HOTPATCH FatalAppExitA (UINT action, LPCSTR str)
 
void WINAPI DECLSPEC_HOTPATCH FatalAppExitW (UINT action, LPCWSTR str)
 
BOOL WINAPI IsDebuggerPresent (void)
 
static LONG WINAPI debug_exception_handler (EXCEPTION_POINTERS *eptr)
 
void WINAPI DECLSPEC_HOTPATCH OutputDebugStringA (LPCSTR str)
 
static LONG WINAPI debug_exception_handler_wide (EXCEPTION_POINTERS *eptr)
 
void WINAPI DECLSPEC_HOTPATCH OutputDebugStringW (LPCWSTR str)
 
void WINAPI DECLSPEC_HOTPATCH RaiseException (DWORD code, DWORD flags, DWORD count, const ULONG_PTR *args)
 
void WINAPI DECLSPEC_HOTPATCH RaiseFailFastException (EXCEPTION_RECORD *record, CONTEXT *context, DWORD flags)
 
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI DECLSPEC_HOTPATCH SetUnhandledExceptionFilter (LPTOP_LEVEL_EXCEPTION_FILTER filter)
 
static void format_exception_msg (const EXCEPTION_POINTERS *ptr, char *buffer, int size)
 
static BOOL start_debugger (EXCEPTION_POINTERS *epointers, HANDLE event)
 
static BOOL start_debugger_atomic (EXCEPTION_POINTERS *epointers)
 
static BOOL check_resource_write (void *addr)
 
LONG WINAPI UnhandledExceptionFilter (EXCEPTION_POINTERS *epointers)
 
HRESULT WINAPI WerGetFlags (HANDLE process, DWORD *flags)
 
HRESULT WINAPI WerRegisterFile (const WCHAR *file, WER_REGISTER_FILE_TYPE type, DWORD flags)
 
HRESULT WINAPI WerRegisterMemoryBlock (void *block, DWORD size)
 
HRESULT WINAPI WerRegisterRuntimeExceptionModule (const WCHAR *dll, void *context)
 
HRESULT WINAPI WerSetFlags (DWORD flags)
 
HRESULT WINAPI WerUnregisterFile (const WCHAR *file)
 
HRESULT WINAPI WerUnregisterMemoryBlock (void *block)
 
HRESULT WINAPI WerUnregisterRuntimeExceptionModule (const WCHAR *dll, void *context)
 
static BOOL init_module_iterator_wow64 (struct module_iterator *iter, HANDLE process)
 
static BOOL init_module_iterator (struct module_iterator *iter, HANDLE process)
 
static int module_iterator_next (struct module_iterator *iter)
 
static BOOL get_ldr_module (HANDLE process, HMODULE module, LDR_DATA_TABLE_ENTRY *ldr_module)
 
static BOOL get_ldr_module32 (HANDLE process, HMODULE module, LDR_DATA_TABLE_ENTRY32 *ldr_module)
 
BOOL WINAPI DECLSPEC_HOTPATCH EmptyWorkingSet (HANDLE process)
 
BOOL WINAPI EnumDeviceDrivers (void **image_base, DWORD count, DWORD *needed)
 
BOOL WINAPI EnumPageFilesA (PENUM_PAGE_FILE_CALLBACKA callback, void *context)
 
BOOL WINAPI EnumPageFilesW (PENUM_PAGE_FILE_CALLBACKW callback, void *context)
 
BOOL WINAPI DECLSPEC_HOTPATCH EnumProcessModules (HANDLE process, HMODULE *module, DWORD count, DWORD *needed)
 
static void module_push (struct module_push *mp, HMODULE module)
 
static void module_push_iter (struct module_push *mp, struct module_iterator *iter)
 
static int module_push_all (struct module_push *mp, struct module_iterator *iter)
 
BOOL WINAPI EnumProcessModulesEx (HANDLE process, HMODULE *module, DWORD count, DWORD *needed, DWORD filter)
 
BOOL WINAPI EnumProcesses (DWORD *ids, DWORD count, DWORD *used)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetDeviceDriverBaseNameA (void *image_base, char *name, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetDeviceDriverBaseNameW (void *image_base, WCHAR *name, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetDeviceDriverFileNameA (void *image_base, char *name, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetDeviceDriverFileNameW (void *image_base, WCHAR *name, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetMappedFileNameA (HANDLE process, void *addr, char *name, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetMappedFileNameW (HANDLE process, void *addr, WCHAR *name, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetModuleBaseNameA (HANDLE process, HMODULE module, char *name, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetModuleBaseNameW (HANDLE process, HMODULE module, WCHAR *name, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetModuleFileNameExA (HANDLE process, HMODULE module, char *name, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetModuleFileNameExW (HANDLE process, HMODULE module, WCHAR *name, DWORD size)
 
BOOL WINAPI GetModuleInformation (HANDLE process, HMODULE module, MODULEINFO *modinfo, DWORD count)
 
BOOL WINAPI DECLSPEC_HOTPATCH GetPerformanceInfo (PPERFORMANCE_INFORMATION info, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetProcessImageFileNameA (HANDLE process, char *file, DWORD size)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetProcessImageFileNameW (HANDLE process, WCHAR *file, DWORD size)
 
BOOL WINAPI DECLSPEC_HOTPATCH GetProcessMemoryInfo (HANDLE process, PROCESS_MEMORY_COUNTERS *pmc, DWORD count)
 
BOOL WINAPI DECLSPEC_HOTPATCH GetWsChanges (HANDLE process, PSAPI_WS_WATCH_INFORMATION *info, DWORD size)
 
BOOL WINAPI DECLSPEC_HOTPATCH GetWsChangesEx (HANDLE process, PSAPI_WS_WATCH_INFORMATION_EX *info, DWORD *size)
 
BOOL WINAPI InitializeProcessForWsWatch (HANDLE process)
 
BOOL WINAPI DECLSPEC_HOTPATCH QueryWorkingSet (HANDLE process, void *buffer, DWORD size)
 
BOOL WINAPI QueryWorkingSetEx (HANDLE process, void *buffer, DWORD size)
 
BOOL WINAPI DECLSPEC_HOTPATCH QueryFullProcessImageNameA (HANDLE process, DWORD flags, char *name, DWORD *size)
 
BOOL WINAPI DECLSPEC_HOTPATCH QueryFullProcessImageNameW (HANDLE process, DWORD flags, WCHAR *name, DWORD *size)
 

Variables

static PTOP_LEVEL_EXCEPTION_FILTER top_filter
 
voiddummy = RtlUnwind
 

Macro Definition Documentation

◆ PSAPI_VERSION

#define PSAPI_VERSION   1 /* avoid K32 function remapping */

Definition at line 33 of file debug.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 26 of file debug.c.

Typedef Documentation

◆ LDR_DATA_TABLE_ENTRY32

◆ MessageBoxA_funcptr

typedef INT(WINAPI * MessageBoxA_funcptr) (HWND, LPCSTR, LPCSTR, UINT)

Definition at line 45 of file debug.c.

◆ MessageBoxW_funcptr

typedef INT(WINAPI * MessageBoxW_funcptr) (HWND, LPCWSTR, LPCWSTR, UINT)

Definition at line 46 of file debug.c.

Function Documentation

◆ check_resource_write()

static BOOL check_resource_write ( void addr)
static

Definition at line 713 of file debug.c.

714{
715 DWORD old_prot;
716 void *rsrc;
717 DWORD size;
719
720 if (!VirtualQuery( addr, &info, sizeof(info) )) return FALSE;
721 if (info.State == MEM_FREE || !(info.Type & MEM_IMAGE)) return FALSE;
722 if (!(rsrc = RtlImageDirectoryEntryToData( info.AllocationBase, TRUE,
724 return FALSE;
725 if (addr < rsrc || (char *)addr >= (char *)rsrc + size) return FALSE;
726 TRACE( "Broken app is writing to the resource data, enabling work-around\n" );
727 VirtualProtect( rsrc, size, PAGE_READWRITE, &old_prot );
728 return TRUE;
729}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLenum const GLvoid * addr
Definition: glext.h:9621
#define MEM_IMAGE
Definition: mmtypes.h:89
#define MEM_FREE
Definition: nt_native.h:1317
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pedump.c:261
#define TRACE(s)
Definition: solgame.cpp:4
BOOL NTAPI VirtualProtect(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flNewProtect, OUT PDWORD lpflOldProtect)
Definition: virtmem.c:135
SIZE_T NTAPI VirtualQuery(IN LPCVOID lpAddress, OUT PMEMORY_BASIC_INFORMATION lpBuffer, IN SIZE_T dwLength)
Definition: virtmem.c:211

Referenced by UnhandledExceptionFilter().

◆ CheckRemoteDebuggerPresent()

BOOL WINAPI DECLSPEC_HOTPATCH CheckRemoteDebuggerPresent ( HANDLE  process,
BOOL present 
)

Definition at line 55 of file debug.c.

56{
58
59 if (!process || !present)
60 {
62 return FALSE;
63 }
65 return FALSE;
66 *present = !!port;
67 return TRUE;
68}
@ ProcessDebugPort
Definition: cicbase.cpp:45
#define NULL
Definition: types.h:112
static __inline BOOL set_ntstatus(NTSTATUS status)
Definition: security.c:227
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
USHORT port
Definition: uri.c:228
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
uint32_t DWORD_PTR
Definition: typedefs.h:65

◆ ContinueDebugEvent()

BOOL WINAPI DECLSPEC_HOTPATCH ContinueDebugEvent ( DWORD  pid,
DWORD  tid,
DWORD  status 
)

Definition at line 74 of file debug.c.

75{
77
78 id.UniqueProcess = ULongToHandle( pid );
79 id.UniqueThread = ULongToHandle( tid );
80 return set_ntstatus( DbgUiContinue( &id, status ));
81}
#define ULongToHandle(h)
Definition: basetsd.h:81
NTSTATUS NTAPI DbgUiContinue(IN PCLIENT_ID ClientId, IN NTSTATUS ContinueStatus)
Definition: dbgui.c:47
GLuint id
Definition: glext.h:5910
static TfClientId tid
Definition: ps.c:97
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3837

◆ debug_exception_handler()

static LONG WINAPI debug_exception_handler ( EXCEPTION_POINTERS eptr)
static

Definition at line 173 of file debug.c.

174{
177}
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:91
#define DBG_PRINTEXCEPTION_C
Definition: ntstatus.h:53
PEXCEPTION_RECORD ExceptionRecord
Definition: rtltypes.h:200
DWORD ExceptionCode
Definition: compat.h:208

Referenced by OutputDebugStringA().

◆ debug_exception_handler_wide()

static LONG WINAPI debug_exception_handler_wide ( EXCEPTION_POINTERS eptr)
static

Definition at line 268 of file debug.c.

269{
272}
#define DBG_PRINTEXCEPTION_WIDE_C
Definition: winnt_old.h:147

Referenced by OutputDebugStringW().

◆ DebugActiveProcess()

BOOL WINAPI DECLSPEC_HOTPATCH DebugActiveProcess ( DWORD  pid)

Definition at line 87 of file debug.c.

88{
91
92 if (!set_ntstatus( DbgUiConnectToDbg() )) return FALSE;
95 return FALSE;
98 return set_ntstatus( status );
99}
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI DbgUiDebugActiveProcess(IN HANDLE Process)
Definition: dbgui.c:355
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
#define PROCESS_SUSPEND_RESUME
Definition: pstypes.h:168
#define PROCESS_VM_READ
Definition: pstypes.h:162
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:167
#define PROCESS_VM_WRITE
Definition: pstypes.h:163
#define PROCESS_CREATE_THREAD
Definition: pstypes.h:159
NTSYSAPI NTSTATUS WINAPI DbgUiConnectToDbg(void)
Definition: dbgui.c:25
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402

◆ DebugActiveProcessStop()

BOOL WINAPI DECLSPEC_HOTPATCH DebugActiveProcessStop ( DWORD  pid)

Definition at line 105 of file debug.c.

106{
109
111 return FALSE;
113 NtClose( process );
114 return set_ntstatus( status );
115}
NTSTATUS NTAPI DbgUiStopDebugging(IN HANDLE Process)
Definition: dbgui.c:381

◆ EmptyWorkingSet()

BOOL WINAPI DECLSPEC_HOTPATCH EmptyWorkingSet ( HANDLE  process)

Definition at line 1014 of file debug.c.

1015{
1016 return SetProcessWorkingSetSizeEx( process, (SIZE_T)-1, (SIZE_T)-1, 0 );
1017}
BOOL WINAPI SetProcessWorkingSetSizeEx(IN HANDLE hProcess, IN SIZE_T dwMinimumWorkingSetSize, IN SIZE_T dwMaximumWorkingSetSize, IN DWORD Flags)
Definition: proc.c:1027
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by test_ws_functions().

◆ EnumDeviceDrivers()

BOOL WINAPI EnumDeviceDrivers ( void **  image_base,
DWORD  count,
DWORD needed 
)

Definition at line 1024 of file debug.c.

1025{
1026 FIXME( "(%p, %ld, %p): stub\n", image_base, count, needed );
1027 if (needed) *needed = 0;
1028 return TRUE;
1029}
#define FIXME(fmt,...)
Definition: precomp.h:53
static void * image_base(void)
Definition: dll_register.c:28
GLuint GLuint GLsizei count
Definition: gl.h:1545

◆ EnumPageFilesA()

BOOL WINAPI EnumPageFilesA ( PENUM_PAGE_FILE_CALLBACKA  callback,
void context 
)

Definition at line 1036 of file debug.c.

1037{
1038 FIXME( "(%p, %p) stub\n", callback, context );
1039 return FALSE;
1040}
static IPrintDialogCallback callback
Definition: printdlg.c:326
Definition: http.c:7252

◆ EnumPageFilesW()

BOOL WINAPI EnumPageFilesW ( PENUM_PAGE_FILE_CALLBACKW  callback,
void context 
)

Definition at line 1047 of file debug.c.

1048{
1049 FIXME( "(%p, %p) stub\n", callback, context );
1050 return FALSE;
1051}

◆ EnumProcesses()

BOOL WINAPI EnumProcesses ( DWORD ids,
DWORD  count,
DWORD used 
)

Definition at line 1204 of file debug.c.

1205{
1207 ULONG size = 0x4000;
1208 void *buf = NULL;
1210
1211 do
1212 {
1213 size *= 2;
1214 HeapFree( GetProcessHeap(), 0, buf );
1215 if (!(buf = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
1218
1219 if (!set_ntstatus( status ))
1220 {
1221 HeapFree( GetProcessHeap(), 0, buf );
1222 return FALSE;
1223 }
1224 spi = buf;
1225 for (*used = 0; count >= sizeof(DWORD); count -= sizeof(DWORD))
1226 {
1227 *ids++ = HandleToUlong( spi->UniqueProcessId );
1228 *used += sizeof(DWORD);
1229 if (spi->NextEntryOffset == 0) break;
1230 spi = (SYSTEM_PROCESS_INFORMATION *)(((PCHAR)spi) + spi->NextEntryOffset);
1231 }
1232 HeapFree( GetProcessHeap(), 0, buf );
1233 return TRUE;
1234}
static int used
Definition: adh-main.c:39
#define HandleToUlong(h)
Definition: basetsd.h:79
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
@ SystemProcessInformation
Definition: ntddk_ex.h:16
GLuint * ids
Definition: glext.h:5907
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define DWORD
Definition: nt_native.h:44
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133

Referenced by enumerate_processes(), ProcessList_Update(), and test_EnumProcesses().

◆ EnumProcessModules()

BOOL WINAPI DECLSPEC_HOTPATCH EnumProcessModules ( HANDLE  process,
HMODULE module,
DWORD  count,
DWORD needed 
)

Definition at line 1058 of file debug.c.

1060{
1061 return EnumProcessModulesEx( process, module, count, needed, LIST_MODULES_DEFAULT );
1062}
BOOL WINAPI EnumProcessModulesEx(HANDLE process, HMODULE *module, DWORD count, DWORD *needed, DWORD filter)
Definition: debug.c:1104

Referenced by debug_target_init_modules_info(), DllMain(), EnumerateLoadedModulesW64(), get_process_name_from_pid(), and test_EnumProcessModules().

◆ EnumProcessModulesEx()

BOOL WINAPI EnumProcessModulesEx ( HANDLE  process,
HMODULE module,
DWORD  count,
DWORD needed,
DWORD  filter 
)

Definition at line 1104 of file debug.c.

1106{
1107 struct module_push mp = {module, count, 0};
1108 unsigned list_mode;
1109 BOOL target_wow64;
1110 INT ret = 0;
1111
1112 TRACE( "(%p, %p, %ld, %p, %ld)\n", process, module, count, needed, filter );
1113
1114 if (process != GetCurrentProcess())
1115 {
1116 if (!IsWow64Process( process, &target_wow64 )) return FALSE;
1117 }
1118 else target_wow64 = is_wow64;
1119
1120 if (filter & ~LIST_MODULES_ALL)
1121 {
1123 return FALSE;
1124 }
1125 list_mode = filter & LIST_MODULES_ALL;
1126 /* Can't access 64bit process from (wow64) 32bit */
1127 if (is_wow64 && !target_wow64)
1128 {
1130 return FALSE;
1131 }
1132 if (count && !module)
1133 {
1135 return FALSE;
1136 }
1137
1138 if (process == GetCurrentProcess())
1139 {
1140 if (!(is_win64 && list_mode == LIST_MODULES_32BIT))
1141 {
1142 PPEB_LDR_DATA ldr_data = NtCurrentTeb()->Peb->LdrData;
1144 PLIST_ENTRY entry = head->Flink;
1145
1146 while (entry != head)
1147 {
1149 module_push( &mp, ldr->DllBase );
1150 entry = entry->Flink;
1151 }
1152 }
1153 }
1154 else
1155 {
1156 struct module_iterator iter;
1157
1158 if (is_win64 && target_wow64 && (list_mode & LIST_MODULES_32BIT))
1159 {
1160 if (!init_module_iterator_wow64( &iter, process ) || module_push_all( &mp, &iter ) < 0)
1161 return FALSE;
1162 }
1163 if (!(is_win64 && list_mode == LIST_MODULES_32BIT))
1164 {
1165 if (init_module_iterator( &iter, process ))
1166 {
1167 if (is_win64 && target_wow64 && (list_mode & LIST_MODULES_64BIT))
1168 /* Don't add main module twice in _ALL mode */
1169 ret = module_iterator_next( &iter );
1170 if (ret >= 0) ret = module_push_all( &mp, &iter );
1171 }
1172 else if (GetLastError() == ERROR_EMPTY)
1173 {
1174 /* We're running on "old" wow configuration.
1175 * Fallback to PEB32 to get at least main module if requested.
1176 */
1177 if (list_mode == LIST_MODULES_DEFAULT)
1178 {
1179 if (init_module_iterator_wow64( &iter, process ) && module_iterator_next( &iter ) > 0)
1180 module_push_iter( &mp, &iter );
1181 else
1182 ret = -1;
1183 }
1184 }
1185 else
1186 return FALSE;
1187 }
1188 }
1189
1190 if (!needed)
1191 {
1193 return FALSE;
1194 }
1195 *needed = mp.size;
1196 return ret == 0;
1197}
struct outqueuenode * head
Definition: adnsresfilter.c:66
#define GetCurrentProcess()
Definition: compat.h:759
#define IsWow64Process
Definition: compat.h:760
static void module_push_iter(struct module_push *mp, struct module_iterator *iter)
Definition: debug.c:1082
static int module_push_all(struct module_push *mp, struct module_iterator *iter)
Definition: debug.c:1090
static int module_iterator_next(struct module_iterator *iter)
Definition: debug.c:935
static BOOL init_module_iterator_wow64(struct module_iterator *iter, HANDLE process)
Definition: debug.c:881
static BOOL init_module_iterator(struct module_iterator *iter, HANDLE process)
Definition: debug.c:904
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
#define NtCurrentTeb
uint32_t entry
Definition: isohybrid.c:63
BOOL is_wow64
Definition: main.c:38
static const BOOL is_win64
Definition: kernelbase.h:49
Definition: btrfs_drv.h:1876
PVOID DllBase
Definition: btrfs_drv.h:1880
Definition: typedefs.h:120
LIST_ENTRY InLoadOrderModuleList
Definition: ldrtypes.h:124
unsigned size
Definition: debug.c:1069
HMODULE * module
Definition: debug.c:1067
int32_t INT
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_PARTIAL_COPY
Definition: winerror.h:303
#define ERROR_EMPTY
Definition: winerror.h:1250
#define ERROR_NOACCESS
Definition: winerror.h:578

Referenced by EnumProcessModules().

◆ FatalAppExitA()

void WINAPI DECLSPEC_HOTPATCH FatalAppExitA ( UINT  action,
LPCSTR  str 
)

Definition at line 137 of file debug.c.

138{
139 HMODULE mod = GetModuleHandleA( "user32.dll" );
140 MessageBoxA_funcptr pMessageBoxA = NULL;
141
142 if (mod) pMessageBoxA = (MessageBoxA_funcptr)GetProcAddress( mod, "MessageBoxA" );
143 if (pMessageBoxA) pMessageBoxA( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
144 else ERR( "%s\n", debugstr_a(str) );
146}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
#define ERR(fmt,...)
Definition: precomp.h:57
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
INT(WINAPI * MessageBoxA_funcptr)(HWND, LPCSTR, LPCSTR, UINT)
Definition: debug.c:45
NTSYSAPI void DECLSPEC_NORETURN WINAPI RtlExitUserProcess(ULONG)
#define debugstr_a
Definition: kernel32.h:31
const WCHAR * str
#define MB_SYSTEMMODAL
Definition: winuser.h:826
#define MB_OK
Definition: winuser.h:801

◆ FatalAppExitW()

void WINAPI DECLSPEC_HOTPATCH FatalAppExitW ( UINT  action,
LPCWSTR  str 
)

Definition at line 152 of file debug.c.

153{
154 HMODULE mod = GetModuleHandleW( L"user32.dll" );
155 MessageBoxW_funcptr pMessageBoxW = NULL;
156
157 if (mod) pMessageBoxW = (MessageBoxW_funcptr)GetProcAddress( mod, "MessageBoxW" );
158 if (pMessageBoxW) pMessageBoxW( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
159 else ERR( "%s\n", debugstr_w(str) );
161}
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
INT(WINAPI * MessageBoxW_funcptr)(HWND, LPCWSTR, LPCWSTR, UINT)
Definition: debug.c:46
#define L(x)
Definition: resources.c:13
#define debugstr_w
Definition: kernel32.h:32

◆ format_exception_msg()

static void format_exception_msg ( const EXCEPTION_POINTERS ptr,
char buffer,
int  size 
)
static

Definition at line 436 of file debug.c.

437{
438 const EXCEPTION_RECORD *rec = ptr->ExceptionRecord;
439 int len;
440
441 switch(rec->ExceptionCode)
442 {
444 len = snprintf( buffer, size, "Unhandled division by zero" );
445 break;
447 len = snprintf( buffer, size, "Unhandled overflow" );
448 break;
450 len = snprintf( buffer, size, "Unhandled array bounds" );
451 break;
453 len = snprintf( buffer, size, "Unhandled illegal instruction" );
454 break;
456 len = snprintf( buffer, size, "Unhandled stack overflow" );
457 break;
459 len = snprintf( buffer, size, "Unhandled privileged instruction" );
460 break;
462 if (rec->NumberParameters == 2)
463 len = snprintf( buffer, size, "Unhandled page fault on %s access to %p",
464 rec->ExceptionInformation[0] == EXCEPTION_WRITE_FAULT ? "write" :
465 rec->ExceptionInformation[0] == EXCEPTION_EXECUTE_FAULT ? "execute" : "read",
466 (void *)rec->ExceptionInformation[1]);
467 else
468 len = snprintf( buffer, size, "Unhandled page fault");
469 break;
471 len = snprintf( buffer, size, "Unhandled alignment" );
472 break;
473 case CONTROL_C_EXIT:
474 len = snprintf( buffer, size, "Unhandled ^C");
475 break;
477 len = snprintf( buffer, size, "Critical section %p wait failed",
478 (void *)rec->ExceptionInformation[0]);
479 break;
481 if ((ULONG_PTR)rec->ExceptionInformation[1] >> 16)
482 len = snprintf( buffer, size, "Unimplemented function %s.%s called",
483 (char *)rec->ExceptionInformation[0], (char *)rec->ExceptionInformation[1] );
484 else
485 len = snprintf( buffer, size, "Unimplemented function %s.%Id called",
486 (char *)rec->ExceptionInformation[0], rec->ExceptionInformation[1] );
487 break;
489 len = snprintf( buffer, size, "Assertion failed" );
490 break;
491 default:
492 len = snprintf( buffer, size, "Unhandled exception 0x%08lx in thread %lx",
494 break;
495 }
496 if (len < 0 || len >= size) return;
497 snprintf( buffer + len, size - len, " at address %p", ptr->ExceptionRecord->ExceptionAddress );
498}
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
static PVOID ptr
Definition: dispmode.c:27
#define STATUS_POSSIBLE_DEADLOCK
Definition: ntstatus.h:637
#define EXCEPTION_WINE_ASSERTION
Definition: exception.h:22
#define EXCEPTION_WRITE_FAULT
#define EXCEPTION_EXECUTE_FAULT
DWORD NumberParameters
Definition: compat.h:212
ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]
Definition: compat.h:213
#define EXCEPTION_WINE_STUB
Definition: stubs.h:31
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define EXCEPTION_STACK_OVERFLOW
Definition: winbase.h:362
#define CONTROL_C_EXIT
Definition: winbase.h:366
#define EXCEPTION_INT_DIVIDE_BY_ZERO
Definition: winbase.h:356
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
#define EXCEPTION_INT_OVERFLOW
Definition: winbase.h:357
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED
Definition: winbase.h:348
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: winbase.h:345
#define EXCEPTION_ILLEGAL_INSTRUCTION
Definition: winbase.h:360
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:344
#define EXCEPTION_PRIV_INSTRUCTION
Definition: winbase.h:358
#define snprintf
Definition: wintirpc.h:48

Referenced by start_debugger().

◆ get_ldr_module()

static BOOL get_ldr_module ( HANDLE  process,
HMODULE  module,
LDR_DATA_TABLE_ENTRY ldr_module 
)
static

Definition at line 961 of file debug.c.

962{
963 struct module_iterator iter;
964 INT ret;
965
966 if (!init_module_iterator( &iter, process )) return FALSE;
967
968 while ((ret = module_iterator_next( &iter )) > 0)
969 /* When hModule is NULL we return the process image - which will be
970 * the first module since our iterator uses InLoadOrderModuleList */
971 if (!module || module == iter.ldr_module.DllBase)
972 {
973 *ldr_module = iter.ldr_module;
974 return TRUE;
975 }
976
978 return FALSE;
979}
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
LDR_DATA_TABLE_ENTRY ldr_module
Definition: debug.c:876

Referenced by GetModuleBaseNameW(), GetModuleFileNameExW(), and GetModuleInformation().

◆ get_ldr_module32()

static BOOL get_ldr_module32 ( HANDLE  process,
HMODULE  module,
LDR_DATA_TABLE_ENTRY32 ldr_module 
)
static

Definition at line 982 of file debug.c.

983{
984 struct module_iterator iter;
985 INT ret;
986
987#ifdef _WIN64
988 if ((ULONG_PTR)module >> 32)
989 {
991 return FALSE;
992 }
993#endif
994 if (!init_module_iterator_wow64( &iter, process )) return FALSE;
995
996 while ((ret = module_iterator_next( &iter )) > 0)
997 /* When hModule is NULL we return the process image - which will be
998 * the first module since our iterator uses InLoadOrderModuleList */
999 if (!module || (DWORD)(DWORD_PTR)module == iter.ldr_module32.BaseAddress)
1000 {
1001 *ldr_module = iter.ldr_module32;
1002 return TRUE;
1003 }
1004
1006 return FALSE;
1007}

Referenced by GetModuleBaseNameW(), GetModuleFileNameExW(), and GetModuleInformation().

◆ GetDeviceDriverBaseNameA()

DWORD WINAPI DECLSPEC_HOTPATCH GetDeviceDriverBaseNameA ( void image_base,
char name,
DWORD  size 
)

Definition at line 1241 of file debug.c.

1242{
1243 FIXME( "(%p, %p, %ld): stub\n", image_base, name, size );
1244 if (name && size) name[0] = 0;
1245 return 0;
1246}
Definition: name.c:39

◆ GetDeviceDriverBaseNameW()

DWORD WINAPI DECLSPEC_HOTPATCH GetDeviceDriverBaseNameW ( void image_base,
WCHAR name,
DWORD  size 
)

Definition at line 1253 of file debug.c.

1254{
1255 FIXME( "(%p, %p, %ld): stub\n", image_base, name, size );
1256 if (name && size) name[0] = 0;
1257 return 0;
1258}

◆ GetDeviceDriverFileNameA()

DWORD WINAPI DECLSPEC_HOTPATCH GetDeviceDriverFileNameA ( void image_base,
char name,
DWORD  size 
)

Definition at line 1265 of file debug.c.

1266{
1267 FIXME( "(%p, %p, %ld): stub\n", image_base, name, size );
1268 if (name && size) name[0] = 0;
1269 return 0;
1270}

◆ GetDeviceDriverFileNameW()

DWORD WINAPI DECLSPEC_HOTPATCH GetDeviceDriverFileNameW ( void image_base,
WCHAR name,
DWORD  size 
)

Definition at line 1277 of file debug.c.

1278{
1279 FIXME( "(%p, %p, %ld): stub\n", image_base, name, size );
1280 if (name && size) name[0] = 0;
1281 return 0;
1282}

◆ GetMappedFileNameA()

DWORD WINAPI DECLSPEC_HOTPATCH GetMappedFileNameA ( HANDLE  process,
void addr,
char name,
DWORD  size 
)

Definition at line 1289 of file debug.c.

1290{
1292 DWORD len;
1293
1294 if (size && !name)
1295 {
1297 return 0;
1298 }
1299 if (!GetMappedFileNameW( process, addr, nameW, MAX_PATH )) return 0;
1300 if (!size)
1301 {
1303 return 0;
1304 }
1306 name[min(len, size - 1)] = 0;
1307 return len;
1308}
static const WCHAR nameW[]
Definition: main.c:49
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI DECLSPEC_HOTPATCH GetMappedFileNameW(HANDLE process, void *addr, WCHAR *name, DWORD size)
Definition: debug.c:1315
DWORD file_name_WtoA(LPCWSTR src, INT srclen, LPSTR dest, INT destlen)
Definition: file.c:438
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define min(a, b)
Definition: monoChain.cc:55
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by test_GetMappedFileName(), and test_GetProcessImageFileName().

◆ GetMappedFileNameW()

DWORD WINAPI DECLSPEC_HOTPATCH GetMappedFileNameW ( HANDLE  process,
void addr,
WCHAR name,
DWORD  size 
)

Definition at line 1315 of file debug.c.

1316{
1317 ULONG_PTR buffer[(sizeof(MEMORY_SECTION_NAME) + MAX_PATH * sizeof(WCHAR)) / sizeof(ULONG_PTR)];
1319 DWORD len;
1320
1321 if (size && !name)
1322 {
1324 return 0;
1325 }
1327 mem, sizeof(buffer), NULL )))
1328 return 0;
1329
1330 len = mem->SectionFileName.Length / sizeof(WCHAR);
1331 memcpy( name, mem->SectionFileName.Buffer, min( mem->SectionFileName.Length, size * sizeof(WCHAR) ));
1333 name[min(len, size - 1)] = 0;
1334 return len;
1335}
@ MemoryMappedFilenameInformation
Definition: winternl.h:2387
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
NTSTATUS NTAPI NtQueryVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN MEMORY_INFORMATION_CLASS MemoryInformationClass, OUT PVOID MemoryInformation, IN SIZE_T MemoryInformationLength, OUT PSIZE_T ReturnLength)
Definition: virtual.c:4369
Definition: mem.c:349

Referenced by GetMappedFileNameA(), and test_GetMappedFileName().

◆ GetModuleBaseNameA()

DWORD WINAPI DECLSPEC_HOTPATCH GetModuleBaseNameA ( HANDLE  process,
HMODULE  module,
char name,
DWORD  size 
)

Definition at line 1342 of file debug.c.

1344{
1345 WCHAR *name_w;
1346 DWORD len, ret = 0;
1347
1348 if (!name || !size)
1349 {
1351 return 0;
1352 }
1353 if (!(name_w = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR) * size ))) return 0;
1354
1355 len = GetModuleBaseNameW( process, module, name_w, size );
1356 TRACE( "%ld, %s\n", len, debugstr_w(name_w) );
1357 if (len)
1358 {
1359 ret = WideCharToMultiByte( CP_ACP, 0, name_w, len, name, size, NULL, NULL );
1360 if (ret < size) name[ret] = 0;
1361 }
1362 HeapFree( GetProcessHeap(), 0, name_w );
1363 return ret;
1364}
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
DWORD WINAPI DECLSPEC_HOTPATCH GetModuleBaseNameW(HANDLE process, HMODULE module, WCHAR *name, DWORD size)
Definition: debug.c:1371

Referenced by test_EnumProcessModules(), and test_GetModuleBaseName().

◆ GetModuleBaseNameW()

DWORD WINAPI DECLSPEC_HOTPATCH GetModuleBaseNameW ( HANDLE  process,
HMODULE  module,
WCHAR name,
DWORD  size 
)

Definition at line 1371 of file debug.c.

1373{
1374 BOOL wow64, found = FALSE;
1375
1376 if (!IsWow64Process( process, &wow64 )) return 0;
1377
1378 if (is_win64 && wow64)
1379 {
1380 LDR_DATA_TABLE_ENTRY32 ldr_module32;
1381
1382 if (get_ldr_module32(process, module, &ldr_module32))
1383 {
1384 size = min( ldr_module32.BaseDllName.Length / sizeof(WCHAR), size );
1385 if (ReadProcessMemory( process, (void *)(DWORD_PTR)ldr_module32.BaseDllName.Buffer,
1386 name, size * sizeof(WCHAR), NULL ))
1387 found = TRUE;
1388 }
1389 }
1390 if (!found)
1391 {
1392 LDR_DATA_TABLE_ENTRY ldr_module;
1393
1394 if (!get_ldr_module( process, module, &ldr_module )) return 0;
1395 size = min( ldr_module.BaseDllName.Length / sizeof(WCHAR), size );
1396 if (!ReadProcessMemory( process, ldr_module.BaseDllName.Buffer,
1397 name, size * sizeof(WCHAR), NULL ))
1398 return 0;
1399 }
1400 name[size] = 0;
1401 return size;
1402}
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:758
static BOOL get_ldr_module(HANDLE process, HMODULE module, LDR_DATA_TABLE_ENTRY *ldr_module)
Definition: debug.c:961
static BOOL get_ldr_module32(HANDLE process, HMODULE module, LDR_DATA_TABLE_ENTRY32 *ldr_module)
Definition: debug.c:982
static BOOL wow64
Definition: psapi_main.c:44
UNICODE_STRING32 BaseDllName
Definition: debug.c:867
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:149
ULONG Buffer
Definition: umtypes.h:167
USHORT Length
Definition: umtypes.h:165

Referenced by EnumerateLoadedModulesW64(), get_process_name_from_pid(), GetModuleBaseNameA(), and GetOwnerModuleFromPidEntry().

◆ GetModuleFileNameExA()

DWORD WINAPI DECLSPEC_HOTPATCH GetModuleFileNameExA ( HANDLE  process,
HMODULE  module,
char name,
DWORD  size 
)

Definition at line 1409 of file debug.c.

1411{
1412 WCHAR *ptr;
1413 DWORD len;
1414
1415 TRACE( "(process=%p, module=%p, %p, %ld)\n", process, module, name, size );
1416
1417 if (!name || !size)
1418 {
1420 return 0;
1421 }
1422 if (process == GetCurrentProcess())
1423 {
1425 name[size - 1] = '\0';
1426 return len;
1427 }
1428
1429 if (!(ptr = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return 0;
1431 if (!len)
1432 {
1433 name[0] = 0;
1434 }
1435 else
1436 {
1437 if (!WideCharToMultiByte( CP_ACP, 0, ptr, -1, name, size, NULL, NULL ))
1438 {
1439 name[size - 1] = 0;
1440 len = size;
1441 }
1442 else if (len < size) len = strlen( name );
1443 }
1444 HeapFree( GetProcessHeap(), 0, ptr );
1445 return len;
1446}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define GetModuleFileNameExW(w, x, y, z)
Definition: compat.h:922
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539

Referenced by debug_target_init_modules_info(), test_EnumProcessModules(), test_GetModuleFileNameEx(), and ModuleData::Update().

◆ GetModuleFileNameExW()

DWORD WINAPI DECLSPEC_HOTPATCH GetModuleFileNameExW ( HANDLE  process,
HMODULE  module,
WCHAR name,
DWORD  size 
)

Definition at line 1453 of file debug.c.

1455{
1456 BOOL wow64, found = FALSE;
1457 DWORD len = 0;
1458
1459 if (!size) return 0;
1460
1461 if (!IsWow64Process( process, &wow64 )) return 0;
1462
1463 if (is_win64 && wow64)
1464 {
1465 LDR_DATA_TABLE_ENTRY32 ldr_module32;
1466
1467 if (get_ldr_module32( process, module, &ldr_module32 ))
1468 {
1469 len = ldr_module32.FullDllName.Length / sizeof(WCHAR);
1470 if (ReadProcessMemory( process, (void *)(DWORD_PTR)ldr_module32.FullDllName.Buffer,
1471 name, min( len, size ) * sizeof(WCHAR), NULL ))
1472 found = TRUE;
1473 }
1474 }
1475 if (!found)
1476 {
1477 LDR_DATA_TABLE_ENTRY ldr_module;
1478
1479 if (!get_ldr_module(process, module, &ldr_module)) return 0;
1480 len = ldr_module.FullDllName.Length / sizeof(WCHAR);
1481 if (!ReadProcessMemory( process, ldr_module.FullDllName.Buffer,
1482 name, min( len, size ) * sizeof(WCHAR), NULL ))
1483 return 0;
1484 }
1485
1486 if (len < size)
1487 {
1488 name[len] = 0;
1489 return len;
1490 }
1491 else
1492 {
1493 name[size - 1] = 0;
1494 return size;
1495 }
1496}
UNICODE_STRING32 FullDllName
Definition: debug.c:866
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1882

◆ GetModuleInformation()

BOOL WINAPI GetModuleInformation ( HANDLE  process,
HMODULE  module,
MODULEINFO modinfo,
DWORD  count 
)

Definition at line 1503 of file debug.c.

1504{
1505 BOOL wow64, found = FALSE;
1506
1507 if (count < sizeof(MODULEINFO))
1508 {
1510 return FALSE;
1511 }
1512
1513 if (!IsWow64Process( process, &wow64 )) return FALSE;
1514
1515 if (is_win64 && wow64)
1516 {
1517 LDR_DATA_TABLE_ENTRY32 ldr_module32;
1518
1519 if (get_ldr_module32( process, module, &ldr_module32 ))
1520 {
1521 modinfo->lpBaseOfDll = (void *)(DWORD_PTR)ldr_module32.BaseAddress;
1522 modinfo->SizeOfImage = ldr_module32.SizeOfImage;
1523 modinfo->EntryPoint = (void *)(DWORD_PTR)ldr_module32.EntryPoint;
1524 found = TRUE;
1525 }
1526 }
1527 if (!found)
1528 {
1529 LDR_DATA_TABLE_ENTRY ldr_module;
1530
1531 if (!get_ldr_module( process, module, &ldr_module )) return FALSE;
1532 modinfo->lpBaseOfDll = ldr_module.DllBase;
1533 modinfo->SizeOfImage = ldr_module.SizeOfImage;
1534 modinfo->EntryPoint = ldr_module.EntryPoint;
1535 }
1536 return TRUE;
1537}
static HMODULE MODULEINFO * modinfo
Definition: module.c:33
PVOID EntryPoint
Definition: ntddk_ex.h:203
ULONG SizeOfImage
Definition: ldrtypes.h:147

Referenced by debug_target_init_modules_info(), EnumerateLoadedModulesW64(), test_EnumProcessModules(), test_GetModuleInformation(), and ModuleData::Update().

◆ GetPerformanceInfo()

BOOL WINAPI DECLSPEC_HOTPATCH GetPerformanceInfo ( PPERFORMANCE_INFORMATION  info,
DWORD  size 
)

Definition at line 1544 of file debug.c.

1545{
1549 DWORD info_size;
1551
1552 TRACE( "(%p, %ld)\n", info, size );
1553
1554 if (size < sizeof(*info))
1555 {
1557 return FALSE;
1558 }
1559
1561 if (!set_ntstatus( status )) return FALSE;
1562 status = NtQuerySystemInformation( SystemBasicInformation, &basic, sizeof(basic), NULL );
1563 if (!set_ntstatus( status )) return FALSE;
1564
1565 info->cb = sizeof(*info);
1566 info->CommitTotal = perf.TotalCommittedPages;
1567 info->CommitLimit = perf.TotalCommitLimit;
1568 info->CommitPeak = perf.PeakCommitment;
1569 info->PhysicalTotal = basic.MmNumberOfPhysicalPages;
1570 info->PhysicalAvailable = perf.AvailablePages;
1571 info->SystemCache = 0;
1572 info->KernelTotal = perf.PagedPoolUsage + perf.NonPagedPoolUsage;
1573 info->KernelPaged = perf.PagedPoolUsage;
1574 info->KernelNonpaged = perf.NonPagedPoolUsage;
1575 info->PageSize = basic.PageSize;
1576
1577 /* fields from SYSTEM_PROCESS_INFORMATION */
1579 for (;;)
1580 {
1581 process = HeapAlloc( GetProcessHeap(), 0, info_size );
1582 if (!process)
1583 {
1585 return FALSE;
1586 }
1588 if (!status) break;
1591 {
1593 return FALSE;
1594 }
1595 }
1596 info->HandleCount = info->ProcessCount = info->ThreadCount = 0;
1597 spi = process;
1598 for (;;)
1599 {
1600 info->ProcessCount++;
1601 info->HandleCount += spi->HandleCount;
1602 info->ThreadCount += spi->dwThreadCount;
1603 if (spi->NextEntryOffset == 0) break;
1604 spi = (SYSTEM_PROCESS_INFORMATION *)((char *)spi + spi->NextEntryOffset);
1605 }
1607 return TRUE;
1608}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
@ SystemBasicInformation
Definition: ntddk_ex.h:11
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define SystemPerformanceInformation
Definition: memtest.h:87
#define ERROR_BAD_LENGTH
Definition: winerror.h:127

Referenced by test_GetPerformanceInfo().

◆ GetProcessImageFileNameA()

DWORD WINAPI DECLSPEC_HOTPATCH GetProcessImageFileNameA ( HANDLE  process,
char file,
DWORD  size 
)

Definition at line 1615 of file debug.c.

1616{
1618}
BOOL WINAPI DECLSPEC_HOTPATCH QueryFullProcessImageNameA(HANDLE process, DWORD flags, char *name, DWORD *size)
Definition: debug.c:1725
Definition: fci.c:127
#define PROCESS_NAME_NATIVE
Definition: winbase.h:31

Referenced by test_GetProcessImageFileName().

◆ GetProcessImageFileNameW()

DWORD WINAPI DECLSPEC_HOTPATCH GetProcessImageFileNameW ( HANDLE  process,
WCHAR file,
DWORD  size 
)

Definition at line 1625 of file debug.c.

1626{
1628}
BOOL WINAPI DECLSPEC_HOTPATCH QueryFullProcessImageNameW(HANDLE process, DWORD flags, WCHAR *name, DWORD *size)
Definition: debug.c:1743

Referenced by NonConsoleProcessShutdown(), test_GetProcessImageFileName(), and UserClientShutdown().

◆ GetProcessMemoryInfo()

BOOL WINAPI DECLSPEC_HOTPATCH GetProcessMemoryInfo ( HANDLE  process,
PROCESS_MEMORY_COUNTERS pmc,
DWORD  count 
)

Definition at line 1635 of file debug.c.

1637{
1638 VM_COUNTERS vmc;
1639
1640 if (count < sizeof(PROCESS_MEMORY_COUNTERS))
1641 {
1643 return FALSE;
1644 }
1645
1647 return FALSE;
1648
1649 pmc->cb = sizeof(PROCESS_MEMORY_COUNTERS);
1650 pmc->PageFaultCount = vmc.PageFaultCount;
1652 pmc->WorkingSetSize = vmc.WorkingSetSize;
1657 pmc->PagefileUsage = vmc.PagefileUsage;
1659 return TRUE;
1660}
@ ProcessVmCounters
Definition: winternl.h:1885
struct _PROCESS_MEMORY_COUNTERS PROCESS_MEMORY_COUNTERS
SIZE_T PeakPagefileUsage
Definition: psapi.h:47
SIZE_T QuotaNonPagedPoolUsage
Definition: psapi.h:45
SIZE_T PeakWorkingSetSize
Definition: psapi.h:40
SIZE_T QuotaPeakNonPagedPoolUsage
Definition: psapi.h:44
SIZE_T QuotaPeakPagedPoolUsage
Definition: psapi.h:42
SIZE_T QuotaPagedPoolUsage
Definition: psapi.h:43
SIZE_T PeakWorkingSetSize
Definition: winternl.h:3134
SIZE_T PeakPagefileUsage
Definition: winternl.h:3141
ULONG PageFaultCount
Definition: winternl.h:3133
SIZE_T QuotaPagedPoolUsage
Definition: winternl.h:3137
SIZE_T QuotaPeakPagedPoolUsage
Definition: winternl.h:3136
SIZE_T QuotaPeakNonPagedPoolUsage
Definition: winternl.h:3138
SIZE_T QuotaNonPagedPoolUsage
Definition: winternl.h:3139
SIZE_T WorkingSetSize
Definition: winternl.h:3135
SIZE_T PagefileUsage
Definition: winternl.h:3140

Referenced by test_GetProcessMemoryInfo().

◆ GetWsChanges()

BOOL WINAPI DECLSPEC_HOTPATCH GetWsChanges ( HANDLE  process,
PSAPI_WS_WATCH_INFORMATION info,
DWORD  size 
)

Definition at line 1667 of file debug.c.

1668{
1669 TRACE( "(%p, %p, %ld)\n", process, info, size );
1671}
@ ProcessWorkingSetWatch
Definition: winternl.h:1897

Referenced by test_ws_functions().

◆ GetWsChangesEx()

BOOL WINAPI DECLSPEC_HOTPATCH GetWsChangesEx ( HANDLE  process,
PSAPI_WS_WATCH_INFORMATION_EX *  info,
DWORD size 
)

Definition at line 1678 of file debug.c.

1680{
1681 FIXME( "(%p, %p, %p)\n", process, info, size );
1683 return FALSE;
1684}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102

◆ init_module_iterator()

static BOOL init_module_iterator ( struct module_iterator iter,
HANDLE  process 
)
static

Definition at line 904 of file debug.c.

905{
907 PPEB_LDR_DATA ldr_data;
908
909 iter->wow64 = FALSE;
911 &pbi, sizeof(pbi), NULL )))
912 return FALSE;
913
914 /* read address of LdrData from PEB */
915 if (!ReadProcessMemory( process, &pbi.PebBaseAddress->LdrData, &ldr_data, sizeof(ldr_data), NULL ))
916 return FALSE;
917
918 /* This happens when running "old" wow64 configuration. Mark it as such. */
919 if (!ldr_data)
920 {
922 return FALSE;
923 }
924 /* read address of first module from LdrData */
926 &iter->current, sizeof(iter->current), NULL ))
927 return FALSE;
928
929 iter->head = &ldr_data->InLoadOrderModuleList;
930 iter->process = process;
931 return TRUE;
932}
@ ProcessBasicInformation
Definition: cicbase.cpp:44
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY * head
Definition: debug.c:873
LIST_ENTRY * current
Definition: debug.c:874
HANDLE process
Definition: debug.c:872
BOOL wow64
Definition: debug.c:875
_Inout_ PERBANDINFO * pbi
Definition: winddi.h:3917

Referenced by EnumProcessModulesEx(), and get_ldr_module().

◆ init_module_iterator_wow64()

static BOOL init_module_iterator_wow64 ( struct module_iterator iter,
HANDLE  process 
)
static

Definition at line 881 of file debug.c.

882{
883 PEB_LDR_DATA32 *ldr_data32_ptr;
884 DWORD ldr_data32, first_module;
885 PEB32 *peb32;
886
887 iter->wow64 = TRUE;
889 &peb32, sizeof(peb32), NULL )))
890 return FALSE;
891 if (!ReadProcessMemory( process, &peb32->LdrData, &ldr_data32, sizeof(ldr_data32), NULL ))
892 return FALSE;
893 ldr_data32_ptr = (PEB_LDR_DATA32 *)(DWORD_PTR) ldr_data32;
895 &first_module, sizeof(first_module), NULL ))
896 return FALSE;
897 iter->head = (LIST_ENTRY *)&ldr_data32_ptr->InLoadOrderModuleList;
898 iter->current = (LIST_ENTRY *)(DWORD_PTR)first_module;
899 iter->process = process;
900 return TRUE;
901}
@ ProcessWow64Information
Definition: cicbase.cpp:46
ULONG Flink
Definition: winternl.h:751
ULONG LdrData
Definition: winternl.h:937
LIST_ENTRY32 InLoadOrderModuleList
Definition: winternl.h:901
#define DWORD_PTR
Definition: treelist.c:76

Referenced by EnumProcessModulesEx(), and get_ldr_module32().

◆ InitializeProcessForWsWatch()

BOOL WINAPI InitializeProcessForWsWatch ( HANDLE  process)

Definition at line 1691 of file debug.c.

1692{
1693 FIXME( "(process=%p): stub\n", process );
1694 return TRUE;
1695}

Referenced by test_ws_functions().

◆ IsDebuggerPresent()

BOOL WINAPI IsDebuggerPresent ( void  )

Definition at line 167 of file debug.c.

168{
169 return NtCurrentTeb()->Peb->BeingDebugged;
170}

Referenced by _CrtDbgReportWindow(), common_show_message_box(), ConsoleControlDispatcher(), DbgBreakOnEvent(), init_funcs(), InitThreads(), and wmain().

◆ module_iterator_next()

static int module_iterator_next ( struct module_iterator iter)
static

Definition at line 935 of file debug.c.

936{
937 if (iter->current == iter->head) return 0;
938
939 if (is_win64 && iter->wow64)
940 {
941 LIST_ENTRY32 *entry32 = (LIST_ENTRY32 *)iter->current;
942
944 CONTAINING_RECORD(entry32, LDR_DATA_TABLE_ENTRY32, InLoadOrderModuleList),
945 &iter->ldr_module32, sizeof(iter->ldr_module32), NULL ))
946 return -1;
948 return 1;
949 }
950
951 if (!ReadProcessMemory( iter->process,
952 CONTAINING_RECORD(iter->current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks),
953 &iter->ldr_module, sizeof(iter->ldr_module), NULL ))
954 return -1;
955
957 return 1;
958}
if(dx< 0)
Definition: linetemp.h:194
$ULONG Flink
Definition: ntbasedef.h:630
LIST_ENTRY32 InLoadOrderModuleList
Definition: debug.c:860
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:142
LDR_DATA_TABLE_ENTRY32 ldr_module32
Definition: debug.c:877

Referenced by EnumProcessModulesEx(), get_ldr_module(), get_ldr_module32(), and module_push_all().

◆ module_push()

static void module_push ( struct module_push mp,
HMODULE  module 
)
static

Definition at line 1072 of file debug.c.

1073{
1074 if (mp->count >= sizeof(HMODULE))
1075 {
1076 *mp->module++ = module;
1077 mp->count -= sizeof(HMODULE);
1078 }
1079 mp->size += sizeof(HMODULE);
1080}
unsigned count
Definition: debug.c:1068
HANDLE HMODULE
Definition: typedefs.h:77

◆ module_push_all()

static int module_push_all ( struct module_push mp,
struct module_iterator iter 
)
static

Definition at line 1090 of file debug.c.

1091{
1092 int ret;
1093
1094 while ((ret = module_iterator_next( iter )) > 0)
1095 module_push_iter( mp, iter );
1096
1097 return ret;
1098}

Referenced by EnumProcessModulesEx().

◆ module_push_iter()

static void module_push_iter ( struct module_push mp,
struct module_iterator iter 
)
static

Definition at line 1082 of file debug.c.

1083{
1084 if (is_win64 && iter->wow64)
1086 else
1087 module_push( mp, iter->ldr_module.DllBase );
1088}

Referenced by EnumProcessModulesEx(), and module_push_all().

◆ OutputDebugStringA()

void WINAPI DECLSPEC_HOTPATCH OutputDebugStringA ( LPCSTR  str)

Definition at line 182 of file debug.c.

183{
184 static HANDLE DBWinMutex = NULL;
185 static BOOL mutex_inited = FALSE;
186 BOOL caught_by_dbg = TRUE;
187
188 if (!str) str = "";
189 WARN( "%s\n", debugstr_a(str) );
190
191 /* raise exception, WaitForDebugEvent() will generate a corresponding debug event */
192 __TRY
193 {
194 ULONG_PTR args[2];
195 args[0] = strlen(str) + 1;
196 args[1] = (ULONG_PTR)str;
198 }
200 {
201 caught_by_dbg = FALSE;
202 }
204 if (caught_by_dbg) return;
205
206 /* send string to a system-wide monitor */
207 if (!mutex_inited)
208 {
209 /* first call to OutputDebugString, initialize mutex handle */
210 HANDLE mutex = CreateMutexExW( NULL, L"DBWinMutex", 0, SYNCHRONIZE );
211 if (mutex)
212 {
213 if (InterlockedCompareExchangePointer( &DBWinMutex, mutex, 0 ) != 0)
214 /* someone beat us here... */
216 }
217 mutex_inited = TRUE;
218 }
219
220 if (DBWinMutex)
221 {
223
224 mapping = OpenFileMappingW( FILE_MAP_WRITE, FALSE, L"DBWIN_BUFFER" );
225 if (mapping)
226 {
228 HANDLE eventbuffer, eventdata;
229
231 eventbuffer = OpenEventW( SYNCHRONIZE, FALSE, L"DBWIN_BUFFER_READY" );
232 eventdata = OpenEventW( EVENT_MODIFY_STATE, FALSE, L"DBWIN_DATA_READY" );
233
234 if (buffer && eventbuffer && eventdata)
235 {
236 /* monitor is present, synchronize with other OutputDebugString invocations */
237 WaitForSingleObject( DBWinMutex, INFINITE );
238
239 /* acquire control over the buffer */
240 if (WaitForSingleObject( eventbuffer, 10000 ) == WAIT_OBJECT_0)
241 {
242 int str_len = strlen( str );
243 struct _mon_buffer_t
244 {
245 DWORD pid;
246 char buffer[1];
247 } *mon_buffer = (struct _mon_buffer_t*) buffer;
248
249 if (str_len > (4096 - sizeof(DWORD) - 1)) str_len = 4096 - sizeof(DWORD) - 1;
250 mon_buffer->pid = GetCurrentProcessId();
251 memcpy( mon_buffer->buffer, str, str_len );
252 mon_buffer->buffer[str_len] = 0;
253
254 /* signal data ready */
255 SetEvent( eventdata );
256 }
257 ReleaseMutex( DBWinMutex );
258 }
259
261 if (eventbuffer) CloseHandle( eventbuffer );
262 if (eventdata) CloseHandle( eventdata );
264 }
265 }
266}
#define WARN(fmt,...)
Definition: precomp.h:61
#define CloseHandle
Definition: compat.h:739
#define UnmapViewOfFile
Definition: compat.h:746
#define __TRY
Definition: compat.h:80
#define __ENDTRY
Definition: compat.h:82
#define MapViewOfFile
Definition: compat.h:745
static LONG WINAPI debug_exception_handler(EXCEPTION_POINTERS *eptr)
Definition: debug.c:173
void WINAPI DECLSPEC_HOTPATCH RaiseException(DWORD code, DWORD flags, DWORD count, const ULONG_PTR *args)
Definition: debug.c:388
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExW(SECURITY_ATTRIBUTES *sa, LPCWSTR name, DWORD flags, DWORD access)
Definition: sync.c:700
#define INFINITE
Definition: serial.h:102
#define ULONG_PTR
Definition: config.h:101
HANDLE NTAPI OpenFileMappingW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: filemap.c:297
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
#define InterlockedCompareExchangePointer
Definition: interlocked.h:144
#define SYNCHRONIZE
Definition: nt_native.h:61
#define __EXCEPT(func)
Definition: exception.h:59
Definition: match.c:390
Definition: module.h:456
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: synch.c:682
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define str_len
Definition: treelist.c:89
#define FILE_MAP_WRITE
Definition: winbase.h:162
#define EVENT_MODIFY_STATE
Definition: winbase.h:171
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
#define WAIT_OBJECT_0
Definition: winbase.h:439

Referenced by OutputDebugStringW().

◆ OutputDebugStringW()

void WINAPI DECLSPEC_HOTPATCH OutputDebugStringW ( LPCWSTR  str)

Definition at line 277 of file debug.c.

278{
280 STRING strA;
281
282 WARN( "%s\n", debugstr_w(str) );
283
286 {
287 BOOL exc_handled;
288
289 __TRY
290 {
291 ULONG_PTR args[4];
292 args[0] = wcslen(str) + 1;
293 args[1] = (ULONG_PTR)str;
294 args[2] = strlen(strA.Buffer) + 1;
295 args[3] = (ULONG_PTR)strA.Buffer;
297 exc_handled = TRUE;
298 }
300 {
301 exc_handled = FALSE;
302 }
304
305 if (!exc_handled)
306 OutputDebugStringA( strA.Buffer );
307
309 }
310}
void WINAPI DECLSPEC_HOTPATCH OutputDebugStringA(LPCSTR str)
Definition: debug.c:182
static LONG WINAPI debug_exception_handler_wide(EXCEPTION_POINTERS *eptr)
Definition: debug.c:268
std::wstring STRING
Definition: fontsub.cpp:33
WCHAR strW[12]
Definition: clipboard.c:2025
char strA[12]
Definition: clipboard.c:2024
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

◆ QueryFullProcessImageNameA()

BOOL WINAPI DECLSPEC_HOTPATCH QueryFullProcessImageNameA ( HANDLE  process,
DWORD  flags,
char name,
DWORD size 
)

Definition at line 1725 of file debug.c.

1727{
1728 BOOL ret;
1729 DWORD sizeW = *size;
1730 WCHAR *nameW = HeapAlloc( GetProcessHeap(), 0, *size * sizeof(WCHAR) );
1731
1733 if (ret) ret = (WideCharToMultiByte( CP_ACP, 0, nameW, -1, name, *size, NULL, NULL) > 0);
1734 if (ret) *size = strlen( name );
1735 HeapFree( GetProcessHeap(), 0, nameW );
1736 return ret;
1737}
static const WCHAR sizeW[]
Definition: editor.c:79
GLbitfield flags
Definition: glext.h:7161

Referenced by GetProcessImageFileNameA().

◆ QueryFullProcessImageNameW()

BOOL WINAPI DECLSPEC_HOTPATCH QueryFullProcessImageNameW ( HANDLE  process,
DWORD  flags,
WCHAR name,
DWORD size 
)

Definition at line 1743 of file debug.c.

1745{
1746 BYTE buffer[sizeof(UNICODE_STRING) + MAX_PATH*sizeof(WCHAR)]; /* this buffer should be enough */
1747 UNICODE_STRING *dynamic_buffer = NULL;
1750 DWORD needed;
1751
1752 /* FIXME: Use ProcessImageFileName for the PROCESS_NAME_NATIVE case */
1754 sizeof(buffer) - sizeof(WCHAR), &needed );
1756 {
1757 dynamic_buffer = HeapAlloc( GetProcessHeap(), 0, needed + sizeof(WCHAR) );
1759 needed, &needed );
1760 result = dynamic_buffer;
1761 }
1762 else
1764
1765 if (status) goto cleanup;
1766
1767 if (flags & PROCESS_NAME_NATIVE && result->Length > 2 * sizeof(WCHAR))
1768 {
1769 WCHAR drive[3];
1770 WCHAR device[1024];
1771 DWORD ntlen, devlen;
1772
1773 if (result->Buffer[1] != ':' || result->Buffer[0] < 'A' || result->Buffer[0] > 'Z')
1774 {
1775 /* We cannot convert it to an NT device path so fail */
1777 goto cleanup;
1778 }
1779
1780 /* Find this drive's NT device path */
1781 drive[0] = result->Buffer[0];
1782 drive[1] = ':';
1783 drive[2] = 0;
1785 {
1787 goto cleanup;
1788 }
1789
1790 devlen = lstrlenW(device);
1791 ntlen = devlen + (result->Length/sizeof(WCHAR) - 2);
1792 if (ntlen + 1 > *size)
1793 {
1795 goto cleanup;
1796 }
1797 *size = ntlen;
1798
1799 memcpy( name, device, devlen * sizeof(*device) );
1800 memcpy( name + devlen, result->Buffer + 2, result->Length - 2 * sizeof(WCHAR) );
1801 name[*size] = 0;
1802 TRACE( "NT path: %s\n", debugstr_w(name) );
1803 }
1804 else
1805 {
1806 if (result->Length/sizeof(WCHAR) + 1 > *size)
1807 {
1809 goto cleanup;
1810 }
1811
1812 *size = result->Length/sizeof(WCHAR);
1813 memcpy( name, result->Buffer, result->Length );
1814 name[*size] = 0;
1815 }
1816
1817cleanup:
1818 HeapFree( GetProcessHeap(), 0, dynamic_buffer );
1819 return set_ntstatus( status );
1820}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define lstrlenW
Definition: compat.h:750
static void cleanup(void)
Definition: main.c:1335
DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
Definition: dosdev.c:542
struct _UNICODE_STRING UNICODE_STRING
GLuint64EXT * result
Definition: glext.h:11304
@ ProcessImageFileNameWin32
Definition: winternl.h:1925
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
Definition: devices.h:37
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
unsigned char BYTE
Definition: xxhash.c:193

Referenced by GetProcessImageFileNameW(), and QueryFullProcessImageNameA().

◆ QueryWorkingSet()

BOOL WINAPI DECLSPEC_HOTPATCH QueryWorkingSet ( HANDLE  process,
void buffer,
DWORD  size 
)

Definition at line 1702 of file debug.c.

1703{
1704 TRACE( "(%p, %p, %ld)\n", process, buffer, size );
1706 buffer, size, NULL ));
1707}
@ MemoryWorkingSetInformation
Definition: winternl.h:2386

Referenced by test_ws_functions().

◆ QueryWorkingSetEx()

BOOL WINAPI QueryWorkingSetEx ( HANDLE  process,
void buffer,
DWORD  size 
)

Definition at line 1714 of file debug.c.

1715{
1716 TRACE( "(%p, %p, %ld)\n", process, buffer, size );
1718 buffer, size, NULL ));
1719}
@ MemoryWorkingSetExInformation
Definition: winternl.h:2389

◆ RaiseException()

void WINAPI DECLSPEC_HOTPATCH RaiseException ( DWORD  code,
DWORD  flags,
DWORD  count,
const ULONG_PTR args 
)

Definition at line 388 of file debug.c.

389{
391
392 record.ExceptionCode = code;
393 record.ExceptionFlags = flags & EXCEPTION_NONCONTINUABLE;
394 record.ExceptionRecord = NULL;
395 record.ExceptionAddress = RaiseException;
396 if (count && args)
397 {
399 record.NumberParameters = count;
400 memcpy( record.ExceptionInformation, args, count * sizeof(*args) );
401 }
402 else record.NumberParameters = 0;
403
405}
#define EXCEPTION_MAXIMUM_PARAMETERS
Definition: compat.h:206
NTSYSAPI VOID NTAPI RtlRaiseException(_In_ PEXCEPTION_RECORD ExceptionRecord)
Definition: inflate.c:139
#define EXCEPTION_NONCONTINUABLE
Definition: stubs.h:23

Referenced by OutputDebugStringA(), OutputDebugStringW(), and RaiseException().

◆ RaiseFailFastException()

void WINAPI DECLSPEC_HOTPATCH RaiseFailFastException ( EXCEPTION_RECORD record,
CONTEXT context,
DWORD  flags 
)

Definition at line 417 of file debug.c.

418{
419 FIXME( "(%p, %p, %ld) stub\n", record, context, flags );
421}
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
#define STATUS_FAIL_FAST_EXCEPTION
Definition: ntstatus.h:1095

◆ SetUnhandledExceptionFilter()

Definition at line 426 of file debug.c.

428{
429 return InterlockedExchangePointer( (void **)&top_filter, filter );
430}
static PTOP_LEVEL_EXCEPTION_FILTER top_filter
Definition: debug.c:48
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45

◆ start_debugger()

static BOOL start_debugger ( EXCEPTION_POINTERS epointers,
HANDLE  event 
)
static

Definition at line 506 of file debug.c.

507{
509 UNICODE_STRING nameW = RTL_CONSTANT_STRING( L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug" );
510 WCHAR *cmdline, *env, *p, *format = NULL;
511 HANDLE dbg_key;
512 DWORD autostart = TRUE;
515 BOOL ret = FALSE;
516 char buffer[256];
517
518 format_exception_msg( epointers, buffer, sizeof(buffer) );
519 MESSAGE( "wine: %s (thread %04lx), starting debugger...\n", buffer, GetCurrentThreadId() );
520
521 attr.Length = sizeof(attr);
522 attr.RootDirectory = 0;
523 attr.ObjectName = &nameW;
524 attr.Attributes = 0;
525 attr.SecurityDescriptor = NULL;
526 attr.SecurityQualityOfService = NULL;
527
528 if (!NtOpenKey( &dbg_key, KEY_READ, &attr ))
529 {
531 DWORD format_size = 0;
532
533 RtlInitUnicodeString( &nameW, L"Debugger" );
536 {
537 char *data = HeapAlloc( GetProcessHeap(), 0, format_size );
541 format = HeapAlloc( GetProcessHeap(), 0, info->DataLength + sizeof(WCHAR) );
542 memcpy( format, info->Data, info->DataLength );
543 format[info->DataLength / sizeof(WCHAR)] = 0;
544
545 if (info->Type == REG_EXPAND_SZ)
546 {
547 WCHAR *tmp;
548
550 tmp = HeapAlloc( GetProcessHeap(), 0, format_size * sizeof(WCHAR));
553 format = tmp;
554 }
556 }
557
558 RtlInitUnicodeString( &nameW, L"Auto" );
560 buffer, sizeof(buffer)-sizeof(WCHAR), &format_size ))
561 {
563 if (info->Type == REG_DWORD) memcpy( &autostart, info->Data, sizeof(DWORD) );
564 else if (info->Type == REG_SZ)
565 {
566 WCHAR *str = (WCHAR *)info->Data;
567 str[info->DataLength/sizeof(WCHAR)] = 0;
568 autostart = wcstol( str, NULL, 10 );
569 }
570 }
571
572 NtClose( dbg_key );
573 }
574
575 if (format)
576 {
577 size_t format_size = lstrlenW( format ) + 2*20;
578 cmdline = HeapAlloc( GetProcessHeap(), 0, format_size * sizeof(WCHAR) );
581 }
582 else
583 {
584 cmdline = HeapAlloc( GetProcessHeap(), 0, 80 * sizeof(WCHAR) );
585 swprintf( cmdline, 80, L"winedbg --auto %ld %ld", GetCurrentProcessId(), HandleToLong(event) );
586 }
587
588 if (!autostart)
589 {
590 HMODULE mod = GetModuleHandleA( "user32.dll" );
591 MessageBoxA_funcptr pMessageBoxA = NULL;
592
593 if (mod) pMessageBoxA = (void *)GetProcAddress( mod, "MessageBoxA" );
594 if (pMessageBoxA)
595 {
596 static const char msg[] = ".\nDo you wish to debug it?";
597
598 format_exception_msg( epointers, buffer, sizeof(buffer) - sizeof(msg) );
599 strcat( buffer, msg );
600 if (pMessageBoxA( 0, buffer, "Exception raised", MB_YESNO | MB_ICONHAND ) == IDNO)
601 {
602 TRACE( "Killing process\n" );
603 goto exit;
604 }
605 }
606 }
607
608 /* make WINEDEBUG empty in the environment */
610 if (!TRACE_ON(winedbg))
611 {
612 for (p = env; *p; p += lstrlenW(p) + 1)
613 {
614 if (!wcsncmp( p, L"WINEDEBUG=", 10 ))
615 {
616 WCHAR *next = p + lstrlenW(p);
617 WCHAR *end = next + 1;
618 while (*end) end += lstrlenW(end) + 1;
619 memmove( p + 10, next, end + 1 - next );
620 break;
621 }
622 }
623 }
624
625 TRACE( "Starting debugger %s\n", debugstr_w(cmdline) );
626 memset( &startup, 0, sizeof(startup) );
627 startup.cb = sizeof(startup);
629 startup.wShowWindow = SW_SHOWNORMAL;
632
633 if (ret)
634 {
635 /* wait for debugger to come up... */
636 HANDLE handles[2];
637 CloseHandle( info.hThread );
638 handles[0] = event;
639 handles[1] = info.hProcess;
641 CloseHandle( info.hProcess );
642 }
643 else ERR( "Couldn't start debugger %s (%ld)\n"
644 "Read the Wine Developers Guide on how to set up winedbg or another debugger\n",
646exit:
648 return ret;
649}
static void startup(void)
#define msg(x)
Definition: auth_time.c:54
#define HandleToLong(h)
Definition: basetsd.h:80
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:170
void format_size(uint64_t size, wstring &s, bool show_bytes)
Definition: main.cpp:65
#define TRACE_ON(x)
Definition: compat.h:75
BOOL WINAPI FreeEnvironmentStringsW(IN LPWSTR EnvironmentStrings)
Definition: environ.c:389
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4598
static void format_exception_msg(const EXCEPTION_POINTERS *ptr, char *buffer, int size)
Definition: debug.c:436
LPWSTR WINAPI DECLSPEC_HOTPATCH GetEnvironmentStringsW(void)
Definition: process.c:1538
#define swprintf
Definition: precomp.h:40
GLuint GLuint end
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
struct _cl_event * event
Definition: glext.h:7739
GLfloat GLfloat p
Definition: glext.h:8902
#define REG_SZ
Definition: layer.c:22
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define MESSAGE
Definition: options.h:86
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
static unsigned __int64 next
Definition: rand_nt.c:6
#define REG_DWORD
Definition: sdbapi.c:596
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
strcat
Definition: string.h:92
#define exit(n)
Definition: config.h:202
#define memset(x, y, z)
Definition: compat.h:39
TCHAR * cmdline
Definition: stretchblt.cpp:32
Definition: cookie.c:202
Definition: format.c:58
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
static EFI_HANDLE * handles
Definition: uefidisk.c:62
#define STARTF_USESHOWWINDOW
Definition: winbase.h:524
#define CREATE_UNICODE_ENVIRONMENT
Definition: winbase.h:196
#define SW_SHOWNORMAL
Definition: winuser.h:781
#define MB_ICONHAND
Definition: winuser.h:799
#define MB_YESNO
Definition: winuser.h:828
#define IDNO
Definition: winuser.h:847

Referenced by start_debugger_atomic().

◆ start_debugger_atomic()

static BOOL start_debugger_atomic ( EXCEPTION_POINTERS epointers)
static

Definition at line 661 of file debug.c.

662{
663 static HANDLE once;
664
665 if (once == 0)
666 {
669
670 attr.Length = sizeof(attr);
671 attr.RootDirectory = 0;
672 attr.Attributes = OBJ_INHERIT;
673 attr.ObjectName = NULL;
674 attr.SecurityDescriptor = NULL;
675 attr.SecurityQualityOfService = NULL;
676
677 /* ask for manual reset, so that once the debugger is started,
678 * every thread will know it */
680 if (InterlockedCompareExchangePointer( &once, event, 0 ) == 0)
681 {
682 /* ok, our event has been set... we're the winning thread */
683 BOOL ret = start_debugger( epointers, once );
684
685 if (!ret)
686 {
687 /* so that the other threads won't be stuck */
688 NtSetEvent( once, NULL );
689 }
690 return ret;
691 }
692
693 /* someone beat us here... */
695 }
696
697 /* and wait for the winner to have actually created the debugger */
699 /* in fact, here, we only know that someone has tried to start the debugger,
700 * we'll know by reposting the exception if it has actually attached
701 * to the current process */
702 return TRUE;
703}
static BOOL start_debugger(EXCEPTION_POINTERS *epointers, HANDLE event)
Definition: debug.c:506
#define OBJ_INHERIT
Definition: winternl.h:225
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
@ NotificationEvent
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96

Referenced by UnhandledExceptionFilter().

◆ UnhandledExceptionFilter()

LONG WINAPI UnhandledExceptionFilter ( EXCEPTION_POINTERS epointers)

Definition at line 735 of file debug.c.

736{
737 const EXCEPTION_RECORD *rec = epointers->ExceptionRecord;
738
740 {
741 switch (rec->ExceptionInformation[0])
742 {
744 if (check_resource_write( (void *)rec->ExceptionInformation[1] ))
746 break;
747 }
748 }
749
751 {
752 if (rec->ExceptionCode == CONTROL_C_EXIT)
753 {
754 /* do not launch the debugger on ^C, simply terminate the process */
756 }
757
758 if (top_filter)
759 {
760 LONG ret = top_filter( epointers );
761 if (ret != EXCEPTION_CONTINUE_SEARCH) return ret;
762 }
763
767 }
769}
PPEB Peb
Definition: dllmain.c:27
static BOOL start_debugger_atomic(EXCEPTION_POINTERS *epointers)
Definition: debug.c:661
static BOOL check_resource_write(void *addr)
Definition: debug.c:713
UINT WINAPI DECLSPEC_HOTPATCH GetErrorMode(void)
Definition: process.c:775
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:92
#define SEM_NOGPFAULTERRORBOX
Definition: rtltypes.h:70
long LONG
Definition: pedump.c:60
BYTE BeingDebugged
Definition: btrfs_drv.h:1909

◆ WerGetFlags()

HRESULT WINAPI WerGetFlags ( HANDLE  process,
DWORD flags 
)

Definition at line 775 of file debug.c.

776{
777 FIXME( "(%p, %p) stub\n", process, flags );
778 return E_NOTIMPL;
779}
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ WerRegisterFile()

HRESULT WINAPI WerRegisterFile ( const WCHAR file,
WER_REGISTER_FILE_TYPE  type,
DWORD  flags 
)

Definition at line 785 of file debug.c.

787{
788 FIXME( "(%s, %d, %ld) stub\n", debugstr_w(file), type, flags );
789 return E_NOTIMPL;
790}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545

◆ WerRegisterMemoryBlock()

HRESULT WINAPI WerRegisterMemoryBlock ( void block,
DWORD  size 
)

Definition at line 796 of file debug.c.

797{
798 FIXME( "(%p %ld) stub\n", block, size );
799 return E_NOTIMPL;
800}
static unsigned int block
Definition: xmlmemory.c:101

◆ WerRegisterRuntimeExceptionModule()

HRESULT WINAPI WerRegisterRuntimeExceptionModule ( const WCHAR dll,
void context 
)

Definition at line 806 of file debug.c.

807{
808 FIXME( "(%s, %p) stub\n", debugstr_w(dll), context );
809 return S_OK;
810}
#define S_OK
Definition: intsafe.h:52
static HMODULE dll
Definition: str.c:188

◆ WerSetFlags()

HRESULT WINAPI WerSetFlags ( DWORD  flags)

Definition at line 816 of file debug.c.

817{
818 FIXME("(%ld) stub\n", flags);
819 return S_OK;
820}

◆ WerUnregisterFile()

HRESULT WINAPI WerUnregisterFile ( const WCHAR file)

Definition at line 826 of file debug.c.

827{
828 FIXME( "(%s) stub\n", debugstr_w(file) );
829 return E_NOTIMPL;
830}

◆ WerUnregisterMemoryBlock()

HRESULT WINAPI WerUnregisterMemoryBlock ( void block)

Definition at line 836 of file debug.c.

837{
838 FIXME( "(%p) stub\n", block );
839 return E_NOTIMPL;
840}

◆ WerUnregisterRuntimeExceptionModule()

HRESULT WINAPI WerUnregisterRuntimeExceptionModule ( const WCHAR dll,
void context 
)

Definition at line 846 of file debug.c.

847{
848 FIXME( "(%s, %p) stub\n", debugstr_w(dll), context );
849 return S_OK;
850}

◆ WINE_DECLARE_DEBUG_CHANNEL()

WINE_DECLARE_DEBUG_CHANNEL ( winedbg  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( seh  )

Variable Documentation

◆ dummy

Definition at line 50 of file debug.c.

◆ top_filter

PTOP_LEVEL_EXCEPTION_FILTER top_filter
static

Definition at line 48 of file debug.c.

Referenced by SetUnhandledExceptionFilter(), and UnhandledExceptionFilter().