msxml3: Remove get_ownerDocument() forward.
[wine] / dlls / ntdll / version.c
index c89d26f..46385c9 100644 (file)
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
 #include "config.h"
 #include <stdarg.h>
 #include <stdio.h>
 #include "ntstatus.h"
+#define WIN32_NO_STATUS
 #include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
-#include "winuser.h"
-#include "winreg.h"
-#include "winternl.h"
-#include "winerror.h"
-#include "module.h"
 #include "wine/unicode.h"
 #include "wine/debug.h"
 #include "ntdll_misc.h"
+#include "ddk/wdm.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(ver);
 
@@ -56,12 +51,15 @@ typedef enum
     NT2K,    /* Windows 2000 */
     WINXP,   /* Windows XP */
     WIN2K3,  /* Windows 2003 */
+    WINVISTA,/* Windows Vista */
+    WIN2K8,  /* Windows 2008 */
+    WIN7,    /* Windows 7 */
     NB_WINDOWS_VERSIONS
 } WINDOWS_VERSION;
 
 /* FIXME: compare values below with original and fix.
  * An *excellent* win9x version page (ALL versions !)
- * can be found at members.aol.com/axcel216/ver.htm */
+ * can be found at www.mdgx.com/ver.htm */
 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
 {
     /* WIN20 FIXME: verify values */
@@ -90,8 +88,6 @@ static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
          * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
          * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
          * Win95a/b can be discerned via regkey SubVersionNumber
-         * See also:
-         * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
          */
         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
         {0},
@@ -121,26 +117,44 @@ static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
     /* NT40 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6',0},
+        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
         6, 0, 0, VER_NT_WORKSTATION, 0
     },
     /* NT2K */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
-        3, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
+        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
+        4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
     },
     /* WINXP */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
-        1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
+        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
+        3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
     },
     /* WIN2K3 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
-        {0},
+        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
+        2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
+    },
+    /* WINVISTA */
+    {
+        sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
+        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
+        2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
+    },
+    /* WIN2K8 */
+    {
+        sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1771, VER_PLATFORM_WIN32_NT,
+        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
         0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
+    },
+    /* WIN7 */
+    {
+        sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
+        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
+        1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
     }
 };
 
@@ -156,48 +170,234 @@ static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
     "nt40",                       /* NT40 */
     "win2000,win2k,nt2k,nt2000",  /* NT2K */
     "winxp",                      /* WINXP */
-    "win2003,win2k3"              /* WIN2K3 */
+    "win2003,win2k3",             /* WIN2K3 */
+    "vista,winvista",             /* WINVISTA*/
+    "win2008,win2k8",             /* WIN2K8 */
+    "win7",                       /* WIN7 */
 };
 
-/* names to print out in debug traces */
-static const char * const debug_names[NB_WINDOWS_VERSIONS] =
+
+/* initialized to null so that we crash if we try to retrieve the version too early at startup */
+static const RTL_OSVERSIONINFOEXW *current_version;
+
+
+/**********************************************************************
+ *         get_nt_registry_version
+ *
+ * Fetch the version information from the NT-style registry keys.
+ */
+static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
 {
-    "Windows 2.0",       /* WIN20 */
-    "Windows 3.0",       /* WIN30 */
-    "Windows 3.1",       /* WIN31 */
-    "Windows 95",        /* WIN95 */
-    "Windows 98",        /* WIN98 */
-    "Windows Me",        /* WINME */
-    "Windows NT 3.51",   /* NT351 */
-    "Windows NT 4.0",    /* NT40 */
-    "Windows 2000",      /* NT2K */
-    "Windows XP",        /* WINXP */
-    "Windows 2003"       /* WIN2K3 */
-};
+    static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
+                                         'S','o','f','t','w','a','r','e','\\',
+                                         'M','i','c','r','o','s','o','f','t','\\',
+                                         'W','i','n','d','o','w','s',' ','N','T','\\',
+                                         'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
+    static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
+                                              'S','y','s','t','e','m','\\',
+                                              'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+                                              'C','o','n','t','r','o','l','\\',
+                                              'W','i','n','d','o','w','s',0};
+    static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
+                                         'S','y','s','t','e','m','\\',
+                                         'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+                                         'C','o','n','t','r','o','l','\\',
+                                         'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
+    static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
+    static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
+    static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
+    static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
+    static const WCHAR WinNTW[]    = {'W','i','n','N','T',0};
+    static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
+    static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
+
+    OBJECT_ATTRIBUTES attr;
+    UNICODE_STRING nameW, valueW;
+    HANDLE hkey, hkey2;
+    char tmp[64];
+    DWORD count;
+    BOOL ret = FALSE;
+    KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
+
+    attr.Length = sizeof(attr);
+    attr.RootDirectory = 0;
+    attr.ObjectName = &nameW;
+    attr.Attributes = 0;
+    attr.SecurityDescriptor = NULL;
+    attr.SecurityQualityOfService = NULL;
+    RtlInitUnicodeString( &nameW, version_keyW );
+
+    if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
+
+    memset( version, 0, sizeof(*version) );
+
+    RtlInitUnicodeString( &valueW, CurrentVersionW );
+    if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
+    {
+        WCHAR *p, *str = (WCHAR *)info->Data;
+        str[info->DataLength / sizeof(WCHAR)] = 0;
+        p = strchrW( str, '.' );
+        if (p)
+        {
+            *p++ = 0;
+            version->dwMinorVersion = atoiW( p );
+        }
+        version->dwMajorVersion = atoiW( str );
+    }
+
+    if (version->dwMajorVersion)   /* we got the main version, now fetch the other fields */
+    {
+        ret = TRUE;
+        version->dwPlatformId = VER_PLATFORM_WIN32_NT;
+
+        /* get build number */
+
+        RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
+        if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
+        {
+            WCHAR *str = (WCHAR *)info->Data;
+            str[info->DataLength / sizeof(WCHAR)] = 0;
+            version->dwBuildNumber = atoiW( str );
+        }
 
-/* if one of the following dlls is importing ntdll the windows
-version autodetection switches wine to unicode (nt 3.51 or 4.0) */
-static const WCHAR special_dlls[][16] =
+        /* get version description */
+
+        RtlInitUnicodeString( &valueW, CSDVersionW );
+        if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
+        {
+            DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
+            memcpy( version->szCSDVersion, info->Data, len );
+            version->szCSDVersion[len / sizeof(WCHAR)] = 0;
+        }
+
+        /* get service pack version */
+
+        RtlInitUnicodeString( &nameW, service_pack_keyW );
+        if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
+        {
+            RtlInitUnicodeString( &valueW, CSDVersionW );
+            if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
+            {
+                if (info->DataLength >= sizeof(DWORD))
+                {
+                    DWORD dw = *(DWORD *)info->Data;
+                    version->wServicePackMajor = LOWORD(dw) >> 8;
+                    version->wServicePackMinor = LOWORD(dw) & 0xff;
+                }
+            }
+            NtClose( hkey2 );
+        }
+
+        /* get product type */
+
+        RtlInitUnicodeString( &nameW, product_keyW );
+        if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
+        {
+            RtlInitUnicodeString( &valueW, ProductTypeW );
+            if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
+            {
+                WCHAR *str = (WCHAR *)info->Data;
+                str[info->DataLength / sizeof(WCHAR)] = 0;
+                if (!strcmpiW( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
+                else if (!strcmpiW( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
+                else if (!strcmpiW( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
+            }
+            NtClose( hkey2 );
+        }
+
+        /* FIXME: get wSuiteMask */
+    }
+
+    NtClose( hkey );
+    return ret;
+}
+
+
+/**********************************************************************
+ *         get_win9x_registry_version
+ *
+ * Fetch the version information from the Win9x-style registry keys.
+ */
+static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
 {
-    {'c','o','m','d','l','g','3','2','.','d','l','l',0},
-    {'c','o','m','c','t','l','3','2','.','d','l','l',0},
-    {'s','h','e','l','l','3','2','.','d','l','l',0},
-    {'o','l','e','3','2','.','d','l','l',0},
-    {'r','p','c','r','t','4','.','d','l','l',0}
-};
+    static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
+                                         'S','o','f','t','w','a','r','e','\\',
+                                         'M','i','c','r','o','s','o','f','t','\\',
+                                         'W','i','n','d','o','w','s','\\',
+                                         'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
+    static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
+    static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
+
+    OBJECT_ATTRIBUTES attr;
+    UNICODE_STRING nameW, valueW;
+    HANDLE hkey;
+    char tmp[64];
+    DWORD count;
+    BOOL ret = FALSE;
+    KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
+
+    attr.Length = sizeof(attr);
+    attr.RootDirectory = 0;
+    attr.ObjectName = &nameW;
+    attr.Attributes = 0;
+    attr.SecurityDescriptor = NULL;
+    attr.SecurityQualityOfService = NULL;
+    RtlInitUnicodeString( &nameW, version_keyW );
+
+    if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
+
+    memset( version, 0, sizeof(*version) );
+
+    RtlInitUnicodeString( &valueW, VersionNumberW );
+    if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
+    {
+        WCHAR *p, *str = (WCHAR *)info->Data;
+        str[info->DataLength / sizeof(WCHAR)] = 0;
+        p = strchrW( str, '.' );
+        if (p) *p++ = 0;
+        version->dwMajorVersion = atoiW( str );
+        if (p)
+        {
+            str = p;
+            p = strchrW( str, '.' );
+            if (p)
+            {
+                *p++ = 0;
+                version->dwBuildNumber = atoiW( p );
+            }
+            version->dwMinorVersion = atoiW( str );
+        }
+        /* build number contains version too on Win9x */
+        version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
+    }
+
+    if (version->dwMajorVersion)   /* we got the main version, now fetch the other fields */
+    {
+        ret = TRUE;
+        version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
+
+        RtlInitUnicodeString( &valueW, SubVersionNumberW );
+        if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
+        {
+            DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
+            memcpy( version->szCSDVersion, info->Data, len );
+            version->szCSDVersion[len / sizeof(WCHAR)] = 0;
+        }
+    }
+
+    NtClose( hkey );
+    return ret;
+}
 
-/* the current version has not been autodetected but forced via cmdline */
-static BOOL versionForced = FALSE;
-static WINDOWS_VERSION forcedWinVersion; /* init value irrelevant */
 
 /**********************************************************************
  *         parse_win_version
  *
  * Parse the contents of the Version key.
  */
-static BOOL parse_win_version( HKEY hkey )
+static BOOL parse_win_version( HANDLE hkey )
 {
-    static const WCHAR WindowsW[] = {'W','i','n','d','o','w','s',0};
+    static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
 
     UNICODE_STRING valueW;
     char tmp[64], buffer[50];
@@ -205,7 +405,7 @@ static BOOL parse_win_version( HKEY hkey )
     DWORD count, len;
     int i;
 
-    RtlInitUnicodeString( &valueW, WindowsW );
+    RtlInitUnicodeString( &valueW, VersionW );
     if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
         return FALSE;
 
@@ -221,9 +421,8 @@ static BOOL parse_win_version( HKEY hkey )
             len = p ? p - pCurr : strlen(pCurr);
             if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
             {
-                forcedWinVersion = i;
-                versionForced = TRUE;
-                TRACE( "got win version %s\n", WinVersionNames[forcedWinVersion] );
+                current_version = &VersionData[i];
+                TRACE( "got win version %s\n", WinVersionNames[i] );
                 return TRUE;
             }
             pCurr = p+1;
@@ -246,270 +445,132 @@ static BOOL parse_win_version( HKEY hkey )
 
 
 /**********************************************************************
- *         VERSION_Init
+ *         version_init
  */
-void VERSION_Init( const WCHAR *appname )
+void version_init( const WCHAR *appname )
 {
+    static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
+    static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
+
     OBJECT_ATTRIBUTES attr;
     UNICODE_STRING nameW;
-    HKEY hkey, config_key;
-    static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
-                                    'S','o','f','t','w','a','r','e','\\',
-                                    'W','i','n','e','\\',
-                                    'W','i','n','e','\\',
-                                    'C','o','n','f','i','g',0};
-    static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
-    static const WCHAR versionW[] = {'\\','V','e','r','s','i','o','n',0};
+    HANDLE root, hkey, config_key;
+    BOOL got_win_ver = FALSE;
 
+    current_version = &VersionData[WINXP];  /* default if nothing else is specified */
+
+    RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
     attr.Length = sizeof(attr);
-    attr.RootDirectory = 0;
+    attr.RootDirectory = root;
     attr.ObjectName = &nameW;
     attr.Attributes = 0;
     attr.SecurityDescriptor = NULL;
     attr.SecurityQualityOfService = NULL;
     RtlInitUnicodeString( &nameW, configW );
 
-    if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) return;
-    attr.RootDirectory = config_key;
+    /* @@ Wine registry key: HKCU\Software\Wine */
+    if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
+    NtClose( root );
+    if (!config_key) goto done;
 
-    /* open AppDefaults\\appname\\Version key */
+    /* open AppDefaults\\appname key */
     if (appname && *appname)
     {
         const WCHAR *p;
         WCHAR appversion[MAX_PATH+20];
-        BOOL got_win_ver = FALSE;
 
         if ((p = strrchrW( appname, '/' ))) appname = p + 1;
         if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
 
         strcpyW( appversion, appdefaultsW );
         strcatW( appversion, appname );
-        strcatW( appversion, versionW );
-        TRACE( "getting version from %s\n", debugstr_w(appversion) );
         RtlInitUnicodeString( &nameW, appversion );
+        attr.RootDirectory = config_key;
 
+        /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
         if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
         {
+            TRACE( "getting version from %s\n", debugstr_w(appversion) );
             got_win_ver = parse_win_version( hkey );
             NtClose( hkey );
         }
-        if (got_win_ver) goto done;
     }
 
-    TRACE( "getting default version\n" );
-    RtlInitUnicodeString( &nameW, versionW + 1 );
-    if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
+    if (!got_win_ver)
     {
-        parse_win_version( hkey );
-        NtClose( hkey );
+        TRACE( "getting default version\n" );
+        got_win_ver = parse_win_version( config_key );
     }
-
- done:
     NtClose( config_key );
-}
-
-
-/**********************************************************************
- *      VERSION_GetSystemDLLVersion
- *
- * This function tries to figure out if a given (native) dll comes from
- * win95/98 or winnt. Since all values in the OptionalHeader are not a
- * usable hint, we test if a dll imports the ntdll.
- * This is at least working for all system dlls like comctl32, comdlg32 and
- * shell32.
- * If you have a better idea to figure this out...
- */
-static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
-{
-    DWORD size;
-    IMAGE_IMPORT_DESCRIPTOR *pe_imp;
-
-    if ((pe_imp = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
-    {
-        for ( ; pe_imp->Name; pe_imp++)
-        {
-            char * name = (char *)hmod + (unsigned int)pe_imp->Name;
-            TRACE("%s\n", name);
-
-            if (!strncasecmp(name, "ntdll", 5))
-            {
-              switch(RtlImageNtHeader(hmod)->OptionalHeader.MajorOperatingSystemVersion) {
-                  case 3:
-                          MESSAGE("WARNING: very old native DLL (NT 3.x) used, might cause instability.\n");
-                          return NT351;
-                  case 4: return NT40;
-                  case 5: return NT2K;
-                  case 6: return WINXP;
-                  case 7: return WIN2K3; /* FIXME: Not sure, should be verified with a Win2K3 dll */
-                  default:
-                          FIXME("Unknown DLL OS version, please report !!\n");
-                          return WIN2K3;
-              }
-            }
-        }
-    }
-    return WIN95;
-}
-
 
-/**********************************************************************
- *      VERSION_GetLinkedDllVersion
- *
- * Some version data (not reliable!):
- * linker/OS/image/subsys
- *
- * x.xx/1.00/0.00/3.10  Win32s          (any version ?)
- * 2.39/1.00/0.00/3.10  Win32s          freecell.exe (any version)
- * 2.50/1.00/4.00/4.00  Win32s 1.30     winhlp32.exe
- * 2.60/3.51/3.51/3.51  NT351SP5        system dlls
- * 2.60/3.51/3.51/4.00  NT351SP5        comctl32 dll
- * 2.xx/1.00/0.00/4.00  Win95           system files
- * x.xx/4.00/0.00/4.00  Win95           most applications
- * 3.10/4.00/0.00/4.00  Win98           notepad
- * x.xx/5.00/5.00/4.00  Win98           system dlls (e.g. comctl32.dll)
- * x.xx/4.00/4.00/4.00  NT 4            most apps
- * 5.12/5.00/5.00/4.00  NT4+IE5         comctl32.dll
- * 5.12/5.00/5.00/4.00  Win98           calc
- * x.xx/5.00/5.00/4.00  win95/win98/NT4 IE5 files
- */
-static DWORD VERSION_GetLinkedDllVersion(void)
-{
-    WINDOWS_VERSION WinVersion = NB_WINDOWS_VERSIONS;
-    PIMAGE_OPTIONAL_HEADER ophd;
-    IMAGE_NT_HEADERS *nt;
-    const WCHAR *name;
-    PLIST_ENTRY mark, entry;
-    PLDR_MODULE mod;
-    int i;
-
-    /* First check the native dlls provided. These have to be
-       from one windows version */
-
-    mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
-    for (entry = mark->Flink; entry != mark; entry = entry->Flink)
+done:
+    if (!got_win_ver)
     {
-        mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
-        if (mod->Flags & LDR_WINE_INTERNAL) continue;
-        nt = RtlImageNtHeader(mod->BaseAddress);
-        ophd = &nt->OptionalHeader;
-        name = strrchrW( mod->FullDllName.Buffer, '\\' );
-        if (name) name++;
-        else name = mod->FullDllName.Buffer;
-
-        TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
-              debugstr_w(name), ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
-              ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
-              ophd->MajorImageVersion, ophd->MinorImageVersion,
-              ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
-
-        for (i = 0; i < sizeof(special_dlls)/sizeof(special_dlls[0]); i++)
-        {
-            /* test if it is a special dll */
-            if (!strcmpiW(name, special_dlls[i]))
-            {
-                DWORD DllVersion = VERSION_GetSystemDLLVersion(mod->BaseAddress);
-                if (WinVersion == NB_WINDOWS_VERSIONS) WinVersion = DllVersion;
-                else if (WinVersion != DllVersion)
-                {
-                    ERR("You mixed system DLLs from different windows versions! Expect a crash! (%s: expected version %s, but is %s)\n",
-                        debugstr_w(name),
-                        debugstr_w(VersionData[WinVersion].szCSDVersion),
-                        debugstr_w(VersionData[DllVersion].szCSDVersion));
-                    return WIN20; /* this may let the exe exit */
-                }
-                break;
-            }
-        }
-    }
+        static RTL_OSVERSIONINFOEXW registry_version;
 
-    if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
-
-    /* we are using no external system dlls, look at the exe */
-    nt = RtlImageNtHeader(NtCurrentTeb()->Peb->ImageBaseAddress);
-    ophd = &nt->OptionalHeader;
-
-    TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
-          ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
-          ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
-          ophd->MajorImageVersion, ophd->MinorImageVersion,
-          ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
-
-    /* special nt 3.51 */
-    if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
-    {
-        return NT351;
+        TRACE( "getting registry version\n" );
+        if (get_nt_registry_version( &registry_version ) ||
+            get_win9x_registry_version( &registry_version ))
+            current_version = &registry_version;
     }
 
-    /* the MajorSubsystemVersion is the only usable sign */
-    if (ophd->MajorSubsystemVersion < 4)
-    {
-        if ( ophd->MajorOperatingSystemVersion == 1
-             && ophd->MinorOperatingSystemVersion == 0)
-        {
-            return WIN31; /* win32s */
-        }
-
-        if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
-            return NT351; /* FIXME: NT 3.1, not tested */
-        else
-            return WIN95;
-    }
 
-    return WIN95;
+    NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
+    NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
+    NtCurrentTeb()->Peb->OSBuildNumber  = current_version->dwBuildNumber;
+    NtCurrentTeb()->Peb->OSPlatformId   = current_version->dwPlatformId;
+
+    user_shared_data->NtProductType      = current_version->wProductType;
+    user_shared_data->ProductTypeIsValid = TRUE;
+    user_shared_data->MajorNtVersion     = current_version->dwMajorVersion;
+    user_shared_data->MinorNtVersion     = current_version->dwMinorVersion;
+    user_shared_data->MinorNtVersion     = current_version->dwMinorVersion;
+    user_shared_data->SuiteMask          = current_version->wSuiteMask;
+
+    TRACE( "got %d.%d platform %d build %x name %s service pack %d.%d product %d\n",
+           current_version->dwMajorVersion, current_version->dwMinorVersion,
+           current_version->dwPlatformId, current_version->dwBuildNumber,
+           debugstr_w(current_version->szCSDVersion),
+           current_version->wServicePackMajor, current_version->wServicePackMinor,
+           current_version->wProductType );
 }
 
-/**********************************************************************
- *         VERSION_GetVersion
+/***********************************************************************
+ *           GetProductInfo       (NTDLL.@)
  *
- * WARNING !!!
- * Don't call this function too early during the Wine init,
- * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
- * be NULL in such cases, which causes the winver to ALWAYS be detected
- * as WIN31.
- * And as we cache the winver once it has been determined, this is bad.
- * This can happen much easier than you might think, as this function
- * is called by EVERY GetVersion*() API !
+ * Gives info about the current Windows product type, in a format compatible
+ * with the given Windows version
  *
+ * Returns TRUE if the input is valid, FALSE otherwise
  */
-static const RTL_OSVERSIONINFOEXW *VERSION_GetVersion(void)
+BOOLEAN WINAPI RtlGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion,
+                                 DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType)
 {
-    static WORD winver = 0xffff;
+    FIXME("(%d,%d,%d,%d,%p): stub\n", dwOSMajorVersion, dwOSMinorVersion,
+          dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType);
 
-    if (versionForced)
-        return &VersionData[forcedWinVersion];  /* user has overridden any sensible checks */
+    *pdwReturnedProductType = PRODUCT_ULTIMATE_N;
 
-    if (winver == 0xffff) /* to be determined */
-    {
-        WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion();
-
-        /* cache determined value, but do not store in case of WIN31 */
-        if (retver != WIN31) winver = retver;
-        return &VersionData[retver];
-    }
-    return &VersionData[winver];
+    return TRUE;
 }
 
-
 /***********************************************************************
  *         RtlGetVersion   (NTDLL.@)
  */
 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
 {
-    const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
-
-    info->dwMajorVersion = current->dwMajorVersion;
-    info->dwMinorVersion = current->dwMinorVersion;
-    info->dwBuildNumber  = current->dwBuildNumber;
-    info->dwPlatformId   = current->dwPlatformId;
-    strcpyW( info->szCSDVersion, current->szCSDVersion );
+    info->dwMajorVersion = current_version->dwMajorVersion;
+    info->dwMinorVersion = current_version->dwMinorVersion;
+    info->dwBuildNumber  = current_version->dwBuildNumber;
+    info->dwPlatformId   = current_version->dwPlatformId;
+    strcpyW( info->szCSDVersion, current_version->szCSDVersion );
     if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
     {
-        info->wServicePackMajor = current->wServicePackMajor;
-        info->wServicePackMinor = current->wServicePackMinor;
-        info->wSuiteMask        = current->wSuiteMask;
-        info->wProductType      = current->wProductType;
+        info->wServicePackMajor = current_version->wServicePackMajor;
+        info->wServicePackMinor = current_version->wServicePackMinor;
+        info->wSuiteMask        = current_version->wSuiteMask;
+        info->wProductType      = current_version->wProductType;
     }
-    TRACE("<-- %s (%s)\n", debug_names[current - VersionData], debugstr_w(current->szCSDVersion) );
     return STATUS_SUCCESS;
 }
 
@@ -532,17 +593,49 @@ NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
  */
 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
 {
-    const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
-
-    if (major) *major = current->dwMajorVersion;
-    if (minor) *minor = current->dwMinorVersion;
+    if (major) *major = current_version->dwMajorVersion;
+    if (minor) *minor = current_version->dwMinorVersion;
     /* FIXME: Does anybody know the real formula? */
-    if (build) *build = (0xF0000000 | current->dwBuildNumber);
+    if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
 }
 
 
 /******************************************************************************
- *        VerifyVersionInfoW   (KERNEL32.@)
+ *  RtlGetNtProductType   (NTDLL.@)
+ */
+BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
+{
+    if (type) *type = current_version->wProductType;
+    return TRUE;
+}
+
+
+static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
+{
+    switch (condition) {
+        case VER_EQUAL:
+            if (left != right) return STATUS_REVISION_MISMATCH;
+            break;
+        case VER_GREATER:
+            if (left <= right) return STATUS_REVISION_MISMATCH;
+            break;
+        case VER_GREATER_EQUAL:
+            if (left < right) return STATUS_REVISION_MISMATCH;
+            break;
+        case VER_LESS:
+            if (left >= right) return STATUS_REVISION_MISMATCH;
+            break;
+        case VER_LESS_EQUAL:
+            if (left > right) return STATUS_REVISION_MISMATCH;
+            break;
+        default:
+            return STATUS_REVISION_MISMATCH;
+    }
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ *        RtlVerifyVersionInfo   (NTDLL.@)
  */
 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
                                       DWORD dwTypeMask, DWORDLONG dwlConditionMask )
@@ -550,15 +643,7 @@ NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
     RTL_OSVERSIONINFOEXW ver;
     NTSTATUS status;
 
-    FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n",
-          info, dwTypeMask, dwlConditionMask);
-
-    /* FIXME:
-        - Check the following special case on Windows (various versions):
-          o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
-          o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
-        - MSDN talks about some tests being impossible. Check what really happens.
-     */
+    TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
 
     ver.dwOSVersionInfoSize = sizeof(ver);
     if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
@@ -566,25 +651,11 @@ NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
     if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
 
     if(dwTypeMask & VER_PRODUCT_TYPE)
-        switch(dwlConditionMask >> 7*3 & 0x07) {
-            case VER_EQUAL:
-                if(ver.wProductType != info->wProductType) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER:
-                if(ver.wProductType <= info->wProductType) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER_EQUAL:
-                if(ver.wProductType < info->wProductType) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS:
-                if(ver.wProductType >= info->wProductType) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS_EQUAL:
-                if(ver.wProductType > info->wProductType) return STATUS_REVISION_MISMATCH;
-                break;
-            default:
-                return STATUS_INVALID_PARAMETER;
-        }
+    {
+        status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
+        if (status != STATUS_SUCCESS)
+            return status;
+    }
     if(dwTypeMask & VER_SUITENAME)
         switch(dwlConditionMask >> 6*3 & 0x07)
         {
@@ -600,131 +671,58 @@ NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
                 return STATUS_INVALID_PARAMETER;
         }
     if(dwTypeMask & VER_PLATFORMID)
-        switch(dwlConditionMask >> 3*3 & 0x07)
-        {
-            case VER_EQUAL:
-                if(ver.dwPlatformId != info->dwPlatformId) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER:
-                if(ver.dwPlatformId <= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER_EQUAL:
-                if(ver.dwPlatformId < info->dwPlatformId) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS:
-                if(ver.dwPlatformId >= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS_EQUAL:
-                if(ver.dwPlatformId > info->dwPlatformId) return STATUS_REVISION_MISMATCH;
-                break;
-            default:
-                return STATUS_INVALID_PARAMETER;
-        }
+    {
+        status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
+        if (status != STATUS_SUCCESS)
+            return status;
+    }
     if(dwTypeMask & VER_BUILDNUMBER)
-        switch(dwlConditionMask >> 2*3 & 0x07)
+    {
+        status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
+        if (status != STATUS_SUCCESS)
+            return status;
+    }
+
+    if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
+    {
+        unsigned char condition = 0;
+        BOOLEAN do_next_check = TRUE;
+
+        if(dwTypeMask & VER_MAJORVERSION)
+            condition = dwlConditionMask >> 1*3 & 0x07;
+        else if(dwTypeMask & VER_MINORVERSION)
+            condition = dwlConditionMask >> 0*3 & 0x07;
+        else if(dwTypeMask & VER_SERVICEPACKMAJOR)
+            condition = dwlConditionMask >> 5*3 & 0x07;
+        else if(dwTypeMask & VER_SERVICEPACKMINOR)
+            condition = dwlConditionMask >> 4*3 & 0x07;
+
+        if(dwTypeMask & VER_MAJORVERSION)
         {
-            case VER_EQUAL:
-                if(ver.dwBuildNumber != info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER:
-                if(ver.dwBuildNumber <= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER_EQUAL:
-                if(ver.dwBuildNumber < info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS:
-                if(ver.dwBuildNumber >= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS_EQUAL:
-                if(ver.dwBuildNumber > info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
-                break;
-            default:
-                return STATUS_INVALID_PARAMETER;
+            status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
+            do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
+                ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
         }
-    if(dwTypeMask & VER_MAJORVERSION)
-        switch(dwlConditionMask >> 1*3 & 0x07)
+        if((dwTypeMask & VER_MINORVERSION) && do_next_check)
         {
-            case VER_EQUAL:
-                if(ver.dwMajorVersion != info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER:
-                if(ver.dwMajorVersion <= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER_EQUAL:
-                if(ver.dwMajorVersion < info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS:
-                if(ver.dwMajorVersion >= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS_EQUAL:
-                if(ver.dwMajorVersion > info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            default:
-                return STATUS_INVALID_PARAMETER;
-        }
-    if(dwTypeMask & VER_MINORVERSION)
-        switch(dwlConditionMask >> 0*3 & 0x07)
-        {
-            case VER_EQUAL:
-                if(ver.dwMinorVersion != info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER:
-                if(ver.dwMinorVersion <= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER_EQUAL:
-                if(ver.dwMinorVersion < info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS:
-                if(ver.dwMinorVersion >= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS_EQUAL:
-                if(ver.dwMinorVersion > info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
-                break;
-            default:
-                return STATUS_INVALID_PARAMETER;
+            status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
+            do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
+                ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
         }
-    if(dwTypeMask & VER_SERVICEPACKMAJOR)
-        switch(dwlConditionMask >> 5*3 & 0x07)
+        if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
         {
-            case VER_EQUAL:
-                if(ver.wServicePackMajor != info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER:
-                if(ver.wServicePackMajor <= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER_EQUAL:
-                if(ver.wServicePackMajor < info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS:
-                if(ver.wServicePackMajor >= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS_EQUAL:
-                if(ver.wServicePackMajor > info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
-                break;
-            default:
-                return STATUS_INVALID_PARAMETER;
+            status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
+            do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
+                ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
         }
-    if(dwTypeMask & VER_SERVICEPACKMINOR)
-        switch(dwlConditionMask >> 4*3 & 0x07)
+        if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
         {
-            case VER_EQUAL:
-                if(ver.wServicePackMinor != info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER:
-                if(ver.wServicePackMinor <= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_GREATER_EQUAL:
-                if(ver.wServicePackMinor < info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS:
-                if(ver.wServicePackMinor >= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
-                break;
-            case VER_LESS_EQUAL:
-                if(ver.wServicePackMinor > info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
-                break;
-            default:
-                return STATUS_INVALID_PARAMETER;
+            status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
         }
 
+        if (status != STATUS_SUCCESS)
+            return status;
+    }
+
     return STATUS_SUCCESS;
 }