1 //===-- HostInfoWindows.cpp -------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Host/windows/windows.h" 11 12 #include <mutex> // std::once 13 14 #include "lldb/Host/windows/HostInfoWindows.h" 15 #include "llvm/ADT/SmallString.h" 16 #include "llvm/Support/raw_ostream.h" 17 18 using namespace lldb_private; 19 20 FileSpec HostInfoWindows::m_program_filespec; 21 22 size_t 23 HostInfoWindows::GetPageSize() 24 { 25 SYSTEM_INFO systemInfo; 26 GetNativeSystemInfo(&systemInfo); 27 return systemInfo.dwPageSize; 28 } 29 30 bool 31 HostInfoWindows::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update) 32 { 33 OSVERSIONINFOEX info; 34 35 ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); 36 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 37 #pragma warning(push) 38 #pragma warning(disable : 4996) 39 // Starting with Microsoft SDK for Windows 8.1, this function is deprecated in favor of the 40 // new Windows Version Helper APIs. Since we don't specify a minimum SDK version, it's easier 41 // to simply disable the warning rather than try to support both APIs. 42 if (GetVersionEx((LPOSVERSIONINFO)&info) == 0) 43 { 44 return false; 45 } 46 #pragma warning(pop) 47 48 major = info.dwMajorVersion; 49 minor = info.dwMinorVersion; 50 update = info.wServicePackMajor; 51 52 return true; 53 } 54 55 bool 56 HostInfoWindows::GetOSBuildString(std::string &s) 57 { 58 s.clear(); 59 uint32_t major, minor, update; 60 if (!GetOSVersion(major, minor, update)) 61 return false; 62 63 llvm::raw_string_ostream stream(s); 64 stream << "Windows NT " << major << "." << minor << "." << update; 65 return true; 66 } 67 68 bool 69 HostInfoWindows::GetOSKernelDescription(std::string &s) 70 { 71 return GetOSBuildString(s); 72 } 73 74 bool 75 HostInfoWindows::GetHostname(std::string &s) 76 { 77 char buffer[MAX_COMPUTERNAME_LENGTH + 1]; 78 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1; 79 if (!::GetComputerName(buffer, &dwSize)) 80 return false; 81 82 s.assign(buffer, buffer + dwSize); 83 return true; 84 } 85 86 FileSpec 87 HostInfoWindows::GetProgramFileSpec() 88 { 89 static std::once_flag g_once_flag; 90 std::call_once(g_once_flag, []() { 91 char buffer[PATH_MAX]; 92 ::GetModuleFileName(NULL, buffer, sizeof(buffer)); 93 m_program_filespec.SetFile(buffer, false); 94 }); 95 return m_program_filespec; 96 } 97 98 FileSpec 99 HostInfoWindows::GetDefaultShell() 100 { 101 return FileSpec(::getenv("ComSpec"), false); 102 } 103 104 bool 105 HostInfoWindows::ComputePythonDirectory(FileSpec &file_spec) 106 { 107 FileSpec lldb_file_spec; 108 if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec)) 109 return false; 110 111 char raw_path[PATH_MAX]; 112 lldb_file_spec.AppendPathComponent("../lib/site-packages"); 113 lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); 114 115 file_spec.GetDirectory().SetCString(raw_path); 116 return true; 117 } 118