dbghelp: Remove an "#if 1" preprocessor directive.
[wine/multimedia.git] / dlls / ntdll / version.c
blob57e586a62f340d1a5fa6cac527b00f9620ae5d19
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 NB_WINDOWS_VERSIONS
61 } WINDOWS_VERSION;
63 /* FIXME: compare values below with original and fix.
64 * An *excellent* win9x version page (ALL versions !)
65 * can be found at www.mdgx.com/ver.htm */
66 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
68 /* WIN20 FIXME: verify values */
70 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
71 {'W','i','n','3','2','s',' ','1','.','3',0},
72 0, 0, 0, 0, 0
74 /* WIN30 FIXME: verify values */
76 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
77 {'W','i','n','3','2','s',' ','1','.','3',0},
78 0, 0, 0, 0, 0
80 /* WIN31 */
82 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
83 {'W','i','n','3','2','s',' ','1','.','3',0},
84 0, 0, 0, 0, 0
86 /* WIN95 */
88 /* Win95: 4, 0, 0x40003B6, ""
89 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
90 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
91 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
92 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
93 * Win95a/b can be discerned via regkey SubVersionNumber
95 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
96 {0},
97 0, 0, 0, 0, 0
99 /* WIN98 (second edition) */
101 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
102 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
104 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
105 {' ','A',' ',0},
106 0, 0, 0, 0, 0
108 /* WINME */
110 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
111 {' ',0},
112 0, 0, 0, 0, 0
114 /* NT351 */
116 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
117 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','5',0},
118 5, 0, 0, VER_NT_WORKSTATION, 0
120 /* NT40 */
122 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
123 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
124 6, 0, 0, VER_NT_WORKSTATION, 0
126 /* NT2K */
128 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
129 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
130 4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
132 /* WINXP */
134 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
135 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
136 3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
138 /* WINXP64 */
140 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
141 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
142 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
144 /* WIN2K3 */
146 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
147 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
148 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
150 /* WINVISTA */
152 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
153 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
154 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
156 /* WIN2K8 */
158 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
159 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
160 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
162 /* WIN7 */
164 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
165 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
166 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
168 /* WIN2K8R2 */
170 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
171 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
172 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
174 /* WIN8 */
176 sizeof(RTL_OSVERSIONINFOEXW), 6, 2, 0x23F0, VER_PLATFORM_WIN32_NT,
177 {' ',0},
178 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
183 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
184 { /* no spaces in here ! */
185 "win20", /* WIN20 */
186 "win30", /* WIN30 */
187 "win31", /* WIN31 */
188 "win95", /* WIN95 */
189 "win98", /* WIN98 */
190 "winme", /* WINME */
191 "nt351", /* NT351 */
192 "nt40", /* NT40 */
193 "win2000,win2k,nt2k,nt2000", /* NT2K */
194 "winxp", /* WINXP */
195 "winxp64", /* WINXP64 */
196 "win2003,win2k3", /* WIN2K3 */
197 "vista,winvista", /* WINVISTA*/
198 "win2008,win2k8", /* WIN2K8 */
199 "win2008r2,win2k8r2", /* WIN2K8R2 */
200 "win7", /* WIN7 */
201 "win8", /* WIN8 */
205 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
206 static const RTL_OSVERSIONINFOEXW *current_version;
209 /**********************************************************************
210 * get_nt_registry_version
212 * Fetch the version information from the NT-style registry keys.
214 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
216 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
217 'S','o','f','t','w','a','r','e','\\',
218 'M','i','c','r','o','s','o','f','t','\\',
219 'W','i','n','d','o','w','s',' ','N','T','\\',
220 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
221 static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
222 'S','y','s','t','e','m','\\',
223 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
224 'C','o','n','t','r','o','l','\\',
225 'W','i','n','d','o','w','s',0};
226 static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
227 'S','y','s','t','e','m','\\',
228 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
229 'C','o','n','t','r','o','l','\\',
230 'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
231 static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
232 static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
233 static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
234 static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
235 static const WCHAR WinNTW[] = {'W','i','n','N','T',0};
236 static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
237 static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
239 OBJECT_ATTRIBUTES attr;
240 UNICODE_STRING nameW, valueW;
241 HANDLE hkey, hkey2;
242 char tmp[64];
243 DWORD count;
244 BOOL ret = FALSE;
245 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
247 attr.Length = sizeof(attr);
248 attr.RootDirectory = 0;
249 attr.ObjectName = &nameW;
250 attr.Attributes = 0;
251 attr.SecurityDescriptor = NULL;
252 attr.SecurityQualityOfService = NULL;
253 RtlInitUnicodeString( &nameW, version_keyW );
255 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
257 memset( version, 0, sizeof(*version) );
259 RtlInitUnicodeString( &valueW, CurrentVersionW );
260 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
262 WCHAR *p, *str = (WCHAR *)info->Data;
263 str[info->DataLength / sizeof(WCHAR)] = 0;
264 p = strchrW( str, '.' );
265 if (p)
267 *p++ = 0;
268 version->dwMinorVersion = atoiW( p );
270 version->dwMajorVersion = atoiW( str );
273 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
275 ret = TRUE;
276 version->dwPlatformId = VER_PLATFORM_WIN32_NT;
278 /* get build number */
280 RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
281 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
283 WCHAR *str = (WCHAR *)info->Data;
284 str[info->DataLength / sizeof(WCHAR)] = 0;
285 version->dwBuildNumber = atoiW( str );
288 /* get version description */
290 RtlInitUnicodeString( &valueW, CSDVersionW );
291 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
293 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
294 memcpy( version->szCSDVersion, info->Data, len );
295 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
298 /* get service pack version */
300 RtlInitUnicodeString( &nameW, service_pack_keyW );
301 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
303 RtlInitUnicodeString( &valueW, CSDVersionW );
304 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
306 if (info->DataLength >= sizeof(DWORD))
308 DWORD dw = *(DWORD *)info->Data;
309 version->wServicePackMajor = LOWORD(dw) >> 8;
310 version->wServicePackMinor = LOWORD(dw) & 0xff;
313 NtClose( hkey2 );
316 /* get product type */
318 RtlInitUnicodeString( &nameW, product_keyW );
319 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
321 RtlInitUnicodeString( &valueW, ProductTypeW );
322 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
324 WCHAR *str = (WCHAR *)info->Data;
325 str[info->DataLength / sizeof(WCHAR)] = 0;
326 if (!strcmpiW( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
327 else if (!strcmpiW( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
328 else if (!strcmpiW( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
330 NtClose( hkey2 );
333 /* FIXME: get wSuiteMask */
336 NtClose( hkey );
337 return ret;
341 /**********************************************************************
342 * get_win9x_registry_version
344 * Fetch the version information from the Win9x-style registry keys.
346 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
348 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
349 'S','o','f','t','w','a','r','e','\\',
350 'M','i','c','r','o','s','o','f','t','\\',
351 'W','i','n','d','o','w','s','\\',
352 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
353 static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
354 static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
356 OBJECT_ATTRIBUTES attr;
357 UNICODE_STRING nameW, valueW;
358 HANDLE hkey;
359 char tmp[64];
360 DWORD count;
361 BOOL ret = FALSE;
362 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
364 attr.Length = sizeof(attr);
365 attr.RootDirectory = 0;
366 attr.ObjectName = &nameW;
367 attr.Attributes = 0;
368 attr.SecurityDescriptor = NULL;
369 attr.SecurityQualityOfService = NULL;
370 RtlInitUnicodeString( &nameW, version_keyW );
372 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
374 memset( version, 0, sizeof(*version) );
376 RtlInitUnicodeString( &valueW, VersionNumberW );
377 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
379 WCHAR *p, *str = (WCHAR *)info->Data;
380 str[info->DataLength / sizeof(WCHAR)] = 0;
381 p = strchrW( str, '.' );
382 if (p) *p++ = 0;
383 version->dwMajorVersion = atoiW( str );
384 if (p)
386 str = p;
387 p = strchrW( str, '.' );
388 if (p)
390 *p++ = 0;
391 version->dwBuildNumber = atoiW( p );
393 version->dwMinorVersion = atoiW( str );
395 /* build number contains version too on Win9x */
396 version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
399 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
401 ret = TRUE;
402 version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
404 RtlInitUnicodeString( &valueW, SubVersionNumberW );
405 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
407 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
408 memcpy( version->szCSDVersion, info->Data, len );
409 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
413 NtClose( hkey );
414 return ret;
418 /**********************************************************************
419 * parse_win_version
421 * Parse the contents of the Version key.
423 static BOOL parse_win_version( HANDLE hkey )
425 static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
427 UNICODE_STRING valueW;
428 char tmp[64], buffer[50];
429 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
430 DWORD count, len;
431 int i;
433 RtlInitUnicodeString( &valueW, VersionW );
434 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
435 return FALSE;
437 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
438 buffer[len] = 0;
440 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
442 const char *p, *pCurr = WinVersionNames[i];
443 /* iterate through all winver aliases separated by comma */
444 do {
445 p = strchr(pCurr, ',');
446 len = p ? p - pCurr : strlen(pCurr);
447 if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
449 current_version = &VersionData[i];
450 TRACE( "got win version %s\n", WinVersionNames[i] );
451 return TRUE;
453 pCurr = p+1;
454 } while (p);
457 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
458 MESSAGE("Valid versions are:" );
459 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
461 /* only list the first, "official" alias in case of aliases */
462 const char *pCurr = WinVersionNames[i];
463 const char *p = strchr(pCurr, ',');
464 len = (p) ? p - pCurr : strlen(pCurr);
466 MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
468 return FALSE;
472 /**********************************************************************
473 * version_init
475 void version_init( const WCHAR *appname )
477 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
478 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
479 static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
480 OBJECT_ATTRIBUTES attr;
481 UNICODE_STRING nameW;
482 HANDLE root, hkey, config_key;
483 BOOL got_win_ver = FALSE;
485 if (is_win64 || is_wow64)
486 current_version = &VersionData[WINXP64]; /* default if nothing else is specified */
487 else
488 current_version = &VersionData[WINXP];
490 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
491 attr.Length = sizeof(attr);
492 attr.RootDirectory = root;
493 attr.ObjectName = &nameW;
494 attr.Attributes = 0;
495 attr.SecurityDescriptor = NULL;
496 attr.SecurityQualityOfService = NULL;
497 RtlInitUnicodeString( &nameW, configW );
499 /* @@ Wine registry key: HKCU\Software\Wine */
500 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
501 NtClose( root );
502 if (!config_key) goto done;
504 /* open AppDefaults\\appname key */
505 if (appname && *appname)
507 const WCHAR *p;
508 WCHAR appversion[MAX_PATH+20];
510 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
511 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
513 strcpyW( appversion, appdefaultsW );
514 strcatW( appversion, appname );
515 RtlInitUnicodeString( &nameW, appversion );
516 attr.RootDirectory = config_key;
518 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
519 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
521 TRACE( "getting version from %s\n", debugstr_w(appversion) );
522 got_win_ver = parse_win_version( hkey );
523 NtClose( hkey );
527 if (!got_win_ver)
529 TRACE( "getting default version\n" );
530 got_win_ver = parse_win_version( config_key );
532 NtClose( config_key );
534 done:
535 if (!got_win_ver)
537 static RTL_OSVERSIONINFOEXW registry_version;
539 TRACE( "getting registry version\n" );
540 if (get_nt_registry_version( &registry_version ) ||
541 get_win9x_registry_version( &registry_version ))
542 current_version = &registry_version;
546 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
547 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
548 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
549 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
551 user_shared_data->NtProductType = current_version->wProductType;
552 user_shared_data->ProductTypeIsValid = TRUE;
553 user_shared_data->NtMajorVersion = current_version->dwMajorVersion;
554 user_shared_data->NtMinorVersion = current_version->dwMinorVersion;
555 user_shared_data->SuiteMask = current_version->wSuiteMask;
557 TRACE( "got %d.%d platform %d build %x name %s service pack %d.%d product %d\n",
558 current_version->dwMajorVersion, current_version->dwMinorVersion,
559 current_version->dwPlatformId, current_version->dwBuildNumber,
560 debugstr_w(current_version->szCSDVersion),
561 current_version->wServicePackMajor, current_version->wServicePackMinor,
562 current_version->wProductType );
565 /***********************************************************************
566 * RtlGetProductInfo (NTDLL.@)
568 * Gives info about the current Windows product type, in a format compatible
569 * with the given Windows version
571 * Returns TRUE if the input is valid, FALSE otherwise
573 BOOLEAN WINAPI RtlGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion,
574 DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType)
576 TRACE("(%d, %d, %d, %d, %p)\n", dwOSMajorVersion, dwOSMinorVersion,
577 dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType);
579 if (!pdwReturnedProductType)
580 return FALSE;
582 if (dwOSMajorVersion < 6)
584 *pdwReturnedProductType = PRODUCT_UNDEFINED;
585 return FALSE;
588 if (current_version->wProductType == VER_NT_WORKSTATION)
589 *pdwReturnedProductType = PRODUCT_ULTIMATE_N;
590 else
591 *pdwReturnedProductType = PRODUCT_STANDARD_SERVER;
593 return TRUE;
596 /***********************************************************************
597 * RtlGetVersion (NTDLL.@)
599 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
601 info->dwMajorVersion = current_version->dwMajorVersion;
602 info->dwMinorVersion = current_version->dwMinorVersion;
603 info->dwBuildNumber = current_version->dwBuildNumber;
604 info->dwPlatformId = current_version->dwPlatformId;
605 strcpyW( info->szCSDVersion, current_version->szCSDVersion );
606 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
608 info->wServicePackMajor = current_version->wServicePackMajor;
609 info->wServicePackMinor = current_version->wServicePackMinor;
610 info->wSuiteMask = current_version->wSuiteMask;
611 info->wProductType = current_version->wProductType;
613 return STATUS_SUCCESS;
617 /******************************************************************************
618 * RtlGetNtVersionNumbers (NTDLL.@)
620 * Get the version numbers of the run time library.
622 * PARAMS
623 * major [O] Destination for the Major version
624 * minor [O] Destination for the Minor version
625 * build [O] Destination for the Build version
627 * RETURNS
628 * Nothing.
630 * NOTES
631 * Introduced in Windows XP (NT5.1)
633 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
635 if (major) *major = current_version->dwMajorVersion;
636 if (minor) *minor = current_version->dwMinorVersion;
637 /* FIXME: Does anybody know the real formula? */
638 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
642 /******************************************************************************
643 * RtlGetNtProductType (NTDLL.@)
645 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
647 if (type) *type = current_version->wProductType;
648 return TRUE;
652 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
654 switch (condition) {
655 case VER_EQUAL:
656 if (left != right) return STATUS_REVISION_MISMATCH;
657 break;
658 case VER_GREATER:
659 if (left <= right) return STATUS_REVISION_MISMATCH;
660 break;
661 case VER_GREATER_EQUAL:
662 if (left < right) return STATUS_REVISION_MISMATCH;
663 break;
664 case VER_LESS:
665 if (left >= right) return STATUS_REVISION_MISMATCH;
666 break;
667 case VER_LESS_EQUAL:
668 if (left > right) return STATUS_REVISION_MISMATCH;
669 break;
670 default:
671 return STATUS_REVISION_MISMATCH;
673 return STATUS_SUCCESS;
676 /******************************************************************************
677 * RtlVerifyVersionInfo (NTDLL.@)
679 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
680 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
682 RTL_OSVERSIONINFOEXW ver;
683 NTSTATUS status;
685 TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
687 ver.dwOSVersionInfoSize = sizeof(ver);
688 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
690 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
692 if(dwTypeMask & VER_PRODUCT_TYPE)
694 status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
695 if (status != STATUS_SUCCESS)
696 return status;
698 if(dwTypeMask & VER_SUITENAME)
699 switch(dwlConditionMask >> 6*3 & 0x07)
701 case VER_AND:
702 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
703 return STATUS_REVISION_MISMATCH;
704 break;
705 case VER_OR:
706 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
707 return STATUS_REVISION_MISMATCH;
708 break;
709 default:
710 return STATUS_INVALID_PARAMETER;
712 if(dwTypeMask & VER_PLATFORMID)
714 status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
715 if (status != STATUS_SUCCESS)
716 return status;
718 if(dwTypeMask & VER_BUILDNUMBER)
720 status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
721 if (status != STATUS_SUCCESS)
722 return status;
725 if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
727 unsigned char condition = 0;
728 BOOLEAN do_next_check = TRUE;
730 if(dwTypeMask & VER_MAJORVERSION)
731 condition = dwlConditionMask >> 1*3 & 0x07;
732 else if(dwTypeMask & VER_MINORVERSION)
733 condition = dwlConditionMask >> 0*3 & 0x07;
734 else if(dwTypeMask & VER_SERVICEPACKMAJOR)
735 condition = dwlConditionMask >> 5*3 & 0x07;
736 else if(dwTypeMask & VER_SERVICEPACKMINOR)
737 condition = dwlConditionMask >> 4*3 & 0x07;
739 if(dwTypeMask & VER_MAJORVERSION)
741 status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
742 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
743 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
745 if((dwTypeMask & VER_MINORVERSION) && do_next_check)
747 status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
748 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
749 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
751 if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
753 status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
754 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
755 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
757 if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
759 status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
762 if (status != STATUS_SUCCESS)
763 return status;
766 return STATUS_SUCCESS;