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