diff options
author | McCabe Maxsted | 2011-04-06 11:11:19 -0700 |
---|---|---|
committer | McCabe Maxsted | 2011-04-06 11:13:06 -0700 |
commit | 029644867ad5a7926b8af954385acabab59f8fc4 (patch) | |
tree | 8e2d0570d2a69116ba3e133bb961108046991299 /linden | |
parent | Initialize local variables in llimagegl.cpp, from Singularity, patch by Shyotl (diff) | |
download | meta-impy-029644867ad5a7926b8af954385acabab59f8fc4.zip meta-impy-029644867ad5a7926b8af954385acabab59f8fc4.tar.gz meta-impy-029644867ad5a7926b8af954385acabab59f8fc4.tar.bz2 meta-impy-029644867ad5a7926b8af954385acabab59f8fc4.tar.xz |
Extended windows detection to include Windows 7, ported from Singularity, patch by Shyotl
Diffstat (limited to 'linden')
-rw-r--r-- | linden/indra/llcommon/llsys.cpp | 124 | ||||
-rw-r--r-- | linden/indra/llcommon/llsys.h | 7 |
2 files changed, 122 insertions, 9 deletions
diff --git a/linden/indra/llcommon/llsys.cpp b/linden/indra/llcommon/llsys.cpp index a56ac47..ee27a49 100644 --- a/linden/indra/llcommon/llsys.cpp +++ b/linden/indra/llcommon/llsys.cpp | |||
@@ -76,6 +76,75 @@ extern int errno; | |||
76 | static const S32 CPUINFO_BUFFER_SIZE = 16383; | 76 | static const S32 CPUINFO_BUFFER_SIZE = 16383; |
77 | LLCPUInfo gSysCPU; | 77 | LLCPUInfo gSysCPU; |
78 | 78 | ||
79 | #if LL_WINDOWS | ||
80 | #ifndef DLLVERSIONINFO | ||
81 | typedef struct _DllVersionInfo | ||
82 | { | ||
83 | DWORD cbSize; | ||
84 | DWORD dwMajorVersion; | ||
85 | DWORD dwMinorVersion; | ||
86 | DWORD dwBuildNumber; | ||
87 | DWORD dwPlatformID; | ||
88 | }DLLVERSIONINFO; | ||
89 | #endif | ||
90 | |||
91 | #ifndef DLLGETVERSIONPROC | ||
92 | typedef int (FAR WINAPI *DLLGETVERSIONPROC) (DLLVERSIONINFO *); | ||
93 | #endif | ||
94 | |||
95 | bool get_shell32_dll_version(DWORD& major, DWORD& minor, DWORD& build_number) | ||
96 | { | ||
97 | bool result = false; | ||
98 | const U32 BUFF_SIZE = 32767; | ||
99 | WCHAR tempBuf[BUFF_SIZE]; | ||
100 | if(GetSystemDirectory((LPWSTR)&tempBuf, BUFF_SIZE)) | ||
101 | { | ||
102 | |||
103 | std::basic_string<WCHAR> shell32_path(tempBuf); | ||
104 | |||
105 | // Shell32.dll contains the DLLGetVersion function. | ||
106 | // according to msdn its not part of the API | ||
107 | // so you have to go in and get it. | ||
108 | // http://msdn.microsoft.com/en-us/library/bb776404(VS.85).aspx | ||
109 | shell32_path += TEXT("\\shell32.dll"); | ||
110 | |||
111 | HMODULE hDllInst = LoadLibrary(shell32_path.c_str()); //load the DLL | ||
112 | if(hDllInst) | ||
113 | { // Could successfully load the DLL | ||
114 | DLLGETVERSIONPROC pDllGetVersion; | ||
115 | /* | ||
116 | You must get this function explicitly because earlier versions of the DLL | ||
117 | don't implement this function. That makes the lack of implementation of the | ||
118 | function a version marker in itself. | ||
119 | */ | ||
120 | pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hDllInst, | ||
121 | "DllGetVersion"); | ||
122 | |||
123 | if(pDllGetVersion) | ||
124 | { | ||
125 | // DLL supports version retrieval function | ||
126 | DLLVERSIONINFO dvi; | ||
127 | |||
128 | ZeroMemory(&dvi, sizeof(dvi)); | ||
129 | dvi.cbSize = sizeof(dvi); | ||
130 | HRESULT hr = (*pDllGetVersion)(&dvi); | ||
131 | |||
132 | if(SUCCEEDED(hr)) | ||
133 | { // Finally, the version is at our hands | ||
134 | major = dvi.dwMajorVersion; | ||
135 | minor = dvi.dwMinorVersion; | ||
136 | build_number = dvi.dwBuildNumber; | ||
137 | result = true; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | FreeLibrary(hDllInst); // Release DLL | ||
142 | } | ||
143 | } | ||
144 | return result; | ||
145 | } | ||
146 | #endif // LL_WINDOWS | ||
147 | |||
79 | LLOSInfo::LLOSInfo() : | 148 | LLOSInfo::LLOSInfo() : |
80 | mMajorVer(0), mMinorVer(0), mBuild(0) | 149 | mMajorVer(0), mMinorVer(0), mBuild(0) |
81 | { | 150 | { |
@@ -98,6 +167,11 @@ LLOSInfo::LLOSInfo() : | |||
98 | mMinorVer = osvi.dwMinorVersion; | 167 | mMinorVer = osvi.dwMinorVersion; |
99 | mBuild = osvi.dwBuildNumber; | 168 | mBuild = osvi.dwBuildNumber; |
100 | 169 | ||
170 | DWORD shell32_major, shell32_minor, shell32_build; | ||
171 | bool got_shell32_version = get_shell32_dll_version(shell32_major, | ||
172 | shell32_minor, | ||
173 | shell32_build); | ||
174 | |||
101 | switch(osvi.dwPlatformId) | 175 | switch(osvi.dwPlatformId) |
102 | { | 176 | { |
103 | case VER_PLATFORM_WIN32_NT: | 177 | case VER_PLATFORM_WIN32_NT: |
@@ -146,8 +220,8 @@ LLOSInfo::LLOSInfo() : | |||
146 | pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); //load kernel32 get function | 220 | pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); //load kernel32 get function |
147 | if(NULL != pGNSI) //check if it has failed | 221 | if(NULL != pGNSI) //check if it has failed |
148 | pGNSI(&si); //success | 222 | pGNSI(&si); //success |
149 | else | 223 | else |
150 | GetSystemInfo(&si); //if it fails get regular system info | 224 | GetSystemInfo(&si); //if it fails get regular system info |
151 | //(Warning: If GetSystemInfo it may result in incorrect information in a WOW64 machine, if the kernel fails to load) | 225 | //(Warning: If GetSystemInfo it may result in incorrect information in a WOW64 machine, if the kernel fails to load) |
152 | 226 | ||
153 | //msdn microsoft finds 32 bit and 64 bit flavors this way.. | 227 | //msdn microsoft finds 32 bit and 64 bit flavors this way.. |
@@ -206,6 +280,7 @@ LLOSInfo::LLOSInfo() : | |||
206 | csdversion.c_str(), | 280 | csdversion.c_str(), |
207 | (osvi.dwBuildNumber & 0xffff)); | 281 | (osvi.dwBuildNumber & 0xffff)); |
208 | } | 282 | } |
283 | |||
209 | mOSString = mOSStringSimple + tmpstr; | 284 | mOSString = mOSStringSimple + tmpstr; |
210 | } | 285 | } |
211 | break; | 286 | break; |
@@ -235,6 +310,21 @@ LLOSInfo::LLOSInfo() : | |||
235 | mOSString = mOSStringSimple; | 310 | mOSString = mOSStringSimple; |
236 | break; | 311 | break; |
237 | } | 312 | } |
313 | |||
314 | std::string compatibility_mode; | ||
315 | if(got_shell32_version) | ||
316 | { | ||
317 | if(osvi.dwMajorVersion != shell32_major | ||
318 | || osvi.dwMinorVersion != shell32_minor) | ||
319 | { | ||
320 | compatibility_mode = llformat(" compatibility mode. real ver: %d.%d (Build %d)", | ||
321 | shell32_major, | ||
322 | shell32_minor, | ||
323 | shell32_build); | ||
324 | } | ||
325 | } | ||
326 | mOSString += compatibility_mode; | ||
327 | |||
238 | #else | 328 | #else |
239 | struct utsname un; | 329 | struct utsname un; |
240 | if(uname(&un) != -1) | 330 | if(uname(&un) != -1) |
@@ -262,8 +352,8 @@ LLOSInfo::LLOSInfo() : | |||
262 | else if (ostype == "Linux") | 352 | else if (ostype == "Linux") |
263 | { | 353 | { |
264 | // Only care about major and minor Linux versions, truncate at second '.' | 354 | // Only care about major and minor Linux versions, truncate at second '.' |
265 | S32 idx1 = mOSStringSimple.find_first_of(".", 0); | 355 | std::string::size_type idx1 = mOSStringSimple.find_first_of(".", 0); |
266 | S32 idx2 = (idx1 != std::string::npos) ? mOSStringSimple.find_first_of(".", idx1+1) : std::string::npos; | 356 | std::string::size_type idx2 = (idx1 != std::string::npos) ? mOSStringSimple.find_first_of(".", idx1+1) : std::string::npos; |
267 | std::string simple = mOSStringSimple.substr(0, idx2); | 357 | std::string simple = mOSStringSimple.substr(0, idx2); |
268 | if (simple.length() > 0) | 358 | if (simple.length() > 0) |
269 | mOSStringSimple = simple; | 359 | mOSStringSimple = simple; |
@@ -429,7 +519,7 @@ LLCPUInfo::LLCPUInfo() | |||
429 | mHasSSE = info->_Ext.SSE_StreamingSIMD_Extensions; | 519 | mHasSSE = info->_Ext.SSE_StreamingSIMD_Extensions; |
430 | mHasSSE2 = info->_Ext.SSE2_StreamingSIMD2_Extensions; | 520 | mHasSSE2 = info->_Ext.SSE2_StreamingSIMD2_Extensions; |
431 | mHasAltivec = info->_Ext.Altivec_Extensions; | 521 | mHasAltivec = info->_Ext.Altivec_Extensions; |
432 | mCPUMhz = (S32)(proc.GetCPUFrequency(50)/1000000.0); | 522 | mCPUMhz = (F64)(proc.GetCPUFrequency(50)/1000000.0); |
433 | mFamily.assign( info->strFamily ); | 523 | mFamily.assign( info->strFamily ); |
434 | mCPUString = "Unknown"; | 524 | mCPUString = "Unknown"; |
435 | 525 | ||
@@ -482,7 +572,7 @@ LLCPUInfo::LLCPUInfo() | |||
482 | if (LLStringUtil::convertToF64(cpuinfo["cpu mhz"], mhz) | 572 | if (LLStringUtil::convertToF64(cpuinfo["cpu mhz"], mhz) |
483 | && 200.0 < mhz && mhz < 10000.0) | 573 | && 200.0 < mhz && mhz < 10000.0) |
484 | { | 574 | { |
485 | mCPUMhz = (S32)llrint(mhz); | 575 | mCPUMhz = (F64)llrint(mhz); |
486 | } | 576 | } |
487 | if (!cpuinfo["model name"].empty()) | 577 | if (!cpuinfo["model name"].empty()) |
488 | mCPUString = cpuinfo["model name"]; | 578 | mCPUString = cpuinfo["model name"]; |
@@ -505,7 +595,7 @@ bool LLCPUInfo::hasSSE2() const | |||
505 | return mHasSSE2; | 595 | return mHasSSE2; |
506 | } | 596 | } |
507 | 597 | ||
508 | S32 LLCPUInfo::getMhz() const | 598 | F64 LLCPUInfo::getMhz() const |
509 | { | 599 | { |
510 | return mCPUMhz; | 600 | return mCPUMhz; |
511 | } | 601 | } |
@@ -631,6 +721,26 @@ U32 LLMemoryInfo::getPhysicalMemoryClamped() const | |||
631 | } | 721 | } |
632 | } | 722 | } |
633 | 723 | ||
724 | //static | ||
725 | void LLMemoryInfo::getAvailableMemoryKB(U32& avail_physical_mem_kb, U32& avail_virtual_mem_kb) | ||
726 | { | ||
727 | #if LL_WINDOWS | ||
728 | MEMORYSTATUSEX state; | ||
729 | state.dwLength = sizeof(state); | ||
730 | GlobalMemoryStatusEx(&state); | ||
731 | |||
732 | avail_physical_mem_kb = (U32)(state.ullAvailPhys/1024) ; | ||
733 | avail_virtual_mem_kb = (U32)(state.ullAvailVirtual/1024) ; | ||
734 | |||
735 | #else | ||
736 | //do not know how to collect available memory info for other systems. | ||
737 | //leave it blank here for now. | ||
738 | |||
739 | avail_physical_mem_kb = -1 ; | ||
740 | avail_virtual_mem_kb = -1 ; | ||
741 | #endif | ||
742 | } | ||
743 | |||
634 | void LLMemoryInfo::stream(std::ostream& s) const | 744 | void LLMemoryInfo::stream(std::ostream& s) const |
635 | { | 745 | { |
636 | #if LL_WINDOWS | 746 | #if LL_WINDOWS |
diff --git a/linden/indra/llcommon/llsys.h b/linden/indra/llcommon/llsys.h index d5575b2..d680e1a 100644 --- a/linden/indra/llcommon/llsys.h +++ b/linden/indra/llcommon/llsys.h | |||
@@ -81,7 +81,7 @@ public: | |||
81 | bool hasAltivec() const; | 81 | bool hasAltivec() const; |
82 | bool hasSSE() const; | 82 | bool hasSSE() const; |
83 | bool hasSSE2() const; | 83 | bool hasSSE2() const; |
84 | S32 getMhz() const; | 84 | F64 getMhz() const; |
85 | 85 | ||
86 | // Family is "AMD Duron" or "Intel Pentium Pro" | 86 | // Family is "AMD Duron" or "Intel Pentium Pro" |
87 | const std::string& getFamily() const { return mFamily; } | 87 | const std::string& getFamily() const { return mFamily; } |
@@ -90,7 +90,7 @@ private: | |||
90 | bool mHasSSE; | 90 | bool mHasSSE; |
91 | bool mHasSSE2; | 91 | bool mHasSSE2; |
92 | bool mHasAltivec; | 92 | bool mHasAltivec; |
93 | S32 mCPUMhz; | 93 | F64 mCPUMhz; |
94 | std::string mFamily; | 94 | std::string mFamily; |
95 | std::string mCPUString; | 95 | std::string mCPUString; |
96 | }; | 96 | }; |
@@ -120,6 +120,9 @@ public: | |||
120 | ** be returned. | 120 | ** be returned. |
121 | */ | 121 | */ |
122 | U32 getPhysicalMemoryClamped() const; ///< Memory size in clamped bytes | 122 | U32 getPhysicalMemoryClamped() const; ///< Memory size in clamped bytes |
123 | |||
124 | //get the available memory infomation in KiloBytes. | ||
125 | static void getAvailableMemoryKB(U32& avail_physical_mem_kb, U32& avail_virtual_mem_kb); | ||
123 | }; | 126 | }; |
124 | 127 | ||
125 | 128 | ||