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] =
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 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
160 if (!strcmp( WinVersionNames[i], arg ))
162 defaultWinVersion = (WINDOWS_VERSION)i;
163 versionForced = TRUE;
167 MESSAGE("Invalid winver value '%s' specified.\n", arg );
168 MESSAGE("Valid versions are:" );
169 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
170 MESSAGE(" '%s'%c", WinVersionNames[i],
171 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
176 /**********************************************************************
177 * VERSION_ParseDosVersion
179 void VERSION_ParseDosVersion( const char *arg )
182 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
184 VersionData[WIN31].getVersion16 =
185 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
190 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
195 /**********************************************************************
196 * VERSION_GetSystemDLLVersion
198 * This function tries to figure out if a given (native) dll comes from
199 * win95/98 or winnt. Since all values in the OptionalHeader are not a
200 * usable hint, we test if a dll imports the ntdll.
201 * This is at least working for all system dlls like comctl32, comdlg32 and
203 * If you have a better idea to figure this out...
205 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
207 IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
208 + IMAGE_DIRECTORY_ENTRY_IMPORT;
209 if (dir->Size && dir->VirtualAddress)
211 IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
212 for ( ; pe_imp->Name; pe_imp++)
214 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
217 if (!strncasecmp(name, "ntdll", 5))
219 if (3 == PE_HEADER(hmod)->OptionalHeader.MajorOperatingSystemVersion)
228 /**********************************************************************
229 * VERSION_GetLinkedDllVersion
231 * Some version data (not reliable!):
232 * linker/OS/image/subsys
234 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
235 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
236 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
237 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
238 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
239 * 2.xx/1.00/0.00/4.00 Win95 system files
240 * x.xx/4.00/0.00/4.00 Win95 most applications
241 * 3.10/4.00/0.00/4.00 Win98 notepad
242 * x.xx/5.00/5.00/4.00 Win98 system dlls
243 * x.xx/4.00/4.00/4.00 NT 4 most apps
244 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
245 * 5.12/5.00/5.00/4.00 Win98 calc
246 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
248 DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
251 DWORD WinVersion = NB_WINDOWS_VERSIONS;
252 PIMAGE_OPTIONAL_HEADER ophd;
254 if (!pdb->exe_modref)
256 if (!pdb->modref_list)
259 /* FIXME: The above condition will never trigger, since all our
260 * standard dlls load their win32 equivalents. We have usually at
261 * this point: kernel32.dll and ntdll.dll.
265 /* First check the native dlls provided. These have to be
266 from one windows version */
267 for ( wm = pdb->modref_list; wm; wm=wm->next )
269 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
271 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
273 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
274 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
275 ophd->MajorImageVersion, ophd->MinorImageVersion,
276 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
278 /* test if it is an external (native) dll */
279 if (!(wm->flags & WINE_MODREF_INTERNAL))
282 for (i = 0; special_dlls[i]; i++)
284 /* test if it is a special dll */
285 if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
287 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
288 if (WinVersion == NB_WINDOWS_VERSIONS)
289 WinVersion = DllVersion;
291 if (WinVersion != DllVersion) {
292 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
294 VersionData[WinVersion].getVersionEx.szCSDVersion,
295 VersionData[DllVersion].getVersionEx.szCSDVersion);
296 return WIN31; /* this may let the exe exiting */
305 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
307 /* we are using no external system dlls, look at the exe */
308 ophd = &(PE_HEADER(pdb->exe_modref->module)->OptionalHeader);
310 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
311 pdb->exe_modref->modname,
312 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
313 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
314 ophd->MajorImageVersion, ophd->MinorImageVersion,
315 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
317 /* special nt 3.51 */
318 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
323 /* the MajorSubsystemVersion is the only usable sign */
324 if (ophd->MajorSubsystemVersion < 4)
326 if ( ophd->MajorOperatingSystemVersion == 1
327 && ophd->MinorOperatingSystemVersion == 0)
329 return WIN31; /* win32s */
332 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
333 return NT351; /* FIXME: NT 3.1, not tested */
341 /**********************************************************************
345 * Don't call this function too early during the Wine init,
346 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
347 * be NULL in such cases, which causes the winver to ALWAYS be detected
349 * And as we cache the winver once it has been determined, this is bad.
350 * This can happen much easier than you might think, as this function
351 * is called by EVERY GetVersion*() API !
354 static WINDOWS_VERSION VERSION_GetVersion(void)
356 static WORD winver = 0xffff;
358 if (versionForced) /* user has overridden any sensible checks */
359 return defaultWinVersion;
361 if (winver == 0xffff) /* to be determined */ {
362 WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion( PROCESS_Current() );
364 if (retver != WIN31) winver = retver;
371 /***********************************************************************
372 * GetVersion16 (KERNEL.3)
374 LONG WINAPI GetVersion16(void)
376 WINDOWS_VERSION ver = VERSION_GetVersion();
377 return VersionData[ver].getVersion16;
381 /***********************************************************************
382 * GetVersion (KERNEL32.427)
384 LONG WINAPI GetVersion(void)
386 WINDOWS_VERSION ver = VERSION_GetVersion();
387 return VersionData[ver].getVersion32;
391 /***********************************************************************
392 * GetVersionEx16 (KERNEL.149)
394 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
396 WINDOWS_VERSION ver = VERSION_GetVersion();
397 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
399 WARN("wrong OSVERSIONINFO size from app");
400 SetLastError(ERROR_INSUFFICIENT_BUFFER);
403 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
404 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
405 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
406 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
407 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
412 /***********************************************************************
413 * GetVersionExA (KERNEL32.428)
415 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
417 WINDOWS_VERSION ver = VERSION_GetVersion();
418 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
420 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
421 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
422 SetLastError(ERROR_INSUFFICIENT_BUFFER);
425 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
426 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
427 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
428 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
429 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
434 /***********************************************************************
435 * GetVersionExW (KERNEL32.429)
437 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
439 WINDOWS_VERSION ver = VERSION_GetVersion();
441 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFOW))
443 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
444 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
445 SetLastError(ERROR_INSUFFICIENT_BUFFER);
448 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
449 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
450 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
451 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
452 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
453 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
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));