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
17 #include "wine/winbase16.h"
20 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(ver);
27 WIN20, /* Windows 2.0 */
28 WIN30, /* Windows 3.0 */
29 WIN31, /* Windows 3.1 */
30 WIN95, /* Windows 95 */
31 WIN98, /* Windows 98 */
32 WINME, /* Windows Me */
33 NT351, /* Windows NT 3.51 */
34 NT40, /* Windows NT 4.0 */
35 NT2K, /* Windows 2000 */
36 WINXP, /* Windows XP */
44 OSVERSIONINFOA getVersionEx;
47 /* FIXME: compare values below with original and fix */
48 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
50 /* WIN20 FIXME: verify values */
52 MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
53 MAKELONG( 0x0003, 0x8000 ),
55 sizeof(OSVERSIONINFOA), 2, 0, 0,
56 VER_PLATFORM_WIN32s, "Win32s 1.3"
59 /* WIN30 FIXME: verify values */
61 MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
62 MAKELONG( 0x0003, 0x8000 ),
64 sizeof(OSVERSIONINFOA), 3, 0, 0,
65 VER_PLATFORM_WIN32s, "Win32s 1.3"
70 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
71 MAKELONG( 0x0a03, 0x8000 ),
73 sizeof(OSVERSIONINFOA), 3, 10, 0,
74 VER_PLATFORM_WIN32s, "Win32s 1.3"
82 /* Win95: 4, 0, 0x40003B6, ""
83 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
84 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
85 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
86 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
87 * Win95a/b can be discerned via regkey SubVersionNumber
89 * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
91 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
92 VER_PLATFORM_WIN32_WINDOWS, ""
100 /* Win98: 4, 10, 0x40A07CE, " "
101 * Win98SE: 4, 10, 0x40A08AE, " A "
103 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
104 VER_PLATFORM_WIN32_WINDOWS, " "
109 0x07005F03, /* Assuming DOS 7 like the other Win9x */
112 sizeof(OSVERSIONINFOA), 4, 90, 0x45A0BB8,
113 VER_PLATFORM_WIN32_WINDOWS, " "
121 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
122 VER_PLATFORM_WIN32_NT, "Service Pack 2"
130 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
131 VER_PLATFORM_WIN32_NT, "Service Pack 6"
139 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
140 VER_PLATFORM_WIN32_NT, "Service Pack 2"
145 0x05005F03, /* Assuming DOS 5 like the other NT */
148 sizeof(OSVERSIONINFOA), 5, 1, 0xA28,
149 VER_PLATFORM_WIN32_NT, ""
154 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
155 { /* no spaces in here ! */
164 "win2000,win2k,nt2k,nt2000",
168 /* if one of the following dlls is importing ntdll the windows
169 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
170 static char * special_dlls[] =
180 /* the current version has not been autodetected but forced via cmdline */
181 static BOOL versionForced = FALSE;
182 static WINDOWS_VERSION defaultWinVersion = WIN31;
184 /**********************************************************************
185 * VERSION_ParseWinVersion
187 void VERSION_ParseWinVersion( const char *arg )
190 const char *pCurr, *p;
191 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
193 pCurr = WinVersionNames[i];
194 /* iterate through all winver aliases separated by comma */
196 p = strchr(pCurr, ',');
197 len = p ? (int)p - (int)pCurr : strlen(pCurr);
198 if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
200 defaultWinVersion = (WINDOWS_VERSION)i;
201 versionForced = TRUE;
207 MESSAGE("Invalid winver value '%s' specified.\n", arg );
208 MESSAGE("Valid versions are:" );
209 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
211 /* only list the first, "official" alias in case of aliases */
212 pCurr = WinVersionNames[i];
213 p = strchr(pCurr, ',');
214 len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
216 MESSAGE(" '%.*s'%c", len, pCurr,
217 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
223 /**********************************************************************
224 * VERSION_ParseDosVersion
226 void VERSION_ParseDosVersion( const char *arg )
229 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
231 VersionData[WIN31].getVersion16 =
232 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
237 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
242 /**********************************************************************
243 * VERSION_GetSystemDLLVersion
245 * This function tries to figure out if a given (native) dll comes from
246 * win95/98 or winnt. Since all values in the OptionalHeader are not a
247 * usable hint, we test if a dll imports the ntdll.
248 * This is at least working for all system dlls like comctl32, comdlg32 and
250 * If you have a better idea to figure this out...
252 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
254 IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
255 + IMAGE_DIRECTORY_ENTRY_IMPORT;
256 if (dir->Size && dir->VirtualAddress)
258 IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
259 for ( ; pe_imp->Name; pe_imp++)
261 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
264 if (!strncasecmp(name, "ntdll", 5))
266 if (3 == PE_HEADER(hmod)->OptionalHeader.MajorOperatingSystemVersion)
275 /**********************************************************************
276 * VERSION_GetLinkedDllVersion
278 * Some version data (not reliable!):
279 * linker/OS/image/subsys
281 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
282 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
283 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
284 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
285 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
286 * 2.xx/1.00/0.00/4.00 Win95 system files
287 * x.xx/4.00/0.00/4.00 Win95 most applications
288 * 3.10/4.00/0.00/4.00 Win98 notepad
289 * x.xx/5.00/5.00/4.00 Win98 system dlls
290 * x.xx/4.00/4.00/4.00 NT 4 most apps
291 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
292 * 5.12/5.00/5.00/4.00 Win98 calc
293 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
295 DWORD VERSION_GetLinkedDllVersion(void)
298 DWORD WinVersion = NB_WINDOWS_VERSIONS;
299 PIMAGE_OPTIONAL_HEADER ophd;
301 /* First check the native dlls provided. These have to be
302 from one windows version */
303 for ( wm = MODULE_modref_list; wm; wm=wm->next )
305 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
307 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
309 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
310 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
311 ophd->MajorImageVersion, ophd->MinorImageVersion,
312 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
314 /* test if it is an external (native) dll */
315 if (!(wm->flags & WINE_MODREF_INTERNAL))
318 for (i = 0; special_dlls[i]; i++)
320 /* test if it is a special dll */
321 if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
323 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
324 if (WinVersion == NB_WINDOWS_VERSIONS)
325 WinVersion = DllVersion;
327 if (WinVersion != DllVersion) {
328 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
330 VersionData[WinVersion].getVersionEx.szCSDVersion,
331 VersionData[DllVersion].getVersionEx.szCSDVersion);
332 return WIN31; /* this may let the exe exiting */
341 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
343 /* we are using no external system dlls, look at the exe */
344 ophd = &(PE_HEADER(GetModuleHandleA(NULL))->OptionalHeader);
346 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
347 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
348 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
349 ophd->MajorImageVersion, ophd->MinorImageVersion,
350 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
352 /* special nt 3.51 */
353 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
358 /* the MajorSubsystemVersion is the only usable sign */
359 if (ophd->MajorSubsystemVersion < 4)
361 if ( ophd->MajorOperatingSystemVersion == 1
362 && ophd->MinorOperatingSystemVersion == 0)
364 return WIN31; /* win32s */
367 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
368 return NT351; /* FIXME: NT 3.1, not tested */
376 /**********************************************************************
380 * Don't call this function too early during the Wine init,
381 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
382 * be NULL in such cases, which causes the winver to ALWAYS be detected
384 * And as we cache the winver once it has been determined, this is bad.
385 * This can happen much easier than you might think, as this function
386 * is called by EVERY GetVersion*() API !
389 static WINDOWS_VERSION VERSION_GetVersion(void)
391 static WORD winver = 0xffff;
393 if (winver == 0xffff) /* to be determined */
395 WINDOWS_VERSION retver;
397 if (versionForced) /* user has overridden any sensible checks */
398 winver = defaultWinVersion;
401 retver = VERSION_GetLinkedDllVersion();
403 /* cache determined value, but do not store in case of WIN31 */
404 if (retver != WIN31) winver = retver;
414 /***********************************************************************
415 * GetVersion (KERNEL.3)
417 LONG WINAPI GetVersion16(void)
419 WINDOWS_VERSION ver = VERSION_GetVersion();
420 return VersionData[ver].getVersion16;
424 /***********************************************************************
425 * GetVersion (KERNEL32.@)
427 LONG WINAPI GetVersion(void)
429 WINDOWS_VERSION ver = VERSION_GetVersion();
430 return VersionData[ver].getVersion32;
434 /***********************************************************************
435 * GetVersionEx (KERNEL.149)
437 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
439 WINDOWS_VERSION ver = VERSION_GetVersion();
440 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
442 WARN("wrong OSVERSIONINFO size from app\n");
443 SetLastError(ERROR_INSUFFICIENT_BUFFER);
446 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
447 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
448 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
449 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
450 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
455 /***********************************************************************
456 * GetVersionExA (KERNEL32.@)
458 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
460 WINDOWS_VERSION ver = VERSION_GetVersion();
461 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOA))
463 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
464 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
465 SetLastError(ERROR_INSUFFICIENT_BUFFER);
468 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
469 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
470 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
471 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
472 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
477 /***********************************************************************
478 * GetVersionExW (KERNEL32.@)
480 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
482 WINDOWS_VERSION ver = VERSION_GetVersion();
484 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOW))
486 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
487 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
488 SetLastError(ERROR_INSUFFICIENT_BUFFER);
491 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
492 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
493 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
494 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
495 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
496 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
501 /***********************************************************************
502 * GetWinFlags (KERNEL.132)
504 DWORD WINAPI GetWinFlags16(void)
506 static const long cpuflags[5] =
507 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
514 /* There doesn't seem to be any Pentium flag. */
515 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
516 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
517 ovi.dwOSVersionInfoSize = sizeof(ovi);
519 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
520 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
526 /* Not used at this time. This is here for documentation only */
528 /* WINDEBUGINFO flags values */
529 #define WDI_OPTIONS 0x0001
530 #define WDI_FILTER 0x0002
531 #define WDI_ALLOCBREAK 0x0004
533 /* dwOptions values */
534 #define DBO_CHECKHEAP 0x0001
535 #define DBO_BUFFERFILL 0x0004
536 #define DBO_DISABLEGPTRAPPING 0x0010
537 #define DBO_CHECKFREE 0x0020
539 #define DBO_SILENT 0x8000
541 #define DBO_TRACEBREAK 0x2000
542 #define DBO_WARNINGBREAK 0x1000
543 #define DBO_NOERRORBREAK 0x0800
544 #define DBO_NOFATALBREAK 0x0400
545 #define DBO_INT3BREAK 0x0100
547 /* DebugOutput flags values */
548 #define DBF_TRACE 0x0000
549 #define DBF_WARNING 0x4000
550 #define DBF_ERROR 0x8000
551 #define DBF_FATAL 0xc000
553 /* dwFilter values */
554 #define DBF_KERNEL 0x1000
555 #define DBF_KRN_MEMMAN 0x0001
556 #define DBF_KRN_LOADMODULE 0x0002
557 #define DBF_KRN_SEGMENTLOAD 0x0004
558 #define DBF_USER 0x0800
559 #define DBF_GDI 0x0400
560 #define DBF_MMSYSTEM 0x0040
561 #define DBF_PENWIN 0x0020
562 #define DBF_APPLICATION 0x0008
563 #define DBF_DRIVER 0x0010
565 #endif /* NOLOGERROR */
568 /***********************************************************************
569 * GetWinDebugInfo (KERNEL.355)
571 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
573 FIXME("(%8lx,%d): stub returning 0\n",
574 (unsigned long)lpwdi, flags);
575 /* 0 means not in debugging mode/version */
576 /* Can this type of debugging be used in wine ? */
577 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
582 /***********************************************************************
583 * SetWinDebugInfo (KERNEL.356)
585 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
587 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
588 /* 0 means not in debugging mode/version */
589 /* Can this type of debugging be used in wine ? */
590 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
595 /***********************************************************************
599 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
601 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
603 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
606 /***********************************************************************
607 * DiagQuery (KERNEL.339)
609 * returns TRUE if Win called with "/b" (bootlog.txt)
611 BOOL16 WINAPI DiagQuery16()
613 /* perhaps implement a Wine "/b" command line flag sometime ? */
617 /***********************************************************************
618 * DiagOutput (KERNEL.340)
620 * writes a debug string into <windir>\bootlog.txt
622 void WINAPI DiagOutput16(LPCSTR str)
625 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));