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"
24 DEFAULT_DEBUG_CHANNEL(ver);
28 WIN20, /* Windows 2.0 */
29 WIN30, /* Windows 3.0 */
30 WIN31, /* Windows 3.1 */
31 WIN95, /* Windows 95 */
32 WIN98, /* Windows 98 */
33 /* insert Windows ME here as WINME if needed */
34 NT351, /* Windows NT 3.51 */
35 NT40, /* Windows NT 4.0 */
36 NT2K, /* Windows 2000 */
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 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
83 VER_PLATFORM_WIN32_WINDOWS, "Win95"
91 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
92 VER_PLATFORM_WIN32_WINDOWS, "Win98"
100 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
101 VER_PLATFORM_WIN32_NT, "Service Pack 2"
109 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
110 VER_PLATFORM_WIN32_NT, "Service Pack 6"
113 /* NT2K FIXME: verify values */
116 0x08930005, /* better build ? using 2195 (final) for now */
118 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
119 VER_PLATFORM_WIN32_NT, "FIXME: OS version string not known yet"
124 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
125 { /* no spaces in here ! */
133 "win2000,win2k,nt2k,nt2000"
136 /* if one of the following dlls is importing ntdll the windows
137 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
138 static char * special_dlls[] =
148 /* the current version has not been autodetected but forced via cmdline */
149 static BOOL versionForced = FALSE;
150 static WINDOWS_VERSION defaultWinVersion = WIN31;
152 /**********************************************************************
153 * VERSION_ParseWinVersion
155 void VERSION_ParseWinVersion( const char *arg )
158 const char *pCurr, *p;
159 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
161 pCurr = WinVersionNames[i];
162 /* iterate through all winver aliases separated by comma */
164 p = strchr(pCurr, ',');
165 len = p ? (int)p - (int)pCurr : strlen(pCurr);
166 if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
168 defaultWinVersion = (WINDOWS_VERSION)i;
169 versionForced = TRUE;
175 MESSAGE("Invalid winver value '%s' specified.\n", arg );
176 MESSAGE("Valid versions are:" );
177 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
179 /* only list the first, "official" alias in case of aliases */
180 pCurr = WinVersionNames[i];
181 p = strchr(pCurr, ',');
182 len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
184 MESSAGE(" '%.*s'%c", len, pCurr,
185 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
191 /**********************************************************************
192 * VERSION_ParseDosVersion
194 void VERSION_ParseDosVersion( const char *arg )
197 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
199 VersionData[WIN31].getVersion16 =
200 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
205 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
210 /**********************************************************************
211 * VERSION_GetSystemDLLVersion
213 * This function tries to figure out if a given (native) dll comes from
214 * win95/98 or winnt. Since all values in the OptionalHeader are not a
215 * usable hint, we test if a dll imports the ntdll.
216 * This is at least working for all system dlls like comctl32, comdlg32 and
218 * If you have a better idea to figure this out...
220 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
222 IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
223 + IMAGE_DIRECTORY_ENTRY_IMPORT;
224 if (dir->Size && dir->VirtualAddress)
226 IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
227 for ( ; pe_imp->Name; pe_imp++)
229 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
232 if (!strncasecmp(name, "ntdll", 5))
234 if (3 == PE_HEADER(hmod)->OptionalHeader.MajorOperatingSystemVersion)
243 /**********************************************************************
244 * VERSION_GetLinkedDllVersion
246 * Some version data (not reliable!):
247 * linker/OS/image/subsys
249 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
250 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
251 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
252 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
253 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
254 * 2.xx/1.00/0.00/4.00 Win95 system files
255 * x.xx/4.00/0.00/4.00 Win95 most applications
256 * 3.10/4.00/0.00/4.00 Win98 notepad
257 * x.xx/5.00/5.00/4.00 Win98 system dlls
258 * x.xx/4.00/4.00/4.00 NT 4 most apps
259 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
260 * 5.12/5.00/5.00/4.00 Win98 calc
261 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
263 DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
266 DWORD WinVersion = NB_WINDOWS_VERSIONS;
267 PIMAGE_OPTIONAL_HEADER ophd;
269 if (!pdb->exe_modref)
271 if (!pdb->modref_list)
274 /* FIXME: The above condition will never trigger, since all our
275 * standard dlls load their win32 equivalents. We have usually at
276 * this point: kernel32.dll and ntdll.dll.
280 /* First check the native dlls provided. These have to be
281 from one windows version */
282 for ( wm = pdb->modref_list; wm; wm=wm->next )
284 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
286 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
288 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
289 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
290 ophd->MajorImageVersion, ophd->MinorImageVersion,
291 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
293 /* test if it is an external (native) dll */
294 if (!(wm->flags & WINE_MODREF_INTERNAL))
297 for (i = 0; special_dlls[i]; i++)
299 /* test if it is a special dll */
300 if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
302 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
303 if (WinVersion == NB_WINDOWS_VERSIONS)
304 WinVersion = DllVersion;
306 if (WinVersion != DllVersion) {
307 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
309 VersionData[WinVersion].getVersionEx.szCSDVersion,
310 VersionData[DllVersion].getVersionEx.szCSDVersion);
311 return WIN31; /* this may let the exe exiting */
320 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
322 /* we are using no external system dlls, look at the exe */
323 ophd = &(PE_HEADER(pdb->exe_modref->module)->OptionalHeader);
325 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
326 pdb->exe_modref->modname,
327 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
328 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
329 ophd->MajorImageVersion, ophd->MinorImageVersion,
330 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
332 /* special nt 3.51 */
333 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
338 /* the MajorSubsystemVersion is the only usable sign */
339 if (ophd->MajorSubsystemVersion < 4)
341 if ( ophd->MajorOperatingSystemVersion == 1
342 && ophd->MinorOperatingSystemVersion == 0)
344 return WIN31; /* win32s */
347 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
348 return NT351; /* FIXME: NT 3.1, not tested */
356 /**********************************************************************
360 * Don't call this function too early during the Wine init,
361 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
362 * be NULL in such cases, which causes the winver to ALWAYS be detected
364 * And as we cache the winver once it has been determined, this is bad.
365 * This can happen much easier than you might think, as this function
366 * is called by EVERY GetVersion*() API !
369 static WINDOWS_VERSION VERSION_GetVersion(void)
371 static WORD winver = 0xffff;
373 if (versionForced) /* user has overridden any sensible checks */
374 return defaultWinVersion;
376 if (winver == 0xffff) /* to be determined */ {
377 WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion( PROCESS_Current() );
379 if (retver != WIN31) winver = retver;
386 /***********************************************************************
387 * GetVersion16 (KERNEL.3)
389 LONG WINAPI GetVersion16(void)
391 WINDOWS_VERSION ver = VERSION_GetVersion();
392 return VersionData[ver].getVersion16;
396 /***********************************************************************
397 * GetVersion (KERNEL32.427)
399 LONG WINAPI GetVersion(void)
401 WINDOWS_VERSION ver = VERSION_GetVersion();
402 return VersionData[ver].getVersion32;
406 /***********************************************************************
407 * GetVersionEx16 (KERNEL.149)
409 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
411 WINDOWS_VERSION ver = VERSION_GetVersion();
412 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
414 WARN("wrong OSVERSIONINFO size from app");
415 SetLastError(ERROR_INSUFFICIENT_BUFFER);
418 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
419 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
420 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
421 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
422 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
427 /***********************************************************************
428 * GetVersionExA (KERNEL32.428)
430 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
432 WINDOWS_VERSION ver = VERSION_GetVersion();
433 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
435 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
436 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
437 SetLastError(ERROR_INSUFFICIENT_BUFFER);
440 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
441 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
442 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
443 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
444 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
449 /***********************************************************************
450 * GetVersionExW (KERNEL32.429)
452 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
454 WINDOWS_VERSION ver = VERSION_GetVersion();
456 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFOW))
458 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
459 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
460 SetLastError(ERROR_INSUFFICIENT_BUFFER);
463 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
464 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
465 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
466 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
467 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
468 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
473 /***********************************************************************
474 * GetWinFlags (KERNEL.132)
476 DWORD WINAPI GetWinFlags16(void)
478 static const long cpuflags[5] =
479 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
486 /* There doesn't seem to be any Pentium flag. */
487 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
488 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
489 ovi.dwOSVersionInfoSize = sizeof(ovi);
491 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
492 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
497 /***********************************************************************
498 * GetWinDebugInfo (KERNEL.355)
500 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO *lpwdi, UINT16 flags)
502 FIXME("(%8lx,%d): stub returning 0\n",
503 (unsigned long)lpwdi, flags);
504 /* 0 means not in debugging mode/version */
505 /* Can this type of debugging be used in wine ? */
506 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
511 /***********************************************************************
512 * SetWinDebugInfo (KERNEL.356)
514 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO *lpwdi)
516 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
517 /* 0 means not in debugging mode/version */
518 /* Can this type of debugging be used in wine ? */
519 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
524 /***********************************************************************
525 * DebugFillBuffer (KERNEL.329)
528 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
530 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
532 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
535 /***********************************************************************
536 * DiagQuery (KERNEL.339)
538 * returns TRUE if Win called with "/b" (bootlog.txt)
540 BOOL16 WINAPI DiagQuery16()
542 /* perhaps implement a Wine "/b" command line flag sometime ? */
546 /***********************************************************************
547 * DiagOutput (KERNEL.340)
549 * writes a debug string into <windir>\bootlog.txt
551 void WINAPI DiagOutput16(LPCSTR str)
554 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));