+
+/* Define dummy functions which always return error for the rare cases where
+ these functions could not be found. */
+static BOOL WINAPI
+bad_DebugActiveProcessStop (DWORD w)
+{
+ return FALSE;
+}
+static BOOL WINAPI
+bad_DebugBreakProcess (HANDLE w)
+{
+ return FALSE;
+}
+static BOOL WINAPI
+bad_DebugSetProcessKillOnExit (BOOL w)
+{
+ return FALSE;
+}
+static BOOL WINAPI
+bad_EnumProcessModules (HANDLE w, HMODULE *x, DWORD y, LPDWORD z)
+{
+ return FALSE;
+}
+
+#ifdef __USEWIDE
+static DWORD WINAPI
+bad_GetModuleFileNameExW (HANDLE w, HMODULE x, LPWSTR y, DWORD z)
+{
+ return 0;
+}
+#else
+static DWORD WINAPI
+bad_GetModuleFileNameExA (HANDLE w, HMODULE x, LPSTR y, DWORD z)
+{
+ return 0;
+}
+#endif
+
+static BOOL WINAPI
+bad_GetModuleInformation (HANDLE w, HMODULE x, LPMODULEINFO y, DWORD z)
+{
+ return FALSE;
+}
+
+static BOOL WINAPI
+bad_OpenProcessToken (HANDLE w, DWORD x, PHANDLE y)
+{
+ return FALSE;
+}
+
+static BOOL WINAPI
+bad_GetCurrentConsoleFont (HANDLE w, BOOL bMaxWindow, CONSOLE_FONT_INFO *f)
+{
+ f->nFont = 0;
+ return 1;
+}
+static COORD WINAPI
+bad_GetConsoleFontSize (HANDLE w, DWORD nFont)
+{
+ COORD size;
+ size.X = 8;
+ size.Y = 12;
+ return size;
+}
+
+/* Load any functions which may not be available in ancient versions
+ of Windows. */
+void
+_initialize_loadable (void)
+{
+ HMODULE hm = NULL;
+
+ hm = LoadLibrary ("kernel32.dll");
+ if (hm)
+ {
+ DebugActiveProcessStop = (void *)
+ GetProcAddress (hm, "DebugActiveProcessStop");
+ DebugBreakProcess = (void *)
+ GetProcAddress (hm, "DebugBreakProcess");
+ DebugSetProcessKillOnExit = (void *)
+ GetProcAddress (hm, "DebugSetProcessKillOnExit");
+ GetConsoleFontSize = (void *)
+ GetProcAddress (hm, "GetConsoleFontSize");
+ GetCurrentConsoleFont = (void *)
+ GetProcAddress (hm, "GetCurrentConsoleFont");
+ }
+
+ /* Set variables to dummy versions of these processes if the function
+ wasn't found in kernel32.dll. */
+ if (!DebugBreakProcess)
+ DebugBreakProcess = bad_DebugBreakProcess;
+ if (!DebugActiveProcessStop || !DebugSetProcessKillOnExit)
+ {
+ DebugActiveProcessStop = bad_DebugActiveProcessStop;
+ DebugSetProcessKillOnExit = bad_DebugSetProcessKillOnExit;
+ }
+ if (!GetConsoleFontSize)
+ GetConsoleFontSize = bad_GetConsoleFontSize;
+ if (!GetCurrentConsoleFont)
+ GetCurrentConsoleFont = bad_GetCurrentConsoleFont;
+
+ /* Load optional functions used for retrieving filename information
+ associated with the currently debugged process or its dlls. */
+ hm = LoadLibrary ("psapi.dll");
+ if (hm)
+ {
+ EnumProcessModules = (void *)
+ GetProcAddress (hm, "EnumProcessModules");
+ GetModuleInformation = (void *)
+ GetProcAddress (hm, "GetModuleInformation");
+ GetModuleFileNameEx = (void *)
+ GetProcAddress (hm, GetModuleFileNameEx_name);
+ }
+
+ if (!EnumProcessModules || !GetModuleInformation || !GetModuleFileNameEx)
+ {
+ /* Set variables to dummy versions of these processes if the function
+ wasn't found in psapi.dll. */
+ EnumProcessModules = bad_EnumProcessModules;
+ GetModuleInformation = bad_GetModuleInformation;
+ GetModuleFileNameEx = bad_GetModuleFileNameEx;
+ /* This will probably fail on Windows 9x/Me. Let the user know
+ that we're missing some functionality. */
+ warning(_("\
+cannot automatically find executable file or library to read symbols.\n\
+Use \"file\" or \"dll\" command to load executable/libraries directly."));
+ }
+
+ hm = LoadLibrary ("advapi32.dll");
+ if (hm)
+ {
+ OpenProcessToken = (void *) GetProcAddress (hm, "OpenProcessToken");
+ LookupPrivilegeValueA = (void *)
+ GetProcAddress (hm, "LookupPrivilegeValueA");
+ AdjustTokenPrivileges = (void *)
+ GetProcAddress (hm, "AdjustTokenPrivileges");
+ /* Only need to set one of these since if OpenProcessToken fails nothing
+ else is needed. */
+ if (!OpenProcessToken || !LookupPrivilegeValueA
+ || !AdjustTokenPrivileges)
+ OpenProcessToken = bad_OpenProcessToken;
+ }
+}