2 * Windows and DOS version functions
4 * Copyright 1997 Alexandre Julliard
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998 Patrik Stridvall
7 * Copyright 1998 Andreas Mohr
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/winbase16.h"
34 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ver);
41 WIN20, /* Windows 2.0 */
42 WIN30, /* Windows 3.0 */
43 WIN31, /* Windows 3.1 */
44 WIN95, /* Windows 95 */
45 WIN98, /* Windows 98 */
46 WINME, /* Windows Me */
47 NT351, /* Windows NT 3.51 */
48 NT40, /* Windows NT 4.0 */
49 NT2K, /* Windows 2000 */
50 WINXP, /* Windows XP */
58 OSVERSIONINFOA getVersionEx;
61 /* FIXME: compare values below with original and fix */
62 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
64 /* WIN20 FIXME: verify values */
66 MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
67 MAKELONG( 0x0003, 0x8000 ),
69 sizeof(OSVERSIONINFOA), 2, 0, 0,
70 VER_PLATFORM_WIN32s, "Win32s 1.3"
73 /* WIN30 FIXME: verify values */
75 MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
76 MAKELONG( 0x0003, 0x8000 ),
78 sizeof(OSVERSIONINFOA), 3, 0, 0,
79 VER_PLATFORM_WIN32s, "Win32s 1.3"
84 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
85 MAKELONG( 0x0a03, 0x8000 ),
87 sizeof(OSVERSIONINFOA), 3, 10, 0,
88 VER_PLATFORM_WIN32s, "Win32s 1.3"
96 /* Win95: 4, 0, 0x40003B6, ""
97 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
98 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
99 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
100 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
101 * Win95a/b can be discerned via regkey SubVersionNumber
103 * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
105 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
106 VER_PLATFORM_WIN32_WINDOWS, ""
114 /* Win98: 4, 10, 0x40A07CE, " "
115 * Win98SE: 4, 10, 0x40A08AE, " A "
117 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
118 VER_PLATFORM_WIN32_WINDOWS, " "
123 0x07005F03, /* Assuming DOS 7 like the other Win9x */
126 sizeof(OSVERSIONINFOA), 4, 90, 0x45A0BB8,
127 VER_PLATFORM_WIN32_WINDOWS, " "
135 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
136 VER_PLATFORM_WIN32_NT, "Service Pack 2"
144 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
145 VER_PLATFORM_WIN32_NT, "Service Pack 6"
153 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
154 VER_PLATFORM_WIN32_NT, "Service Pack 2"
159 0x05005F03, /* Assuming DOS 5 like the other NT */
162 sizeof(OSVERSIONINFOA), 5, 1, 0xA28,
163 VER_PLATFORM_WIN32_NT, ""
168 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
169 { /* no spaces in here ! */
178 "win2000,win2k,nt2k,nt2000",
182 /* if one of the following dlls is importing ntdll the windows
183 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
184 static char * special_dlls[] =
194 /* the current version has not been autodetected but forced via cmdline */
195 static BOOL versionForced = FALSE;
196 static WINDOWS_VERSION defaultWinVersion = WIN31;
198 /**********************************************************************
199 * VERSION_ParseWinVersion
201 static void VERSION_ParseWinVersion( const char *arg )
204 const char *pCurr, *p;
205 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
207 pCurr = WinVersionNames[i];
208 /* iterate through all winver aliases separated by comma */
210 p = strchr(pCurr, ',');
211 len = p ? (int)p - (int)pCurr : strlen(pCurr);
212 if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
214 defaultWinVersion = (WINDOWS_VERSION)i;
215 versionForced = TRUE;
221 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", arg );
222 MESSAGE("Valid versions are:" );
223 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
225 /* only list the first, "official" alias in case of aliases */
226 pCurr = WinVersionNames[i];
227 p = strchr(pCurr, ',');
228 len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
230 MESSAGE(" '%.*s'%c", len, pCurr,
231 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
237 /**********************************************************************
238 * VERSION_ParseDosVersion
240 static void VERSION_ParseDosVersion( const char *arg )
243 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
245 VersionData[WIN31].getVersion16 =
246 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
251 MESSAGE("Wrong format for DOS version in config file. Use \"x.xx\"\n");
257 /**********************************************************************
260 static void VERSION_Init(void)
264 BOOL got_win_ver = FALSE, got_dos_ver = FALSE;
265 char buffer[MAX_PATH+16], *appname, *p;
266 static BOOL init_done;
268 if (init_done) return;
269 if (!GetModuleFileName16( GetCurrentTask(), buffer, MAX_PATH ) &&
270 !GetModuleFileNameA( 0, buffer, MAX_PATH ))
272 WARN( "could not get module file name\n" );
277 if ((p = strrchr( appname, '/' ))) appname = p + 1;
278 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
280 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\AppDefaults", &hkey ))
282 /* open AppDefaults\\appname\\Version key */
283 strcat( appname, "\\Version" );
284 if (!RegOpenKeyA( hkey, appname, &appkey ))
286 count = sizeof(buffer);
287 if (!RegQueryValueExA( appkey, "Windows", NULL, &type, buffer, &count ))
289 VERSION_ParseWinVersion( buffer );
290 TRACE( "got app win version %s\n", WinVersionNames[defaultWinVersion] );
293 count = sizeof(buffer);
294 if (!RegQueryValueExA( appkey, "DOS", NULL, &type, buffer, &count ))
296 VERSION_ParseDosVersion( buffer );
297 TRACE( "got app dos version %lx\n", VersionData[WIN31].getVersion16 );
300 RegCloseKey( appkey );
305 if (got_win_ver && got_dos_ver) return;
307 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Version", &hkey ))
311 count = sizeof(buffer);
312 if (!RegQueryValueExA( hkey, "Windows", NULL, &type, buffer, &count ))
314 VERSION_ParseWinVersion( buffer );
315 TRACE( "got default win version %s\n", WinVersionNames[defaultWinVersion] );
320 count = sizeof(buffer);
321 if (!RegQueryValueExA( hkey, "DOS", NULL, &type, buffer, &count ))
323 VERSION_ParseDosVersion( buffer );
324 TRACE( "got default dos version %lx\n", VersionData[WIN31].getVersion16 );
332 /**********************************************************************
333 * VERSION_GetSystemDLLVersion
335 * This function tries to figure out if a given (native) dll comes from
336 * win95/98 or winnt. Since all values in the OptionalHeader are not a
337 * usable hint, we test if a dll imports the ntdll.
338 * This is at least working for all system dlls like comctl32, comdlg32 and
340 * If you have a better idea to figure this out...
342 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
344 IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
345 + IMAGE_DIRECTORY_ENTRY_IMPORT;
346 if (dir->Size && dir->VirtualAddress)
348 IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
349 for ( ; pe_imp->Name; pe_imp++)
351 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
354 if (!strncasecmp(name, "ntdll", 5))
356 if (3 == PE_HEADER(hmod)->OptionalHeader.MajorOperatingSystemVersion)
365 /**********************************************************************
366 * VERSION_GetLinkedDllVersion
368 * Some version data (not reliable!):
369 * linker/OS/image/subsys
371 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
372 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
373 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
374 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
375 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
376 * 2.xx/1.00/0.00/4.00 Win95 system files
377 * x.xx/4.00/0.00/4.00 Win95 most applications
378 * 3.10/4.00/0.00/4.00 Win98 notepad
379 * x.xx/5.00/5.00/4.00 Win98 system dlls
380 * x.xx/4.00/4.00/4.00 NT 4 most apps
381 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
382 * 5.12/5.00/5.00/4.00 Win98 calc
383 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
385 DWORD VERSION_GetLinkedDllVersion(void)
388 DWORD WinVersion = NB_WINDOWS_VERSIONS;
389 PIMAGE_OPTIONAL_HEADER ophd;
391 /* First check the native dlls provided. These have to be
392 from one windows version */
393 for ( wm = MODULE_modref_list; wm; wm=wm->next )
395 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
397 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
399 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
400 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
401 ophd->MajorImageVersion, ophd->MinorImageVersion,
402 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
404 /* test if it is an external (native) dll */
405 if (!(wm->flags & WINE_MODREF_INTERNAL))
408 for (i = 0; special_dlls[i]; i++)
410 /* test if it is a special dll */
411 if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
413 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
414 if (WinVersion == NB_WINDOWS_VERSIONS)
415 WinVersion = DllVersion;
417 if (WinVersion != DllVersion) {
418 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
420 VersionData[WinVersion].getVersionEx.szCSDVersion,
421 VersionData[DllVersion].getVersionEx.szCSDVersion);
422 return WIN31; /* this may let the exe exiting */
431 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
433 /* we are using no external system dlls, look at the exe */
434 ophd = &(PE_HEADER(GetModuleHandleA(NULL))->OptionalHeader);
436 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
437 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
438 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
439 ophd->MajorImageVersion, ophd->MinorImageVersion,
440 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
442 /* special nt 3.51 */
443 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
448 /* the MajorSubsystemVersion is the only usable sign */
449 if (ophd->MajorSubsystemVersion < 4)
451 if ( ophd->MajorOperatingSystemVersion == 1
452 && ophd->MinorOperatingSystemVersion == 0)
454 return WIN31; /* win32s */
457 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
458 return NT351; /* FIXME: NT 3.1, not tested */
466 /**********************************************************************
470 * Don't call this function too early during the Wine init,
471 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
472 * be NULL in such cases, which causes the winver to ALWAYS be detected
474 * And as we cache the winver once it has been determined, this is bad.
475 * This can happen much easier than you might think, as this function
476 * is called by EVERY GetVersion*() API !
479 static WINDOWS_VERSION VERSION_GetVersion(void)
481 static WORD winver = 0xffff;
483 if (winver == 0xffff) /* to be determined */
485 WINDOWS_VERSION retver;
488 if (versionForced) /* user has overridden any sensible checks */
489 winver = defaultWinVersion;
492 retver = VERSION_GetLinkedDllVersion();
494 /* cache determined value, but do not store in case of WIN31 */
495 if (retver != WIN31) winver = retver;
505 /***********************************************************************
506 * GetVersion (KERNEL.3)
508 LONG WINAPI GetVersion16(void)
510 WINDOWS_VERSION ver = VERSION_GetVersion();
511 return VersionData[ver].getVersion16;
515 /***********************************************************************
516 * GetVersion (KERNEL32.@)
518 LONG WINAPI GetVersion(void)
520 WINDOWS_VERSION ver = VERSION_GetVersion();
521 return VersionData[ver].getVersion32;
525 /***********************************************************************
526 * GetVersionEx (KERNEL.149)
528 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
530 WINDOWS_VERSION ver = VERSION_GetVersion();
531 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
533 WARN("wrong OSVERSIONINFO size from app\n");
534 SetLastError(ERROR_INSUFFICIENT_BUFFER);
537 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
538 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
539 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
540 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
541 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
546 /***********************************************************************
547 * GetVersionExA (KERNEL32.@)
549 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
551 WINDOWS_VERSION ver = VERSION_GetVersion();
552 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOA))
554 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
555 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
556 SetLastError(ERROR_INSUFFICIENT_BUFFER);
559 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
560 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
561 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
562 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
563 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
568 /***********************************************************************
569 * GetVersionExW (KERNEL32.@)
571 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
573 WINDOWS_VERSION ver = VERSION_GetVersion();
575 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOW))
577 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
578 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
579 SetLastError(ERROR_INSUFFICIENT_BUFFER);
582 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
583 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
584 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
585 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
586 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
587 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
593 /******************************************************************************
594 * VerifyVersionInfoW (KERNEL32.@)
596 BOOL WINAPI VerifyVersionInfoW( /* LPOSVERSIONINFOEXW */ LPVOID lpVersionInfo, DWORD dwTypeMask,
597 DWORDLONG dwlConditionMask)
599 FIXME("%p %lu %llx\n", lpVersionInfo, dwTypeMask, dwlConditionMask);
604 /***********************************************************************
605 * GetWinFlags (KERNEL.132)
607 DWORD WINAPI GetWinFlags16(void)
609 static const long cpuflags[5] =
610 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
617 /* There doesn't seem to be any Pentium flag. */
618 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
619 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
620 ovi.dwOSVersionInfoSize = sizeof(ovi);
622 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
623 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
629 /* Not used at this time. This is here for documentation only */
631 /* WINDEBUGINFO flags values */
632 #define WDI_OPTIONS 0x0001
633 #define WDI_FILTER 0x0002
634 #define WDI_ALLOCBREAK 0x0004
636 /* dwOptions values */
637 #define DBO_CHECKHEAP 0x0001
638 #define DBO_BUFFERFILL 0x0004
639 #define DBO_DISABLEGPTRAPPING 0x0010
640 #define DBO_CHECKFREE 0x0020
642 #define DBO_SILENT 0x8000
644 #define DBO_TRACEBREAK 0x2000
645 #define DBO_WARNINGBREAK 0x1000
646 #define DBO_NOERRORBREAK 0x0800
647 #define DBO_NOFATALBREAK 0x0400
648 #define DBO_INT3BREAK 0x0100
650 /* DebugOutput flags values */
651 #define DBF_TRACE 0x0000
652 #define DBF_WARNING 0x4000
653 #define DBF_ERROR 0x8000
654 #define DBF_FATAL 0xc000
656 /* dwFilter values */
657 #define DBF_KERNEL 0x1000
658 #define DBF_KRN_MEMMAN 0x0001
659 #define DBF_KRN_LOADMODULE 0x0002
660 #define DBF_KRN_SEGMENTLOAD 0x0004
661 #define DBF_USER 0x0800
662 #define DBF_GDI 0x0400
663 #define DBF_MMSYSTEM 0x0040
664 #define DBF_PENWIN 0x0020
665 #define DBF_APPLICATION 0x0008
666 #define DBF_DRIVER 0x0010
668 #endif /* NOLOGERROR */
671 /***********************************************************************
672 * GetWinDebugInfo (KERNEL.355)
674 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
676 FIXME("(%8lx,%d): stub returning 0\n",
677 (unsigned long)lpwdi, flags);
678 /* 0 means not in debugging mode/version */
679 /* Can this type of debugging be used in wine ? */
680 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
685 /***********************************************************************
686 * SetWinDebugInfo (KERNEL.356)
688 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
690 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
691 /* 0 means not in debugging mode/version */
692 /* Can this type of debugging be used in wine ? */
693 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
698 /***********************************************************************
702 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
704 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
706 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
709 /***********************************************************************
710 * DiagQuery (KERNEL.339)
712 * returns TRUE if Win called with "/b" (bootlog.txt)
714 BOOL16 WINAPI DiagQuery16()
716 /* perhaps implement a Wine "/b" command line flag sometime ? */
720 /***********************************************************************
721 * DiagOutput (KERNEL.340)
723 * writes a debug string into <windir>\bootlog.txt
725 void WINAPI DiagOutput16(LPCSTR str)
728 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));