Bug 925599 - Introduce version test functions using VerifyVersionInfo(). r=bbondy
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 19 Oct 2013 03:14:31 +0900
changeset 166144 4d2eb79e83b32ce6f4774d456159da72448656a2
parent 166143 0abc9e2319ee31512fe90012ae84d0a391b3a7db
child 166145 df958bc8af6d1855fb3ad8a74fc208fb129da79b
push idunknown
push userunknown
push dateunknown
reviewersbbondy
bugs925599
milestone27.0a1
Bug 925599 - Introduce version test functions using VerifyVersionInfo(). r=bbondy
dom/plugins/base/nsNPAPIPlugin.cpp
hal/windows/WindowsBattery.cpp
toolkit/mozapps/update/common/uachelper.cpp
toolkit/mozapps/update/common/uachelper.h
toolkit/xre/nsWindowsDllBlocklist.cpp
xpcom/base/WindowsVersion.h
xpcom/base/moz.build
xpcom/base/nsWindowsHelpers.h
xpcom/glue/nsThreadUtils.cpp
--- a/dom/plugins/base/nsNPAPIPlugin.cpp
+++ b/dom/plugins/base/nsNPAPIPlugin.cpp
@@ -88,17 +88,17 @@ using mozilla::PluginPRLibrary;
 using mozilla::plugins::PluginModuleParent;
 
 #ifdef MOZ_X11
 #include "mozilla/X11Util.h"
 #endif
 
 #ifdef XP_WIN
 #include <windows.h>
-#include "nsWindowsHelpers.h"
+#include "mozilla/WindowsVersion.h"
 #ifdef ACCESSIBILITY
 #include "mozilla/a11y/Compatibility.h"
 #endif
 #endif
 
 #ifdef MOZ_WIDGET_ANDROID
 #include <android/log.h>
 #include "android_npapi.h"
--- a/hal/windows/WindowsBattery.cpp
+++ b/hal/windows/WindowsBattery.cpp
@@ -6,17 +6,17 @@
 #include "Hal.h"
 #include "HalImpl.h"
 #include "nsITimer.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/battery/Constants.h"
 #include "nsComponentManagerUtils.h"
 
 #include <windows.h>
-#include "nsWindowsHelpers.h"
+#include "mozilla/WindowsVersion.h"
 
 using namespace mozilla::dom::battery;
 
 namespace mozilla {
 namespace hal_impl {
 
 static nsCOMPtr<nsITimer> sUpdateTimer;
 
--- a/toolkit/mozapps/update/common/uachelper.cpp
+++ b/toolkit/mozapps/update/common/uachelper.cpp
@@ -51,30 +51,16 @@ LPCTSTR UACHelper::PrivsToDisable[] = {
   SE_TCB_NAME,
   SE_TIME_ZONE_NAME,
   SE_TRUSTED_CREDMAN_ACCESS_NAME,
   SE_UNDOCK_NAME,
   SE_UNSOLICITED_INPUT_NAME
 };
 
 /**
- * Determines if the OS is vista or later
- *
- * @return TRUE if the OS is vista or later.
- */
-BOOL
-UACHelper::IsVistaOrLater()
-{
-  // Check if we are running Vista or later.
-  OSVERSIONINFO osInfo;
-  osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-  return GetVersionEx(&osInfo) && osInfo.dwMajorVersion >= 6;
-}
-
-/**
  * Opens a user token for the given session ID
  *
  * @param  sessionID  The session ID for the token to obtain
  * @return A handle to the token to obtain which will be primary if enough
  *         permissions exist.  Caller should close the handle.
  */
 HANDLE
 UACHelper::OpenUserToken(DWORD sessionID)
--- a/toolkit/mozapps/update/common/uachelper.h
+++ b/toolkit/mozapps/update/common/uachelper.h
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef _UACHELPER_H_
 #define _UACHELPER_H_
 
 class UACHelper
 {
 public:
-  static BOOL IsVistaOrLater();
   static HANDLE OpenUserToken(DWORD sessionID);
   static HANDLE OpenLinkedToken(HANDLE token);
   static BOOL DisablePrivileges(HANDLE token);
 
 private:
   static BOOL SetPrivilege(HANDLE token, LPCTSTR privs, BOOL enable);
   static BOOL DisableUnneededPrivileges(HANDLE token, 
                                         LPCTSTR *unneededPrivs, size_t count);
--- a/toolkit/xre/nsWindowsDllBlocklist.cpp
+++ b/toolkit/xre/nsWindowsDllBlocklist.cpp
@@ -14,17 +14,17 @@
 #include "nsXULAppAPI.h"
 
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 
 #include "prlog.h"
 
 #include "nsWindowsDllInterceptor.h"
-#include "nsWindowsHelpers.h"
+#include "mozilla/WindowsVersion.h"
 
 using namespace mozilla;
 
 #if defined(MOZ_CRASHREPORTER) && !defined(NO_BLOCKLIST_CRASHREPORTER)
 #include "nsExceptionHandler.h"
 #endif
 
 #define ALL_VERSIONS   ((unsigned long long)-1LL)
@@ -299,26 +299,16 @@ wchar_t* getFullPath (PWCHAR filePath, w
   }
 
   // now actually grab it
   SearchPathW(sanitizedFilePath, fname, L".dll", pathlen + 1, full_fname,
               nullptr);
   return full_fname;
 }
 
-static bool
-IsWin8OrLater()
-{
-  OSVERSIONINFOW osInfo;
-  osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
-  GetVersionExW(&osInfo);
-  return (osInfo.dwMajorVersion > 6) ||
-    (osInfo.dwMajorVersion >= 6 && osInfo.dwMinorVersion >= 2);
-}
-
 static NTSTATUS NTAPI
 patched_LdrLoadDll (PWCHAR filePath, PULONG flags, PUNICODE_STRING moduleFileName, PHANDLE handle)
 {
   // We have UCS2 (UTF16?), we want ASCII, but we also just want the filename portion
 #define DLLNAME_MAX 128
   char dllName[DLLNAME_MAX+1];
   wchar_t *dll_part;
   DllBlockInfo *info;
new file mode 100644
--- /dev/null
+++ b/xpcom/base/WindowsVersion.h
@@ -0,0 +1,70 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_WindowsVersion_h
+#define mozilla_WindowsVersion_h
+
+#include "nscore.h"
+#include <windows.h>
+
+namespace mozilla
+{
+  inline bool
+  IsWindowsVersionOrLater(uint64_t aVersion)
+  {
+    static uint64_t minVersion = 0;
+    static uint64_t maxVersion = UINT64_MAX;
+
+    if (minVersion >= aVersion) {
+      return true;
+    }
+
+    if (aVersion >= maxVersion) {
+      return false;
+    }
+
+    OSVERSIONINFOEX info;
+    ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
+    info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+    info.dwMajorVersion = aVersion >> 48;
+    info.dwMinorVersion = (aVersion >> 32) & 0xFFFF;
+    info.wServicePackMajor = (aVersion >> 16) & 0xFFFF;
+    info.wServicePackMinor = aVersion & 0xFFFF;
+
+    DWORDLONG conditionMask = 0;
+    VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
+    VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
+    VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
+    VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL);
+
+    if (VerifyVersionInfo(&info,
+                          VER_MAJORVERSION | VER_MINORVERSION |
+                          VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
+                          conditionMask)) {
+      minVersion = aVersion;
+      return true;
+    }
+
+    maxVersion = aVersion;
+    return false;
+  }
+
+  MOZ_ALWAYS_INLINE bool
+  IsVistaOrLater()
+  { return IsWindowsVersionOrLater(0x0006000000000000ull); }
+
+  MOZ_ALWAYS_INLINE bool
+  IsWin7OrLater()
+  { return IsWindowsVersionOrLater(0x0006000100000000ull); }
+
+  MOZ_ALWAYS_INLINE bool
+  IsWin7SP1OrLater()
+  { return IsWindowsVersionOrLater(0x0006000100010000ull); }
+
+  MOZ_ALWAYS_INLINE bool
+  IsWin8OrLater()
+  { return IsWindowsVersionOrLater(0x0006000200000000ull); }
+}
+
+#endif /* mozilla_WindowsVersion_h */
--- a/xpcom/base/moz.build
+++ b/xpcom/base/moz.build
@@ -77,16 +77,21 @@ EXPORTS.mozilla += [
     'CycleCollectedJSRuntime.h',
     'StackWalk.h',
     'StaticMutex.h',
     'StaticPtr.h',
     'VisualEventTracer.h',
     'nsMemoryInfoDumper.h',
 ]
 
+if CONFIG['OS_ARCH'] == 'WINNT':
+    EXPORTS.mozilla += [
+        'WindowsVersion.h',
+    ]
+
 CPP_SOURCES += [
     'AvailableMemoryTracker.cpp',
     'ClearOnShutdown.cpp',
     'CycleCollectedJSRuntime.cpp',
     'VisualEventTracer.cpp',
     'nsConsoleMessage.cpp',
     'nsConsoleService.cpp',
     'nsCycleCollector.cpp',
--- a/xpcom/base/nsWindowsHelpers.h
+++ b/xpcom/base/nsWindowsHelpers.h
@@ -101,26 +101,16 @@ public:
 typedef nsAutoRef<HKEY> nsAutoRegKey;
 typedef nsAutoRef<SC_HANDLE> nsAutoServiceHandle;
 typedef nsAutoRef<HANDLE> nsAutoHandle;
 typedef nsAutoRef<HMODULE> nsModuleHandle;
 
 namespace
 {
   bool
-  IsVistaOrLater()
-  {
-    OSVERSIONINFO info;
-    ZeroMemory(&info, sizeof(OSVERSIONINFO));
-    info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    GetVersionEx(&info);
-    return info.dwMajorVersion >= 6;
-  }
-
-  bool
   IsRunningInWindowsMetro()
   {
     static bool alreadyChecked = false;
     static bool isMetro = false;
     if (alreadyChecked) {
       return isMetro;
     }
 
--- a/xpcom/glue/nsThreadUtils.cpp
+++ b/xpcom/glue/nsThreadUtils.cpp
@@ -13,17 +13,18 @@
 #else
 # include "nsXPCOMCIDInternal.h"
 # include "nsIThreadManager.h"
 # include "nsServiceManagerUtils.h"
 #endif
 
 #ifdef XP_WIN
 #include <windows.h>
-#include "nsWindowsHelpers.h"
+#include "mozilla/WindowsVersion.h"
+using mozilla::IsVistaOrLater;
 #elif defined(XP_MACOSX)
 #include <sys/resource.h>
 #endif
 
 #include <pratom.h>
 #include <prthread.h>
 
 #ifndef XPCOM_GLUE_AVOID_NSPR