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
31 #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 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 winver value '%s' specified.\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 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("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
256 /**********************************************************************
257 * VERSION_GetSystemDLLVersion
259 * This function tries to figure out if a given (native) dll comes from
260 * win95/98 or winnt. Since all values in the OptionalHeader are not a
261 * usable hint, we test if a dll imports the ntdll.
262 * This is at least working for all system dlls like comctl32, comdlg32 and
264 * If you have a better idea to figure this out...
266 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
268 IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
269 + IMAGE_DIRECTORY_ENTRY_IMPORT;
270 if (dir->Size && dir->VirtualAddress)
272 IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
273 for ( ; pe_imp->Name; pe_imp++)
275 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
278 if (!strncasecmp(name, "ntdll", 5))
280 if (3 == PE_HEADER(hmod)->OptionalHeader.MajorOperatingSystemVersion)
289 /**********************************************************************
290 * VERSION_GetLinkedDllVersion
292 * Some version data (not reliable!):
293 * linker/OS/image/subsys
295 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
296 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
297 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
298 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
299 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
300 * 2.xx/1.00/0.00/4.00 Win95 system files
301 * x.xx/4.00/0.00/4.00 Win95 most applications
302 * 3.10/4.00/0.00/4.00 Win98 notepad
303 * x.xx/5.00/5.00/4.00 Win98 system dlls
304 * x.xx/4.00/4.00/4.00 NT 4 most apps
305 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
306 * 5.12/5.00/5.00/4.00 Win98 calc
307 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
309 DWORD VERSION_GetLinkedDllVersion(void)
312 DWORD WinVersion = NB_WINDOWS_VERSIONS;
313 PIMAGE_OPTIONAL_HEADER ophd;
315 /* First check the native dlls provided. These have to be
316 from one windows version */
317 for ( wm = MODULE_modref_list; wm; wm=wm->next )
319 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
321 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
323 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
324 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
325 ophd->MajorImageVersion, ophd->MinorImageVersion,
326 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
328 /* test if it is an external (native) dll */
329 if (!(wm->flags & WINE_MODREF_INTERNAL))
332 for (i = 0; special_dlls[i]; i++)
334 /* test if it is a special dll */
335 if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
337 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
338 if (WinVersion == NB_WINDOWS_VERSIONS)
339 WinVersion = DllVersion;
341 if (WinVersion != DllVersion) {
342 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
344 VersionData[WinVersion].getVersionEx.szCSDVersion,
345 VersionData[DllVersion].getVersionEx.szCSDVersion);
346 return WIN31; /* this may let the exe exiting */
355 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
357 /* we are using no external system dlls, look at the exe */
358 ophd = &(PE_HEADER(GetModuleHandleA(NULL))->OptionalHeader);
360 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
361 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
362 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
363 ophd->MajorImageVersion, ophd->MinorImageVersion,
364 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
366 /* special nt 3.51 */
367 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
372 /* the MajorSubsystemVersion is the only usable sign */
373 if (ophd->MajorSubsystemVersion < 4)
375 if ( ophd->MajorOperatingSystemVersion == 1
376 && ophd->MinorOperatingSystemVersion == 0)
378 return WIN31; /* win32s */
381 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
382 return NT351; /* FIXME: NT 3.1, not tested */
390 /**********************************************************************
394 * Don't call this function too early during the Wine init,
395 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
396 * be NULL in such cases, which causes the winver to ALWAYS be detected
398 * And as we cache the winver once it has been determined, this is bad.
399 * This can happen much easier than you might think, as this function
400 * is called by EVERY GetVersion*() API !
403 static WINDOWS_VERSION VERSION_GetVersion(void)
405 static WORD winver = 0xffff;
407 if (winver == 0xffff) /* to be determined */
409 WINDOWS_VERSION retver;
411 if (versionForced) /* user has overridden any sensible checks */
412 winver = defaultWinVersion;
415 retver = VERSION_GetLinkedDllVersion();
417 /* cache determined value, but do not store in case of WIN31 */
418 if (retver != WIN31) winver = retver;
428 /***********************************************************************
429 * GetVersion (KERNEL.3)
431 LONG WINAPI GetVersion16(void)
433 WINDOWS_VERSION ver = VERSION_GetVersion();
434 return VersionData[ver].getVersion16;
438 /***********************************************************************
439 * GetVersion (KERNEL32.@)
441 LONG WINAPI GetVersion(void)
443 WINDOWS_VERSION ver = VERSION_GetVersion();
444 return VersionData[ver].getVersion32;
448 /***********************************************************************
449 * GetVersionEx (KERNEL.149)
451 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
453 WINDOWS_VERSION ver = VERSION_GetVersion();
454 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
456 WARN("wrong OSVERSIONINFO size from app\n");
457 SetLastError(ERROR_INSUFFICIENT_BUFFER);
460 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
461 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
462 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
463 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
464 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
469 /***********************************************************************
470 * GetVersionExA (KERNEL32.@)
472 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
474 WINDOWS_VERSION ver = VERSION_GetVersion();
475 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOA))
477 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
478 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
479 SetLastError(ERROR_INSUFFICIENT_BUFFER);
482 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
483 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
484 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
485 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
486 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
491 /***********************************************************************
492 * GetVersionExW (KERNEL32.@)
494 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
496 WINDOWS_VERSION ver = VERSION_GetVersion();
498 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOW))
500 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
501 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
502 SetLastError(ERROR_INSUFFICIENT_BUFFER);
505 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
506 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
507 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
508 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
509 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
510 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
516 /******************************************************************************
517 * VerifyVersionInfoW (KERNEL32.@)
519 BOOL WINAPI VerifyVersionInfoW( /* LPOSVERSIONINFOEXW */ LPVOID lpVersionInfo, DWORD dwTypeMask,
520 DWORDLONG dwlConditionMask)
522 FIXME("%p %lu %llx\n", lpVersionInfo, dwTypeMask, dwlConditionMask);
527 /***********************************************************************
528 * GetWinFlags (KERNEL.132)
530 DWORD WINAPI GetWinFlags16(void)
532 static const long cpuflags[5] =
533 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
540 /* There doesn't seem to be any Pentium flag. */
541 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
542 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
543 ovi.dwOSVersionInfoSize = sizeof(ovi);
545 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
546 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
552 /* Not used at this time. This is here for documentation only */
554 /* WINDEBUGINFO flags values */
555 #define WDI_OPTIONS 0x0001
556 #define WDI_FILTER 0x0002
557 #define WDI_ALLOCBREAK 0x0004
559 /* dwOptions values */
560 #define DBO_CHECKHEAP 0x0001
561 #define DBO_BUFFERFILL 0x0004
562 #define DBO_DISABLEGPTRAPPING 0x0010
563 #define DBO_CHECKFREE 0x0020
565 #define DBO_SILENT 0x8000
567 #define DBO_TRACEBREAK 0x2000
568 #define DBO_WARNINGBREAK 0x1000
569 #define DBO_NOERRORBREAK 0x0800
570 #define DBO_NOFATALBREAK 0x0400
571 #define DBO_INT3BREAK 0x0100
573 /* DebugOutput flags values */
574 #define DBF_TRACE 0x0000
575 #define DBF_WARNING 0x4000
576 #define DBF_ERROR 0x8000
577 #define DBF_FATAL 0xc000
579 /* dwFilter values */
580 #define DBF_KERNEL 0x1000
581 #define DBF_KRN_MEMMAN 0x0001
582 #define DBF_KRN_LOADMODULE 0x0002
583 #define DBF_KRN_SEGMENTLOAD 0x0004
584 #define DBF_USER 0x0800
585 #define DBF_GDI 0x0400
586 #define DBF_MMSYSTEM 0x0040
587 #define DBF_PENWIN 0x0020
588 #define DBF_APPLICATION 0x0008
589 #define DBF_DRIVER 0x0010
591 #endif /* NOLOGERROR */
594 /***********************************************************************
595 * GetWinDebugInfo (KERNEL.355)
597 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
599 FIXME("(%8lx,%d): stub returning 0\n",
600 (unsigned long)lpwdi, flags);
601 /* 0 means not in debugging mode/version */
602 /* Can this type of debugging be used in wine ? */
603 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
608 /***********************************************************************
609 * SetWinDebugInfo (KERNEL.356)
611 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
613 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
614 /* 0 means not in debugging mode/version */
615 /* Can this type of debugging be used in wine ? */
616 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
621 /***********************************************************************
625 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
627 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
629 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
632 /***********************************************************************
633 * DiagQuery (KERNEL.339)
635 * returns TRUE if Win called with "/b" (bootlog.txt)
637 BOOL16 WINAPI DiagQuery16()
639 /* perhaps implement a Wine "/b" command line flag sometime ? */
643 /***********************************************************************
644 * DiagOutput (KERNEL.340)
646 * writes a debug string into <windir>\bootlog.txt
648 void WINAPI DiagOutput16(LPCSTR str)
651 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));