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"
18 #include "wine/winestring.h"
21 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(ver);
29 WIN20, /* Windows 2.0 */
30 WIN30, /* Windows 3.0 */
31 WIN31, /* Windows 3.1 */
32 WIN95, /* Windows 95 */
33 WIN98, /* Windows 98 */
34 /* insert Windows ME here as WINME if needed */
35 NT351, /* Windows NT 3.51 */
36 NT40, /* Windows NT 4.0 */
37 NT2K, /* Windows 2000 */
45 OSVERSIONINFOA getVersionEx;
48 /* FIXME: compare values below with original and fix */
49 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
51 /* WIN20 FIXME: verify values */
53 MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
54 MAKELONG( 0x0003, 0x8000 ),
56 sizeof(OSVERSIONINFOA), 2, 0, 0,
57 VER_PLATFORM_WIN32s, "Win32s 1.3"
60 /* WIN30 FIXME: verify values */
62 MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
63 MAKELONG( 0x0003, 0x8000 ),
65 sizeof(OSVERSIONINFOA), 3, 0, 0,
66 VER_PLATFORM_WIN32s, "Win32s 1.3"
71 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
72 MAKELONG( 0x0a03, 0x8000 ),
74 sizeof(OSVERSIONINFOA), 3, 10, 0,
75 VER_PLATFORM_WIN32s, "Win32s 1.3"
83 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
84 VER_PLATFORM_WIN32_WINDOWS, "Win95"
92 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
93 VER_PLATFORM_WIN32_WINDOWS, "Win98"
101 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
102 VER_PLATFORM_WIN32_NT, "Service Pack 2"
110 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
111 VER_PLATFORM_WIN32_NT, "Service Pack 6"
114 /* NT2K FIXME: verify values */
117 0x08930005, /* better build ? using 2195 (final) for now */
119 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
120 VER_PLATFORM_WIN32_NT, "FIXME: OS version string not known yet"
125 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
137 /* if one of the following dlls is importing ntdll the windows
138 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
139 static char * special_dlls[] =
149 /* the current version has not been autodetected but forced via cmdline */
150 static BOOL versionForced = FALSE;
151 static WINDOWS_VERSION defaultWinVersion = WIN31;
153 /**********************************************************************
154 * VERSION_ParseWinVersion
156 void VERSION_ParseWinVersion( const char *arg )
159 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
161 if (!strcmp( WinVersionNames[i], arg ))
163 defaultWinVersion = (WINDOWS_VERSION)i;
164 versionForced = TRUE;
168 MESSAGE("Invalid winver value '%s' specified.\n", arg );
169 MESSAGE("Valid versions are:" );
170 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
171 MESSAGE(" '%s'%c", WinVersionNames[i],
172 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
177 /**********************************************************************
178 * VERSION_ParseDosVersion
180 void VERSION_ParseDosVersion( const char *arg )
183 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
185 VersionData[WIN31].getVersion16 =
186 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
191 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
196 /**********************************************************************
197 * VERSION_GetSystemDLLVersion
199 * This function tries to figure out if a given (native) dll comes from
200 * win95/98 or winnt. Since all values in the OptionalHeader are not a
201 * usable hint, we test if a dll imports the ntdll.
202 * This is at least working for all system dlls like comctl32, comdlg32 and
204 * If you have a better idea to figure this out...
206 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
208 IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
209 + IMAGE_DIRECTORY_ENTRY_IMPORT;
210 if (dir->Size && dir->VirtualAddress)
212 IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
213 for ( ; pe_imp->Name; pe_imp++)
215 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
218 if (!strncasecmp(name, "ntdll", 5))
220 if (3 == PE_HEADER(hmod)->OptionalHeader.MajorOperatingSystemVersion)
229 /**********************************************************************
230 * VERSION_GetLinkedDllVersion
232 * Some version data (not reliable!):
233 * linker/OS/image/subsys
235 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
236 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
237 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
238 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
239 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
240 * 2.xx/1.00/0.00/4.00 Win95 system files
241 * x.xx/4.00/0.00/4.00 Win95 most applications
242 * 3.10/4.00/0.00/4.00 Win98 notepad
243 * x.xx/5.00/5.00/4.00 Win98 system dlls
244 * x.xx/4.00/4.00/4.00 NT 4 most apps
245 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
246 * 5.12/5.00/5.00/4.00 Win98 calc
247 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
249 DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
252 DWORD WinVersion = NB_WINDOWS_VERSIONS;
253 PIMAGE_OPTIONAL_HEADER ophd;
255 if (!pdb->exe_modref)
257 if (!pdb->modref_list)
260 /* FIXME: The above condition will never trigger, since all our
261 * standard dlls load their win32 equivalents. We have usually at
262 * this point: kernel32.dll and ntdll.dll.
266 /* First check the native dlls provided. These have to be
267 from one windows version */
268 for ( wm = pdb->modref_list; wm; wm=wm->next )
270 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
272 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
274 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
275 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
276 ophd->MajorImageVersion, ophd->MinorImageVersion,
277 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
279 /* test if it is an external (native) dll */
280 if (!(wm->flags & WINE_MODREF_INTERNAL))
283 for (i = 0; special_dlls[i]; i++)
285 /* test if it is a special dll */
286 if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
288 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
289 if (WinVersion == NB_WINDOWS_VERSIONS)
290 WinVersion = DllVersion;
292 if (WinVersion != DllVersion) {
293 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
295 VersionData[WinVersion].getVersionEx.szCSDVersion,
296 VersionData[DllVersion].getVersionEx.szCSDVersion);
297 return WIN31; /* this may let the exe exiting */
306 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
308 /* we are using no external system dlls, look at the exe */
309 ophd = &(PE_HEADER(pdb->exe_modref->module)->OptionalHeader);
311 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
312 pdb->exe_modref->modname,
313 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
314 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
315 ophd->MajorImageVersion, ophd->MinorImageVersion,
316 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
318 /* special nt 3.51 */
319 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
324 /* the MajorSubsystemVersion is the only usable sign */
325 if (ophd->MajorSubsystemVersion < 4)
327 if ( ophd->MajorOperatingSystemVersion == 1
328 && ophd->MinorOperatingSystemVersion == 0)
330 return WIN31; /* win32s */
333 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
334 return NT351; /* FIXME: NT 3.1, not tested */
342 /**********************************************************************
346 * Don't call this function too early during the Wine init,
347 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
348 * be NULL in such cases, which causes the winver to ALWAYS be detected
350 * And as we cache the winver once it has been determined, this is bad.
351 * This can happen much easier than you might think, as this function
352 * is called by EVERY GetVersion*() API !
355 static WINDOWS_VERSION VERSION_GetVersion(void)
357 static WORD winver = 0xffff;
359 if (versionForced) /* user has overridden any sensible checks */
360 return defaultWinVersion;
362 if (winver == 0xffff) /* to be determined */ {
363 WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion( PROCESS_Current() );
365 if (retver != WIN31) winver = retver;
372 /***********************************************************************
373 * GetVersion16 (KERNEL.3)
375 LONG WINAPI GetVersion16(void)
377 WINDOWS_VERSION ver = VERSION_GetVersion();
378 return VersionData[ver].getVersion16;
382 /***********************************************************************
383 * GetVersion (KERNEL32.427)
385 LONG WINAPI GetVersion(void)
387 WINDOWS_VERSION ver = VERSION_GetVersion();
388 return VersionData[ver].getVersion32;
392 /***********************************************************************
393 * GetVersionEx16 (KERNEL.149)
395 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
397 WINDOWS_VERSION ver = VERSION_GetVersion();
398 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
400 WARN("wrong OSVERSIONINFO size from app");
401 SetLastError(ERROR_INSUFFICIENT_BUFFER);
404 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
405 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
406 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
407 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
408 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
413 /***********************************************************************
414 * GetVersionExA (KERNEL32.428)
416 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
418 WINDOWS_VERSION ver = VERSION_GetVersion();
419 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
421 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
422 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
423 SetLastError(ERROR_INSUFFICIENT_BUFFER);
426 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
427 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
428 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
429 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
430 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
435 /***********************************************************************
436 * GetVersionExW (KERNEL32.429)
438 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
440 WINDOWS_VERSION ver = VERSION_GetVersion();
442 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFOW))
444 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
445 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
446 SetLastError(ERROR_INSUFFICIENT_BUFFER);
449 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
450 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
451 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
452 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
453 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
458 /***********************************************************************
459 * GetWinFlags (KERNEL.132)
461 DWORD WINAPI GetWinFlags16(void)
463 static const long cpuflags[5] =
464 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
471 /* There doesn't seem to be any Pentium flag. */
472 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
473 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
474 ovi.dwOSVersionInfoSize = sizeof(ovi);
476 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
477 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
482 /***********************************************************************
483 * GetWinDebugInfo (KERNEL.355)
485 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO *lpwdi, UINT16 flags)
487 FIXME("(%8lx,%d): stub returning 0\n",
488 (unsigned long)lpwdi, flags);
489 /* 0 means not in debugging mode/version */
490 /* Can this type of debugging be used in wine ? */
491 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
496 /***********************************************************************
497 * SetWinDebugInfo (KERNEL.356)
499 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO *lpwdi)
501 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
502 /* 0 means not in debugging mode/version */
503 /* Can this type of debugging be used in wine ? */
504 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
509 /***********************************************************************
510 * DebugFillBuffer (KERNEL.329)
513 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
515 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
517 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
520 /***********************************************************************
521 * DiagQuery (KERNEL.339)
523 * returns TRUE if Win called with "/b" (bootlog.txt)
525 BOOL16 WINAPI DiagQuery16()
527 /* perhaps implement a Wine "/b" command line flag sometime ? */
531 /***********************************************************************
532 * DiagOutput (KERNEL.340)
534 * writes a debug string into <windir>\bootlog.txt
536 void WINAPI DiagOutput16(LPCSTR str)
539 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));