mshtml: Don't crash creating a URI if we have no document.
[wine.git] / dlls / ntdll / version.c
blobb6cafc601a7c2b7ba21ef6b86626702a8f4ce2f0
1 /*
2 * Windows and DOS version functions
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Patrik Stridvall
6 * Copyright 1998, 2003 Andreas Mohr
7 * Copyright 1997, 2003 Alexandre Julliard
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "windef.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
36 #include "ntdll_misc.h"
37 #include "ddk/wdm.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ver);
41 typedef enum
43 WIN20, /* Windows 2.0 */
44 WIN30, /* Windows 3.0 */
45 WIN31, /* Windows 3.1 */
46 WIN95, /* Windows 95 */
47 WIN98, /* Windows 98 */
48 WINME, /* Windows Me */
49 NT351, /* Windows NT 3.51 */
50 NT40, /* Windows NT 4.0 */
51 NT2K, /* Windows 2000 */
52 WINXP, /* Windows XP */
53 WINXP64, /* Windows XP 64-bit */
54 WIN2K3, /* Windows 2003 */
55 WINVISTA,/* Windows Vista */
56 WIN2K8, /* Windows 2008 */
57 WIN2K8R2,/* Windows 2008 R2 */
58 WIN7, /* Windows 7 */
59 WIN8, /* Windows 8 */
60 WIN81, /* Windows 8.1 */
61 WIN10, /* Windows 10 */
62 NB_WINDOWS_VERSIONS
63 } WINDOWS_VERSION;
65 /* FIXME: compare values below with original and fix.
66 * An *excellent* win9x version page (ALL versions !)
67 * can be found at www.mdgx.com/ver.htm */
68 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
70 /* WIN20 FIXME: verify values */
72 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
73 {'W','i','n','3','2','s',' ','1','.','3',0},
74 0, 0, 0, 0, 0
76 /* WIN30 FIXME: verify values */
78 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
79 {'W','i','n','3','2','s',' ','1','.','3',0},
80 0, 0, 0, 0, 0
82 /* WIN31 */
84 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
85 {'W','i','n','3','2','s',' ','1','.','3',0},
86 0, 0, 0, 0, 0
88 /* WIN95 */
90 /* Win95: 4, 0, 0x40003B6, ""
91 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
92 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
93 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
94 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
95 * Win95a/b can be discerned via regkey SubVersionNumber
97 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
98 {0},
99 0, 0, 0, 0, 0
101 /* WIN98 (second edition) */
103 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
104 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
106 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
107 {' ','A',' ',0},
108 0, 0, 0, 0, 0
110 /* WINME */
112 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
113 {' ',0},
114 0, 0, 0, 0, 0
116 /* NT351 */
118 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
119 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','5',0},
120 5, 0, 0, VER_NT_WORKSTATION, 0
122 /* NT40 */
124 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
125 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
126 6, 0, 0, VER_NT_WORKSTATION, 0
128 /* NT2K */
130 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
131 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
132 4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
134 /* WINXP */
136 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
137 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
138 3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
140 /* WINXP64 */
142 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
143 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
144 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
146 /* WIN2K3 */
148 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
149 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
150 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
152 /* WINVISTA */
154 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
155 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
156 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
158 /* WIN2K8 */
160 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
161 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
162 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
164 /* WIN7 */
166 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
167 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
168 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
170 /* WIN2K8R2 */
172 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
173 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
174 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
176 /* WIN8 */
178 sizeof(RTL_OSVERSIONINFOEXW), 6, 2, 0x23F0, VER_PLATFORM_WIN32_NT,
179 {' ',0},
180 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
182 /* WIN81 */
184 sizeof(RTL_OSVERSIONINFOEXW), 6, 3, 0x2580, VER_PLATFORM_WIN32_NT,
185 {' ',0},
186 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
188 /* WIN10 */
190 sizeof(RTL_OSVERSIONINFOEXW), 10, 0, 0x3839, VER_PLATFORM_WIN32_NT,
191 {' ',0},
192 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
197 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
198 { /* no spaces in here ! */
199 "win20", /* WIN20 */
200 "win30", /* WIN30 */
201 "win31", /* WIN31 */
202 "win95", /* WIN95 */
203 "win98", /* WIN98 */
204 "winme", /* WINME */
205 "nt351", /* NT351 */
206 "nt40", /* NT40 */
207 "win2000,win2k,nt2k,nt2000", /* NT2K */
208 "winxp", /* WINXP */
209 "winxp64", /* WINXP64 */
210 "win2003,win2k3", /* WIN2K3 */
211 "vista,winvista", /* WINVISTA*/
212 "win2008,win2k8", /* WIN2K8 */
213 "win2008r2,win2k8r2", /* WIN2K8R2 */
214 "win7", /* WIN7 */
215 "win8", /* WIN8 */
216 "win81", /* WIN81 */
217 "win10", /* WIN10 */
221 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
222 static const RTL_OSVERSIONINFOEXW *current_version;
225 /**********************************************************************
226 * get_nt_registry_version
228 * Fetch the version information from the NT-style registry keys.
230 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
232 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
233 'S','o','f','t','w','a','r','e','\\',
234 'M','i','c','r','o','s','o','f','t','\\',
235 'W','i','n','d','o','w','s',' ','N','T','\\',
236 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
237 static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
238 'S','y','s','t','e','m','\\',
239 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
240 'C','o','n','t','r','o','l','\\',
241 'W','i','n','d','o','w','s',0};
242 static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
243 'S','y','s','t','e','m','\\',
244 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
245 'C','o','n','t','r','o','l','\\',
246 'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
247 static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
248 static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
249 static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
250 static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
251 static const WCHAR WinNTW[] = {'W','i','n','N','T',0};
252 static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
253 static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
255 OBJECT_ATTRIBUTES attr;
256 UNICODE_STRING nameW, valueW;
257 HANDLE hkey, hkey2;
258 char tmp[64];
259 DWORD count;
260 BOOL ret = FALSE;
261 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
263 attr.Length = sizeof(attr);
264 attr.RootDirectory = 0;
265 attr.ObjectName = &nameW;
266 attr.Attributes = 0;
267 attr.SecurityDescriptor = NULL;
268 attr.SecurityQualityOfService = NULL;
269 RtlInitUnicodeString( &nameW, version_keyW );
271 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
273 memset( version, 0, sizeof(*version) );
275 RtlInitUnicodeString( &valueW, CurrentVersionW );
276 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
278 WCHAR *p, *str = (WCHAR *)info->Data;
279 str[info->DataLength / sizeof(WCHAR)] = 0;
280 p = strchrW( str, '.' );
281 if (p)
283 *p++ = 0;
284 version->dwMinorVersion = atoiW( p );
286 version->dwMajorVersion = atoiW( str );
289 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
291 ret = TRUE;
292 version->dwPlatformId = VER_PLATFORM_WIN32_NT;
294 /* get build number */
296 RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
297 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
299 WCHAR *str = (WCHAR *)info->Data;
300 str[info->DataLength / sizeof(WCHAR)] = 0;
301 version->dwBuildNumber = atoiW( str );
304 /* get version description */
306 RtlInitUnicodeString( &valueW, CSDVersionW );
307 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
309 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
310 memcpy( version->szCSDVersion, info->Data, len );
311 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
314 /* get service pack version */
316 RtlInitUnicodeString( &nameW, service_pack_keyW );
317 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
319 RtlInitUnicodeString( &valueW, CSDVersionW );
320 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
322 if (info->DataLength >= sizeof(DWORD))
324 DWORD dw = *(DWORD *)info->Data;
325 version->wServicePackMajor = LOWORD(dw) >> 8;
326 version->wServicePackMinor = LOWORD(dw) & 0xff;
329 NtClose( hkey2 );
332 /* get product type */
334 RtlInitUnicodeString( &nameW, product_keyW );
335 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
337 RtlInitUnicodeString( &valueW, ProductTypeW );
338 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
340 WCHAR *str = (WCHAR *)info->Data;
341 str[info->DataLength / sizeof(WCHAR)] = 0;
342 if (!strcmpiW( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
343 else if (!strcmpiW( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
344 else if (!strcmpiW( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
346 NtClose( hkey2 );
349 /* FIXME: get wSuiteMask */
352 NtClose( hkey );
353 return ret;
357 /**********************************************************************
358 * get_win9x_registry_version
360 * Fetch the version information from the Win9x-style registry keys.
362 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
364 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
365 'S','o','f','t','w','a','r','e','\\',
366 'M','i','c','r','o','s','o','f','t','\\',
367 'W','i','n','d','o','w','s','\\',
368 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
369 static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
370 static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
372 OBJECT_ATTRIBUTES attr;
373 UNICODE_STRING nameW, valueW;
374 HANDLE hkey;
375 char tmp[64];
376 DWORD count;
377 BOOL ret = FALSE;
378 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
380 attr.Length = sizeof(attr);
381 attr.RootDirectory = 0;
382 attr.ObjectName = &nameW;
383 attr.Attributes = 0;
384 attr.SecurityDescriptor = NULL;
385 attr.SecurityQualityOfService = NULL;
386 RtlInitUnicodeString( &nameW, version_keyW );
388 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
390 memset( version, 0, sizeof(*version) );
392 RtlInitUnicodeString( &valueW, VersionNumberW );
393 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
395 WCHAR *p, *str = (WCHAR *)info->Data;
396 str[info->DataLength / sizeof(WCHAR)] = 0;
397 p = strchrW( str, '.' );
398 if (p) *p++ = 0;
399 version->dwMajorVersion = atoiW( str );
400 if (p)
402 str = p;
403 p = strchrW( str, '.' );
404 if (p)
406 *p++ = 0;
407 version->dwBuildNumber = atoiW( p );
409 version->dwMinorVersion = atoiW( str );
411 /* build number contains version too on Win9x */
412 version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
415 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
417 ret = TRUE;
418 version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
420 RtlInitUnicodeString( &valueW, SubVersionNumberW );
421 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
423 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
424 memcpy( version->szCSDVersion, info->Data, len );
425 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
429 NtClose( hkey );
430 return ret;
434 /**********************************************************************
435 * parse_win_version
437 * Parse the contents of the Version key.
439 static BOOL parse_win_version( HANDLE hkey )
441 static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
443 UNICODE_STRING valueW;
444 char tmp[64], buffer[50];
445 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
446 DWORD count, len;
447 int i;
449 RtlInitUnicodeString( &valueW, VersionW );
450 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
451 return FALSE;
453 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
454 buffer[len] = 0;
456 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
458 const char *p, *pCurr = WinVersionNames[i];
459 /* iterate through all winver aliases separated by comma */
460 do {
461 p = strchr(pCurr, ',');
462 len = p ? p - pCurr : strlen(pCurr);
463 if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
465 current_version = &VersionData[i];
466 TRACE( "got win version %s\n", WinVersionNames[i] );
467 return TRUE;
469 pCurr = p+1;
470 } while (p);
473 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
474 MESSAGE("Valid versions are:" );
475 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
477 /* only list the first, "official" alias in case of aliases */
478 const char *pCurr = WinVersionNames[i];
479 const char *p = strchr(pCurr, ',');
480 len = (p) ? p - pCurr : strlen(pCurr);
482 MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
484 return FALSE;
488 /**********************************************************************
489 * version_init
491 void version_init( const WCHAR *appname )
493 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
494 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
495 static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
496 OBJECT_ATTRIBUTES attr;
497 UNICODE_STRING nameW;
498 HANDLE root, hkey, config_key;
499 BOOL got_win_ver = FALSE;
501 if (is_win64 || is_wow64)
502 current_version = &VersionData[WINXP64]; /* default if nothing else is specified */
503 else
504 current_version = &VersionData[WINXP];
506 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
507 attr.Length = sizeof(attr);
508 attr.RootDirectory = root;
509 attr.ObjectName = &nameW;
510 attr.Attributes = 0;
511 attr.SecurityDescriptor = NULL;
512 attr.SecurityQualityOfService = NULL;
513 RtlInitUnicodeString( &nameW, configW );
515 /* @@ Wine registry key: HKCU\Software\Wine */
516 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
517 NtClose( root );
518 if (!config_key) goto done;
520 /* open AppDefaults\\appname key */
521 if (appname && *appname)
523 const WCHAR *p;
524 WCHAR appversion[MAX_PATH+20];
526 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
527 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
529 strcpyW( appversion, appdefaultsW );
530 strcatW( appversion, appname );
531 RtlInitUnicodeString( &nameW, appversion );
532 attr.RootDirectory = config_key;
534 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
535 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
537 TRACE( "getting version from %s\n", debugstr_w(appversion) );
538 got_win_ver = parse_win_version( hkey );
539 NtClose( hkey );
543 if (!got_win_ver)
545 TRACE( "getting default version\n" );
546 got_win_ver = parse_win_version( config_key );
548 NtClose( config_key );
550 done:
551 if (!got_win_ver)
553 static RTL_OSVERSIONINFOEXW registry_version;
555 TRACE( "getting registry version\n" );
556 if (get_nt_registry_version( &registry_version ) ||
557 get_win9x_registry_version( &registry_version ))
558 current_version = &registry_version;
562 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
563 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
564 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
565 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
567 user_shared_data->NtProductType = current_version->wProductType;
568 user_shared_data->ProductTypeIsValid = TRUE;
569 user_shared_data->NtMajorVersion = current_version->dwMajorVersion;
570 user_shared_data->NtMinorVersion = current_version->dwMinorVersion;
571 user_shared_data->SuiteMask = current_version->wSuiteMask;
573 TRACE( "got %d.%d platform %d build %x name %s service pack %d.%d product %d\n",
574 current_version->dwMajorVersion, current_version->dwMinorVersion,
575 current_version->dwPlatformId, current_version->dwBuildNumber,
576 debugstr_w(current_version->szCSDVersion),
577 current_version->wServicePackMajor, current_version->wServicePackMinor,
578 current_version->wProductType );
581 /***********************************************************************
582 * RtlGetProductInfo (NTDLL.@)
584 * Gives info about the current Windows product type, in a format compatible
585 * with the given Windows version
587 * Returns TRUE if the input is valid, FALSE otherwise
589 BOOLEAN WINAPI RtlGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion,
590 DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType)
592 TRACE("(%d, %d, %d, %d, %p)\n", dwOSMajorVersion, dwOSMinorVersion,
593 dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType);
595 if (!pdwReturnedProductType)
596 return FALSE;
598 if (dwOSMajorVersion < 6)
600 *pdwReturnedProductType = PRODUCT_UNDEFINED;
601 return FALSE;
604 if (current_version->wProductType == VER_NT_WORKSTATION)
605 *pdwReturnedProductType = PRODUCT_ULTIMATE_N;
606 else
607 *pdwReturnedProductType = PRODUCT_STANDARD_SERVER;
609 return TRUE;
612 /***********************************************************************
613 * RtlGetVersion (NTDLL.@)
615 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
617 info->dwMajorVersion = current_version->dwMajorVersion;
618 info->dwMinorVersion = current_version->dwMinorVersion;
619 info->dwBuildNumber = current_version->dwBuildNumber;
620 info->dwPlatformId = current_version->dwPlatformId;
621 strcpyW( info->szCSDVersion, current_version->szCSDVersion );
622 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
624 info->wServicePackMajor = current_version->wServicePackMajor;
625 info->wServicePackMinor = current_version->wServicePackMinor;
626 info->wSuiteMask = current_version->wSuiteMask;
627 info->wProductType = current_version->wProductType;
629 return STATUS_SUCCESS;
633 /******************************************************************************
634 * RtlGetNtVersionNumbers (NTDLL.@)
636 * Get the version numbers of the run time library.
638 * PARAMS
639 * major [O] Destination for the Major version
640 * minor [O] Destination for the Minor version
641 * build [O] Destination for the Build version
643 * RETURNS
644 * Nothing.
646 * NOTES
647 * Introduced in Windows XP (NT5.1)
649 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
651 if (major) *major = current_version->dwMajorVersion;
652 if (minor) *minor = current_version->dwMinorVersion;
653 /* FIXME: Does anybody know the real formula? */
654 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
658 /******************************************************************************
659 * RtlGetNtProductType (NTDLL.@)
661 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
663 if (type) *type = current_version->wProductType;
664 return TRUE;
668 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
670 switch (condition) {
671 case VER_EQUAL:
672 if (left != right) return STATUS_REVISION_MISMATCH;
673 break;
674 case VER_GREATER:
675 if (left <= right) return STATUS_REVISION_MISMATCH;
676 break;
677 case VER_GREATER_EQUAL:
678 if (left < right) return STATUS_REVISION_MISMATCH;
679 break;
680 case VER_LESS:
681 if (left >= right) return STATUS_REVISION_MISMATCH;
682 break;
683 case VER_LESS_EQUAL:
684 if (left > right) return STATUS_REVISION_MISMATCH;
685 break;
686 default:
687 return STATUS_REVISION_MISMATCH;
689 return STATUS_SUCCESS;
692 /******************************************************************************
693 * RtlVerifyVersionInfo (NTDLL.@)
695 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
696 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
698 RTL_OSVERSIONINFOEXW ver;
699 NTSTATUS status;
701 TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
703 ver.dwOSVersionInfoSize = sizeof(ver);
704 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
706 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
708 if(dwTypeMask & VER_PRODUCT_TYPE)
710 status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
711 if (status != STATUS_SUCCESS)
712 return status;
714 if(dwTypeMask & VER_SUITENAME)
715 switch(dwlConditionMask >> 6*3 & 0x07)
717 case VER_AND:
718 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
719 return STATUS_REVISION_MISMATCH;
720 break;
721 case VER_OR:
722 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
723 return STATUS_REVISION_MISMATCH;
724 break;
725 default:
726 return STATUS_INVALID_PARAMETER;
728 if(dwTypeMask & VER_PLATFORMID)
730 status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
731 if (status != STATUS_SUCCESS)
732 return status;
734 if(dwTypeMask & VER_BUILDNUMBER)
736 status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
737 if (status != STATUS_SUCCESS)
738 return status;
741 if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
743 unsigned char condition = 0;
744 BOOLEAN do_next_check = TRUE;
746 if(dwTypeMask & VER_MAJORVERSION)
747 condition = dwlConditionMask >> 1*3 & 0x07;
748 else if(dwTypeMask & VER_MINORVERSION)
749 condition = dwlConditionMask >> 0*3 & 0x07;
750 else if(dwTypeMask & VER_SERVICEPACKMAJOR)
751 condition = dwlConditionMask >> 5*3 & 0x07;
752 else if(dwTypeMask & VER_SERVICEPACKMINOR)
753 condition = dwlConditionMask >> 4*3 & 0x07;
755 if(dwTypeMask & VER_MAJORVERSION)
757 status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
758 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
759 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
761 if((dwTypeMask & VER_MINORVERSION) && do_next_check)
763 status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
764 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
765 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
767 if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
769 status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
770 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
771 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
773 if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
775 status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
778 if (status != STATUS_SUCCESS)
779 return status;
782 return STATUS_SUCCESS;